Esempio n. 1
0
		public static void AddAndExecute(IUndoCommandManager undoCommandManager, HexDocument doc, ulong offset, byte[] data, string descr = null) {
			if (doc == null)
				throw new ArgumentNullException();
			if (data == null || data.Length == 0)
				return;
			undoCommandManager.Add(new WriteHexUndoCommand(doc, offset, data, descr));
		}
Esempio n. 2
0
		protected HexField(HexDocument doc, string parentName, string name, ulong start, int size) {
			this.doc = doc;
			this.parentName = parentName;
			this.name = name;
			this.startOffset = start;
			this.endOffset = start + (ulong)size - 1;
		}
Esempio n. 3
0
		WriteHexUndoCommand(HexDocument doc, ulong offset, byte[] data, string descr) {
			this.doc = doc;
			this.offset = offset;
			this.newData = (byte[])data.Clone();
			this.origData = this.doc.ReadBytes(offset, data.Length);
			this.descr = descr;
		}
Esempio n. 4
0
		public MetaDataTableNode(HexDocument doc, MDTable mdTable, IMetaData md)
			: base((ulong)mdTable.StartOffset, (ulong)mdTable.EndOffset - 1) {
			this.doc = doc;
			this.tableInfo = mdTable.TableInfo;
			this.tablesStreamVM = MetaDataTableVM.Create(this, doc, StartOffset, mdTable);
			this.tablesStreamVM.FindMetaDataTable = FindMetaDataTable;
			this.tablesStreamVM.InitializeHeapOffsets((ulong)md.StringsStream.StartOffset, (ulong)md.StringsStream.EndOffset - 1);
		}
Esempio n. 5
0
		public StorageStreamNode(HexDocument doc, StreamHeader sh, int streamNumber, DotNetStream knownStream, IMetaData md)
			: base((ulong)sh.StartOffset, (ulong)sh.EndOffset - 1) {
			this.streamNumber = streamNumber;
			this.storageStreamType = GetStorageStreamType(knownStream);
			this.storageStreamVM = new StorageStreamVM(this, doc, StartOffset, (int)(EndOffset - StartOffset + 1 - 8));

			var tblStream = knownStream as TablesStream;
			if (tblStream != null)
				this.newChild = new TablesStreamNode(doc, tblStream, md);
		}
Esempio n. 6
0
		public TablesStreamNode(HexDocument doc, TablesStream tblStream, IMetaData md)
			: base((ulong)tblStream.StartOffset, (ulong)tblStream.MDTables[0].StartOffset - 1) {
			this.tablesStreamVM = new TablesStreamVM(this, doc, tblStream);

			this.newChildren = new List<ITreeNodeData>();
			foreach (var mdTable in tblStream.MDTables) {
				if (mdTable.Rows != 0)
					this.newChildren.Add(new MetaDataTableNode(doc, mdTable, md));
			}
		}
Esempio n. 7
0
 public HexBoxFileTabContent(HexDocument hexDocument, IMenuManager menuManager, IHexEditorSettings hexEditorSettings, IAppSettings appSettings, Lazy<IHexBoxUndoManager> hexBoxUndoManager)
 {
     if (hexDocument == null)
         throw new ArgumentNullException();
     this.hexDocument = hexDocument;
     this.menuManager = menuManager;
     this.hexEditorSettings = hexEditorSettings;
     this.appSettings = appSettings;
     this.hexBoxUndoManager = hexBoxUndoManager;
 }
Esempio n. 8
0
		public HexBoxUndoCommand(HexBox hexBox, HexBoxPosition origCaretPos, ulong offset, byte[] origData, string descr) {
			this.doc = hexBox.Document;
			this.hexBoxWeakRef = new WeakReference(hexBox);
			this.origCaretPos = origCaretPos;
			this.newCaretPos = hexBox.CaretPosition;
			this.offset = offset;
			this.origData = origData;
			this.newData = doc.ReadBytes(offset, origData.Length);
			this.descr = descr;
			this.canExecute = false;
		}
Esempio n. 9
0
		public StorageStreamVM(object owner, HexDocument doc, ulong startOffset, int stringLen)
			: base(owner) {
			this.iOffsetVM = new UInt32HexField(doc, Name, "iOffset", startOffset + 0);
			this.iSizeVM = new UInt32HexField(doc, Name, "iSize", startOffset + 4);
			this.rcNameVM = new StringHexField(doc, Name, "rcName", startOffset + 8, Encoding.ASCII, stringLen);

			this.hexFields = new HexField[] {
				iOffsetVM,
				iSizeVM,
				rcNameVM,
			};
		}
Esempio n. 10
0
		public StorageHeaderVM(object owner, HexDocument doc, ulong startOffset)
			: base(owner) {
			this.fFlagsVM = new ByteFlagsHexField(doc, Name, "fFlags", startOffset + 0);
			this.fFlagsVM.Add(new BooleanHexBitField("ExtraData", 0));
			this.padVM = new ByteHexField(doc, Name, "pad", startOffset + 1);
			this.iStreamsVM = new UInt16HexField(doc, Name, "iStreams", startOffset + 2);

			this.hexFields = new HexField[] {
				fFlagsVM,
				padVM,
				iStreamsVM,
			};
		}
Esempio n. 11
0
		public ImageOptionalHeader32VM(object owner, HexDocument doc, ulong startOffset, ulong endOffset)
			: base(owner, doc, startOffset, endOffset, 0x20, 0x58) {
			this.baseOfDataVM = new UInt32HexField(doc, Name, "BaseOfData", startOffset + 0x18);
			this.imageBaseVM = new UInt32HexField(doc, Name, "ImageBase", startOffset + 0x1C);

			this.sizeOfStackReserveVM = new UInt32HexField(doc, Name, "SizeOfStackReserve", startOffset + 0x48);
			this.sizeOfStackCommitVM = new UInt32HexField(doc, Name, "SizeOfStackCommit", startOffset + 0x4C);
			this.sizeOfHeapReserveVM = new UInt32HexField(doc, Name, "SizeOfHeapReserve", startOffset + 0x50);
			this.sizeOfHeapCommitVM = new UInt32HexField(doc, Name, "SizeOfHeapCommit", startOffset + 0x54);

			var list = new List<HexField> {
				MagicVM,
				MajorLinkerVersionVM,
				MinorLinkerVersionVM,
				SizeOfCodeVM,
				SizeOfInitializedDataVM,
				SizeOfUninitializedDataVM,
				AddressOfEntryPointVM,
				BaseOfCodeVM,
				BaseOfDataVM,
				ImageBaseVM,
				SectionAlignmentVM,
				FileAlignmentVM,
				MajorOperatingSystemVersionVM,
				MinorOperatingSystemVersionVM,
				MajorImageVersionVM,
				MinorImageVersionVM,
				MajorSubsystemVersionVM,
				MinorSubsystemVersionVM,
				Win32VersionValueVM,
				SizeOfImageVM,
				SizeOfHeadersVM,
				CheckSumVM,
				SubsystemVM,
				DllCharacteristicsVM,
				SizeOfStackReserveVM,
				SizeOfStackCommitVM,
				SizeOfHeapReserveVM,
				SizeOfHeapCommitVM,
				LoaderFlagsVM,
				NumberOfRvaAndSizesVM,
			};

			AddDataDirs(list, endOffset);
		}
Esempio n. 12
0
		public StorageSignatureVM(object owner, HexDocument doc, ulong startOffset, int stringLen)
			: base(owner) {
			this.lSignatureVM = new UInt32HexField(doc, Name, "lSignature", startOffset + 0);
			this.iMajorVerVM = new UInt16HexField(doc, Name, "iMajorVer", startOffset + 4, true);
			this.iMinorVerVM = new UInt16HexField(doc, Name, "iMinorVer", startOffset + 6, true);
			this.iExtraDataVM = new UInt32HexField(doc, Name, "iExtraData", startOffset + 8);
			this.iVersionStringVM = new UInt32HexField(doc, Name, "iVersionString", startOffset + 0x0C);
			this.versionStringVM = new StringHexField(doc, Name, "VersionString", startOffset + 0x10, Encoding.UTF8, stringLen);

			this.hexFields = new HexField[] {
				lSignatureVM,
				iMajorVerVM,
				iMinorVerVM,
				iExtraDataVM,
				iVersionStringVM,
				versionStringVM,
			};
		}
Esempio n. 13
0
		public ImageSectionHeaderNode(HexDocument doc, ImageSectionHeader sectHdr, int sectionNumber)
			: base((ulong)sectHdr.StartOffset, (ulong)sectHdr.EndOffset - 1) {
			this.sectionNumber = sectionNumber;
			this.imageSectionHeaderVM = new ImageSectionHeaderVM(this, doc, StartOffset);
		}
Esempio n. 14
0
		public DataDirVM(HexDocument doc, string parentName, string name, ulong start) {
			this.name = name;
			this.rvaVM = new UInt32HexField(doc, parentName, string.Format(dnSpy_AsmEditor_Resources.HexField_RelativeVirtualAddress, name), start);
			this.sizeVM = new UInt32HexField(doc, parentName, string.Format(dnSpy_AsmEditor_Resources.HexField_Size, name), start + 4);
		}
Esempio n. 15
0
		public UInt64FlagsHexField(HexDocument doc, string parentName, string name, ulong start)
			: base(doc, parentName, name, start, 8) {
			this.data = new UInt64VM(doc.ReadUInt64(start), a => UpdateValue(), false);
		}
Esempio n. 16
0
		public Int16FlagsHexField(HexDocument doc, string parentName, string name, ulong start)
			: base(doc, parentName, name, start, 2) {
			this.data = new Int16VM(doc.ReadInt16(start), a => UpdateValue(), false);
		}
Esempio n. 17
0
		public ByteFlagsHexField(HexDocument doc, string parentName, string name, ulong start)
			: base(doc, parentName, name, start, 1) {
			this.data = new ByteVM((byte)doc.ReadByte(start), a => UpdateValue(), false);
		}
Esempio n. 18
0
		internal static UInt16FlagsHexField CreateGenericParamAttributesField(ColumnInfo colInfo, HexDocument doc, string name, ulong startOffset) {
			var field = new UInt16FlagsHexField(doc, name, colInfo.Name, startOffset + (uint)colInfo.Offset);
			field.Add(new IntegerHexBitField("Variance", 0, 2, VarianceInfos));
			field.Add(new BooleanHexBitField("Reference", 2));
			field.Add(new BooleanHexBitField("Struct", 3));
			field.Add(new BooleanHexBitField("Default ctor", 4));
			return field;
		}
Esempio n. 19
0
		protected ImageOptionalHeaderVM(object owner, HexDocument doc, ulong startOffset, ulong endOffset, ulong offs1, ulong offs2)
			: base(owner) {
			this.magicVM = new UInt16HexField(doc, Name, "Magic", startOffset + 0);
			this.majorLinkerVersionVM = new ByteHexField(doc, Name, "MajorLinkerVersion", startOffset + 2, true);
			this.minorLinkerVersionVM = new ByteHexField(doc, Name, "MinorLinkerVersion", startOffset + 3, true);
			this.sizeOfCodeVM = new UInt32HexField(doc, Name, "SizeOfCode", startOffset + 4);
			this.sizeOfInitializedDataVM = new UInt32HexField(doc, Name, "SizeOfInitializedData", startOffset + 8);
			this.sizeOfUninitializedDataVM = new UInt32HexField(doc, Name, "SizeOfUninitializedData", startOffset + 0x0C);
			this.addressOfEntryPointVM = new UInt32HexField(doc, Name, "AddressOfEntryPoint", startOffset + 0x10);
			this.baseOfCodeVM = new UInt32HexField(doc, Name, "BaseOfCode", startOffset + 0x14);

			this.sectionAlignmentVM = new UInt32HexField(doc, Name, "SectionAlignment", startOffset + offs1 + 0);
			this.fileAlignmentVM = new UInt32HexField(doc, Name, "FileAlignment", startOffset + offs1 + 4);
			this.majorOperatingSystemVersionVM = new UInt16HexField(doc, Name, "MajorOperatingSystemVersion", startOffset + offs1 + 8, true);
			this.minorOperatingSystemVersionVM = new UInt16HexField(doc, Name, "MinorOperatingSystemVersion", startOffset + offs1 + 0x0A, true);
			this.majorImageVersionVM = new UInt16HexField(doc, Name, "MajorImageVersion", startOffset + offs1 + 0x0C, true);
			this.minorImageVersionVM = new UInt16HexField(doc, Name, "MinorImageVersion", startOffset + offs1 + 0x0E, true);
			this.majorSubsystemVersionVM = new UInt16HexField(doc, Name, "MajorSubsystemVersion", startOffset + offs1 + 0x10, true);
			this.minorSubsystemVersionVM = new UInt16HexField(doc, Name, "MinorSubsystemVersion", startOffset + offs1 + 0x12, true);
			this.win32VersionValueVM = new UInt32HexField(doc, Name, "Win32VersionValue", startOffset + offs1 + 0x14, true);
			this.sizeOfImageVM = new UInt32HexField(doc, Name, "SizeOfImage", startOffset + offs1 + 0x18);
			this.sizeOfHeadersVM = new UInt32HexField(doc, Name, "SizeOfHeaders", startOffset + offs1 + 0x1C);
			this.checkSumVM = new UInt32HexField(doc, Name, "CheckSum", startOffset + offs1 + 0x20);
			this.subsystemVM = new UInt16FlagsHexField(doc, Name, "Subsystem", startOffset + offs1 + 0x24);
			this.subsystemVM.Add(new IntegerHexBitField("Subsystem", 0, 16, SubsystemInfos));
			this.dllCharacteristicsVM = new UInt16FlagsHexField(doc, Name, "DllCharacteristics", startOffset + offs1 + 0x26);
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("Reserved1", 0));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("Reserved2", 1));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("Reserved3", 2));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("Reserved4", 3));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("Reserved5", 4));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("High Entropy VA", 5));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("Dynamic Base", 6));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("Force Integrity", 7));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("NX Compat", 8));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("No Isolation", 9));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("No SEH", 10));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("No Bind", 11));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("AppContainer", 12));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("WDM Driver", 13));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("Guard CF", 14));
			this.dllCharacteristicsVM.Add(new BooleanHexBitField("Terminal Server Aware", 15));
			this.loaderFlagsVM = new UInt32HexField(doc, Name, "LoaderFlags", startOffset + offs2 + 0);
			this.numberOfRvaAndSizesVM = new UInt32HexField(doc, Name, "NumberOfRvaAndSizes", startOffset + offs2 + 4);

			ulong doffs = offs2 + 8;
			this.dataDir0VM = new DataDirVM(doc, Name, "Export", startOffset + doffs + 0);
			this.dataDir1VM = new DataDirVM(doc, Name, "Import", startOffset + doffs + 8);
			this.dataDir2VM = new DataDirVM(doc, Name, "Resource", startOffset + doffs + 0x10);
			this.dataDir3VM = new DataDirVM(doc, Name, "Exception", startOffset + doffs + 0x18);
			this.dataDir4VM = new DataDirVM(doc, Name, "Security", startOffset + doffs + 0x20);
			this.dataDir5VM = new DataDirVM(doc, Name, "Base Reloc", startOffset + doffs + 0x28);
			this.dataDir6VM = new DataDirVM(doc, Name, "Debug", startOffset + doffs + 0x30);
			this.dataDir7VM = new DataDirVM(doc, Name, "Architecture", startOffset + doffs + 0x38);
			this.dataDir8VM = new DataDirVM(doc, Name, "Global Ptr", startOffset + doffs + 0x40);
			this.dataDir9VM = new DataDirVM(doc, Name, "TLS", startOffset + doffs + 0x48);
			this.dataDir10VM = new DataDirVM(doc, Name, "Load Config", startOffset + doffs + 0x50);
			this.dataDir11VM = new DataDirVM(doc, Name, "Bound Import", startOffset + doffs + 0x58);
			this.dataDir12VM = new DataDirVM(doc, Name, "IAT", startOffset + doffs + 0x60);
			this.dataDir13VM = new DataDirVM(doc, Name, "Delay Import", startOffset + doffs + 0x68);
			this.dataDir14VM = new DataDirVM(doc, Name, ".NET", startOffset + doffs + 0x70);
			this.dataDir15VM = new DataDirVM(doc, Name, "Reserved15", startOffset + doffs + 0x78);
		}
Esempio n. 20
0
		internal static UInt32FlagsHexField CreateAssemblyAttributesField(ColumnInfo colInfo, HexDocument doc, string name, ulong startOffset) {
			var field = new UInt32FlagsHexField(doc, name, colInfo.Name, startOffset + (uint)colInfo.Offset);
			field.Add(new BooleanHexBitField("PublicKey", 0));
			field.Add(new IntegerHexBitField("Processor Arch", 4, 3, PAInfos));
			field.Add(new BooleanHexBitField("Processor Arch Specified", 7));
			field.Add(new BooleanHexBitField("Retargetable", 8));
			field.Add(new IntegerHexBitField("ContentType", 9, 3, ContentTypeInfos));
			field.Add(new BooleanHexBitField("DisableJITcompileOptimizer", 14));
			field.Add(new BooleanHexBitField("EnableJITcompileTracking", 15));
			return field;
		}
Esempio n. 21
0
		public UInt64HexField(HexDocument doc, string parentName, string name, ulong start, bool useDecimal = false)
			: base(doc, parentName, name, start, 8) {
			this.data = new UInt64VM(doc.ReadUInt64(start), a => UpdateValue(), useDecimal);
		}
Esempio n. 22
0
		public Int32HexField(HexDocument doc, string parentName, string name, ulong start, bool useDecimal = false)
			: base(doc, parentName, name, start, 4) {
			this.data = new Int32VM(doc.ReadInt32(start), a => UpdateValue(), useDecimal);
		}
Esempio n. 23
0
		uint ReadFieldValue(HexDocument doc, ColumnInfo col) {
			ulong start = StartOffset + (ulong)col.Offset;
			if (col.Size == 2)
				return doc.ReadUInt16(start);
			else if (col.Size == 4)
				return doc.ReadUInt32(start);
			throw new InvalidOperationException();
		}
Esempio n. 24
0
        void AddHooks(HexDocument doc)
        {
            if (doc == null)
                return;
            if (!IsLoaded)
                return;

            doc.OnDocumentModified += OnDocumentModified;
            InvalidateCachedLinesAndRefresh();
        }
Esempio n. 25
0
		public ImageOptionalHeader32Node(HexDocument doc, ImageOptionalHeader32 optHdr)
			: base((ulong)optHdr.StartOffset, (ulong)optHdr.EndOffset - 1) {
			this.imageOptionalHeader32VM = new ImageOptionalHeader32VM(this, doc, StartOffset, EndOffset);
		}
Esempio n. 26
0
		protected FlagsHexField(HexDocument doc, string parentName, string name, ulong start, int size)
			: base(doc, parentName, name, start, size) {
			this.bitFields = new Dictionary<int, HexBitField>();
		}
Esempio n. 27
0
		public StringHexField(HexDocument doc, string parentName, string name, ulong start, Encoding encoding, int dataLen)
			: base(doc, parentName, name, start, dataLen) {
			this.encoding = encoding;
            this.data = new StringVM((string)ReadData(), a => UpdateValue());
		}
Esempio n. 28
0
		internal static UInt32FlagsHexField CreateTypeAttributesField(ColumnInfo colInfo, HexDocument doc, string name, ulong startOffset) {
			var field = new UInt32FlagsHexField(doc, name, colInfo.Name, startOffset + (uint)colInfo.Offset);
			field.Add(new IntegerHexBitField("Visibility", 0, 3, VisibilityInfos));
			field.Add(new IntegerHexBitField("Layout", 3, 2, LayoutInfos));
			field.Add(new IntegerHexBitField("Semantics", 5, 1, SemanticsInfos));
			field.Add(new BooleanHexBitField("Abstract", 7));
			field.Add(new BooleanHexBitField("Sealed", 8));
			field.Add(new BooleanHexBitField("SpecialName", 10));
			field.Add(new BooleanHexBitField("RTSpecialName", 11));
			field.Add(new BooleanHexBitField("Import", 12));
			field.Add(new BooleanHexBitField("Serializable", 13));
			field.Add(new BooleanHexBitField("WindowsRuntime", 14));
			field.Add(new IntegerHexBitField("String", 16, 2, StringFormatInfos));
			field.Add(new BooleanHexBitField("HasSecurity", 18));
			field.Add(new BooleanHexBitField("BeforeFieldInit", 20));
			field.Add(new BooleanHexBitField("Forwarder", 21));
			field.Add(new IntegerHexBitField("Custom", 22, 2, CustomFormatInfos));
			return field;
		}
Esempio n. 29
0
        void RemoveHooks(HexDocument doc)
        {
            if (doc == null)
                return;

            doc.OnDocumentModified -= OnDocumentModified;
            InvalidateCachedLinesAndRefresh();
        }
Esempio n. 30
0
		public ByteHexField(HexDocument doc, string parentName, string name, ulong start, bool useDecimal = false)
			: base(doc, parentName, name, start, 1) {
			this.data = new ByteVM((byte)doc.ReadByte(start), a => UpdateValue(), useDecimal);
		}