private void InitializeComponent()
{
this.FunctionsTable = new System.Data.DataTable();
this.colFnAddressID = new System.Data.DataColumn();
this.colName = new System.Data.DataColumn();
this.colComment = new System.Data.DataColumn();
this.colObject = new System.Data.DataColumn();
this.colFunctionID = new System.Data.DataColumn();
this.colQuality = new System.Data.DataColumn();
this.colFunctionAddressTimeShift = new System.Data.DataColumn();
this.AddressesTable = new System.Data.DataTable();
this.colAddressID = new System.Data.DataColumn();
this.colValue = new System.Data.DataColumn();
this.colTimeShift = new System.Data.DataColumn();
this.colAddressObject = new System.Data.DataColumn();
this.colAddressName = new System.Data.DataColumn();
this.InstructionsTable = new System.Data.DataTable();
this.colInstructionAddress = new System.Data.DataColumn();
this.colFnID = new System.Data.DataColumn();
this.colInstructionObject = new System.Data.DataColumn();
this.colInstructionComment = new System.Data.DataColumn();
this.colInstructionID = new System.Data.DataColumn();
this.colBranchToSub = new System.Data.DataColumn();
this.colIsBranch = new System.Data.DataColumn();
this.colAddressTimeShift = new System.Data.DataColumn();
this.OperandsTable = new System.Data.DataTable();
this.colOperandID = new System.Data.DataColumn();
this.colOperandObject = new System.Data.DataColumn();
this.colOperandOrder = new System.Data.DataColumn();
this.colOperandInstructionID = new System.Data.DataColumn();
((System.ComponentModel.ISupportInitialize)(this.FunctionsTable)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.AddressesTable)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.InstructionsTable)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.OperandsTable)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
//
// FunctionsTable
//
this.FunctionsTable.Columns.AddRange(new System.Data.DataColumn[] {
this.colFnAddressID,
this.colName,
this.colComment,
this.colObject,
this.colFunctionID,
this.colQuality,
this.colFunctionAddressTimeShift});
this.FunctionsTable.Constraints.AddRange(new System.Data.Constraint[] {
new System.Data.UniqueConstraint("Constraint1", new string[] {
"FunctionID"}, true),
new System.Data.UniqueConstraint("Constraint3", new string[] {
"Name"}, false)});
this.FunctionsTable.Namespace = "KlaunmoetD.Core";
this.FunctionsTable.PrimaryKey = new System.Data.DataColumn[] {
this.colFunctionID};
this.FunctionsTable.TableName = "Functions";
//
// colFnAddressID
//
this.colFnAddressID.AllowDBNull = false;
this.colFnAddressID.ColumnName = "AddressValue";
this.colFnAddressID.DataType = typeof(long);
//
// colName
//
this.colName.ColumnName = "Name";
//
// colComment
//
this.colComment.Caption = "Comment";
this.colComment.ColumnName = "Comment";
//
// colObject
//
this.colObject.AllowDBNull = false;
this.colObject.ColumnName = "Object";
this.colObject.DataType = typeof(KlaunmoetD.Core.Function);
//
// colFunctionID
//
this.colFunctionID.AllowDBNull = false;
this.colFunctionID.AutoIncrement = true;
this.colFunctionID.ColumnName = "FunctionID";
this.colFunctionID.DataType = typeof(long);
//
// colQuality
//
this.colQuality.AllowDBNull = false;
this.colQuality.ColumnName = "Quality";
this.colQuality.DataType = typeof(int);
//
// colFunctionAddressTimeShift
//
this.colFunctionAddressTimeShift.AllowDBNull = false;
this.colFunctionAddressTimeShift.ColumnName = "AddressTimeShift";
this.colFunctionAddressTimeShift.DataType = typeof(int);
//
// AddressesTable
//
this.AddressesTable.Columns.AddRange(new System.Data.DataColumn[] {
this.colAddressID,
this.colValue,
this.colTimeShift,
this.colAddressObject,
this.colAddressName});
this.AddressesTable.Constraints.AddRange(new System.Data.Constraint[] {
new System.Data.UniqueConstraint("UniqueAddressNameConstraint", new string[] {
"Name"}, false),
new System.Data.UniqueConstraint("Constraint1", new string[] {
"AddressID"}, true)});
this.AddressesTable.PrimaryKey = new System.Data.DataColumn[] {
this.colAddressID};
this.AddressesTable.TableName = "Addresses";
//
// colAddressID
//
this.colAddressID.AllowDBNull = false;
this.colAddressID.AutoIncrement = true;
this.colAddressID.ColumnName = "AddressID";
this.colAddressID.DataType = typeof(long);
this.colAddressID.ReadOnly = true;
//
// colValue
//
this.colValue.ColumnName = "Value";
this.colValue.DataType = typeof(long);
//
// colTimeShift
//
this.colTimeShift.ColumnName = "TimeShift";
this.colTimeShift.DataType = typeof(int);
//
// colAddressObject
//
this.colAddressObject.ColumnName = "Object";
this.colAddressObject.DataType = typeof(KlaunmoetD.Core.Address);
//
// colAddressName
//
this.colAddressName.ColumnName = "Name";
//
// InstructionsTable
//
this.InstructionsTable.Columns.AddRange(new System.Data.DataColumn[] {
this.colInstructionAddress,
this.colFnID,
this.colInstructionObject,
this.colInstructionComment,
this.colInstructionID,
this.colBranchToSub,
this.colIsBranch,
this.colAddressTimeShift});
this.InstructionsTable.Constraints.AddRange(new System.Data.Constraint[] {
new System.Data.UniqueConstraint("Constraint1", new string[] {
"AddressTimeShift",
"AddressValue",
"FunctionID"}, true)});
this.InstructionsTable.PrimaryKey = new System.Data.DataColumn[] {
this.colAddressTimeShift,
this.colInstructionAddress,
this.colFnID};
this.InstructionsTable.TableName = "Instructions";
//
// colInstructionAddress
//
this.colInstructionAddress.AllowDBNull = false;
this.colInstructionAddress.ColumnName = "AddressValue";
this.colInstructionAddress.DataType = typeof(long);
//
// colFnID
//
this.colFnID.AllowDBNull = false;
this.colFnID.Caption = "FunctionID";
this.colFnID.ColumnName = "FunctionID";
this.colFnID.DataType = typeof(long);
//
// colInstructionObject
//
this.colInstructionObject.ColumnName = "Object";
this.colInstructionObject.DataType = typeof(KlaunmoetD.Core.IInstruction);
//
// colInstructionComment
//
this.colInstructionComment.ColumnName = "Comment";
//
// colInstructionID
//
this.colInstructionID.AllowDBNull = false;
this.colInstructionID.AutoIncrement = true;
this.colInstructionID.ColumnName = "InstructionID";
this.colInstructionID.DataType = typeof(long);
//
// colBranchToSub
//
this.colBranchToSub.AllowDBNull = false;
this.colBranchToSub.ColumnName = "isBranchToSub";
this.colBranchToSub.DataType = typeof(bool);
//
// colIsBranch
//
this.colIsBranch.AllowDBNull = false;
this.colIsBranch.ColumnName = "isBranch";
this.colIsBranch.DataType = typeof(bool);
//
// colAddressTimeShift
//
this.colAddressTimeShift.AllowDBNull = false;
this.colAddressTimeShift.ColumnName = "AddressTimeShift";
this.colAddressTimeShift.DataType = typeof(int);
//
// OperandsTable
//
this.OperandsTable.Columns.AddRange(new System.Data.DataColumn[] {
this.colOperandID,
this.colOperandObject,
this.colOperandOrder,
this.colOperandInstructionID});
this.OperandsTable.Constraints.AddRange(new System.Data.Constraint[] {
new System.Data.UniqueConstraint("Constraint1", new string[] {
"OperandID"}, true)});
this.OperandsTable.PrimaryKey = new System.Data.DataColumn[] {
this.colOperandID};
this.OperandsTable.TableName = "Operands";
//
// colOperandID
//
this.colOperandID.AllowDBNull = false;
this.colOperandID.AutoIncrement = true;
this.colOperandID.ColumnName = "OperandID";
this.colOperandID.DataType = typeof(int);
//
// colOperandObject
//
this.colOperandObject.ColumnName = "Object";
this.colOperandObject.DataType = typeof(object);
//
// colOperandOrder
//
this.colOperandOrder.AllowDBNull = false;
this.colOperandOrder.ColumnName = "OperandOrder";
this.colOperandOrder.DataType = typeof(short);
//
// colOperandInstructionID
//
this.colOperandInstructionID.AllowDBNull = false;
this.colOperandInstructionID.ColumnName = "InstructionID";
//
// CodeSet
//
this.Relations.AddRange(new System.Data.DataRelation[] {
new System.Data.DataRelation("Instruction2Function", "Functions", "Instructions", new string[] {
"FunctionID"}, new string[] {
"FunctionID"}, false)});
this.Tables.AddRange(new System.Data.DataTable[] {
this.FunctionsTable,
this.AddressesTable,
this.InstructionsTable,
this.OperandsTable});
((System.ComponentModel.ISupportInitialize)(this.FunctionsTable)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.AddressesTable)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.InstructionsTable)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.OperandsTable)).EndInit();
((System.ComponentModel.ISupportInitialize)(this)).EndInit();
}
// -------- Full class for context ---------
// KlaunmoetD - The 0x90.org disassembler.
// This software is Copyright (C) 2005 jaynus, 0x90.org
// $Id: CodeSet.cs,v 1.13 2005/08/15 19:52:11 nummish Exp $
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Data;
using System.Text;
using System.IO;
using System.Collections;
/*
Addresses -
Id
Address object
Functions -
Address id
Name
Comment
Function Object
Instructions Address Id Array
Instructions -
*/
namespace KlaunmoetD.Core
{
/// Implementation of Dataset for storing and accessing disassembly structures.
public class CodeSet : DataSet
{
private System.Data.DataTable FunctionsTable;
private System.Data.DataColumn colName;
private System.Data.DataColumn colComment;
private System.Data.DataColumn colObject;
private System.Data.DataTable AddressesTable;
private System.Data.DataColumn colValue;
private System.Data.DataColumn colTimeShift;
private System.Data.DataColumn colAddressObject;
private System.Data.DataTable InstructionsTable;
private System.Data.DataColumn colInstructionAddress;
private System.Data.DataColumn colInstructionObject;
private System.Data.DataColumn colFnAddressID;
private System.Data.DataColumn colAddressID;
private System.Data.DataColumn colAddressName;
private System.Data.DataColumn colFunctionID;
private System.Data.DataColumn colQuality;
private System.Data.DataColumn colInstructionComment;
private System.Data.DataTable OperandsTable;
private System.Data.DataColumn colOperandID;
private System.Data.DataColumn colInstructionID;
private System.Data.DataColumn colOperandObject;
private System.Data.DataColumn colOperandInstructionID;
private System.Data.DataColumn colBranchToSub;
private System.Data.DataColumn colIsBranch;
private System.Data.DataColumn colOperandOrder;
private System.Data.DataColumn colAddressTimeShift;
private System.Data.DataColumn colFunctionAddressTimeShift;
private System.Data.DataColumn colFnID;
private static CodeSet _SingletonInstance;
#region Public Properties
// TODO: We need to make this check referencing and stuff later, because these counts arnt the actual decompiled counts,
// They are just table counts, which are *wrong* because we do relational unique references.
/// Returns the current number of addresses within this dissasembly dataset.
public long AddressCount
{
get { return(Tables["Addresses"].Rows.Count); }
}
/// Returns the current number of functions within this dissasembly dataset.
public long FunctionCount
{
get { return(Tables["Functions"].Rows.Count); }
}
/// Returns the current number of instructions within this dissasembly dataset.
public long InstructionCount
{
get { return(Tables["Instructions"].Rows.Count); }
}
/// Returns the current number of operands within this dissasembly dataset.
public long OperandCount
{
get { return(Tables["Operands"].Rows.Count); }
}
#endregion
#region Private Members
#endregion
#region Constructor - Disposal
/// CodeSet constructor
public CodeSet()
{
// This is the autogenerated stuff.. conflicts a bunch, but is easier to trace via the IDE
InitializeComponent();
}
#endregion
#region Public Methods
#region Add Methods
public DataRow FindFunction(Address FunctionAddress)
{
DataRow[] Functions = Tables["Functions"].Select("AddressValue=" + FunctionAddress.Value.ToString() + " AND AddressTimeShift=" + FunctionAddress.TimeShift.ToString());
if (Functions.Length == 0)
return null;
else
return Functions[0];
}
/// Adds a single instance of a Function to this dataset.
/// (DOES NOT ADD INSTRUCTIONS YET)
/// Adds all required address and relational references, as well as duplicate checking and Address
/// re-referencing for already existant addresses. Duplicate checking and working (timeshifting) and Address
/// referencing needs reworking.
/// The instance of Function from the decompiled code to add to this instance.
/// Returns the number of instances successfully added to the dataset, or 0 on error.
private int AddFunction(Function function)
{
DataRow AddressRow, _functionRow;
if(function.VirtualAddress == null)
return(0);
// Check if it exist in function or address, if its in address, just insert to function, if in function, die.
if (FindFunction(function.VirtualAddress) != null)
return(0);
_functionRow = Tables["Functions"].NewRow();
AddressRow = AddAddress(function.VirtualAddress);
_functionRow.SetParentRow(AddressRow);
if (function.Name.Length > 0)
_functionRow["Name"] = function.Name;
else
_functionRow["Name"] = System.DBNull.Value;
_functionRow["Comment"] = function.Comment;
_functionRow["Quality"] = function.Quality;
_functionRow["Object"] = function;
_functionRow["AddressValue"] = function.VirtualAddress.Value;
_functionRow["AddressTimeShift"] = function.VirtualAddress.TimeShift;
Tables["Functions"].Rows.Add(_functionRow);
return(1);
}
public int UpdateFunction(Function WorkingFunction)
{
DataRow FunctionRow = FindFunction(WorkingFunction.VirtualAddress);
if (FunctionRow == null)
return AddFunction(WorkingFunction);
FunctionRow.BeginEdit();
if (WorkingFunction.Name.Length > 0)
FunctionRow["Name"] = WorkingFunction.Name;
else
FunctionRow["Name"] = System.DBNull.Value;
FunctionRow["Comment"] = WorkingFunction.Comment;
FunctionRow["Quality"] = WorkingFunction.Quality;
FunctionRow["Object"] = WorkingFunction;
FunctionRow.EndEdit();
return 1;
}
/// Adds an array of IFunction instances to this dataset.
/// (DOES NOT ADD INSTRUCTIONS YET)
/// Adds all required address and relational references, as well as duplicate checking and Address
/// re-referencing for already existant addresses. Duplicate checking and working (timeshifting) and Address
/// referencing needs reworking.
/// The array of IFunction instances to add to this dataset.
/// Returns the number of instances successfully added to the dataset, or 0 on error.
public int AddFunction(Function[] functionArray)
{
int x = 1;
foreach(Function _func in functionArray)
if(AddFunction(_func) > 0)
x++;
return(x);
}
private string InstructionFunctionSelect(Address FunctionAddress)
{
StringBuilder sb = new StringBuilder();
sb.Append("Parent(Instruction2Function).FunctionID=").Append(FindFunction(FunctionAddress)["FunctionID"]);
return sb.ToString();
}
private string InstructionAddressSelect(Address InstructionAddress)
{
StringBuilder sb = new StringBuilder();
sb.Append("AddressValue=").Append(InstructionAddress.Value.ToString());
sb.Append(" AND AddressTimeShift=").Append(InstructionAddress.TimeShift.ToString());
return sb.ToString();
}
private string UniqueInstructionSelect(Address FunctionAddress, Address InstructionAddress)
{
StringBuilder sb = new StringBuilder();
sb.Append(InstructionAddressSelect(InstructionAddress)).Append(" AND ");
sb.Append(InstructionFunctionSelect(FunctionAddress));
return sb.ToString();
}
///
/// This will add an address to the address table
///
/// The address to add
/// The datarow of the Address in the Address table
private DataRow AddAddress(Address NewAddress)
{
DataRow AddressRow;
StringBuilder sb = new StringBuilder();
sb.Append("Value=").Append(NewAddress.Value.ToString());
sb.Append(" AND TimeShift=").Append(NewAddress.TimeShift.ToString());
DataRow[] Addresses = Tables["Addresses"].Select(sb.ToString());
if(Addresses.Length == 0)
{
AddressRow = Tables["Addresses"].NewRow();
AddressRow["Object"] = NewAddress;
AddressRow["Value"] = NewAddress.Value;
AddressRow["TimeShift"] = NewAddress.TimeShift;
AddressRow["Name"] = NewAddress.Name;
//AddressRow["Comment"] = NewAddress.Name;
Tables["Addresses"].Rows.Add(AddressRow);
}
else
{
AddressRow = Addresses[0];
}
return AddressRow;
}
public int UpdateInstruction(IInstruction instruction)
{
return UpdateInstruction(-1, instruction);
}
public int UpdateInstruction(Int64 FunctionID, IInstruction instruction)
{
DataRow AddressRow, FunctionRow, InstructionRow;
DataRow[] Instructions = Tables["Instructions"].Select(InstructionAddressSelect(instruction.VirtualAddress));
//AddressRow = AddAddress(instruction.VirtualAddress);
if (FunctionID == -1)
{
FunctionRow = FindFunction(instruction.Function);
if (FunctionRow == null)
throw new ApplicationException("Missing a function while updating an instruction.. didn't think this was possible.");
FunctionID = (Int64) FunctionRow["FunctionID"];
}
if (Instructions.Length == 0 || FunctionID != (Int64) Instructions[0]["FunctionID"])
{
//add
InstructionRow = Tables["Instructions"].NewRow();
//InstructionRow.SetParentRow(AddressRow);
InstructionRow["FunctionID"] = FunctionID;
InstructionRow["Comment"] = instruction.Comment;
InstructionRow["Object"] = instruction;
InstructionRow["isBranchToSub"] = instruction.IsBranchToSub;
InstructionRow["isBranch"] = instruction.IsBranch;
InstructionRow["AddressValue"] = instruction.VirtualAddress.Value;
InstructionRow["AddressTimeShift"] = instruction.VirtualAddress.TimeShift;
try
{
Tables["Instructions"].Rows.Add(InstructionRow);
}
catch (System.Data.ConstraintException ce)
{
//TODO: Find out why this contraint keeps getting violated.
int x = 1;
}
}
else
{
// update
InstructionRow = Instructions[0];
if ((Int64) InstructionRow["FunctionID"] != FunctionID)
throw new ApplicationException("Didn't think this was possible");
else
return 0;
InstructionRow.BeginEdit();
InstructionRow["FunctionID"] = FunctionID;
InstructionRow["Comment"] = instruction.Comment;
InstructionRow["isBranchToSub"] = instruction.IsBranchToSub;
InstructionRow["Object"] = instruction;
InstructionRow.EndEdit();
}
// We add the operands first so we can null them out before instruction addition.
// We also propigate the Operand lists.
// TODO: update operands
return(1);
}
/// Adds a single instance of IInstruction to this dataset.
/// (DOES NOT ADD OPERANDS YET)
/// Adds all required address and relational references, as well as duplicate checking and Address
/// re-referencing for already existant addresses. Duplicate checking and working (timeshifting) and Address
/// referencing needs reworking.
/// The instance of IInstruction from the decompiled code to add to this instance.
/// Returns the number of instances successfully added to the dataset, or 0 on error.
public int AddInstruction(IInstruction instruction)
{
DataRow _addressRow, _instRow;
_instRow = Tables["Instructions"].NewRow();
_addressRow = AddAddress(instruction.VirtualAddress);
_instRow.SetParentRow(_addressRow);
_instRow["FunctionAddress"] = instruction.Function;
_instRow["Name"] = instruction.Name;
_instRow["Comment"] = instruction.Comment;
_instRow["Object"] = instruction;
Tables["Functions"].Rows.Add(_instRow);
return(1);
}
/// Adds an array of IInstruction instances to this dataset.
/// (DOES NOT ADD OPERANDS YET)
/// Adds all required address and relational references, as well as duplicate checking and Address
/// re-referencing for already existant addresses. Duplicate checking and working(timeshifting) and Address
/// referencing needs reworking.
/// The array of IInstruction instances to add to this dataset.
/// Returns the number of instances successfully added to the dataset, or 0 on error.
public int AddInstruction(IInstruction[] instructionArray)
{
int x = 1;
foreach(IInstruction _inst in instructionArray)
if(AddInstruction(_inst) > 0)
x++;
return(x);
}
public int AddInstruction(Function parent, IInstruction[] instructionArray)
{
int x = 1;
foreach(IInstruction _inst in instructionArray)
{
_inst.Function = parent.VirtualAddress;
if(AddInstruction(_inst) > 0)
x++;
}
return(x);
}
public int UpdateInstructions(Function parent, IInstruction[] instructionArray)
{
int x = 0;
Int64 FunctionID = parent.FunctionID;
foreach(IInstruction _inst in instructionArray)
{
_inst.Function = parent.VirtualAddress;
if(UpdateInstruction(FunctionID, _inst) > 0)
x++;
}
this.AcceptChanges();
return(x);
}
/// Adds a single instance of Operand to this dataset.
/// (NOT IMPELEMENTED)
///
/// The instance of Operand from the decompiled code to add to this instance.
/// Returns the number of instances successfully added to the dataset, or 0 on error.
public int AddOperand(Operand operand)
{
throw new InvalidOperationException("Method not implemented");
}
/// Adds an array of Operand instances to this dataset.
/// (NOT IMPELEMENTED)
///
/// The array of Operand instances to add to this dataset.
/// Returns the number of instances successfully added to the dataset, or 0 on error.
public int AddOperand(Operand[] operandArray)
{
throw new InvalidOperationException("Method not implemented");
}
#endregion
#region Search Methods
/// Searches for Address objects containing the provided absolute address.
/// (Not Timeshift friendly)
/// the absolute address to search for.
/// Returns an array of type Address[] with all the Addresses containing the provided absolute address.
public Address GetAddress(long address)
{
DataRow _Row;
// Find it.
if((_Row = Tables["Addresses"].Rows.Find(address)) == null)
return(null);
return((Address)_Row["Object"]);
}
/// Searches and gets an array of all objects referencing the provided Address object.
/// (Timeshift friendly)
/// The instance of Address to search for.
/// Returns an object[] array of all objects referencing provided Address.
public object[] GetAtAddress(Address address)
{
DataRow _Row;
ArrayList _ChildRows, _RetList;
// Find it.
if((_Row = Tables["Addresses"].Rows.Find(address)) == null)
return(null);
_ChildRows = new ArrayList();
foreach(DataRelation _Relation in Tables["Addresses"].ChildRelations)
_ChildRows.AddRange(_Row.GetChildRows(_Relation));
_RetList = new ArrayList();
foreach(DataRow _childRow in _ChildRows)
{
if(!_childRow.IsNull("Object"))
if(_childRow["Object"].GetType() == typeof(Function))
_RetList.Add((object) GetFunction((Address)_childRow["VirtualAddress"]));
if(_childRow["Object"].GetType() == typeof(IInstruction))
_RetList.Add((object) GetInstruction((Address)_childRow["VirtualAddress"]));
else
_RetList.Add((object)_childRow["Object"]);
}
_ChildRows = null;
return((object[])_RetList.ToArray(typeof(object)));
}
/// Searches and gets an array of all objects referencing the provided absolute address.
/// (Not Timeshift friendly)
/// the type absolute address to search for.
/// Returns an object[] array of all objects referencing provided Address.
public object[] GetAtAddress(long address)
{
DataRow _Row;
ArrayList _ChildRows, _RetList;
// Find it.
if((_Row = Tables["Addresses"].Rows.Find(address)) == null)
return(null);
_ChildRows = new ArrayList();
foreach(DataRelation _Relation in Tables["Addresses"].ChildRelations)
_ChildRows.AddRange(_Row.GetChildRows(_Relation));
_RetList = new ArrayList();
foreach(DataRow _childRow in _ChildRows)
{
if(!_childRow.IsNull("Object"))
if(_childRow["Object"].GetType() == typeof(Function))
_RetList.Add((object) GetFunction((Address)_childRow["VirtualAddress"]));
if(_childRow["Object"].GetType() == typeof(IInstruction))
_RetList.Add((object) GetInstruction((Address)_childRow["VirtualAddress"]));
else
_RetList.Add((object)_childRow["Object"]);
}
_ChildRows = null;
return((object[])_RetList.ToArray(typeof(object)));
}
/// Searchs for the functions located at the provided address location.
/// The instance of Address to search under.
/// An Array of type IFunction[] with all the IFunctions at the specified Address,
/// or null if none.
public Function[] GetFunction(Address address)
{
// DataRow _Row;
// ArrayList _ChildRows, _RetList;
//
// // Find it.
// if((_Row = Tables["Addresses"].Rows.Find(address)) == null)
// return(null);
//
// _ChildRows = new ArrayList();
// _ChildRows.AddRange(_Row.GetChildRows(GetRelation("Addresses", "Functions")));
//
// _RetList = new ArrayList();
// foreach(DataRow _childRow in _ChildRows)
// if(!_childRow.IsNull("Object"))
// _RetList.Add((Function)RebuildFunction(_childRow));
//
// _ChildRows = null;
// return((Function[])_RetList.ToArray(typeof(Function[])));
throw new NotImplementedException("Not really sure I agree with this");
}
/// Searchs for the functions located at the provided address location.
/// The absolute address to search under.
/// An Array of type IFunction[] with all the IFunctions at the specified address,
/// or null if none.
public Function[] GetFunction(long address)
{
// DataRow _Row;
// ArrayList _ChildRows, _RetList;
//
// // Find it.
// if((_Row = Tables["Addresses"].Rows.Find(address)) == null)
// return(null);
//
// _ChildRows = new ArrayList();
// _ChildRows.AddRange(_Row.GetChildRows(GetRelation("Addresses", "Functions")));
//
// _RetList = new ArrayList();
// foreach(DataRow _childRow in _ChildRows)
// if(!_childRow.IsNull("Object"))
// _RetList.Add((Function)RebuildFunction(_childRow));
//
// _ChildRows = null;
// return((Function[])_RetList.ToArray(typeof(Function[])));
throw new NotImplementedException("Not really sure I agree with this");
}
/// Searchs for the functions given the specified name
/// The name of the custom-named function to search for.
/// An Array of type IFunction[] with all the IFunctions at the specified Address,
/// or null if none.
public Function[] GetFunction(string name)
{
// DataRow _Row;
// ArrayList _ChildRows, _RetList;
//
// // Find it.
// if((_Row = Tables["Addresses"].Rows.Find(name)) == null)
// return(null);
//
// _ChildRows = new ArrayList();
// _ChildRows.AddRange(_Row.GetChildRows(GetRelation("Addresses", "Functions")));
//
// _RetList = new ArrayList();
// foreach(DataRow _childRow in _ChildRows)
// if(!_childRow.IsNull("Object"))
// _RetList.Add((Function)RebuildFunction(_childRow));
//
// _ChildRows = null;
// return((Function[])_RetList.ToArray(typeof(Function[])));
throw new NotImplementedException("Not really sure I agree with this");
}
public Queue GetFullCallList()
{
DataRow[] CallRows = Tables["Instructions"].Select("isBranchToSub=1");
CallInfo[] RetVal = new CallInfo[CallRows.Length];
int Counter = 0;
foreach (DataRow dr in CallRows)
{
RetVal[Counter] = new CallInfo((IInstruction) dr["Object"]);
Counter++;
}
return new Queue(RetVal);
}
public Function[] GetFunctions()
{
Function[] RetVal = new Function[Tables["Functions"].Rows.Count];
int Counter = 0;
foreach (DataRow Functions in Tables["Functions"].Select("", "AddressTimeShift,AddressValue"))
{
RetVal[Counter] = (Function) Functions["Object"];
Counter++;
}
return RetVal;
}
public IInstruction[] GetInstruction(Address address)
{
throw new InvalidOperationException("Method not implemented");
}
public IInstruction[] GetInstruction(long address)
{
throw new InvalidOperationException("Method not implemented");
}
public IInstruction[] GetInstruction(string name)
{
throw new InvalidOperationException("Method not implemented");
}
public IInstruction[] GetInstruction(Function function)
{
throw new InvalidOperationException("Method not implemented");
}
#endregion
#region Other
/// Generates a templated generic table for this dataset with the provided parameters.
/// The name of the DataTable to create.
/// The object type that this DataTable will contain in the "Object" column.
/// An initialized and constructed generic table for usage.
public DataTable GetTemplateTable(string tableName, System.Type objectType)
{
DataTable _retTable = new DataTable(tableName);
// We only add a virtual address if the Object isnt a virtual address.
if(!objectType.Equals(typeof(Address)))
_retTable.Columns.Add(new DataColumn("VirtualAddress", typeof(Address)));
else
_retTable.Columns.Add(new DataColumn("Address", typeof(long)));
if(objectType.Equals(typeof(IInstruction)))
_retTable.Columns.Add(new DataColumn("FunctionAddress", typeof(Address)));
if(objectType.Equals(typeof(Operand)))
_retTable.Columns.Add(new DataColumn("InstructionAddress", typeof(Address)));
_retTable.Columns.Add(new DataColumn("Name", typeof(string)));
_retTable.Columns.Add(new DataColumn("Comment", typeof(string)));
_retTable.Columns.Add(new DataColumn("Object", objectType));
return(_retTable);
}
/// Gets the relationship object between the specified child and parent tables.
/// The string name of the parent table to use.
/// The string name of the child table to use.
/// Returns the DataRelation specified, otherwise null or exception.
public DataRelation GetRelation(string parentTableName, string childTableName)
{
if(!Tables.Contains(parentTableName) || !Tables.Contains(childTableName))
throw new InvalidOperationException("Invalid table name provided");
foreach(DataRelation _Relation in Tables[parentTableName].ChildRelations)
if(_Relation.ChildTable.TableName.Equals(childTableName))
return(_Relation);
return(null);
}
private void InitializeComponent()
{
this.FunctionsTable = new System.Data.DataTable();
this.colFnAddressID = new System.Data.DataColumn();
this.colName = new System.Data.DataColumn();
this.colComment = new System.Data.DataColumn();
this.colObject = new System.Data.DataColumn();
this.colFunctionID = new System.Data.DataColumn();
this.colQuality = new System.Data.DataColumn();
this.colFunctionAddressTimeShift = new System.Data.DataColumn();
this.AddressesTable = new System.Data.DataTable();
this.colAddressID = new System.Data.DataColumn();
this.colValue = new System.Data.DataColumn();
this.colTimeShift = new System.Data.DataColumn();
this.colAddressObject = new System.Data.DataColumn();
this.colAddressName = new System.Data.DataColumn();
this.InstructionsTable = new System.Data.DataTable();
this.colInstructionAddress = new System.Data.DataColumn();
this.colFnID = new System.Data.DataColumn();
this.colInstructionObject = new System.Data.DataColumn();
this.colInstructionComment = new System.Data.DataColumn();
this.colInstructionID = new System.Data.DataColumn();
this.colBranchToSub = new System.Data.DataColumn();
this.colIsBranch = new System.Data.DataColumn();
this.colAddressTimeShift = new System.Data.DataColumn();
this.OperandsTable = new System.Data.DataTable();
this.colOperandID = new System.Data.DataColumn();
this.colOperandObject = new System.Data.DataColumn();
this.colOperandOrder = new System.Data.DataColumn();
this.colOperandInstructionID = new System.Data.DataColumn();
((System.ComponentModel.ISupportInitialize)(this.FunctionsTable)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.AddressesTable)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.InstructionsTable)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.OperandsTable)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
//
// FunctionsTable
//
this.FunctionsTable.Columns.AddRange(new System.Data.DataColumn[] {
this.colFnAddressID,
this.colName,
this.colComment,
this.colObject,
this.colFunctionID,
this.colQuality,
this.colFunctionAddressTimeShift});
this.FunctionsTable.Constraints.AddRange(new System.Data.Constraint[] {
new System.Data.UniqueConstraint("Constraint1", new string[] {
"FunctionID"}, true),
new System.Data.UniqueConstraint("Constraint3", new string[] {
"Name"}, false)});
this.FunctionsTable.Namespace = "KlaunmoetD.Core";
this.FunctionsTable.PrimaryKey = new System.Data.DataColumn[] {
this.colFunctionID};
this.FunctionsTable.TableName = "Functions";
//
// colFnAddressID
//
this.colFnAddressID.AllowDBNull = false;
this.colFnAddressID.ColumnName = "AddressValue";
this.colFnAddressID.DataType = typeof(long);
//
// colName
//
this.colName.ColumnName = "Name";
//
// colComment
//
this.colComment.Caption = "Comment";
this.colComment.ColumnName = "Comment";
//
// colObject
//
this.colObject.AllowDBNull = false;
this.colObject.ColumnName = "Object";
this.colObject.DataType = typeof(KlaunmoetD.Core.Function);
//
// colFunctionID
//
this.colFunctionID.AllowDBNull = false;
this.colFunctionID.AutoIncrement = true;
this.colFunctionID.ColumnName = "FunctionID";
this.colFunctionID.DataType = typeof(long);
//
// colQuality
//
this.colQuality.AllowDBNull = false;
this.colQuality.ColumnName = "Quality";
this.colQuality.DataType = typeof(int);
//
// colFunctionAddressTimeShift
//
this.colFunctionAddressTimeShift.AllowDBNull = false;
this.colFunctionAddressTimeShift.ColumnName = "AddressTimeShift";
this.colFunctionAddressTimeShift.DataType = typeof(int);
//
// AddressesTable
//
this.AddressesTable.Columns.AddRange(new System.Data.DataColumn[] {
this.colAddressID,
this.colValue,
this.colTimeShift,
this.colAddressObject,
this.colAddressName});
this.AddressesTable.Constraints.AddRange(new System.Data.Constraint[] {
new System.Data.UniqueConstraint("UniqueAddressNameConstraint", new string[] {
"Name"}, false),
new System.Data.UniqueConstraint("Constraint1", new string[] {
"AddressID"}, true)});
this.AddressesTable.PrimaryKey = new System.Data.DataColumn[] {
this.colAddressID};
this.AddressesTable.TableName = "Addresses";
//
// colAddressID
//
this.colAddressID.AllowDBNull = false;
this.colAddressID.AutoIncrement = true;
this.colAddressID.ColumnName = "AddressID";
this.colAddressID.DataType = typeof(long);
this.colAddressID.ReadOnly = true;
//
// colValue
//
this.colValue.ColumnName = "Value";
this.colValue.DataType = typeof(long);
//
// colTimeShift
//
this.colTimeShift.ColumnName = "TimeShift";
this.colTimeShift.DataType = typeof(int);
//
// colAddressObject
//
this.colAddressObject.ColumnName = "Object";
this.colAddressObject.DataType = typeof(KlaunmoetD.Core.Address);
//
// colAddressName
//
this.colAddressName.ColumnName = "Name";
//
// InstructionsTable
//
this.InstructionsTable.Columns.AddRange(new System.Data.DataColumn[] {
this.colInstructionAddress,
this.colFnID,
this.colInstructionObject,
this.colInstructionComment,
this.colInstructionID,
this.colBranchToSub,
this.colIsBranch,
this.colAddressTimeShift});
this.InstructionsTable.Constraints.AddRange(new System.Data.Constraint[] {
new System.Data.UniqueConstraint("Constraint1", new string[] {
"AddressTimeShift",
"AddressValue",
"FunctionID"}, true)});
this.InstructionsTable.PrimaryKey = new System.Data.DataColumn[] {
this.colAddressTimeShift,
this.colInstructionAddress,
this.colFnID};
this.InstructionsTable.TableName = "Instructions";
//
// colInstructionAddress
//
this.colInstructionAddress.AllowDBNull = false;
this.colInstructionAddress.ColumnName = "AddressValue";
this.colInstructionAddress.DataType = typeof(long);
//
// colFnID
//
this.colFnID.AllowDBNull = false;
this.colFnID.Caption = "FunctionID";
this.colFnID.ColumnName = "FunctionID";
this.colFnID.DataType = typeof(long);
//
// colInstructionObject
//
this.colInstructionObject.ColumnName = "Object";
this.colInstructionObject.DataType = typeof(KlaunmoetD.Core.IInstruction);
//
// colInstructionComment
//
this.colInstructionComment.ColumnName = "Comment";
//
// colInstructionID
//
this.colInstructionID.AllowDBNull = false;
this.colInstructionID.AutoIncrement = true;
this.colInstructionID.ColumnName = "InstructionID";
this.colInstructionID.DataType = typeof(long);
//
// colBranchToSub
//
this.colBranchToSub.AllowDBNull = false;
this.colBranchToSub.ColumnName = "isBranchToSub";
this.colBranchToSub.DataType = typeof(bool);
//
// colIsBranch
//
this.colIsBranch.AllowDBNull = false;
this.colIsBranch.ColumnName = "isBranch";
this.colIsBranch.DataType = typeof(bool);
//
// colAddressTimeShift
//
this.colAddressTimeShift.AllowDBNull = false;
this.colAddressTimeShift.ColumnName = "AddressTimeShift";
this.colAddressTimeShift.DataType = typeof(int);
//
// OperandsTable
//
this.OperandsTable.Columns.AddRange(new System.Data.DataColumn[] {
this.colOperandID,
this.colOperandObject,
this.colOperandOrder,
this.colOperandInstructionID});
this.OperandsTable.Constraints.AddRange(new System.Data.Constraint[] {
new System.Data.UniqueConstraint("Constraint1", new string[] {
"OperandID"}, true)});
this.OperandsTable.PrimaryKey = new System.Data.DataColumn[] {
this.colOperandID};
this.OperandsTable.TableName = "Operands";
//
// colOperandID
//
this.colOperandID.AllowDBNull = false;
this.colOperandID.AutoIncrement = true;
this.colOperandID.ColumnName = "OperandID";
this.colOperandID.DataType = typeof(int);
//
// colOperandObject
//
this.colOperandObject.ColumnName = "Object";
this.colOperandObject.DataType = typeof(object);
//
// colOperandOrder
//
this.colOperandOrder.AllowDBNull = false;
this.colOperandOrder.ColumnName = "OperandOrder";
this.colOperandOrder.DataType = typeof(short);
//
// colOperandInstructionID
//
this.colOperandInstructionID.AllowDBNull = false;
this.colOperandInstructionID.ColumnName = "InstructionID";
//
// CodeSet
//
this.Relations.AddRange(new System.Data.DataRelation[] {
new System.Data.DataRelation("Instruction2Function", "Functions", "Instructions", new string[] {
"FunctionID"}, new string[] {
"FunctionID"}, false)});
this.Tables.AddRange(new System.Data.DataTable[] {
this.FunctionsTable,
this.AddressesTable,
this.InstructionsTable,
this.OperandsTable});
((System.ComponentModel.ISupportInitialize)(this.FunctionsTable)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.AddressesTable)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.InstructionsTable)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.OperandsTable)).EndInit();
((System.ComponentModel.ISupportInitialize)(this)).EndInit();
}
/// Instantiates or returns a singleton global instance of this object.
/// The current singleton instance (or new instance) of the codeset class.
public static CodeSet Instance()
{
if(_SingletonInstance == null)
_SingletonInstance = new CodeSet();
return(_SingletonInstance);
}
#endregion
#endregion
}
}