[C #] Use dnSpy to decompile and modify the Target Program (EXE or DLL) and compile and run the program,

Source: Internet
Author: User

[C #] Use dnSpy to decompile and modify the Target Program (EXE or DLL) and compile and run the program,

This article is an original article and the source code is the original code. For example, repost/copy the original code, please clearly mark the original name, author, and URL on the webpage/code. Thank you!

The tool used in this article is:

https://github.com/cnxy/dnSpy/archive/v4.0.0.zip

Or dnSpy official:

https://github.com/0xd4d/dnSpy/releases/download/v4.0.0/dnSpy.zip

The software interface is as follows:

The software 64-Bit Memory and 32-Bit Memory, respectively for dnspy.exe and dnSpy-x86.exe, debugging, please pay attention to the corresponding software version.

Enter the topic:

1. First, write a Hello World console running program, as shown in:

The Code is as follows:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ChangeString{    class Program    {        static void Main(string[] args)        {            string str = "Hello World!";            Console.WriteLine(str);            Console.ReadKey();        }    }}

2. Compile and run, as shown in:

Here, the str variable in the program is "Hello World !", Now, you need to use the dnSpy tool to change the internal str variable and debug it online.

Iii. decompile the program using dnSpy:

①Use the dnspytool to decompile the just-generated changestring.exe, as shown in:

② Right-click the menu in the Main function and select "Edit Method (C #)" from the context menu, as shown in:

③ Change the content of the str variable to "Just For Test" and click the "compile" button, as shown in:

④ Click "Save all", retain the default value on the displayed page, and click "OK", as shown in:

⑤ After saving, click the "Start" button, retain the default value in the pop-up interface, click the "OK" button, and then automatically start the application, as shown in:

The program runs successfully!

 

Note:

Note the following during compilation; otherwise, compilation is not allowed:

① Other DLL modules must be included;

② If there are other characters that cannot be identified after decompilation, manually modify OK before compiling.

In addition, this program is not only effective for EXE, but also for DLL. Please test it by yourself. Thank you!

 

Related Article

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.