CodeDom Tutorial
Hello guys, in this tutorial I show u a bit about CodeDom and
how to make a sample application.
Basiclly first, create a new VB.Net Windows Forms App.
Than Add a Button, name it Compile and a two textboxes (set one of them Multiline = true)
and also add a checkbox.
That should basiclly look like this:
how to make a sample application.
Basiclly first, create a new VB.Net Windows Forms App.
Than Add a Button, name it Compile and a two textboxes (set one of them Multiline = true)
and also add a checkbox.
That should basiclly look like this:
[img]http://s14.directupload.net/images/130916/bn562x72.png[/img]
Now Doubleklick the Compile Button.
Here goes our main part. Inside the click procedure you add this:
Here goes our main part. Inside the click procedure you add this:
Code
Dim newCode As String = My.Resources.SourceCodeSourceCode is the name of a text file we will add to the ressources later.
There in the txt file goes the code we want to compile (for example the Rat Server or Keylogger or whatever)
Now we write this:
There in the txt file goes the code we want to compile (for example the Rat Server or Keylogger or whatever)
Now we write this:
Code
Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End TryJust in case that something wents wrong we can display all the compiler errors.
Now we go on inside the Try Statement:
Now we go on inside the Try Statement:
Code
Dim compiler As System.CodeDom.Compiler.ICodeCompiler = New VBCodeProvider().CreateCompiler()Here we basiclly create a New CodeDom Compiler object.
Now we create a new "parameter-variable" for all parameters we need to add to the compiler like this:
Now we create a new "parameter-variable" for all parameters we need to add to the compiler like this:
Code
Dim parameters As New System.CodeDom.Compiler.CompilerParameters()Now another important part:
Code
parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll")There we added a dll as reference. When using "Imports System.Windows.Forms" we need to import that. For
every import there exist different dlls.
U can check msdn for more information.
every import there exist different dlls.
U can check msdn for more information.
Code
parameters.GenerateExecutable = TrueWe want to create an executable so set this to true!
Now the Outputname of our compiled code:
Now the Outputname of our compiled code:
Code
parameters.OutputAssembly = "App" U don't need to write .exe. CodeDom will add this automaticlly
Now we add this:
Now we add this:
Code
parameters.CompilerOptions = "/target:winexe"This tells the compiler we need to create a normale executable file.
I am not exactly sure about different options but I think this is different when choosing a console app/Winform app/DLL etc
Now for the main customization part:
I am not exactly sure about different options but I think this is different when choosing a console app/Winform app/DLL etc
Now for the main customization part:
Code
If Dim results As System.CodeDom.Compiler.CompilerResults = compiler.CompileAssemblyFromSource(parameters, My.Resources.SourceCode.Replace("--MESSAGE--", TextBox2.Text).Replace("--TITLE--", TextBox1.Text).Replace("--BOOLEAN--", CheckBox1.CheckState))What are we gonna do here? Thats simple! here the main compiling starts.
We compile our code we have inside the txt file to an executable.
There we replace the Strings:
We compile our code we have inside the txt file to an executable.
There we replace the Strings:
--MESSAGE-- ==> And fill in whatever is typed in TextBox2
--TITLE-- ==> And fill in whatever is typed in TextBox1
--BOOLEAN-- ==> And fill in whatever checkstate our checkbox has!
--TITLE-- ==> And fill in whatever is typed in TextBox1
--BOOLEAN-- ==> And fill in whatever checkstate our checkbox has!
As u can see it is an if statement so we need to end this:
Code
MsgBox("Error: Line>" & results.Errors(0).Line.ToString & ", " & results.Errors(0).ErrorText) 'Messagebox the error line number and the acctual error
Exit Sub 'Exit the sub, so NO success message
End If 'End the if statementThis logs compiler errors displays the line of the errors etc (similar to the IDE)
If there is an error it stops compiling.
Good news:
If there is an error it stops compiling.
Good news:
WE ARE DONE WITH THE COMPILER!! :)
Now we create a new txt file on our computer.
We Name it SourceCode.txt (or whatever choosen as name above by newCode Variable)
There we add this:
We Name it SourceCode.txt (or whatever choosen as name above by newCode Variable)
There we add this:
Code
Namespace MyApp
Public Class EntryPoint
Public Shared Sub Main()
MessageBox.Show("--MESSAGE--","--TITLE--")
MessageBox.Show("--BOOLEAN--","Boolean Value")
End Sub
End Class
End NamespaceI don't think I have to explain that...
Its basiclly our program we are gonna go to compile.
We show two MessageBoxes with the specific Strings we are replacing above with our TextBox Text.
Also another messageBox for the boolean value :)
Now add the txt file to your compiler-apps ressources (MyProject >> Ressources >> Add ressource >> Choose the txt file)
Its basiclly our program we are gonna go to compile.
We show two MessageBoxes with the specific Strings we are replacing above with our TextBox Text.
Also another messageBox for the boolean value :)
Now add the txt file to your compiler-apps ressources (MyProject >> Ressources >> Add ressource >> Choose the txt file)
[img]http://s14.directupload.net/images/130916/sq5t9ky3.png[/img]
We are Done with our first CodeDom Application :)
Lets try this out guys. Debug the compiler.
And test it :)
Lets try this out guys. Debug the compiler.
And test it :)
[img]http://s7.directupload.net/images/130916/85q8fjpk.gif[/img]
I hope u liked the tutorial. I like like to get a feedback! Any mistakes I've made (I am also just a human), suggestions, questions?
Also thanks to XilluX & Elektroalek, they helped me with CodeDom :)
Also thanks to XilluX & Elektroalek, they helped me with CodeDom :)
by Madara-Uchiha



![[Image: giphy.gif?cid=790b7611b007c1bdd2cd47171b...y.gif&ct=g]](https://media2.giphy.com/media/q7tD3eB8gRXumzbfvS/giphy.gif?cid=790b7611b007c1bdd2cd47171b9e37dc1125057dcbd235e0&rid=giphy.gif&ct=g)
