diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/Converters/ExecutableToFileSystemConverter.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/Converters/ExecutableToFileSystemConverter.cs new file mode 100644 index 00000000..4460dcad --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/Converters/ExecutableToFileSystemConverter.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UniversalEditor.ObjectModels.Executable; +using UniversalEditor.ObjectModels.FileSystem; + +namespace UniversalEditor.Converters +{ + public class ExecutableToFileSystemConverter : Converter + { + private static ConverterReference _cr = null; + public override ConverterReference MakeReference() + { + if (_cr == null) + { + _cr = base.MakeReference(); + _cr.Capabilities.Add(typeof(FileSystemObjectModel), typeof(ExecutableObjectModel)); + _cr.Capabilities.Add(typeof(ExecutableObjectModel), typeof(FileSystemObjectModel)); + } + return _cr; + } + public override void Convert(ObjectModel from, ObjectModel to) + { + if (from is ExecutableObjectModel && to is FileSystemObjectModel) + { + ExecutableObjectModel exe = (from as ExecutableObjectModel); + FileSystemObjectModel fsom = (to as FileSystemObjectModel); + foreach (ExecutableSection section in exe.Sections) + { + fsom.Files.Add(section.Name, section.Data); + } + + // TODO: load resources (?) + return; + } + else if (from is FileSystemObjectModel && to is ExecutableObjectModel) + { + FileSystemObjectModel fsom = (from as FileSystemObjectModel); + ExecutableObjectModel exe = (to as ExecutableObjectModel); + + foreach (File file in fsom.Files) + { + ExecutableSection section = new ExecutableSection(); + section.Name = file.Name; + section.Data = file.GetDataAsByteArray(); + exe.Sections.Add(section); + } + return; + } + throw new ObjectModelNotSupportedException(); + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFCapacity.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFCapacity.cs new file mode 100644 index 00000000..bfde2ef3 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFCapacity.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.Executable.ELF +{ + public enum ELFCapacity : byte + { + elfInvalid = 0, + elf32Bit = 1, + elf64Bit = 2 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFDataFormat.cs new file mode 100644 index 00000000..3768ead8 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFDataFormat.cs @@ -0,0 +1,238 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.Executable; +using UniversalEditor.ObjectModels.FileSystem; + +namespace UniversalEditor.DataFormats.Executable.ELF +{ + public class ELFDataFormat : DataFormat + { + private const byte EV_CURRENT = 1; + + private static DataFormatReference _dfr = null; + public override DataFormatReference MakeReference() + { + if (_dfr == null) + { + _dfr = base.MakeReference(); + _dfr.Capabilities.Add(typeof(ExecutableObjectModel), DataFormatCapabilities.All); + _dfr.Filters.Add("Executable and Linkable Format", new byte?[][] { new byte?[] { (byte)0x7F, (byte)'E', (byte)'L', (byte)'F' } }, new string[] { "*.elf" }); + } + return _dfr; + } + + private ELFCapacity mvarCapacity = ELFCapacity.elf32Bit; + public ELFCapacity Capacity { get { return mvarCapacity; } set { mvarCapacity = value; } } + + private ELFEncoding mvarEncoding = ELFEncoding.TwosComplementLSB; + public ELFEncoding Encoding { get { return mvarEncoding; } set { mvarEncoding = value; } } + + private ELFMachine mvarMachine = ELFMachine.None; + /// + /// Specifies the required architecture for the executable file. + /// + public ELFMachine Machine { get { return mvarMachine; } set { mvarMachine = value; } } + + private ELFObjectFileType mvarObjectFileType = ELFObjectFileType.None; + /// + /// Identifies the object file type. + /// + public ELFObjectFileType ObjectFileType { get { return mvarObjectFileType; } set { mvarObjectFileType = value; } } + + private byte mvarFormatVersion = EV_CURRENT; + public byte FormatVersion { get { return mvarFormatVersion; } set { mvarFormatVersion = value; } } + + /* + Elf32_Addr = Unsigned 4 byte program address + Elf32_Half = Unsigned 2 byte integer + Elf32_Off = Unsigned 4 byte file offset + Elf32_Sword = Signed 4 byte integer + Elf32_Word = Unsigned 4 byte integer + unsigned char = Unsigned 1 byte integer + */ + + private struct ELFSectionEntry + { + public string name; + /// + /// This member specifies the name of the section. Its value is an index into + /// the section header string table section, giving the location of a + /// null-terminated string. + /// + public uint nameindex; + /// + /// This member categorizes the section’s contents and semantics. Section types + /// and their descriptions appear below. + /// + public ELFSectionType type; + /// + /// Sections support 1-bit flags that describe miscellaneous attributes. + /// + public ELFSectionFlags flags; + /// + /// If the section will appear in the memory image of a process, this member + /// gives the address at which the section’s first byte should reside. + /// Otherwise, the member contains 0. + /// + public uint addr; + /// + /// This member’s value gives the byte offset from the beginning of the file + /// to the first byte in the section. One section type, SHT_NOBITS described + /// below, occupies no space in the file, and its sh_offset member locates + /// the conceptual placement in the file. + /// + public uint offset; + /// + /// This member gives the section’s size in bytes. Unless the section type is + /// SHT_NOBITS, the section occupies sh_size bytes in the file. A section of + /// type SHT_NOBITS may have a non-zero size, but it occupies no space in the + /// file. + /// + public uint size; + /// + /// This member holds a section header table index link, whose interpretation + /// depends on the section type. A table below describes the values. + /// + public uint link; + /// + /// This member holds extra information, whose interpretation depends on the + /// section type. A table below describes the values. + /// + public uint info; + /// + /// Some sections have address alignment constraints. For example, if a + /// section holds a doubleword, the system must ensure doubleword alignment + /// for the entire section. That is, the value of sh_addr must be congruent + /// to 0, modulo the value of sh_addralign. Currently, only 0 and positive + /// integral powers of two are allowed. Values 0 and 1 mean the section has + /// no alignment constraints. + /// + public uint addralign; + /// + /// Some sections hold a table of fixed-size entries, such as a symbol table. + /// For such a section, this member gives the size in bytes of each entry. + /// The member contains 0 if the section does not hold a table of fixed-size + /// entries. + /// + public uint entsize; + } + + protected override void LoadInternal(ref ObjectModel objectModel) + { + ExecutableObjectModel exe = (objectModel as ExecutableObjectModel); + if (exe == null) throw new ObjectModelNotSupportedException(); + + Reader br = base.Accessor.Reader; + long baseoffset = br.Accessor.Position; + + #region Header + #region e_ident + { + byte signature1 = br.ReadByte(); + string signature2 = br.ReadFixedLengthString(3); + if (signature1 != 0x7F || signature2 != "ELF") throw new InvalidDataFormatException("File does not begin with 0x7F, \"ELF\""); + + mvarCapacity = (ELFCapacity)br.ReadByte(); + mvarEncoding = (ELFEncoding)br.ReadByte(); + mvarFormatVersion = br.ReadByte(); + byte[] padding = br.ReadBytes(8); + byte nident = br.ReadByte(); // should be 16 + // if (nident != 16) throw new InvalidDataFormatException("n_ident is not equal to 16"); + } + #endregion + mvarObjectFileType = (ELFObjectFileType)br.ReadUInt16(); + mvarMachine = (ELFMachine)br.ReadUInt16(); + uint e_version = br.ReadUInt32(); + + // This member gives the virtual address to which the system first transfers + // control, thus starting the process. If the file has no associated entry + // point, this member holds zero. + uint e_entry = br.ReadUInt32(); + + // This member holds the program header table’s file offset in bytes. If the + // file has no program header table, this member holds zero. + uint e_phoff = br.ReadUInt32(); + + // This member holds the section header table’s file offset in bytes. If the + // file has no section header table, this member holds zero. + uint e_shoff = br.ReadUInt32(); + + // This member holds processor-specific flags associated with the file. Flag + // names take the form EF_machine_flag. See "Machine Information" for flag + // definitions. + uint e_flags = br.ReadUInt32(); + + // This member holds the ELF header’s size in bytes. + ushort e_ehsize = br.ReadUInt16(); + + // This member holds the size in bytes of one entry in the file’s program + // header table; all entries are the same size. + ushort e_phentsize = br.ReadUInt16(); + + // This member holds the number of entries in the program header table. Thus + // the product of e_phentsize and e_phnum gives the table’s size in bytes. If a + // file has no program header table, e_phnum holds the value zero. + ushort e_phnum = br.ReadUInt16(); + + // This member holds a section header’s size in bytes. A section header is one + // entry in the section header table; all entries are the same size. + ushort e_shentsize = br.ReadUInt16(); + + // This member holds the number of entries in the section header table. Thus + // the product of e_shentsize and e_shnum gives the section header table's size + // in bytes. If a file has no section header table, e_shnum holds the value + // zero. + ushort e_shnum = br.ReadUInt16(); + + // This member holds the section header table index of the entry associated with + // the section name string table. If the file has no section name string table, + // this member holds the value SHN_UNDEF. + ushort e_shstrndx = br.ReadUInt16(); + #endregion + #region Section Table + br.Accessor.Position = baseoffset + e_shoff; + List sections = new List(); + for (ushort i = 0; i < e_shnum; i++) + { + ELFSectionEntry sh = new ELFSectionEntry(); + sh.nameindex = br.ReadUInt32(); + sh.type = (ELFSectionType)br.ReadUInt32(); + sh.flags = (ELFSectionFlags)br.ReadUInt32(); + sh.addr = br.ReadUInt32(); + sh.offset = br.ReadUInt32(); + sh.size = br.ReadUInt32(); + sh.link = br.ReadUInt32(); + sh.info = br.ReadUInt32(); + sh.addralign = br.ReadUInt32(); + sh.entsize = br.ReadUInt32(); + sections.Add(sh); + } + #endregion + + // find the section header string table + if (e_shstrndx > 0) + { + ELFSectionEntry shstr = sections[e_shstrndx]; + long pos = br.Accessor.Position; + long stroffset = baseoffset + shstr.offset; + for (int i = 0; i < sections.Count; i++) + { + ELFSectionEntry entry = sections[i]; + br.Accessor.Position = stroffset + entry.nameindex; + entry.name = br.ReadNullTerminatedString(); + sections[i] = entry; + } + br.Accessor.Position = pos; + } + } + + protected override void SaveInternal(ObjectModel objectModel) + { + + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFEncoding.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFEncoding.cs new file mode 100644 index 00000000..ab6941fd --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFEncoding.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.Executable.ELF +{ + public enum ELFEncoding + { + None = 0, + TwosComplementLSB = 1, + TwosComplementMSB = 2 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFMachine.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFMachine.cs new file mode 100644 index 00000000..a2524c32 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFMachine.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.Executable.ELF +{ + /// + /// Specifies the required architecture for the executable file. + /// + public enum ELFMachine : ushort + { + None = 0, + /// + /// AT&T WE 32100 + /// + M32 = 1, + /// + /// SPARC + /// + SPARC = 2, + /// + /// Intel 80386 + /// + Intel80386 = 3, + /// + /// Motorola 68K + /// + Motorola68000 = 4, + /// + /// Motorola 88K + /// + Motorola88000 = 5, + /// + /// Intel 80860 + /// + Intel80860 = 7, + /// + /// MIPS RS3000 + /// + MIPS = 8 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFObjectFileType.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFObjectFileType.cs new file mode 100644 index 00000000..17dc7def --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFObjectFileType.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.Executable.ELF +{ + /// + /// Identifies the object file type. + /// + public enum ELFObjectFileType : ushort + { + /// + /// No file type + /// + None = 0, + /// + /// Relocatable file + /// + Relocatable = 1, + /// + /// Executable file + /// + Executable = 2, + /// + /// Shared object file + /// + SharedObject = 3, + /// + /// Core file + /// + Core = 4, + /// + /// Processor-specific + /// + ProcessorSpecificFF00 = 0xFF00, + /// + /// Processor-specific + /// + ProcessorSpecificFFFF = 0xFFFF + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFSectionFlags.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFSectionFlags.cs new file mode 100644 index 00000000..ac853f7f --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFSectionFlags.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.Executable.ELF +{ + [Flags()] + public enum ELFSectionFlags : uint + { + /// + /// The section contains data that should be writable during process execution. + /// + Writable = 0x1, + /// + /// The section occupies memory during process execution. Some control sections do + /// not reside in the memory image of an object file; this attribute is off for + /// those sections. + /// + Allocated = 0x2, + /// + /// The section contains executable machine instructions. + /// + Executable = 0x4, + /// + /// All bits included in this mask are reserved for processor-specific semantics. + /// + ProcessorSpecificMask = 0xF0000000 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFSectionType.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFSectionType.cs new file mode 100644 index 00000000..1811043e --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFSectionType.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.Executable.ELF +{ + public enum ELFSectionType : uint + { + /// + /// This value marks the section header as inactive; it does not have an associated + /// section. Other members of the section header have undefined values. + /// + Null = 0, + /// + /// The section holds information defined by the program, whose format and meaning + /// are determined solely by the program. + /// + ProgramSpecific = 1, + /// + /// These sections hold a symbol table. Currently, an object file may have only one + /// section of each type, but this restriction may be relaxed in the future. + /// Typically, SHT_SYMTAB provides symbols for link editing, though it may also be + /// used for dynamic linking. As a complete symbol table, it may contain many + /// symbols unnecessary for dynamic linking. Consequently, an object file may also + /// contain a SHT_DYNSYM section, which holds a minimal set of dynamic linking + /// symbols, to save space. + /// + SymbolTable = 2, + /// + /// The section holds a string table. An object file may have multiple string table + /// sections. + /// + StringTable = 3, + /// + /// The section holds relocation entries with explicit addends, such as type + /// Elf32_Rela for the 32-bit class of object files. An object file may have + /// multiple relocation sections. + /// + RelocationWithExplicitAddends = 4, + /// + /// The section holds a symbol hash table. All objects participating in dynamic + /// linking must contain a symbol hash table. Currently, an object file may have + /// only one hash table, but this restriction may be relaxed in the future. + /// + SymbolHashTable = 5, + /// + /// The section holds information for dynamic linking. Currently, an object file + /// may have only one dynamic section, but this restriction may be relaxed in the + /// future. + /// + DynamicLinking = 6, + /// + /// The section holds information that marks the file in some way. + /// + Note = 7, + /// + /// A section of this type occupies no space in the file but otherwise resembles + /// SHT_PROGBITS. Although this section contains no bytes, the sh_offset member + /// contains the conceptual file offset. + /// + NoBits = 8, + /// + /// The section holds relocation entries without explicit addends, such as type + /// Elf32_Rel for the 32-bit class of object files. An object file may have multiple + /// relocation sections. + /// + Relocation = 9, + /// + /// This section type is reserved but has unspecified semantics. Programs that + /// contain a section of this type do not conform to the ABI. + /// + ShLib = 10, + /// + /// These sections hold a symbol table. Currently, an object file may have only one + /// section of each type, but this restriction may be relaxed in the future. + /// Typically, SHT_SYMTAB provides symbols for link editing, though it may also be + /// used for dynamic linking. As a complete symbol table, it may contain many + /// symbols unnecessary for dynamic linking. Consequently, an object file may also + /// contain a SHT_DYNSYM section, which holds a minimal set of dynamic linking + /// symbols, to save space. + /// + DynamicSymbolTable = 11, + /// + /// Values in this inclusive range are reserved for processor-specific semantics. + /// + ProcessorSpecificLo = 0x70000000, + /// + /// Values in this inclusive range are reserved for processor-specific semantics. + /// + ProcessorSpecificHi = 0x7FFFFFFF, + /// + /// This value specifies the lower bound of the range of indexes reserved for + /// application programs. + /// + UserSpecificLo = 0x80000000, + /// + /// This value specifies the upper bound of the range of indexes reserved for + /// application programs. Section types between SHT_LOUSER and SHT_HIUSER may be + /// used by the application, without conflicting with current or future + /// system-defined section types. + /// + UserSpecificHi = 0xFFFFFFFF + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFSpecialSectionIndex.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFSpecialSectionIndex.cs new file mode 100644 index 00000000..e9dee1a5 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/DataFormats/Executable/ELF/ELFSpecialSectionIndex.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.DataFormats.Executable.ELF +{ + public enum ELFSpecialSectionIndex + { + Undefined = 0, + ReservedLo = 0xFF00, + ProcLo = 0xFF00, + ProcHigh = 0xFF1F, + Abs = 0xFFF1, + Common = 0xFFF2, + ReservedHigh = 0xFFFF + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableCharacteristics.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableCharacteristics.cs new file mode 100644 index 00000000..59ed1047 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableCharacteristics.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + /// + /// A set of bit flags indicating attributes of the file. + /// + [Flags()] + public enum ExecutableCharacteristics : ushort + { + /// + /// No characteristics defined. + /// + None = 0, + /// + /// Relocation information stripped from a file. + /// + RelocationInformationStripped = 0x0001, + /// + /// The file is executable. + /// + ExecutableImage = 0x0002, + /// + /// Line numbers stripped from file. + /// + LineNumbersStripped = 0x0004, + /// + /// Local symbols stripped from file. + /// + LocalSymbolsStripped = 0x0008, + /// + /// Lets the OS aggressively trim the working set. + /// + AggressiveWorkingSetTrim = 0x0010, + /// + /// Lets the OS aggressively trim the working set. + /// + MinimalObject = 0x0010, + /// + /// The application can handle addresses greater than two gigabytes. + /// + UpdateObject = 0x0020, + /// + /// The application can handle addresses greater than two gigabytes. + /// + LargeAddressAware = 0x0020, + /// + /// This requires a 32-bit word machine. + /// + Require32BitWord = 0x0100, + /// + /// Debug information is stripped to a .DBG file. + /// + DebugStripped = 0x0200, + /// + /// If the image is on removable media, copy to and run from the swap file. + /// + RemovableRunFromSwap = 0x0400, + /// + /// If the image is on a network, copy to and run from the swap file. + /// + NetworkRunFromSwap = 0x0800, + /// + /// File is a system file. + /// + IsSystemFile = 0x1000, + /// + /// File is a DLL. + /// + IsDynamicLinkLibrary = 0x2000, + /// + /// The file should only be run on single-processor machines. + /// + UniprocessorOnly = 0x4000, + /// + /// Bytes of machine word are reversed + /// + ReverseByteOrder = 0x8000 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableFunctionCall.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableFunctionCall.cs new file mode 100644 index 00000000..46f20389 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableFunctionCall.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + public class ExecutableFunctionCall : ICloneable + { + public class ExecutableFunctionCallCollection + : System.Collections.ObjectModel.Collection + { + } + + private string mvarLibraryName = String.Empty; + public string LibraryName { get { return mvarLibraryName; } set { mvarLibraryName = value; } } + + private string mvarFunctionName = String.Empty; + public string FunctionName { get { return mvarFunctionName; } set { mvarFunctionName = value; } } + + private List mvarParameterValues = new List(); + public List ParameterValues { get { return mvarParameterValues; } } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append(mvarLibraryName); + sb.Append("!"); + sb.Append(mvarFunctionName); + sb.Append("("); + foreach (object obj in mvarParameterValues) + { + if (obj is string) sb.Append("\""); + sb.Append(obj.ToString()); + if (obj is string) sb.Append("\""); + if (mvarParameterValues.IndexOf(obj) < mvarParameterValues.Count - 1) sb.Append(", "); + } + sb.Append(");"); + return sb.ToString(); + } + + public object Clone() + { + ExecutableFunctionCall clone = new ExecutableFunctionCall(); + clone.FunctionName = mvarFunctionName; + clone.LibraryName = mvarLibraryName; + foreach (object obj in mvarParameterValues) + { + clone.ParameterValues.Add(obj); + } + return clone; + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableInstruction.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableInstruction.cs new file mode 100644 index 00000000..81c6cce0 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableInstruction.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + public enum ExecutableInstructionOpcode : byte + { + Add = 0, + Move = 0x89, + Push0 = 0x50, + Push1 = 0x51, + Push2 = 0x52, + Push3 = 0x53, // pushl EBP + Push4 = 0x54, + Push5 = 0x55, + Push6 = 0x56, + Push7 = 0x57, + PushWord = 0x68, + PushByte = 0x6A, + Nop = 0x90, + Call = 0xFF + } + public abstract class ExecutableInstruction + { + public class ExecutableInstructionCollection + : System.Collections.ObjectModel.Collection + { + } + + public abstract ExecutableInstructionOpcode OpCode { get; } + + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableLibraryCharacteristics.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableLibraryCharacteristics.cs new file mode 100644 index 00000000..a52506f0 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableLibraryCharacteristics.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + [Flags()] + public enum ExecutableLibraryCharacteristics : ushort + { + /// + /// No library characteristics have been specified. + /// + None = 0x0000, + /// + /// Call when DLL is first loaded into a process's address space. + /// + CallUponLoad = 0x0001, + /// + /// Call when a thread terminates. + /// + CallUponThreadTerminate = 0x0002, + /// + /// Call when a thread starts up. + /// + CallUponThreadStart = 0x0004, + /// + /// Call when DLL exits. + /// + CallUponLibraryExit = 0x0008, + /// + /// The DLL can be relocated at load time. + /// + DynamicBase = 0x0040, + /// + /// Code integrity checks are forced. If you set this flag and a section contains only + /// uninitialized data, set the PointerToRawData member of IMAGE_SECTION_HEADER for that + /// section to zero; otherwise, the image will fail to load because the digital signature + /// cannot be verified. + /// + ForceCodeIntegrityChecks = 0x0080, + /// + /// The image is compatible with data execution prevention (DEP), the NX bit. + /// + DataExecutionPreventionCompatible = 0x0100, + /// + /// The image is isolation aware, but should not be isolated. + /// + NoIsolation = 0x0200, + /// + /// The image does not use structured exception handling (SEH). No handlers can be called in + /// this image. + /// + NoStructuredExceptionHandling = 0x0400, + /// + /// Do not bind the image. + /// + NoBinding = 0x0800, + /// + /// Reserved. + /// + Reserved4096 = 0x1000, + /// + /// A WDM driver. + /// + WDMDriver = 0x2000, + /// + /// Reserved. + /// + Reserved16384 = 0x4000, + /// + /// The image is terminal server aware. + /// + TerminalServerAware = 0x8000 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableLibraryReference.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableLibraryReference.cs new file mode 100644 index 00000000..9defa2af --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableLibraryReference.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + public class ExecutableLibraryReference : ICloneable + { + public class ExecutableLibraryReferenceCollection + : System.Collections.ObjectModel.Collection + { + public ExecutableLibraryReference Add(int libraryID, int minVer, int numberOfTimesIncluded) + { + ExecutableLibraryReference r = new ExecutableLibraryReference(); + r.ProductID = libraryID; + r.MinimumVersion = minVer; + r.Count = numberOfTimesIncluded; + base.Add(r); + return r; + } + } + + private int mvarProductID = 0; + public int ProductID { get { return mvarProductID; } set { mvarProductID = value; } } + + private int mvarMinimumVersion = 0; + public int MinimumVersion { get { return mvarMinimumVersion; } set { mvarMinimumVersion = value; } } + + private int mvarCount = 0; + public int Count { get { return mvarCount; } set { mvarCount = value; } } + + public override string ToString() + { + return "Product ID: " + mvarProductID.ToString() + ", minimum version " + mvarMinimumVersion.ToString() + ", count: " + mvarCount.ToString(); + } + + public object Clone() + { + ExecutableLibraryReference clone = new ExecutableLibraryReference(); + clone.Count = mvarCount; + clone.MinimumVersion = mvarMinimumVersion; + clone.ProductID = mvarProductID; + return clone; + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableLoaderFlags.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableLoaderFlags.cs new file mode 100644 index 00000000..c7036d13 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableLoaderFlags.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + /// + /// Fields relating to debugging support + /// + public enum ExecutableLoaderFlags + { + /// + /// No loader flags have been defined. + /// + None = 0, + /// + /// Invoke a breakpoint instruction before starting the process. + /// + BreakBeforeStart = 1, + /// + /// Invoke a debugger on the process after it's been loaded. + /// + DebugAfterLoad = 2 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableMachine.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableMachine.cs new file mode 100644 index 00000000..cf978530 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableMachine.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + /// + /// The target CPU for this executable. + /// + public enum ExecutableMachine : ushort + { + /// + /// Machine type unknown + /// + Unknown = 0, + /// + /// Intel 386 (i386) 32-bit machine + /// + Intel386 = 0x014C, + /// + /// Intel 860 + /// + Intel860 = 0x014D, + /// + /// MIPS little-endian, 0540 big-endian + /// + R3000 = 0x0162, + /// + /// MIPS little-endian + /// + R4000 = 0x0166, + /// + /// MIPS little-endian + /// + R10000 = 0x0168, + /// + /// Alpha_AXP 32-bit + /// + AlphaAXP32 = 0x0184, + /// + /// IBM PowerPC Little-Endian + /// + PowerPCLittleEndian = 0x01F0, + /// + /// IBM PowerPC Big-Endian + /// + PowerPCBigEndian = 0x01F2, + /// + /// SH3 little-endian + /// + SH3 = 0x01A2, + /// + /// SH3E little-endian + /// + SH3E = 0x01A4, + /// + /// SH4 little-endian + /// + SH4 = 0x01A6, + /// + /// ARM little-endian + /// + ARM = 0x01C0, + /// + /// Thumb + /// + Thumb = 0x01C2, + /// + /// Intel 64 (ia64) Itanium 64-bit machine + /// + Intel64Bit = 0x0200, + /// + /// MIPS + /// + MIPS16 = 0x0266, + /// + /// Alpha_AXP 64-bit + /// + AlphaAXP64 = 0x0284, + /// + /// MIPS + /// + MIPSFPU = 0x0366, + /// + /// MIPS + /// + MIPSFPU16 = 0x0466, + /// + /// AMD64 64-bit machine + /// + AMD64 = 0x8664, + /// + /// CEF + /// + CEF = 0xC0EF + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableObjectModel.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableObjectModel.cs new file mode 100644 index 00000000..13f4dfd7 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableObjectModel.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + public class ExecutableObjectModel : ObjectModel + { + private ExecutableSection.ExecutableSectionCollection mvarSections = new ExecutableSection.ExecutableSectionCollection(); + public ExecutableSection.ExecutableSectionCollection Sections { get { return mvarSections; } } + + private ExecutableLibraryReference.ExecutableLibraryReferenceCollection mvarLibraryReferences = new ExecutableLibraryReference.ExecutableLibraryReferenceCollection(); + public ExecutableLibraryReference.ExecutableLibraryReferenceCollection LibraryReferences { get { return mvarLibraryReferences; } } + + private ExecutableMachine mvarTargetMachineType = ExecutableMachine.Unknown; + public ExecutableMachine TargetMachineType { get { return mvarTargetMachineType; } set { mvarTargetMachineType = value; } } + + private ExecutableFunctionCall.ExecutableFunctionCallCollection mvarFunctionCalls = new ExecutableFunctionCall.ExecutableFunctionCallCollection(); + public ExecutableFunctionCall.ExecutableFunctionCallCollection FunctionCalls { get { return mvarFunctionCalls; } } + + #region Object Model Methods + public override void Clear() + { + mvarSections.Clear(); + mvarLibraryReferences.Clear(); + mvarTargetMachineType = ExecutableMachine.Unknown; + mvarCharacteristics = ExecutableCharacteristics.None; + mvarLibraryCharacteristics = ExecutableLibraryCharacteristics.None; + mvarRelativeVirtualAddresses.Clear(); + mvarInstructions.Clear(); + mvarFunctionCalls.Clear(); + mvarSubsystem = ExecutableSubsystem.Unknown; + mvarTimestamp = DateTime.Now; + } + public override void CopyTo(ObjectModel where) + { + ExecutableObjectModel clone = (where as ExecutableObjectModel); + foreach (ExecutableSection sect in mvarSections) + { + clone.Sections.Add(sect.Clone() as ExecutableSection); + } + foreach (ExecutableLibraryReference lref in mvarLibraryReferences) + { + clone.LibraryReferences.Add(lref.Clone() as ExecutableLibraryReference); + } + clone.TargetMachineType = mvarTargetMachineType; + clone.Characteristics = mvarCharacteristics; + clone.LibraryCharacteristics = mvarLibraryCharacteristics; + foreach (ExecutableRelativeVirtualAddress rva in mvarRelativeVirtualAddresses) + { + clone.RelativeVirtualAddresses.Add(rva.Clone() as ExecutableRelativeVirtualAddress); + } + foreach (ExecutableFunctionCall func in mvarFunctionCalls) + { + clone.FunctionCalls.Add(func.Clone() as ExecutableFunctionCall); + } + clone.Subsystem = mvarSubsystem; + clone.Timestamp = mvarTimestamp; + } + public override ObjectModelReference MakeReference() + { + ObjectModelReference omr = base.MakeReference(); + omr.Title = "Executable"; + omr.Path = new string[] { "Software Development", "Executable" }; + return omr; + } + #endregion + + private ExecutableCharacteristics mvarCharacteristics = ExecutableCharacteristics.None; + public ExecutableCharacteristics Characteristics { get { return mvarCharacteristics; } set { mvarCharacteristics = value; } } + + private ExecutableLibraryCharacteristics mvarLibraryCharacteristics = ExecutableLibraryCharacteristics.None; + public ExecutableLibraryCharacteristics LibraryCharacteristics { get { return mvarLibraryCharacteristics; } set { mvarLibraryCharacteristics = value; } } + + private ExecutableLoaderFlags mvarLoaderFlags = ExecutableLoaderFlags.None; + public ExecutableLoaderFlags LoaderFlags { get { return mvarLoaderFlags; } set { mvarLoaderFlags = value; } } + + private ExecutableSubsystem mvarSubsystem = ExecutableSubsystem.Unknown; + public ExecutableSubsystem Subsystem { get { return mvarSubsystem; } set { mvarSubsystem = value; } } + + private DateTime mvarTimestamp = DateTime.Now; + public DateTime Timestamp { get { return mvarTimestamp; } set { mvarTimestamp = value; } } + + private ExecutableRelativeVirtualAddress.ExecutableRelativeVirtualAddressCollection mvarRelativeVirtualAddresses = new ExecutableRelativeVirtualAddress.ExecutableRelativeVirtualAddressCollection(); + public ExecutableRelativeVirtualAddress.ExecutableRelativeVirtualAddressCollection RelativeVirtualAddresses { get { return mvarRelativeVirtualAddresses; } } + + private ExecutableInstruction.ExecutableInstructionCollection mvarInstructions = new ExecutableInstruction.ExecutableInstructionCollection(); + public ExecutableInstruction.ExecutableInstructionCollection Instructions { get { return mvarInstructions; } } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableRelativeVirtualAddress.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableRelativeVirtualAddress.cs new file mode 100644 index 00000000..b9d1875e --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableRelativeVirtualAddress.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + public class ExecutableRelativeVirtualAddress : ICloneable + { + public class ExecutableRelativeVirtualAddressCollection + : System.Collections.ObjectModel.Collection + { + } + + private ushort mvarDataDirectoryVirtualAddress = 0; + public ushort DataDirectoryVirtualAddress { get { return mvarDataDirectoryVirtualAddress; } set { mvarDataDirectoryVirtualAddress = value; } } + + private ushort mvarDataDirectorySize = 0; + public ushort DataDirectorySize { get { return mvarDataDirectorySize; } set { mvarDataDirectorySize = value; } } + + public object Clone() + { + ExecutableRelativeVirtualAddress rva = new ExecutableRelativeVirtualAddress(); + rva.DataDirectorySize = mvarDataDirectorySize; + rva.DataDirectoryVirtualAddress = mvarDataDirectoryVirtualAddress; + return rva; + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableResourceBlock.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableResourceBlock.cs new file mode 100644 index 00000000..fc85d31f --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableResourceBlock.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + public enum ExecutableResourceType + { + Custom = -1, + // NewResource = 0x2000, + // Error = 0x7fff, + Cursor = 1, + Bitmap =2, + Icon = 3, + Menu = 4, + Dialog = 5, + String =6, + FontDir = 7, + Font = 8, + Accelerator = 9, + RCData = 10, + MessageTable = 11, + GroupCursor = 12, + GroupIcon = 14, + Version = 16 // , + // NewBitmap = (Bitmap | NewResource), + // NewMenu = (Menu | NewResource), + // NewDialog = (Dialog | NewResource) + } + public abstract class ExecutableResourceBlock : ICloneable + { + public class ExecutableResourceBlockCollection + : System.Collections.ObjectModel.Collection + { + } + + public abstract ExecutableResourceType Type { get; } + + private int mvarID = 0; + public int ID { get { return mvarID; } set { mvarID = value; } } + + private string mvarName = String.Empty; + public string Name { get { return mvarName; } set { mvarName = value; } } + + public abstract object Clone(); + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableSection.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableSection.cs new file mode 100644 index 00000000..63b9235d --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableSection.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + public class ExecutableSection : ICloneable + { + public class ExecutableSectionCollection + : System.Collections.ObjectModel.Collection + { + private Dictionary sectionsByName = new Dictionary(); + + public ExecutableSection Add(string name, byte[] data) + { + ExecutableSection section = new ExecutableSection(); + section.Name = name; + section.Data = data; + Add(section); + return section; + } + + public ExecutableSection this[string name] + { + get + { + if (sectionsByName.ContainsKey(name)) + { + return sectionsByName[name]; + } + return null; + } + } + + public bool Contains(string name) + { + return sectionsByName.ContainsKey(name); + } + public bool Remove(string name) + { + ExecutableSection sect = this[name]; + if (sect != null) + { + Remove(sect); + return true; + } + return false; + } + + internal void UpdateSectionName(ExecutableSection item, string oldName) + { + sectionsByName.Remove(oldName); + sectionsByName.Add(item.Name, item); + } + + protected override void InsertItem(int index, ExecutableSection item) + { + base.InsertItem(index, item); + item.mvarParent = this; + if (!sectionsByName.ContainsKey(item.Name)) + { + sectionsByName.Add(item.Name, item); + } + } + protected override void RemoveItem(int index) + { + string name = this[index].Name; + if (sectionsByName.ContainsKey(name)) + { + sectionsByName.Remove(name); + } + this[index].mvarParent = null; + base.RemoveItem(index); + } + + + public void SaveAll(string Path) + { + foreach (ExecutableSection sect in this) + { + string FileName = Path + "_" + sect.Name; + sect.Save(FileName); + } + } + } + + private ExecutableSectionCollection mvarParent = null; + + private string mvarName = String.Empty; + public string Name + { + get { return mvarName; } + set + { + string oldName = mvarName; + mvarName = value; + if (mvarParent != null) + { + mvarParent.UpdateSectionName(this, oldName); + } + } + } + + private byte[] mvarData = new byte[0]; + public byte[] Data { get { return mvarData; } set { mvarData = value; } } + + private long mvarPhysicalAddress = 0; + public long PhysicalAddress { get { return mvarPhysicalAddress; } set { mvarPhysicalAddress = value; } } + + private long mvarVirtualAddress = 0; + public long VirtualAddress { get { return mvarVirtualAddress; } set { mvarVirtualAddress = value; } } + + public object Clone() + { + ExecutableSection clone = new ExecutableSection(); + clone.Name = mvarName; + clone.Data = (mvarData.Clone() as byte[]); + return clone; + } + + public override string ToString() + { + return mvarName + " (" + mvarCharacteristics.ToString() + "; " + mvarData.Length + " bytes)"; + } + + private ExecutableSectionCharacteristics mvarCharacteristics = ExecutableSectionCharacteristics.None; + public ExecutableSectionCharacteristics Characteristics { get { return mvarCharacteristics; } set { mvarCharacteristics = value; } } + + public void Load(string FileName) + { + mvarData = System.IO.File.ReadAllBytes(FileName); + } + public void Save(string FileName) + { + System.IO.File.WriteAllBytes(FileName, mvarData); + } + + private uint mvarVirtualSize = 0; + public uint VirtualSize { get { return mvarVirtualSize; } set { mvarVirtualSize = value; } } + + private uint mvarRelocationOffset = 0; + public uint RelocationOffset { get { return mvarRelocationOffset; } set { mvarRelocationOffset = value; } } + + private uint mvarLineNumberOffset = 0; + public uint LineNumberOffset { get { return mvarLineNumberOffset; } set { mvarLineNumberOffset = value; } } + + private ushort mvarRelocationCount = 0; + public ushort RelocationCount { get { return mvarRelocationCount; } set { mvarRelocationCount = value; } } + + private ushort mvarLineNumberCount = 0; + public ushort LineNumberCount { get { return mvarLineNumberCount; } set { mvarLineNumberCount = value; } } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableSectionCharacteristics.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableSectionCharacteristics.cs new file mode 100644 index 00000000..3c5b4706 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableSectionCharacteristics.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + [Flags()] + public enum ExecutableSectionCharacteristics : uint + { + None = 0x00000000, + /// + /// Reserved. + /// + TypeNoPad = 0x00000008, + /// + /// Section contains code. + /// + ContainsCode = 0x00000020, + /// + /// Section contains initialized data. + /// + ContainsInitializedData = 0x00000040, + /// + /// Section contains uninitialized data. + /// + ContainsUninitializedData = 0x00000080, + /// + /// Reserved. + /// + LinkOther = 0x00000100, + /// + /// Section contains comments or some other type of information. + /// + LinkInformation = 0x00000200, + /// + /// Section contents will not become part of image. + /// + LinkRemove = 0x00000800, + /// + /// Section contents comdat. + /// + LinkComdat = 0x00001000, + /// + /// Reset speculative exceptions handling bits in the TLB entries for this section. + /// + ResetSpeculativeExceptions = 0x00004000, + /// + /// Section content can be accessed relative to GP + /// + GPRelative = 0x00008000, + MemoryFarData = 0x00008000, + MemoryPurgeable = 0x00020000, + Memory16Bit = 0x00020000, + MemoryLocked = 0x00040000, + MemoryPreload = 0x00080000, + Align1Byte = 0x00100000, + Align2Bytes = 0x00200000, + Align4Bytes = 0x00300000, + Align8Bytes = 0x00400000, + /// + /// Default alignment if no others are specified. + /// + Align16Bytes = 0x00500000, + Align32Bytes = 0x00600000, + Align64Bytes = 0x00700000, + Align128Bytes = 0x00800000, + Align256Bytes = 0x00900000, + Align512Bytes = 0x00A00000, + Align1024Bytes = 0x00B00000, + Align2048Bytes = 0x00C00000, + Align4096Bytes = 0x00D00000, + Align8192Bytes = 0x00E00000, + AlignMask = 0x00F00000, + /// + /// Section contains extended relocations. + /// + LinkExtendedRelocations = 0x01000000, + /// + /// Section can be discarded. + /// + MemoryDiscardable = 0x02000000, + /// + /// Section is not cachable. + /// + MemoryNotCached = 0x04000000, + /// + /// Section is not pageable. + /// + MemoryNotPaged = 0x08000000, + /// + /// Section is shareable. + /// + MemoryShared = 0x10000000, + /// + /// Section is executable. + /// + MemoryExecutable = 0x20000000, + /// + /// Section is readable. + /// + MemoryReadable = 0x40000000, + /// + /// Section is writeable. + /// + MemoryWritable = 0x80000000 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableSubsystem.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableSubsystem.cs new file mode 100644 index 00000000..95816989 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ExecutableSubsystem.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable +{ + public enum ExecutableSubsystem : ushort + { + /// + /// Unknown subsystem. + /// + Unknown = 0, + /// + /// No subsystem required (device drivers and native system processes). + /// + Native = 1, + /// + /// Windows graphical user interface (GUI) subsystem. + /// + WindowsGUI = 2, + /// + /// Windows character-mode user interface (CUI) subsystem. + /// + WindowsCUI = 3, + /// + /// OS/2 character-mode user interface (CUI) subsystem. + /// + OS2CUI = 5, + /// + /// POSIX character-mode user interface (CUI) subsystem. + /// + PosixCUI = 7, + /// + /// Windows CE system. + /// + WindowsCEGUI = 9, + /// + /// Extensible Firmware Interface (EFI) application. + /// + EFIApplication = 10, + /// + /// EFI driver with boot services. + /// + EFIBootServiceDriver = 11, + /// + /// EFI driver with run-time services. + /// + EFIRuntimeServiceDriver = 12, + /// + /// EFI ROM image. + /// + EFIROMImage = 13, + /// + /// Xbox system. + /// + Xbox = 14, + /// + /// Boot application + /// + WindowsBootApplication = 16 + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/Instructions/ExecutableInstructionCall.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/Instructions/ExecutableInstructionCall.cs new file mode 100644 index 00000000..921558ef --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/Instructions/ExecutableInstructionCall.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable.Instructions +{ + public class ExecutableInstructionCall : ExecutableInstruction where T : struct, IComparable, IComparable, IConvertible, IEquatable, IFormattable + { + public override ExecutableInstructionOpcode OpCode + { + get { return ExecutableInstructionOpcode.Call; } + } + + private byte mvarExtra = 0; + public byte Extra { get { return mvarExtra; } set { mvarExtra = value; } } + + private T mvarAddress = default(T); + /// + /// The address of the next instruction to execute. + /// + public T Address { get { return mvarAddress; } set { mvarAddress = value; } } + + public override string ToString() + { + return "CALL 0x" + mvarAddress.ToString("X", null).PadLeft(2, '0'); + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/Instructions/ExecutableInstructionPush.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/Instructions/ExecutableInstructionPush.cs new file mode 100644 index 00000000..c3b5bd09 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/Instructions/ExecutableInstructionPush.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable.Instructions +{ + public class ExecutableInstructionPush : ExecutableInstruction where T : struct, IComparable, IComparable, IConvertible, IEquatable, IFormattable + { + public override ExecutableInstructionOpcode OpCode + { + get { return ExecutableInstructionOpcode.PushByte; } + } + + private T mvarValue = default(T); + /// + /// The value to push onto the stack. + /// + public T Value { get { return mvarValue; } set { mvarValue = value; } } + + public override string ToString() + { + return "PUSH imm" + (System.Runtime.InteropServices.Marshal.SizeOf(mvarValue) * 8).ToString() + " 0x" + mvarValue.ToString("X", null).PadLeft(2, '0'); + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ResourceBlocks/CustomResourceBlock.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ResourceBlocks/CustomResourceBlock.cs new file mode 100644 index 00000000..a119d2e8 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ResourceBlocks/CustomResourceBlock.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable.ResourceBlocks +{ + public class CustomResourceBlock : ExecutableResourceBlock + { + private ExecutableResourceType mvarType = ExecutableResourceType.Custom; + public override ExecutableResourceType Type + { + get { return mvarType; } + } + + private byte[] mvarData = new byte[0]; + public byte[] Data { get { return mvarData; } set { mvarData = value; } } + + public override object Clone() + { + CustomResourceBlock clone = new CustomResourceBlock(); + clone.Data = (mvarData.Clone() as byte[]); + return clone; + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ResourceBlocks/IconResourceBlock.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ResourceBlocks/IconResourceBlock.cs new file mode 100644 index 00000000..e37b35c3 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ResourceBlocks/IconResourceBlock.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable.ResourceBlocks +{ + public class IconResourceBlock : ExecutableResourceBlock + { + public override ExecutableResourceType Type + { + get { return ExecutableResourceType.Icon; } + } + + public override object Clone() + { + throw new NotImplementedException(); + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ResourceBlocks/VersionResourceBlock.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ResourceBlocks/VersionResourceBlock.cs new file mode 100644 index 00000000..6ab90644 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/ObjectModels/Executable/ResourceBlocks/VersionResourceBlock.cs @@ -0,0 +1,361 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Executable.ResourceBlocks +{ + /// + /// Specifies the general type of file. + /// + [Flags()] + public enum VersionFileType : uint + { + /// + /// The file type is unknown to Windows. + /// + Unknown = 0x00000000, + /// + /// The file contains an application. + /// + Application = 0x00000001, + /// + /// The file contains a dynamic-link library (DLL). + /// + DynamicLinkLibrary = 0x00000002, + /// + /// The file contains a device driver. If dwFileType is VFT_DRV, dwFileSubtype contains a more specific description of the driver. + /// + DeviceDriver = 0x00000003, + /// + /// The file contains a font. If dwFileType is VFT_FONT, dwFileSubtype contains a more specific description of the font file. + /// + Font = 0x00000004, + /// + /// The file contains a virtual device driver. + /// + VirtualDeviceDriver = 0x00000005, + /// + /// Unknown purpose. + /// + Reserved = 0x00000006, + /// + /// The file contains a static-link library. + /// + StaticLibrary = 0x00000007 + } + /// + /// Specifies the function of the file. The possible values depend on the value of + /// . If is + /// , contains the virtual device identifier + /// included in the virtual device control block. + /// + [Flags()] + public enum VersionFileSubType : uint + { + /// + /// The driver or font type is unknown by Windows. + /// + Unknown = 0x00000000, + /// + /// The file contains a printer driver or a raster font. + /// + DriverPrinter = 0x00000001, + /// + /// The file contains a keyboard driver or a vector font. + /// + DriverKeyboard = 0x00000002, + /// + /// The file contains a language driver or a TrueType font. + /// + DriverLanguage = 0x00000003, + /// + /// The file contains a display driver. + /// + DriverDisplay = 0x00000004, + /// + /// The file contains a mouse driver. + /// + DriverMouse = 0x00000005, + /// + /// The file contains a network driver. + /// + DriverNetwork = 0x00000006, + /// + /// The file contains a system driver. + /// + DriverSystem = 0x00000007, + /// + /// The file contains an installable driver. + /// + DriverInstallable = 0x00000008, + /// + /// The file contains a sound driver. + /// + DriverSound = 0x00000009, + /// + /// The file contains a communications driver. + /// + DriverCommunications = 0x0000000A, + /// + /// The file contains an input method driver. + /// + DriverInputMethod = 0x0000000B, + /// + /// The file contains a versioned printer driver. + /// + DriverPrinterVersioned = 0x0000000C, + /// + /// The file contains a printer driver or a raster font. + /// + FontRaster = 0x00000001, + /// + /// The file contains a keyboard driver or a vector font. + /// + FontVector = 0x00000002, + /// + /// The file contains a language driver or a TrueType font. + /// + FontTrueType = 0x00000003 + } + /// + /// Specifies the operating system for which this file was designed. + /// + [Flags()] + public enum VersionOperatingSystem : uint + { + /// + /// The operating system for which the file was designed is unknown to Windows. + /// + Unknown = 0x00000000, + /// + /// The file was designed for MS-DOS. + /// + DOS = 0x00010000, + /// + /// The file was designed for Windows NT. + /// + WindowsNT = 0x00040000, + /// + /// The file was designed for 16-bit Windows. + /// + Windows16 = 0x00000001, + /// + /// The file was designed for the Win32 API. + /// + Windows32 = 0x00000004, + /// + /// The file was designed for 16-bit OS/2. + /// + OS216 = 0x00020000, + /// + /// The file was designed for 32-bit OS/2. + /// + OS232 = 0x00030000, + /// + /// The file was designed for 16-bit Presentation Manager. + /// + PresentationManager16 = 0x00000002, + /// + /// The file was designed for 32-bit Presentation Manager. + /// + PresentationManager32 = 0x00000003 + } + /// + /// Contains a bitmask that specifies the Boolean attributes of the file. + /// + [Flags()] + public enum VersionFileAttributes : uint + { + /// + /// The file has no version flags set. + /// + None = 0x00, + /// + /// The file contains debugging information or is compiled with debugging features enabled. + /// + DebugMode = 0x01, + /// + /// The file has been modified and is not identical to the original shipping file of the same + /// version number. + /// + Patched = 0x04, + /// + /// The file is a development version, not a commercially released product. + /// + PreRelease = 0x02, + /// + /// The file was not built using standard release procedures. If this flag is set, the + /// StringFileInfo structure should contain a PrivateBuild entry. + /// + PrivateBuild = 0x08, + /// + /// The file's version structure was created dynamically; therefore, some of the members in + /// this structure may be empty or incorrect. This flag should never be set in a file's + /// VS_VERSION_INFO data. + /// + InformationInferred = 0x10, + /// + /// The file was built by the original company using standard release procedures but is a variation + /// of the normal file of the same version number. If this flag is set, the StringFileInfo structure + /// should contain a SpecialBuild entry. + /// + SpecialBuild = 0x20 + } + + public abstract class VersionResourceChildBlock + { + public class VersionResourceChildBlockCollection + : System.Collections.ObjectModel.Collection + { + } + } + public class VersionResourceFixedFileInfoBlock + { + private bool mvarEnabled = true; + public bool Enabled { get { return mvarEnabled; } set { mvarEnabled = value; } } + + private Version mvarStructureVersion = new Version(); + public Version StructureVersion { get { return mvarStructureVersion; } set { mvarStructureVersion = value; } } + + private Version mvarFileVersion = new Version(); + public Version FileVersion { get { return mvarFileVersion; } set { mvarFileVersion = value; } } + + private Version mvarProductVersion = new Version(); + public Version ProductVersion { get { return mvarProductVersion; } set { mvarProductVersion = value; } } + + private VersionFileAttributes mvarFileAttributes = VersionFileAttributes.None; + /// + /// Contains a bitmask that specifies the Boolean attributes of the file. + /// + public VersionFileAttributes FileAttributes { get { return mvarFileAttributes; } set { mvarFileAttributes = value; } } + + private VersionFileAttributes mvarValidFileAttributes = VersionFileAttributes.None; + /// + /// Contains a bitmask that specifies the valid Boolean attributes of the file. An attribute is valid only if it was defined when the file was created. + /// + public VersionFileAttributes ValidFileAttributes { get { return mvarValidFileAttributes; } set { mvarValidFileAttributes = value; } } + + private VersionOperatingSystem mvarOperatingSystem = VersionOperatingSystem.Unknown; + /// + /// Specifies the operating system for which this file was designed. + /// + public VersionOperatingSystem OperatingSystem { get { return mvarOperatingSystem; } set { mvarOperatingSystem = value; } } + + private VersionFileType mvarFileType = VersionFileType.Unknown; + /// + /// Specifies the general type of file. + /// + public VersionFileType FileType { get { return mvarFileType; } set { mvarFileType = value; } } + + private VersionFileSubType mvarFileSubType = VersionFileSubType.Unknown; + /// + /// Specifies the function of the file. The possible values depend on the value of + /// . If is + /// , contains the virtual device identifier + /// included in the virtual device control block. + /// + public VersionFileSubType FileSubType { get { return mvarFileSubType; } set { mvarFileSubType = value; } } + + private DateTime mvarFileDate = DateTime.Now; + public DateTime FileDate { get { return mvarFileDate; } set { mvarFileDate = value; } } + } + + public class VersionResourceStringFileInfoBlockLanguage + { + public class VersionResourceStringFileInfoBlockEntryCollection + : System.Collections.ObjectModel.Collection + { + } + + private int mvarLanguageID = 0; + public int LanguageID { get { return mvarLanguageID; } set { mvarLanguageID = value; } } + + private VersionResourceStringTableEntry.VersionResourceStringTableEntryCollection mvarStringTableEntries = new VersionResourceStringTableEntry.VersionResourceStringTableEntryCollection(); + public VersionResourceStringTableEntry.VersionResourceStringTableEntryCollection StringTableEntries { get { return mvarStringTableEntries; } } + + public override string ToString() + { + return "0x" + mvarLanguageID.ToString("x"); + } + } + public class VersionResourceStringTableEntry + { + public class VersionResourceStringTableEntryCollection + : System.Collections.ObjectModel.Collection + { + } + + private string mvarName = String.Empty; + public string Name { get { return mvarName; } set { mvarName = value; } } + + private string mvarValue = String.Empty; + public string Value { get { return mvarValue; } set { mvarValue = value; } } + + public override string ToString() + { + return mvarName + ": \"" + mvarValue + "\""; + } + } + + public class VersionResourceStringFileInfoBlock : VersionResourceChildBlock + { + private VersionResourceStringFileInfoBlockLanguage.VersionResourceStringFileInfoBlockEntryCollection mvarEntries = new VersionResourceStringFileInfoBlockLanguage.VersionResourceStringFileInfoBlockEntryCollection(); + public VersionResourceStringFileInfoBlockLanguage.VersionResourceStringFileInfoBlockEntryCollection Entries { get { return mvarEntries; } } + + public override string ToString() + { + return "StringFileInfo"; + } + } + + public class VersionResourceVarFileInfoBlockEntry + { + public class VersionResourceVarFileInfoBlockEntryCollection + : System.Collections.ObjectModel.Collection + { + } + + private List mvarValues = new List(); + public List Values { get { return mvarValues; } } + + public override string ToString() + { + return "Translation"; + } + } + public class VersionResourceVarFileInfoBlock : VersionResourceChildBlock + { + private VersionResourceVarFileInfoBlockEntry.VersionResourceVarFileInfoBlockEntryCollection mvarEntries = new VersionResourceVarFileInfoBlockEntry.VersionResourceVarFileInfoBlockEntryCollection(); + public VersionResourceVarFileInfoBlockEntry.VersionResourceVarFileInfoBlockEntryCollection Entries { get { return mvarEntries; } } + + public override string ToString() + { + return "VarFileInfo"; + } + } + + /// + /// Represents a Version resource in an executable file (VS_VERSION_INFO on Windows). + /// + public class VersionResourceBlock : ExecutableResourceBlock + { + private ExecutableResourceType mvarType = ExecutableResourceType.Version; + public override ExecutableResourceType Type + { + get { return mvarType; } + } + + private VersionResourceFixedFileInfoBlock mvarFixedFileInfo = new VersionResourceFixedFileInfoBlock(); + public VersionResourceFixedFileInfoBlock FixedFileInfo { get { return mvarFixedFileInfo; } } + + private VersionResourceChildBlock.VersionResourceChildBlockCollection mvarChildBlocks = new VersionResourceChildBlock.VersionResourceChildBlockCollection(); + public VersionResourceChildBlock.VersionResourceChildBlockCollection ChildBlocks { get { return mvarChildBlocks; } } + + public override object Clone() + { + VersionResourceBlock clone = new VersionResourceBlock(); + return clone; + } + } +} \ No newline at end of file diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/Properties/AssemblyInfo.cs b/CSharp/Plugins/UniversalEditor.Plugins.Executable/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b60127c5 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UniversalEditor.Plugins.Executable")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("City of Orlando")] +[assembly: AssemblyProduct("UniversalEditor.Plugins.Executable")] +[assembly: AssemblyCopyright("Copyright © City of Orlando 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8fe9f020-8602-426c-b05e-7edabe3f3dd0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Executable/UniversalEditor.Plugins.Executable.csproj b/CSharp/Plugins/UniversalEditor.Plugins.Executable/UniversalEditor.Plugins.Executable.csproj new file mode 100644 index 00000000..c881bc71 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Plugins.Executable/UniversalEditor.Plugins.Executable.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {791A36F8-5D96-452B-89D2-78BA74596A1E} + Library + Properties + UniversalEditor + UniversalEditor.Plugins.Executable + v3.5 + 512 + + + true + full + false + ..\..\Output\Debug\Plugins\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\Output\Release\Plugins\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {a92d520b-ffa3-4464-8cf6-474d18959e03} + UniversalEditor.Core + + + {30467e5c-05bc-4856-aadc-13906ef4cadd} + UniversalEditor.Essential + + + + + \ No newline at end of file