Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

>> CodeDom Tutorial | Detailed with Pictures | Very Easy | For Beginners <<

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:


[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:


Code
Dim newCode As String = My.Resources.SourceCode


SourceCode 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:


Code
Try

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try


Just in case that something wents wrong we can display all the compiler errors.
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:


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.


Code
parameters.GenerateExecutable = True


We want to create an executable so set this to true!
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:


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:


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:


--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!


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 statement


This logs compiler errors displays the line of the errors etc (similar to the IDE)
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:


Code
Namespace MyApp
    Public Class EntryPoint
  Public Shared Sub Main()
        MessageBox.Show("--MESSAGE--","--TITLE--")
        MessageBox.Show("--BOOLEAN--","Boolean Value")
        End Sub
    End Class
End Namespace


I 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)


[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 :)


[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 :)


by Madara-Uchiha
OP is a very talented developer. Everyone who needs help look no further!
Congrats man, I planned to do this, but you are faster than me. I like the tutorial, but yeah, it can be optimized a bit.
Thanks, I know there are is optimazation possible, just post ur code here and Ill take a look.
Since this is made for CodeDom newbies, I havent mentioned Icon changing and Assembly Information Manipulation etc:)
Hey can you help me trough PM or something? My application isn't working.
Very helpful. I would +3 if I could.
[Image: giphy.gif?cid=790b7611b007c1bdd2cd47171b...y.gif&ct=g]
Here is my ub3r short version that is self adding all the imports needed in 90% of uses.Waning it's a 4 liner.

You ask why I added all the imports there, first I made a simple application that you write code and it makes a simple EXE, but I didn't want to be bothered with imports. And all these imports are needed for my RAT, I will use this for my RAT. Here it is, and don't laugh, because it works.

http://pastebin.com/0mFDCmgG


My achievement was making it as short as possible.
(Sep 16, 2013 02:32 PM)Tostig Wrote:  Very helpful. I would +3 if I could.

I'm sorry, but I'm the only noodles here.
i like how your app only shows 2 message box's and its 7KB...


Very nice tutorial! Really detailed with good pictures. Good Job OP
:)
Nice tutorial OP! Detailed and well written
Thanks, I am great you liked it :)
Hope you find some use for this.
Thanks, for posting this! :D
Very nice tutorial! :p
I like the pictures in the tutorial. Makes it high quality.
It's not working as planned...
Any advice? Can someone send me the source because he doesn't explain where to put it too well.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by SIM-2015410Aug 26, 2021 04:29 AM 140 22,579 Aug 26, 2021 04:29 AM
Last Post: skhackit
[Shell] by DеathJul 30, 2017 06:01 PM 51 2,440 Jul 30, 2017 06:01 PM
Last Post: motherfawker666
[C] by Kashmiri HunterMar 11, 2017 08:48 AM 4 374 Mar 11, 2017 08:48 AM
Last Post: Praet0rian