pax_global_header 0000666 0000000 0000000 00000000064 13250336635 0014520 g ustar 00root root 0000000 0000000 52 comment=d57237e61feca7cc6a525abd74b31aab07bb96c7
dnlib-2.1_VS2010/ 0000775 0000000 0000000 00000000000 13250336635 0013365 5 ustar 00root root 0000000 0000000 dnlib-2.1_VS2010/.editorconfig 0000664 0000000 0000000 00000010367 13250336635 0016051 0 ustar 00root root 0000000 0000000 root = true
[*]
indent_size = 4
indent_style = tab
insert_final_newline = true
tab_width = 4
#end_of_line =
[*.json]
[App.config]
[*.yml]
indent_size = 2
indent_style = space
[*.{proj,csproj,vbproj,props,targets,resx,vsixmanifest}]
indent_size = 2
indent_style = space
[app.manifest]
indent_size = 2
indent_style = space
[*.xml]
[*.xaml]
indent_style = space
[*.{cs,vb}]
dotnet_sort_system_directives_first = true
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:none
dotnet_style_predefined_type_for_member_access = true:none
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_separate_import_directive_groups = false
dotnet_style_prefer_is_null_check_over_reference_equality_method = false:suggestion
dotnet_style_require_accessibility_modifiers = never:info
[*.cs]
csharp_style_throw_expression = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_var_for_built_in_types = false:none
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_expression_bodied_constructors = true:suggestion
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_operators = true:suggestion
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion
csharp_prefer_braces = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_parentheses =
csharp_space_after_cast = false
csharp_space_around_declaration_statements = false
csharp_space_before_open_square_brackets = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_square_brackets = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_semicolon_in_for_statement = true
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_around_binary_operators = before_and_after
csharp_indent_braces = false
csharp_indent_block_contents = true
csharp_indent_switch_labels = false
csharp_indent_case_contents = true
csharp_indent_labels = flush_left
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
csharp_new_line_before_open_brace = none
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true
csharp_indent_case_contents_when_block = false
csharp_prefer_inferred_anonymous_type_member_names = true:suggestion
csharp_prefer_inferred_tuple_names = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
#csharp_preferred_modifier_order =
csharp_style_pattern_local_over_anonymous_function = true:suggestion
[*.vb]
visual_basic_prefer_inferred_anonymous_type_member_names = true:suggestion
visual_basic_prefer_inferred_tuple_names = true:suggestion
#visual_basic_preferred_modifier_order =
dnlib-2.1_VS2010/.gitattributes 0000664 0000000 0000000 00000000115 13250336635 0016255 0 ustar 00root root 0000000 0000000 * text=auto
*.cs text diff=csharp
*.sln text eol=crlf
*.csproj text eol=crlf
dnlib-2.1_VS2010/.gitignore 0000664 0000000 0000000 00000000140 13250336635 0015350 0 ustar 00root root 0000000 0000000 *~
*/obj/
*.csproj.user
*.sdf
*.opensdf
*.suo
/.vs/
/Debug/
/Release/
/Examples/bin/
*.tmp_proj
dnlib-2.1_VS2010/Examples/ 0000775 0000000 0000000 00000000000 13250336635 0015143 5 ustar 00root root 0000000 0000000 dnlib-2.1_VS2010/Examples/Example1.cs 0000664 0000000 0000000 00000002624 13250336635 0017152 0 ustar 00root root 0000000 0000000 using System;
using dnlib.DotNet;
namespace dnlib.Examples {
// This example will open mscorlib.dll and then print out all types
// in the assembly, including the number of methods, fields, properties
// and events each type has.
public class Example1 {
public static void Run() {
// Load mscorlib.dll
string filename = typeof(void).Module.FullyQualifiedName;
ModuleDefMD mod = ModuleDefMD.Load(filename);
int totalNumTypes = 0;
// mod.Types only returns non-nested types.
// mod.GetTypes() returns all types, including nested types.
foreach (TypeDef type in mod.GetTypes()) {
totalNumTypes++;
Console.WriteLine();
Console.WriteLine("Type: {0}", type.FullName);
if (type.BaseType != null)
Console.WriteLine(" Base type: {0}", type.BaseType.FullName);
Console.WriteLine(" Methods: {0}", type.Methods.Count);
Console.WriteLine(" Fields: {0}", type.Fields.Count);
Console.WriteLine(" Properties: {0}", type.Properties.Count);
Console.WriteLine(" Events: {0}", type.Events.Count);
Console.WriteLine(" Nested types: {0}", type.NestedTypes.Count);
if (type.Interfaces.Count > 0) {
Console.WriteLine(" Interfaces:");
foreach (InterfaceImpl iface in type.Interfaces)
Console.WriteLine(" {0}", iface.Interface.FullName);
}
}
Console.WriteLine();
Console.WriteLine("Total number of types: {0}", totalNumTypes);
}
}
}
dnlib-2.1_VS2010/Examples/Example2.cs 0000664 0000000 0000000 00000005134 13250336635 0017152 0 ustar 00root root 0000000 0000000 using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace dnlib.Examples {
public class Example2 {
// This will open the current assembly, add a new class and method to it,
// and then save the assembly to disk.
public static void Run() {
// Open the current module
ModuleDefMD mod = ModuleDefMD.Load(typeof(Example2).Module);
// Create a new public class that derives from System.Object
TypeDef type1 = new TypeDefUser("My.Namespace", "MyType",
mod.CorLibTypes.Object.TypeDefOrRef);
type1.Attributes = TypeAttributes.Public | TypeAttributes.AutoLayout |
TypeAttributes.Class | TypeAttributes.AnsiClass;
// Make sure to add it to the module or any other type in the module. This is
// not a nested type, so add it to mod.Types.
mod.Types.Add(type1);
// Create a public static System.Int32 field called MyField
FieldDef field1 = new FieldDefUser("MyField",
new FieldSig(mod.CorLibTypes.Int32),
FieldAttributes.Public | FieldAttributes.Static);
// Add it to the type we created earlier
type1.Fields.Add(field1);
// Add a static method that adds both inputs and the static field
// and returns the result
MethodImplAttributes methImplFlags = MethodImplAttributes.IL | MethodImplAttributes.Managed;
MethodAttributes methFlags = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.ReuseSlot;
MethodDef meth1 = new MethodDefUser("MyMethod",
MethodSig.CreateStatic(mod.CorLibTypes.Int32, mod.CorLibTypes.Int32, mod.CorLibTypes.Int32),
methImplFlags, methFlags);
type1.Methods.Add(meth1);
// Create the CIL method body
CilBody body = new CilBody();
meth1.Body = body;
// Name the 1st and 2nd args a and b, respectively
meth1.ParamDefs.Add(new ParamDefUser("a", 1));
meth1.ParamDefs.Add(new ParamDefUser("b", 2));
// Create a local. We don't really need it but let's add one anyway
Local local1 = new Local(mod.CorLibTypes.Int32);
body.Variables.Add(local1);
// Add the instructions, and use the useless local
body.Instructions.Add(OpCodes.Ldarg_0.ToInstruction());
body.Instructions.Add(OpCodes.Ldarg_1.ToInstruction());
body.Instructions.Add(OpCodes.Add.ToInstruction());
body.Instructions.Add(OpCodes.Ldsfld.ToInstruction(field1));
body.Instructions.Add(OpCodes.Add.ToInstruction());
body.Instructions.Add(OpCodes.Stloc.ToInstruction(local1));
body.Instructions.Add(OpCodes.Ldloc.ToInstruction(local1));
body.Instructions.Add(OpCodes.Ret.ToInstruction());
// Save the assembly to a file on disk
mod.Write(@"C:\saved-assembly.dll");
}
}
}
dnlib-2.1_VS2010/Examples/Example3.cs 0000664 0000000 0000000 00000005731 13250336635 0017156 0 ustar 00root root 0000000 0000000 using System;
using System.Text;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
namespace dnlib.Examples {
// This example creates a new assembly and saves it to disk.
// This is what it will look like if you decompile it:
//
// using System;
// namespace My.Namespace
// {
// internal class Startup
// {
// private static int Main(string[] args)
// {
// Console.WriteLine("Hello World!");
// return 0;
// }
// }
// }
public class Example3 {
public static void Run() {
// Create a new module. The string passed in is the name of the module,
// not the file name.
ModuleDef mod = new ModuleDefUser("MyModule.exe");
// It's a console application
mod.Kind = ModuleKind.Console;
// Add the module to an assembly
AssemblyDef asm = new AssemblyDefUser("MyAssembly", new Version(1, 2, 3, 4), null, null);
asm.Modules.Add(mod);
// Add a .NET resource
byte[] resourceData = Encoding.UTF8.GetBytes("Hello, world!");
mod.Resources.Add(new EmbeddedResource("My.Resource", resourceData,
ManifestResourceAttributes.Private));
// Add the startup type. It derives from System.Object.
TypeDef startUpType = new TypeDefUser("My.Namespace", "Startup", mod.CorLibTypes.Object.TypeDefOrRef);
startUpType.Attributes = TypeAttributes.NotPublic | TypeAttributes.AutoLayout |
TypeAttributes.Class | TypeAttributes.AnsiClass;
// Add the type to the module
mod.Types.Add(startUpType);
// Create the entry point method
MethodDef entryPoint = new MethodDefUser("Main",
MethodSig.CreateStatic(mod.CorLibTypes.Int32, new SZArraySig(mod.CorLibTypes.String)));
entryPoint.Attributes = MethodAttributes.Private | MethodAttributes.Static |
MethodAttributes.HideBySig | MethodAttributes.ReuseSlot;
entryPoint.ImplAttributes = MethodImplAttributes.IL | MethodImplAttributes.Managed;
// Name the 1st argument (argument 0 is the return type)
entryPoint.ParamDefs.Add(new ParamDefUser("args", 1));
// Add the method to the startup type
startUpType.Methods.Add(entryPoint);
// Set module entry point
mod.EntryPoint = entryPoint;
// Create a TypeRef to System.Console
TypeRef consoleRef = new TypeRefUser(mod, "System", "Console", mod.CorLibTypes.AssemblyRef);
// Create a method ref to 'System.Void System.Console::WriteLine(System.String)'
MemberRef consoleWrite1 = new MemberRefUser(mod, "WriteLine",
MethodSig.CreateStatic(mod.CorLibTypes.Void, mod.CorLibTypes.String),
consoleRef);
// Add a CIL method body to the entry point method
CilBody epBody = new CilBody();
entryPoint.Body = epBody;
epBody.Instructions.Add(OpCodes.Ldstr.ToInstruction("Hello World!"));
epBody.Instructions.Add(OpCodes.Call.ToInstruction(consoleWrite1));
epBody.Instructions.Add(OpCodes.Ldc_I4_0.ToInstruction());
epBody.Instructions.Add(OpCodes.Ret.ToInstruction());
// Save the assembly to a file on disk
mod.Write(@"C:\saved-assembly.exe");
}
}
}
dnlib-2.1_VS2010/Examples/Example4.cs 0000664 0000000 0000000 00000015631 13250336635 0017157 0 ustar 00root root 0000000 0000000 using System;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
/*
This example shows how to create an assembly from scratch and create two
instances by calling their constructors. One default constructor and another
one taking two arguments.
ILSpy output of created file:
using System;
namespace Ctor.Test
{
internal class BaseClass
{
public BaseClass()
{
Console.WriteLine("BaseClass: Default .ctor called", null);
}
}
internal class Main : BaseClass
{
public static void Main()
{
new Main();
new Main(12345, null);
}
public Main()
{
Console.WriteLine("Default .ctor called", null);
}
public Main(int count, string name)
{
Console.WriteLine(".ctor(Int32) called with arg {0}", count);
}
}
}
peverify output:
C:\>peverify ctor-test.exe /IL /MD
Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
All Classes and Methods in ctor-test.exe Verified.
Output of program:
C:\>ctor-test.exe
BaseClass: Default .ctor called
Default .ctor called
BaseClass: Default .ctor called
.ctor(Int32) called with arg 12345
*/
namespace dnlib.Examples {
public class Example4 {
public static void Run() {
// This is the file that will be created
string newFileName = @"C:\ctor-test.exe";
// Create the module
var mod = new ModuleDefUser("ctor-test", Guid.NewGuid(),
new AssemblyRefUser(new AssemblyNameInfo(typeof(int).Assembly.GetName().FullName)));
// It's a console app
mod.Kind = ModuleKind.Console;
// Create the assembly and add the created module to it
new AssemblyDefUser("ctor-test", new Version(1, 2, 3, 4)).Modules.Add(mod);
// Create System.Console type reference
var systemConsole = mod.CorLibTypes.GetTypeRef("System", "Console");
// Create 'void System.Console.WriteLine(string,object)' method reference
var writeLine2 = new MemberRefUser(mod, "WriteLine",
MethodSig.CreateStatic(mod.CorLibTypes.Void, mod.CorLibTypes.String,
mod.CorLibTypes.Object),
systemConsole);
// Create System.Object::.ctor method reference. This is the default constructor
var objectCtor = new MemberRefUser(mod, ".ctor",
MethodSig.CreateInstance(mod.CorLibTypes.Void),
mod.CorLibTypes.Object.TypeDefOrRef);
CilBody body;
// Create the base class
var bclass = new TypeDefUser("Ctor.Test", "BaseClass", mod.CorLibTypes.Object.TypeDefOrRef);
// Add it to the module
mod.Types.Add(bclass);
// Create Ctor.Test.BaseClass constructor: BaseClass()
var bctor = new MethodDefUser(".ctor", MethodSig.CreateInstance(mod.CorLibTypes.Void),
MethodImplAttributes.IL | MethodImplAttributes.Managed,
MethodAttributes.Public |
MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
// Add the method to BaseClass
bclass.Methods.Add(bctor);
// Create method body and add a few instructions
bctor.Body = body = new CilBody();
// Make sure we call the base class' constructor
body.Instructions.Add(OpCodes.Ldarg_0.ToInstruction());
body.Instructions.Add(OpCodes.Call.ToInstruction(objectCtor));
body.Instructions.Add(OpCodes.Ldstr.ToInstruction("BaseClass: Default .ctor called"));
body.Instructions.Add(OpCodes.Ldnull.ToInstruction());
body.Instructions.Add(OpCodes.Call.ToInstruction(writeLine2));
body.Instructions.Add(OpCodes.Ret.ToInstruction());
// Create the Ctor.Test.Main type which derives from Ctor.Test.BaseClass
var main = new TypeDefUser("Ctor.Test", "Main", bclass);
// Add it to the module
mod.Types.Add(main);
// Create the static 'void Main()' method
var entryPoint = new MethodDefUser("Main", MethodSig.CreateStatic(mod.CorLibTypes.Void),
MethodImplAttributes.IL | MethodImplAttributes.Managed,
MethodAttributes.Public | MethodAttributes.Static);
// Set entry point to entryPoint and add it as a Ctor.Test.Main method
mod.EntryPoint = entryPoint;
main.Methods.Add(entryPoint);
// Create first Ctor.Test.Main constructor: Main()
var ctor0 = new MethodDefUser(".ctor", MethodSig.CreateInstance(mod.CorLibTypes.Void),
MethodImplAttributes.IL | MethodImplAttributes.Managed,
MethodAttributes.Public |
MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
// Add the method to Main
main.Methods.Add(ctor0);
// Create method body and add a few instructions
ctor0.Body = body = new CilBody();
// Make sure we call the base class' constructor
body.Instructions.Add(OpCodes.Ldarg_0.ToInstruction());
body.Instructions.Add(OpCodes.Call.ToInstruction(bctor));
body.Instructions.Add(OpCodes.Ldstr.ToInstruction("Default .ctor called"));
body.Instructions.Add(OpCodes.Ldnull.ToInstruction());
body.Instructions.Add(OpCodes.Call.ToInstruction(writeLine2));
body.Instructions.Add(OpCodes.Ret.ToInstruction());
// Create second Ctor.Test.Main constructor: Main(int,string)
var ctor1 = new MethodDefUser(".ctor", MethodSig.CreateInstance(mod.CorLibTypes.Void, mod.CorLibTypes.Int32, mod.CorLibTypes.String),
MethodImplAttributes.IL | MethodImplAttributes.Managed,
MethodAttributes.Public |
MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
// Add the method to Main
main.Methods.Add(ctor1);
// Create names for the arguments. This is optional. Since this is an instance method
// (it's a constructor), the first arg is the 'this' pointer. The normal arguments
// begin at index 1.
ctor1.Parameters[1].CreateParamDef();
ctor1.Parameters[1].ParamDef.Name = "count";
ctor1.Parameters[2].CreateParamDef();
ctor1.Parameters[2].ParamDef.Name = "name";
// Create method body and add a few instructions
ctor1.Body = body = new CilBody();
// Make sure we call the base class' constructor
body.Instructions.Add(OpCodes.Ldarg_0.ToInstruction());
body.Instructions.Add(OpCodes.Call.ToInstruction(bctor));
body.Instructions.Add(OpCodes.Ldstr.ToInstruction(".ctor(Int32) called with arg {0}"));
body.Instructions.Add(OpCodes.Ldarg_1.ToInstruction());
body.Instructions.Add(OpCodes.Box.ToInstruction(mod.CorLibTypes.Int32));
body.Instructions.Add(OpCodes.Call.ToInstruction(writeLine2));
body.Instructions.Add(OpCodes.Ret.ToInstruction());
// Create the entry point method body and add instructions to allocate a new Main()
// object and call the two created ctors.
entryPoint.Body = body = new CilBody();
body.Instructions.Add(OpCodes.Newobj.ToInstruction(ctor0));
body.Instructions.Add(OpCodes.Pop.ToInstruction());
body.Instructions.Add(OpCodes.Ldc_I4.ToInstruction(12345));
body.Instructions.Add(OpCodes.Ldnull.ToInstruction());
body.Instructions.Add(OpCodes.Newobj.ToInstruction(ctor1));
body.Instructions.Add(OpCodes.Pop.ToInstruction());
body.Instructions.Add(OpCodes.Ret.ToInstruction());
// Save the assembly
mod.Write(newFileName);
}
}
}
dnlib-2.1_VS2010/Examples/Example5.cs 0000664 0000000 0000000 00000002231 13250336635 0017150 0 ustar 00root root 0000000 0000000 using System;
using System.IO;
using dnlib.DotNet;
using dnlib.PE;
using dnlib.IO;
namespace dnlib.Examples {
///
/// Dumps all PE sections to disk
///
public class Example5 {
public static void Run() {
string sectionFileName = @"c:\section{0}.bin";
// Open the current mscorlib
var mod = ModuleDefMD.Load(typeof(int).Module);
// Get PE image interface
var peImage = mod.MetaData.PEImage;
// Print some info
Console.WriteLine("Machine: {0}", peImage.ImageNTHeaders.FileHeader.Machine);
Console.WriteLine("Characteristics: {0}", peImage.ImageNTHeaders.FileHeader.Characteristics);
Console.WriteLine("Dumping all sections");
for (int i = 0; i < peImage.ImageSectionHeaders.Count; i++) {
var section = peImage.ImageSectionHeaders[i];
// Create a stream for the whole section
var stream = peImage.CreateStream(section.VirtualAddress, section.SizeOfRawData);
// Write the data to disk
var fileName = string.Format(sectionFileName, i);
Console.WriteLine("Dumping section {0} to file {1}", section.DisplayName, fileName);
File.WriteAllBytes(fileName, stream.ReadAllBytes());
}
}
}
}
dnlib-2.1_VS2010/Examples/Example6.cs 0000664 0000000 0000000 00000007625 13250336635 0017165 0 ustar 00root root 0000000 0000000 using System;
using System.IO;
using dnlib.DotNet;
using dnlib.DotNet.MD;
using dnlib.DotNet.Writer;
using dnlib.IO;
using dnlib.PE;
namespace dnlib.Examples {
///
/// This example shows how to create a module writer listener that gets notified of various
/// events. This listener just adds a new PE section to the image and prints the new RIDs.
/// It also shows how to add some dummy .NET heaps, and simple obfuscation that will break
/// most libraries that open .NET assemblies.
///
public class Example6 : IModuleWriterListener {
public static void Run() {
new Example6().DoIt();
}
void DoIt() {
string destFileName = @"c:\output.dll";
// Open the current module
var mod = ModuleDefMD.Load(typeof(Example6).Module);
// Create the writer options
var opts = new ModuleWriterOptions(mod);
// Add a listener that gets notified during the writing process
opts.Listener = this;
// This is normally 16 but setting it to a value less than 14 will fool some
// apps into thinking that there's no .NET metadata available
opts.PEHeadersOptions.NumberOfRvaAndSizes = 13;
// Add extra data. This will break most libraries that open .NET assemblies.
// Any value can be written here.
opts.MetaDataOptions.TablesHeapOptions.ExtraData = 0x12345678;
// Add a few dummy heaps
opts.MetaDataOptions.OtherHeaps.Add(new MyHeap("#US "));
opts.MetaDataOptions.OtherHeaps.Add(new MyHeap("#Strings "));
opts.MetaDataOptions.OtherHeaps.Add(new MyHeap("#Strimgs"));
opts.MetaDataOptions.OtherHeaps.Add(new MyHeap("#GU1D"));
opts.MetaDataOptions.OtherHeapsEnd.Add(new MyHeap("#US "));
opts.MetaDataOptions.OtherHeapsEnd.Add(new MyHeap("#Strings "));
// Write the module. The listener will get notified, see OnWriterEvent() below
mod.Write(destFileName, opts);
}
// A simple heap (must implement the IHeap interface). It just writes 10 bytes to the file.
class MyHeap : IHeap {
string name;
FileOffset offset;
RVA rva;
// This is the data. I chose 10 bytes, but any non-zero value can be used
byte[] heapData = new byte[10];
public MyHeap(string name) {
this.name = name;
}
// The rest of the code is just for implementing the required interface
public string Name {
get { return name; }
}
public bool IsEmpty {
get { return false; }
}
public void SetReadOnly() {
}
public FileOffset FileOffset {
get { return offset; }
}
public RVA RVA {
get { return rva; }
}
public void SetOffset(FileOffset offset, RVA rva) {
this.offset = offset;
this.rva = rva;
}
public uint GetFileLength() {
return (uint)heapData.Length;
}
public uint GetVirtualSize() {
return GetFileLength();
}
public void WriteTo(BinaryWriter writer) {
writer.Write(heapData);
}
}
// Gets notified during module writing
public void OnWriterEvent(ModuleWriterBase writer, ModuleWriterEvent evt) {
switch (evt) {
case ModuleWriterEvent.PESectionsCreated:
// Add a PE section
var sect1 = new PESection(".dummy", 0x40000040);
writer.Sections.Add(sect1);
// Let's add data
sect1.Add(new ByteArrayChunk(new byte[123]), 4);
sect1.Add(new ByteArrayChunk(new byte[10]), 4);
break;
case ModuleWriterEvent.MDEndCreateTables:
// All types, methods etc have gotten their new RIDs. Let's print the new values
Console.WriteLine("Old -> new type and method tokens");
foreach (var type in writer.Module.GetTypes()) {
Console.WriteLine("TYPE: {0:X8} -> {1:X8} {2}",
type.MDToken.Raw,
new MDToken(Table.TypeDef, writer.MetaData.GetRid(type)).Raw,
type.FullName);
foreach (var method in type.Methods)
Console.WriteLine(" METH: {0:X8} -> {1:X8} {2}",
method.MDToken.Raw,
new MDToken(Table.Method, writer.MetaData.GetRid(method)).Raw,
method.FullName);
}
break;
default:
break;
}
}
}
}
dnlib-2.1_VS2010/Examples/Examples.csproj 0000664 0000000 0000000 00000004664 13250336635 0020155 0 ustar 00root root 0000000 0000000
Debug
x86
8.0.30703
2.0
{F27E72B5-C4BD-40BF-AD19-4C8A99B55872}
Exe
Properties
dnlib.Examples
dnlib.Examples
v2.0
512
x86
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
x86
pdbonly
true
bin\Release\
TRACE
prompt
4
{FDFC1237-143F-4919-8318-4926901F4639}
dnlib