Questions tagged [dnlib]

dnlib is a library that can read, write and create .NET assemblies and modules.

dnlib is a library that can read, write and create .NET assemblies and modules.

See:

38 questions
3
votes
1 answer

How to generate C# code from IL Instructions

I'm trying to generate c# code from IL instructions using the dnlib library. The code I'm trying to generate is this one: private string GetIp() { return new WebClient().DownloadString("https://api.myip.com/"); } My code: Type webclientType =…
Milton Cardoso
  • 358
  • 3
  • 14
2
votes
0 answers

How to add call to MessageBox.Show() with dnlib?

I am trying to make a call to MessageBox.Show from dnlib. I have this function that finds the Show method: MethodDef GetSystemMethod(Type DeclaringType, string Methodname, Type[] MethodParams) { var filename =…
catalin00
  • 31
  • 1
  • 4
2
votes
1 answer

dnlib.DotNet.Writer.ModuleWriterException when merging IL of two methods

I am trying to merge the IL of two methods: one method is from an already existing assembly (MyAssembly.dll) and one is in the same project as my dnlib code. I'm trying to read both methods, merge their instructions and then write it to a new…
bramhaag
  • 628
  • 1
  • 9
  • 24
2
votes
1 answer

Dnlib - Execute IL MethodBody from loaded assembly

I am working on an unpacker for a simple .Net packer. I would like to execute a method from a loaded assembly using dnlib. I can't use System.Reflection because the packer pack the original executable and then it will unpack in memory before…
itseeder
  • 133
  • 6
2
votes
0 answers

How to add item to existing List(Of String) using dnlib?

As stated in the question, how to add an item(of String type) to a List(Of String) using dnlib? So far, this is my progress: Private A As AssemblyDef = AssemblyDef.Load(Filename) Public Sub AddtoList(ByVal Listname As String, ByVal Item As String) …
Ravi Kiran
  • 565
  • 1
  • 8
  • 22
2
votes
1 answer

How to initialize a Lazy list?

I've read about Lazy Initialization but practically I don't understand how to initialize the objects inside. This function returns a LazyList which is a kind of custom implementation of a Lazy type Public Function GetMethods(ByVal Assembly As…
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
1
vote
1 answer

Some metadata tokens for local variable types invalid after rewrite with dnlib

What I am doing (partly for fun and learning, partly hopefully as a serious virtualization effort someday) is merging my VM dll with a target assembly via ILMerge. Only afterwards I modify the newly created file with dnlib to replace the method…
Carraway
  • 13
  • 3
1
vote
1 answer

Using DLLImport with dnlib

I have a C# project that I want to modify with dnlib. Modifying it with dnspy, I can add the code in just fine. However, I was not able to find a way to add the DLLImport in with dnlib, and all searches came up dry. How can I pull this off? Can it…
1
vote
1 answer

C# dnlib / IL code - Creating a new dictionary

I am creating my own program for changing .exe code via dnlib. Then I want to create a Dictionary via IL and Dnlib code. But there are not many tutorials for both so it's pretty hard.. It writes wrong Dictionary code and makes DnSpy crash. My…
1
vote
1 answer

How can I get the generic type of the class in dnlib?

I have the following class: public class MyGenericArray { private T[] array; public MyGenericArray(int size) { array = new T[size + 1]; } public T getItem(int index) { var in2 = index + 1; in2 =…
cipri.l
  • 819
  • 10
  • 22
1
vote
1 answer

How to use dnlib library to get the instructions of all the methods?

I'm trying to use the dnlib library wich is part of the de4dot project to load an assembly and get the IL instructions contained on the "body" of all the methods. I've compiled an assmebly with this VB.NET source: Public Class Main Public Sub…
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
0
votes
0 answers

system.reflection dnlib issues

im relatively new to working with dnlib and ive been trying to make a .NET packer & unpacker, but whenever i try and create a method that unpacks the assembly using Assembly.Load it throws an error something along the lines of 'unable to find X…
okaa0
  • 1
0
votes
0 answers

Import property without using typeof in dnlib

could you help, please? To add the following line to the target assembly: this._startTime = DateTime.UtcNow; I use the following code to import the UtcNow property: var utcNowMethodInfo =…
Andrii
  • 689
  • 1
  • 6
  • 12
0
votes
0 answers

How to get resources from EmbeddedResource

var resource = module.FindResource($"{type.Namespace}.{type.Name}.resources"); resource.Name = $"{type.Namespace}.{type.Name}.resources"; EmbeddedResource embedded = (EmbeddedResource)resource; How do I access the resource images from the…
fetix
  • 11
  • 4
0
votes
0 answers

Saving Mixed Mode Assembly on Linux using dnlib

I am using the following code to load System.Net.Http.dll from the .NET Core runtime directory (systemNetHttpPath) and save it to another directory (newSystemNetHttpPath). I do not make any changes to the assembly. I pick the System.Net.Http.dll…
Andrii
  • 689
  • 1
  • 6
  • 12
1
2 3