Home >> Desktop >> Codedom Library in C# – Code entegration into Executable
C# ile Codedom Kütüphanesi ile Kod Entegrasyonu - TheKodProgram
C# ile Codedom Kütüphanesi ile Kod Entegrasyonu - TheKodProgram

Codedom Library in C# – Code entegration into Executable

In this article, I will tell you about C # language and CodeDom library. With this library, I will explain how to change the code structure within the software or to change a field we want.

I’d like to say this. This process is completely legal and not a hacking process. This library allows you to change the code in your programs by windows via the execurable file.

First of all, what is Codedom and how it works:

It is a library used to change and rewrite a code field that we know in the program. By means of a program written with this library, we find and modify the variables or functions we want in the source code through the exe file of another program, and create a modified program by rewriting.

We need to add the following library to the program we will use this library.

There are several articles available with this library, but they are articles based on re-code generation. In this article we will replace the existing code and reprint the program.

We will first search the code block for which we will perform our operations, and then make changes to them.

Now let’s start writing. First, let’s write a simple console application and then change the codes of this console application.

Now that we’ve written the simple program above, let’s move on to the program we’re going to change.

Here we will create the code that we write in the program as if it were a string expression, and when it is found we will replace it with a string expression.

Now we are gonna need some objects below :

  • CodeCompiler object: Is the object we use to recompile the newly created code. We will create and compile new code with child objects of this object. Then you’ll get new exe.
  • With the CSharpCodeProvider object, we will return the assembly code in C # language and print the new code as Assembly.
  • With the CompilerParameters object, we will create and send the parameters that will work with the new codes that we print to our program.
  • With the CompilerResults object, which is the child object of the CompilerSource object, we will recompile the parameters that we have recently sent into the program and the assembley code that we created with the Provider object above. In this way, we will return our newly created program.

With the following code block, we have written a function to compile the program and generate assembly codes. This function will return the code expressions entered in the form of assembly.

Since we write the function that creates the assembly codes above, we need to use this function in order. We will call and use the above function via the function below.
When we run the above code, we replace the function we wrote at the top with the field we wrote at the bottom. So we change the code to string.

Here the above program will no longer work. Because there will be compilation error. Because calls the print function in TheCode class when the program runs. But there is no longer a function called print in the program. however, it does not exist in a class called TheCode. Because we deleted that data and we put something else in its place..

Our newly created assembly code is an object. Because of that, we called object variable type.

So how do we change the executable program. Let’s make an example about this topic and finish our article.

With the following example, we will make a Codedom Application and make changes to the executable entered.

We will call the function above and convert the exe we selected and create an exe file again.

Let’s call the function as follows. Let’s get a form application and do this.

In this way, we re-created our exe file with the codes we prepared and rewrote our program. If you do not receive any compilation errors, the program will compile successfully. And our exe file will re-occur with the code we write.

Let me tell you again, this process is definitely not a hack process. We modify and rebuild the contents of exe files through the libraries provided by Microsoft

So much friends in this article – Stay tuned

Have a nice coding…

Burak Hamdi Tufan

About Burak Hamdi TUFAN

I am a software developer experienced 12 years and here to share all my programming experiences. I have worked on so many platforms and programming languages especially C, C#, C++ and Java. I am studing PhD at Kocaeli University on Aviation Technologies. I am building softwares and technologies on aviation.

Leave a Reply

Your email address will not be published. Required fields are marked *