How to modify a compiled DLL file (Getting started)

Source: Internet
Author: User

Original address: http://www.cnblogs.com/wujy/p/3275855.html

We usually in the work will often encounter some of the DLL has been compiled, and more trouble is no source code can be modified, only for the DLL files to be modified to get the results we want; This article will demonstrate an example of how to accomplish a simple change, and we will use the following tools.

1: Anti-compilation Tool ILSpy.exe: is a very good anti-compilation software, and is free of charge;

2: Microsoft's Tool Ildasm.exe: This is a DLL to generate IL file of a software, Microsoft has brought it, can be found in C:\Program Files\Microsoft Sdks\windows\v7.0a\bin the software;

3: Microcomputer Tool Ilasm.exe: This is the Il file to regenerate the DLL function, you can find the software in C:\Windows\Microsoft.NET\Framework\v4.0.30319;

We create a new Web project, simulate it to insert a dongle to run, of course, this side of the dongle is our metaphor, the example is simple seven steps can be completed;

Step one: Open the Web.dll file with ILSpy.exe, and view its source code:

The source code compiled from the above is not difficult to find the focus is in the Getlicense () method, this is what we want to modify the content, from the above can be seen in no changes before this will be prompted to insert the dongle;

Step two: Next is to use Ildasm.exe to convert the DLL file into Il file;

Dump DLL file to *.il file into a specified folder, get web.il and web.res two files, and sometimes *.resource files

Step three: We can open the web.il file, inside the DLL generated IL content, we can easily locate the desired method, as long as it is fixed to return to true to achieve the successful modification, the IL code inside the method is what we want to modify the content;

Step four: Modify the IL code inside the Getlicense () method to give it a fixed return of true; the next il is to let it return to true; Modify and then save the Il file;

Step five: After modifying the Il file to convert it to a DLL file, open the doc command input into the *.il folder, and then enter the command: C:\windows\microsoft.net\framework\v4.0.30319\ilasm.exe/ Dll/resource=web.res web.il

* 1: To enter the Il file folder 2: where "/dll/" is preceded by a space 3:.res file to precede the. Il file with a space in the middle

Step six: After running the above command, a new DLL file is generated and then copied to our site:

Step Seven: The result of the run:

Complete the above seven steps can successfully modify the DLL file, of course, this example is only a simple modification, to make more complex modification of IL code to have a good understanding of IL knowledge; The following is a code that may be used frequently to return true and false;

    . maxstack 1
    . Locals init (
        [0] bool cs$1$0000)
    L_0000:nop 
    l_0001:ldc.i4.1 
    l_0002:stloc.0 
    l_ 0003:br.s l_0005
    l_0005:ldloc.0 
    L_0006:ret

 

return true;


 

    Code size       7 (0x7)
    . maxstack  1
    . Locals init ([0] bool cs$1$0000)
    il_0000:  nop
    Il_ 0001:  ldc.i4.0
    il_0002:  stloc.0
    il_0003:  br.s       il_0005

    il_0005:  ldloc.0
    il_0006:  ret

 

return false;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.