public void Write(WriterContext ctxt, BlobWriter writer, bool isFat, Func <OpCode, object, Row> findRow) { if (isFat) { writer.WriteUInt32((uint)Flags); writer.WriteUInt32((uint)TryOffset); writer.WriteUInt32((uint)TryLength); writer.WriteUInt32((uint)HandlerOffset); writer.WriteUInt32((uint)HandlerLength); } else { writer.WriteUInt16((ushort)Flags); writer.WriteUInt16((ushort)TryOffset); writer.WriteByte((byte)TryLength); writer.WriteUInt16((ushort)HandlerOffset); writer.WriteByte((byte)HandlerLength); } var rowRef = default(TokenRef); rowRef.Value = Class == null ? null : findRow(OpCode.Ldobj, Class); rowRef.PersistIndexes(ctxt); rowRef.Write(ctxt, writer); if (Flags == CorILExceptionClause.Filter) { writer.WriteUInt32((uint)FilterOffset); } }
private void WriteMethodDataSection(WriterContext ctxt, BlobWriter writer, bool isMoreSects, Func <OpCode, object, Row> findRow) { writer.Align(4); var size = ExceptionHandlingClauses.Count * 12 + 4; var isFat = size > 0xff || ExceptionHandlingClauses.Any(m => m.IsFat()); var flags = CorILMethodSect.EHTable; if (isFat) { flags |= CorILMethodSect.FatFormat; } if (isMoreSects) { flags |= CorILMethodSect.MoreSects; } writer.WriteByte((byte)flags); if (isFat) { size = ExceptionHandlingClauses.Count * 24 + 4; writer.WriteUInt24((uint)size); } else { writer.WriteByte((byte)size); writer.WriteUInt16(0); } for (var i = 0; i < ExceptionHandlingClauses.Count; i++) { ExceptionHandlingClauses[i].Write(ctxt, writer, isFat, findRow); } }
public void Write(WriterContext ctxt, BlobWriter writer, bool isFat, Func<OpCode, object, Row> findRow) { if (isFat) { writer.WriteUInt32((uint)Flags); writer.WriteUInt32((uint)TryOffset); writer.WriteUInt32((uint)TryLength); writer.WriteUInt32((uint)HandlerOffset); writer.WriteUInt32((uint)HandlerLength); } else { writer.WriteUInt16((ushort)Flags); writer.WriteUInt16((ushort)TryOffset); writer.WriteByte((byte)TryLength); writer.WriteUInt16((ushort)HandlerOffset); writer.WriteByte((byte)HandlerLength); } var rowRef = default(TokenRef); rowRef.Value = Class == null ? null : findRow(OpCode.Ldobj, Class); rowRef.PersistIndexes(ctxt); rowRef.Write(ctxt, writer); if (Flags == CorILExceptionClause.Filter) writer.WriteUInt32((uint)FilterOffset); }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteBytes(prefix); LfaNew.Write(writer); writer.WriteBytes(suffix); writer.WriteUInt32(Final); }
public void Write(WriterContext ctxt, BlobWriter writer, Func <OpCode, object, Row> findRow) { var bodySize = 0; for (var i = 0; i < Instructions.Length; i++) { bodySize += Instructions[i].Size(); } var isFat = bodySize > 0x3f; if (LocalVariables != null && LocalVariables.Variables.Count > 0) { isFat = true; } if (ExceptionHandlingClauses.Count > 0 || MaxStack > 8) { isFat = true; } if (isFat) { var flags = CorILMethod.FatFormat; if (IsInitLocals) { flags |= CorILMethod.InitLocals; } if (ExceptionHandlingClauses.Count > 0) { flags |= CorILMethod.MoreSects; } var firstWord = (ushort)((uint)flags | (3 << 12)); writer.WriteUInt16(firstWord); writer.WriteUInt16((ushort)MaxStack); writer.WriteUInt32((uint)bodySize); LocalVarRef.PersistIndexes(ctxt); LocalVarRef.Write(ctxt, writer); } else { var firstByte = (byte)CorILMethod.TinyFormat; firstByte |= (byte)(bodySize << 2); writer.WriteByte(firstByte); } if (Instructions != null && Instructions.Length > 0) { var beginOffset = writer.Offset; for (var i = 0; i < Instructions.Length; i++) { Instructions[i].Write(ctxt, writer, beginOffset, findRow); } } if (ExceptionHandlingClauses.Count > 0) { WriteMethodDataSection(ctxt, writer, false, findRow); } }
public void WriteContents(BlobWriter writer) { var length = writer.dataLimit - writer.baseOffset; Prepare(length); Array.Copy(writer.data, writer.baseOffset, data, currOffset, length); currOffset += length; }
private static void WriteUserString(WriterContext ctxt, BlobWriter writer, string str) { var strref = default(UserStringRef); strref.Value = str; strref.PersistIndexes(ctxt); strref.Write(ctxt, writer); }
private static void WriteToken(WriterContext ctxt, BlobWriter writer, Row row) { var rowRef = default(TokenRef); rowRef.Value = row; rowRef.PersistIndexes(ctxt); rowRef.Write(ctxt, writer); }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteUInt32(prefix); writer.WriteUInt16(machine); writer.WriteUInt16(NumberOfSections); var seconds = (uint)(DateTimeStamp.ToUniversalTime() - nineteenSeventy).TotalSeconds; writer.WriteUInt32(seconds); writer.WriteUInt32(pointerToSymbolTable); writer.WriteUInt32(numberOfSymbols); writer.WriteUInt16(PEOptionalHeader.Size); writer.WriteUInt16((ushort)Flags); }
private void Write(WriterContext ctxt) { // TextSection.PointerToRawData = Helpers.Align((uint)(376 + 40 * PEFileHeader.NumberOfSections), PEOptionalHeader.NTSpecificFields.SectionAlignment); TextSection.PointerToRawData = 0x200; PEOptionalHeader.StandardFields.EntryPointRVA = WriteEntryPoint(); RelocationTable.Blocks.Add (new FixupBlock { PageRVA = TextSection.PointerToRawData, Entries = { new FixupEntry { Offset = (ushort) (PEOptionalHeader.StandardFields.EntryPointRVA - TextSection.PointerToRawData), Type = ImageRelocation.IMAGE_REL_BASED_HIGHLOW } } }); MetadataTables.PersistIndexes(this); MetadataHeader.PersistIndexes(this); CLIHeader.PersistIndexes(this); ImportAddressTable.PersistIndexes(this); ImportLookupTable.PersistIndexes(this); ImportTable.PersistIndexes(this); DosHeader.PersistIndexes(this); PEFileHeader.PersistIndexes(this); PEOptionalHeader.PersistIndexes(this); RelocationTable.Write(RelocationSection.Writer); foreach (var sectionHeader in SectionHeaders) { sectionHeader.PersistIndexes(this); } PEOptionalHeader.DataDirectories.BaseRelocationTable = RelocationSection.PointerToRawData; InitializePEFile(); PersistIndexes(); var writer = new BlobWriter(); DosHeader.Write(writer); PEFileHeader.Write(writer); PEOptionalHeader.Write(writer); // TODO: precalc offsets in written section headers... // TODO: Write stream data foreach (var sectionHeader in SectionHeaders) { sectionHeader.Write(writer); } foreach (var sectionHeader in SectionHeaders) { writer.EnsureAtOffset(sectionHeader.PointerToRawData); sectionHeader.WriteData(this, writer); } return writer.GetBlob(); }
public void Write(WriterContext ctxt, BlobWriter writer) { var word = (ushort)(((byte)Type) << 12 | Offset); writer.WriteUInt16(word); }
public void Write(WriterContext ctxt, BlobWriter writer) { HintNameTable.Write(writer); writer.WriteUInt32(padding); }
public void Write(WriterContext ctxt, BlobWriter writer) { var name = default(string); switch (Section) { case Section.Text: name = ".text"; break; case Section.Rsrc: name = ".rsrc"; break; case Section.Reloc: name = ".reloc"; break; default: throw new ArgumentOutOfRangeException(); } writer.WriteAsciiZeroPaddedString(name, 8); writer.WriteUInt32(VirtualSize); writer.WriteUInt32(VirtualAddress); writer.WriteUInt32(SizeOfRawData); PointerToRawData.Write(writer); writer.WriteUInt32(PointerToRelocations); writer.WriteUInt32(pointerToLinenumbers); writer.WriteUInt16(NumberOfRelocations); writer.WriteUInt16(numberOfLinenumbers); writer.WriteUInt32((uint)Characteristics); }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteUInt64(exportTable); ImportTable.Write(writer); ResourceTable.Write(writer); writer.WriteUInt64(exceptionTable); CertificateTable.Write(writer); BaseRelocationTable.Write(writer); Debug.Write(writer); writer.WriteUInt64(copyright); writer.WriteUInt64(globalPtr); writer.WriteUInt64(tlsTable); writer.WriteUInt64(loadConfigTable); writer.WriteUInt64(boundImport); IAT.Write(writer); writer.WriteUInt64(delayImportDescriptor); CLIHeader.Write(writer); writer.WriteUInt64(reserved); }
private static void WriteToken(WriterContext ctxt, BlobWriter writer, Row row) { var rowRef = default(TokenRef); rowRef.Value = row; rowRef.PersistIndexes(ctxt); rowRef.Write(ctxt, writer); }
public override void Write(WriterContext ctxt, BlobWriter writer) { base.Write(ctxt, writer); Method.Write(ctxt, writer); }
private void WriteMethodDataSection(WriterContext ctxt, BlobWriter writer, bool isMoreSects, Func<OpCode, object, Row> findRow) { writer.Align(4); var size = ExceptionHandlingClauses.Count * 12 + 4; var isFat = size > 0xff || ExceptionHandlingClauses.Any(m => m.IsFat()); var flags = CorILMethodSect.EHTable; if (isFat) flags |= CorILMethodSect.FatFormat; if (isMoreSects) flags |= CorILMethodSect.MoreSects; writer.WriteByte((byte)flags); if (isFat) { size = ExceptionHandlingClauses.Count * 24 + 4; writer.WriteUInt24((uint)size); } else { writer.WriteByte((byte)size); writer.WriteUInt16(0); } for (var i = 0; i < ExceptionHandlingClauses.Count; i++) ExceptionHandlingClauses[i].Write(ctxt, writer, isFat, findRow); }
public void Write(WriterContext ctxt, BlobWriter writer, Func<OpCode, object, Row> findRow) { var bodySize = 0; for (var i = 0; i < Instructions.Length; i++) bodySize += Instructions[i].Size(); var isFat = bodySize > 0x3f; if (LocalVariables != null && LocalVariables.Variables.Count > 0) isFat = true; if (ExceptionHandlingClauses.Count > 0 || MaxStack > 8) isFat = true; if (isFat) { var flags = CorILMethod.FatFormat; if (IsInitLocals) flags |= CorILMethod.InitLocals; if (ExceptionHandlingClauses.Count > 0) flags |= CorILMethod.MoreSects; var firstWord = (ushort)((uint)flags | (3 << 12)); writer.WriteUInt16(firstWord); writer.WriteUInt16((ushort)MaxStack); writer.WriteUInt32((uint)bodySize); LocalVarRef.PersistIndexes(ctxt); LocalVarRef.Write(ctxt, writer); } else { var firstByte = (byte)CorILMethod.TinyFormat; firstByte |= (byte)(bodySize << 2); writer.WriteByte(firstByte); } if (Instructions != null && Instructions.Length > 0) { var beginOffset = writer.Offset; for (var i = 0; i < Instructions.Length; i++) Instructions[i].Write(ctxt, writer, beginOffset, findRow); } if (ExceptionHandlingClauses.Count > 0) WriteMethodDataSection(ctxt, writer, false, findRow); }
public void Write(WriterContext ctxt, BlobWriter writer, uint beginOffset, Func <OpCode, object, Row> findRow) { var offset = (int)(writer.Offset - beginOffset); if (offset != Offset) { throw new PEException("invalid instruction offset"); } var highByte = (ushort)OpCode >> 8; if (highByte > 0) { writer.WriteByte((byte)highByte); } writer.WriteByte((byte)OpCode); switch (OpCode) { case OpCode.Nop: case OpCode.Break: case OpCode.Ldarg_0: case OpCode.Ldarg_1: case OpCode.Ldarg_2: case OpCode.Ldarg_3: case OpCode.Ldloc_0: case OpCode.Ldloc_1: case OpCode.Ldloc_2: case OpCode.Ldloc_3: case OpCode.Stloc_0: case OpCode.Stloc_1: case OpCode.Stloc_2: case OpCode.Stloc_3: case OpCode.Ldnull: case OpCode.Ldc_i4_m1: case OpCode.Ldc_i4_0: case OpCode.Ldc_i4_1: case OpCode.Ldc_i4_2: case OpCode.Ldc_i4_3: case OpCode.Ldc_i4_4: case OpCode.Ldc_i4_5: case OpCode.Ldc_i4_6: case OpCode.Ldc_i4_7: case OpCode.Ldc_i4_8: case OpCode.Dup: case OpCode.Pop: case OpCode.Ret: case OpCode.Ldind_i1: case OpCode.Ldind_u1: case OpCode.Ldind_i2: case OpCode.Ldind_u2: case OpCode.Ldind_i4: case OpCode.Ldind_u4: case OpCode.Ldind_i8: case OpCode.Ldind_i: case OpCode.Ldind_r4: case OpCode.Ldind_r8: case OpCode.Ldind_ref: case OpCode.Stind_ref: case OpCode.Stind_i1: case OpCode.Stind_i2: case OpCode.Stind_i4: case OpCode.Stind_i8: case OpCode.Stind_r4: case OpCode.Stind_r8: case OpCode.Add: case OpCode.Sub: case OpCode.Mul: case OpCode.Div: case OpCode.Div_un: case OpCode.Rem: case OpCode.Rem_un: case OpCode.And: case OpCode.Or: case OpCode.Xor: case OpCode.Shl: case OpCode.Shr: case OpCode.Shr_un: case OpCode.Neg: case OpCode.Not: case OpCode.Conv_i1: case OpCode.Conv_i2: case OpCode.Conv_i4: case OpCode.Conv_i8: case OpCode.Conv_r4: case OpCode.Conv_r8: case OpCode.Conv_u4: case OpCode.Conv_u8: case OpCode.Conv_r_un: case OpCode.Throw: case OpCode.Conv_ovf_i1_un: case OpCode.Conv_ovf_i2_un: case OpCode.Conv_ovf_i4_un: case OpCode.Conv_ovf_i8_un: case OpCode.Conv_ovf_u1_un: case OpCode.Conv_ovf_u2_un: case OpCode.Conv_ovf_u4_un: case OpCode.Conv_ovf_u8_un: case OpCode.Conv_ovf_i_un: case OpCode.Conv_ovf_u_un: case OpCode.Ldlen: case OpCode.Ldelem_i1: case OpCode.Ldelem_u1: case OpCode.Ldelem_i2: case OpCode.Ldelem_u2: case OpCode.Ldelem_i4: case OpCode.Ldelem_u4: case OpCode.Ldelem_i8: case OpCode.Ldelem_i: case OpCode.Ldelem_r4: case OpCode.Ldelem_r8: case OpCode.Ldelem_ref: case OpCode.Stelem_i: case OpCode.Stelem_i1: case OpCode.Stelem_i2: case OpCode.Stelem_i4: case OpCode.Stelem_i8: case OpCode.Stelem_r4: case OpCode.Stelem_r8: case OpCode.Stelem_ref: case OpCode.Conv_ovf_i1: case OpCode.Conv_ovf_u1: case OpCode.Conv_ovf_i2: case OpCode.Conv_ovf_u2: case OpCode.Conv_ovf_i4: case OpCode.Conv_ovf_u4: case OpCode.Conv_ovf_i8: case OpCode.Conv_ovf_u8: case OpCode.Ckfinite: case OpCode.Conv_u2: case OpCode.Conv_u1: case OpCode.Conv_i: case OpCode.Conv_ovf_i: case OpCode.Conv_ovf_u: case OpCode.Add_ovf: case OpCode.Add_ovf_un: case OpCode.Mul_ovf: case OpCode.Mul_ovf_un: case OpCode.Sub_ovf: case OpCode.Sub_ovf_un: case OpCode.Endfinally: case OpCode.Stind_i: case OpCode.Conv_u: case OpCode.Prefix7: case OpCode.Prefix6: case OpCode.Prefix5: case OpCode.Prefix4: case OpCode.Prefix3: case OpCode.Prefix2: case OpCode.Prefix1: case OpCode.Prefixref: case OpCode.Arglist: case OpCode.Ceq: case OpCode.Cgt: case OpCode.Cgt_un: case OpCode.Clt: case OpCode.Clt_un: case OpCode.Localloc: case OpCode.Endfilter: case OpCode.Volatile: case OpCode.Tailcall: case OpCode.Cpblk: case OpCode.Initblk: case OpCode.Rethrow: case OpCode.Refanytype: case OpCode.Readonly: break; case OpCode.Br: case OpCode.Brfalse: case OpCode.Brtrue: case OpCode.Beq: case OpCode.Bge: case OpCode.Bgt: case OpCode.Ble: case OpCode.Blt: case OpCode.Bne_un: case OpCode.Bge_un: case OpCode.Bgt_un: case OpCode.Ble_un: case OpCode.Blt_un: case OpCode.Leave: { var target = (int)Value; // NOTE: Delta is relatative to start of next instruction var delta = (int)beginOffset + target - ((int)writer.Offset + 4); writer.WriteInt32(delta); } break; case OpCode.Br_s: case OpCode.Brfalse_s: case OpCode.Brtrue_s: case OpCode.Beq_s: case OpCode.Bge_s: case OpCode.Bgt_s: case OpCode.Ble_s: case OpCode.Blt_s: case OpCode.Bne_un_s: case OpCode.Bge_un_s: case OpCode.Bgt_un_s: case OpCode.Ble_un_s: case OpCode.Blt_un_s: case OpCode.Leave_s: { var target = (int)Value; // NOTE: Delta is w.r.t. begining of next instruction var delta = (int)beginOffset + target - ((int)writer.Offset + 1); if (delta > 0xff) { throw new PEException("cannot use small form for this instruction"); } writer.WriteSByte((sbyte)delta); } break; case OpCode.Ldc_i4_s: writer.WriteSByte((sbyte)(int)Value); break; case OpCode.Ldarg_s: case OpCode.Ldarga_s: case OpCode.Starg_s: case OpCode.Ldloc_s: case OpCode.Ldloca_s: case OpCode.Stloc_s: case OpCode.Unaligned: writer.WriteByte((byte)(int)Value); break; case OpCode.Ldc_i4: writer.WriteInt32((int)Value); break; case OpCode.Ldarg: case OpCode.Ldarga: case OpCode.Starg: case OpCode.Ldloc: case OpCode.Ldloca: case OpCode.Stloc: writer.WriteUInt32((uint)(int)Value); break; case OpCode.Ldc_i8: writer.WriteInt64((long)Value); break; case OpCode.Ldc_r4: writer.WriteSingle((float)Value); break; case OpCode.Ldc_r8: writer.WriteDouble((double)Value); break; case OpCode.Ldstr: WriteUserString(ctxt, writer, (string)Value); break; case OpCode.Switch: { var targets = (Seq <int>)Value; writer.WriteUInt32((uint)targets.Count); // NOTE: Deltas are w.r.t. start of next instruction for (var i = 0; i < targets.Count; i++) { var delta = (int)beginOffset + targets[i] - ((int)writer.Offset + (targets.Count * 4)); writer.WriteInt32(delta); } } break; case OpCode.Calli: case OpCode.Jmp: case OpCode.Call: case OpCode.Callvirt: case OpCode.Newobj: case OpCode.Ldftn: case OpCode.Ldvirtftn: case OpCode.Ldfld: case OpCode.Ldflda: case OpCode.Stfld: case OpCode.Ldsfld: case OpCode.Ldsflda: case OpCode.Stsfld: case OpCode.Ldtoken: case OpCode.Cpobj: case OpCode.Ldobj: case OpCode.Castclass: case OpCode.Isinst: case OpCode.Unbox: case OpCode.Stobj: case OpCode.Box: case OpCode.Newarr: case OpCode.Ldelema: case OpCode.Ldelem: case OpCode.Stelem: case OpCode.Unbox_any: case OpCode.Refanyval: case OpCode.Mkrefany: case OpCode.Initobj: case OpCode.Constrained: case OpCode.Sizeof: WriteToken(ctxt, writer, findRow(OpCode, Value)); break; default: throw new PEException("unrecognised opcode"); } }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteUInt16(magic); writer.WriteByte(LMajor); writer.WriteByte(lMinor); writer.WriteUInt32(CodeSize); writer.WriteUInt32(InitializedDataSize); writer.WriteUInt32(uninitializedDataSize); EntryPoint.Write(writer); BaseOfCode.Write(writer); BaseOfData.Write(writer); }
private static void WriteUserString(WriterContext ctxt, BlobWriter writer, string str) { var strref = default(UserStringRef); strref.Value = str; strref.PersistIndexes(ctxt); strref.Write(ctxt, writer); }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteUInt32(ImageBase); writer.WriteUInt32(sectionAlignment); writer.WriteUInt32(FileAlignment); writer.WriteUInt16(osMajor); writer.WriteUInt16(osMinor); writer.WriteUInt16(userMajor); writer.WriteUInt16(userMinor); writer.WriteUInt16(subSysMajor); writer.WriteUInt16(subSysMinor); writer.WriteUInt32(reserved); writer.WriteUInt32(ImageSize); writer.WriteUInt32(HeaderSize); writer.WriteUInt32(FileChecksum); writer.WriteUInt16((ushort)SubSystem); writer.WriteUInt16(DllFlags); writer.WriteUInt32(stackReserveSize); writer.WriteUInt32(StackCommitSize); writer.WriteUInt32(HeapReserveSize); writer.WriteUInt32(HeapCommitSize); writer.WriteUInt32(loaderFlags); writer.WriteUInt32(numberOfDataDirectories); }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteUInt32(Page); var blockSize = (uint)((Entries.Length * FixupEntry.Size) + 8); writer.WriteUInt32(blockSize); for (var i = 0; i < Entries.Length; i++) Entries[i].Write(ctxt, writer); writer.Align(4); }
public void Write(WriterContext ctxt, BlobWriter writer) { StandardFields.Write(ctxt, writer); NTSpecificFields.Write(ctxt, writer); DataDirectories.Write(ctxt, writer); }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteUInt32(cb); writer.WriteUInt16(MajorRuntimeVersion); writer.WriteUInt16(MinorRuntimeVersion); MetaData.Write(writer); writer.WriteUInt32((uint)Flags); writer.WriteUInt32(EntryPointToken); Resources.Write(writer); StrongNameSignature.Write(writer); writer.WriteUInt64(codeManagerTable); VtableFixups.Write(writer); writer.WriteUInt64(exportAddressTableJumps); writer.WriteUInt64(managedNativeHeader); }
public uint Write(WriterContext ctxt, BlobWriter writer) { var offset = writer.Offset; ImportLookupTable.Write(writer); writer.WriteUInt32(dateTimeStamp); writer.WriteUInt32(forwarderChain); Name.Write(writer); ImportAddressTable.Write(writer); writer.Pad(paddingBytes); return writer.Offset - offset; }
public void Write(WriterContext ctxt, BlobWriter writer) { for (var i = 0; i < Fixups.Length; i++) Fixups[i].Write(ctxt, writer); }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteUInt16(hint); writer.WriteAsciiZeroTerminatedString(Name, 1); }
public override void Write(WriterContext ctxt, BlobWriter writer) { base.Write(ctxt, writer); writer.WriteCompressedUInt32((uint)Index); }
public void Write(WriterContext ctxt, BlobWriter writer, uint beginOffset, Func<OpCode, object, Row> findRow) { var offset = (int)(writer.Offset - beginOffset); if (offset != Offset) throw new PEException("invalid instruction offset"); var highByte = (ushort)OpCode >> 8; if (highByte > 0) writer.WriteByte((byte)highByte); writer.WriteByte((byte)OpCode); switch (OpCode) { case OpCode.Nop: case OpCode.Break: case OpCode.Ldarg_0: case OpCode.Ldarg_1: case OpCode.Ldarg_2: case OpCode.Ldarg_3: case OpCode.Ldloc_0: case OpCode.Ldloc_1: case OpCode.Ldloc_2: case OpCode.Ldloc_3: case OpCode.Stloc_0: case OpCode.Stloc_1: case OpCode.Stloc_2: case OpCode.Stloc_3: case OpCode.Ldnull: case OpCode.Ldc_i4_m1: case OpCode.Ldc_i4_0: case OpCode.Ldc_i4_1: case OpCode.Ldc_i4_2: case OpCode.Ldc_i4_3: case OpCode.Ldc_i4_4: case OpCode.Ldc_i4_5: case OpCode.Ldc_i4_6: case OpCode.Ldc_i4_7: case OpCode.Ldc_i4_8: case OpCode.Dup: case OpCode.Pop: case OpCode.Ret: case OpCode.Ldind_i1: case OpCode.Ldind_u1: case OpCode.Ldind_i2: case OpCode.Ldind_u2: case OpCode.Ldind_i4: case OpCode.Ldind_u4: case OpCode.Ldind_i8: case OpCode.Ldind_i: case OpCode.Ldind_r4: case OpCode.Ldind_r8: case OpCode.Ldind_ref: case OpCode.Stind_ref: case OpCode.Stind_i1: case OpCode.Stind_i2: case OpCode.Stind_i4: case OpCode.Stind_i8: case OpCode.Stind_r4: case OpCode.Stind_r8: case OpCode.Add: case OpCode.Sub: case OpCode.Mul: case OpCode.Div: case OpCode.Div_un: case OpCode.Rem: case OpCode.Rem_un: case OpCode.And: case OpCode.Or: case OpCode.Xor: case OpCode.Shl: case OpCode.Shr: case OpCode.Shr_un: case OpCode.Neg: case OpCode.Not: case OpCode.Conv_i1: case OpCode.Conv_i2: case OpCode.Conv_i4: case OpCode.Conv_i8: case OpCode.Conv_r4: case OpCode.Conv_r8: case OpCode.Conv_u4: case OpCode.Conv_u8: case OpCode.Conv_r_un: case OpCode.Throw: case OpCode.Conv_ovf_i1_un: case OpCode.Conv_ovf_i2_un: case OpCode.Conv_ovf_i4_un: case OpCode.Conv_ovf_i8_un: case OpCode.Conv_ovf_u1_un: case OpCode.Conv_ovf_u2_un: case OpCode.Conv_ovf_u4_un: case OpCode.Conv_ovf_u8_un: case OpCode.Conv_ovf_i_un: case OpCode.Conv_ovf_u_un: case OpCode.Ldlen: case OpCode.Ldelem_i1: case OpCode.Ldelem_u1: case OpCode.Ldelem_i2: case OpCode.Ldelem_u2: case OpCode.Ldelem_i4: case OpCode.Ldelem_u4: case OpCode.Ldelem_i8: case OpCode.Ldelem_i: case OpCode.Ldelem_r4: case OpCode.Ldelem_r8: case OpCode.Ldelem_ref: case OpCode.Stelem_i: case OpCode.Stelem_i1: case OpCode.Stelem_i2: case OpCode.Stelem_i4: case OpCode.Stelem_i8: case OpCode.Stelem_r4: case OpCode.Stelem_r8: case OpCode.Stelem_ref: case OpCode.Conv_ovf_i1: case OpCode.Conv_ovf_u1: case OpCode.Conv_ovf_i2: case OpCode.Conv_ovf_u2: case OpCode.Conv_ovf_i4: case OpCode.Conv_ovf_u4: case OpCode.Conv_ovf_i8: case OpCode.Conv_ovf_u8: case OpCode.Ckfinite: case OpCode.Conv_u2: case OpCode.Conv_u1: case OpCode.Conv_i: case OpCode.Conv_ovf_i: case OpCode.Conv_ovf_u: case OpCode.Add_ovf: case OpCode.Add_ovf_un: case OpCode.Mul_ovf: case OpCode.Mul_ovf_un: case OpCode.Sub_ovf: case OpCode.Sub_ovf_un: case OpCode.Endfinally: case OpCode.Stind_i: case OpCode.Conv_u: case OpCode.Prefix7: case OpCode.Prefix6: case OpCode.Prefix5: case OpCode.Prefix4: case OpCode.Prefix3: case OpCode.Prefix2: case OpCode.Prefix1: case OpCode.Prefixref: case OpCode.Arglist: case OpCode.Ceq: case OpCode.Cgt: case OpCode.Cgt_un: case OpCode.Clt: case OpCode.Clt_un: case OpCode.Localloc: case OpCode.Endfilter: case OpCode.Volatile: case OpCode.Tailcall: case OpCode.Cpblk: case OpCode.Initblk: case OpCode.Rethrow: case OpCode.Refanytype: case OpCode.Readonly: break; case OpCode.Br: case OpCode.Brfalse: case OpCode.Brtrue: case OpCode.Beq: case OpCode.Bge: case OpCode.Bgt: case OpCode.Ble: case OpCode.Blt: case OpCode.Bne_un: case OpCode.Bge_un: case OpCode.Bgt_un: case OpCode.Ble_un: case OpCode.Blt_un: case OpCode.Leave: { var target = (int)Value; // NOTE: Delta is relatative to start of next instruction var delta = (int)beginOffset + target - ((int)writer.Offset + 4); writer.WriteInt32(delta); } break; case OpCode.Br_s: case OpCode.Brfalse_s: case OpCode.Brtrue_s: case OpCode.Beq_s: case OpCode.Bge_s: case OpCode.Bgt_s: case OpCode.Ble_s: case OpCode.Blt_s: case OpCode.Bne_un_s: case OpCode.Bge_un_s: case OpCode.Bgt_un_s: case OpCode.Ble_un_s: case OpCode.Blt_un_s: case OpCode.Leave_s: { var target = (int)Value; // NOTE: Delta is w.r.t. begining of next instruction var delta = (int)beginOffset + target - ((int)writer.Offset + 1); if (delta > 0xff) throw new PEException("cannot use small form for this instruction"); writer.WriteSByte((sbyte)delta); } break; case OpCode.Ldc_i4_s: writer.WriteSByte((sbyte)(int)Value); break; case OpCode.Ldarg_s: case OpCode.Ldarga_s: case OpCode.Starg_s: case OpCode.Ldloc_s: case OpCode.Ldloca_s: case OpCode.Stloc_s: case OpCode.Unaligned: writer.WriteByte((byte)(int)Value); break; case OpCode.Ldc_i4: writer.WriteInt32((int)Value); break; case OpCode.Ldarg: case OpCode.Ldarga: case OpCode.Starg: case OpCode.Ldloc: case OpCode.Ldloca: case OpCode.Stloc: writer.WriteUInt32((uint)(int)Value); break; case OpCode.Ldc_i8: writer.WriteInt64((long)Value); break; case OpCode.Ldc_r4: writer.WriteSingle((float)Value); break; case OpCode.Ldc_r8: writer.WriteDouble((double)Value); break; case OpCode.Ldstr: WriteUserString(ctxt, writer, (string)Value); break; case OpCode.Switch: { var targets = (Seq<int>)Value; writer.WriteUInt32((uint)targets.Count); // NOTE: Deltas are w.r.t. start of next instruction for (var i = 0; i < targets.Count; i++) { var delta = (int)beginOffset + targets[i] - ((int)writer.Offset + (targets.Count * 4)); writer.WriteInt32(delta); } } break; case OpCode.Calli: case OpCode.Jmp: case OpCode.Call: case OpCode.Callvirt: case OpCode.Newobj: case OpCode.Ldftn: case OpCode.Ldvirtftn: case OpCode.Ldfld: case OpCode.Ldflda: case OpCode.Stfld: case OpCode.Ldsfld: case OpCode.Ldsflda: case OpCode.Stsfld: case OpCode.Ldtoken: case OpCode.Cpobj: case OpCode.Ldobj: case OpCode.Castclass: case OpCode.Isinst: case OpCode.Unbox: case OpCode.Stobj: case OpCode.Box: case OpCode.Newarr: case OpCode.Ldelema: case OpCode.Ldelem: case OpCode.Stelem: case OpCode.Unbox_any: case OpCode.Refanyval: case OpCode.Mkrefany: case OpCode.Initobj: case OpCode.Constrained: case OpCode.Sizeof: WriteToken(ctxt, writer, findRow(OpCode, Value)); break; default: throw new PEException("unrecognised opcode"); } }
public override void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteByte((byte)Tag); }
public void Write(WriterContext ctxt, BlobWriter writer) { for (var i = 0; i < Blocks.Length; i++) Blocks[i].Write(ctxt, writer); }
public void WriteContents(BlobWriter writer) { var length = writer.dataLimit - writer.baseOffset; Prepare(length); Array.Copy(writer.data, writer.baseOffset, data, currOffset, length); currOffset += length; }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteUInt32(VirtualAddress); writer.WriteUInt16(Size); writer.WriteUInt16((ushort)Type); }
public void Write(WriterContext ctxt, BlobWriter writer) { Offset.Write(writer); writer.WriteUInt32(Size); writer.WriteAsciiZeroTerminatedString(Name, 4); }
public void Write(WriterContext ctxt, BlobWriter writer) { writer.WriteUInt32(signature); writer.WriteUInt16(MajorVersion); writer.WriteUInt16(MinorVersion); writer.WriteUInt32(reserved); writer.WriteUTF8SizedZeroPaddedString(Version, 4); writer.WriteUInt16(flags); writer.WriteUInt16((ushort)StreamHeaders.Length); for (var i = 0; i < StreamHeaders.Length; i++) StreamHeaders[i].Write(ctxt, writer); }
public override void Write(WriterContext ctxt, BlobWriter writer) { base.Write(ctxt, writer); Applicand.Write(ctxt, writer); writer.WriteCompressedUInt32((uint)Arguments.Count); foreach (var argument in Arguments) argument.Write(ctxt, writer); }