Hack Forums
[.NET] Codedom - Make your own advanced builder - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Codedom - Make your own advanced builder (/showthread.php?tid=4513089)

Pages: Pages 1 2


Codedom - Make your own advanced builder - BerryP - Oct 29, 2014

Hello,

this is my first sourceshare on HF and my english isnt the best, so dont be so strictly 😭

Lets begin:

What is CodeDom ?: CodeDom

We will use CodeDom to compile our stub code stored in a string, the big advantage is that you can edit the code easily.

I assume that you know, what Classes, Subs, Functions and so on are.

Builder:
First of all you will need the compiler.vb class:

PHP Code

<?php 
Imports System
.CodeDom.Compiler

Public Class compiler
    
Public Shared Sub Compile(ByVal Output As String, ByVal cSource As String)
      
Dim Compiler As ICodeCompiler = New VBCodeProvider().CreateCompiler 'Creating compiler
      Dim Parameters As New CompilerParameters '
A class, holding things like: path to save, imports and more
      Dim cResults 
As CompilerResults 'Used for checking if everything is fine
      Parameters.GenerateExecutable = True '
We want to make an EXE-File
      Parameters
.OutputAssembly = Output 'Declare where to save the file

      Parameters.ReferencedAssemblies.Add("System.dll") '
We need that in order to use the basic .Net Framework. (e.g. Namespaces like System.IO)
      
Parameters.ReferencedAssemblies.Add("System.Data.dll")
      
Parameters.ReferencedAssemblies.Add("System.Core.dll") 

      
Parameters.CompilerOptions = "/optimize+ /platform:X86 /debug- /target:winexe" 'Basic parameters: read more here: http://msdn.microsoft.com/en-us/library/w95cx9k1.aspx

      cResults = Compiler.CompileAssemblyFromSource(Parameters, cSource) '
Compile the code with the Parameters object and the source given in compiler.Compile(pathtofile,My.Resources.Stub)
      If 
cResults.Errors.Count > 0 Then 'Checking for errors
      For Each CompilerError In cResults.Errors '
Looping through all of them, use CompilerError.errorText to get the error
      Messagebox
.Show(CompilerError.errorText)
      
Next
      
ElseIf cResults.Errors.Count = 0 Then 'No errors
      End If
    End Sub
End Class 


You see, its not that much code.

Now add a document to the resources of the project.
With this code here:
PHP Code

<?php 
Imports System
.Net
Imports System
.IO
Imports System
.Collections 'Basic imports (feel free to change them :) )
Module Stub

    Sub main()

    End Sub

End Module 

Now add your code, and replace the variables(given by the user) with something like [FTP].
PHP Code

<?php 
'Basic namepsace imports, also set by Visual Studio 2012
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Drawing
Imports System.Collections 
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Windows.Forms

Module Stub

    Sub main()
      My.Computer.Network.DownloadFile([Dlink],[WhereToSave])
    End Sub

End Module 

Now go to your builder and add something like this:
PHP Code

<?php 
Above the code
: Imports ProjectName.compiler 

PHP Code

<?php 
Dim src 
As String = My.Resources.documentname
src 
= src.Replace("[Dlink]", "You downloadlink")
src = src.Replace("[WhereToSave]","C:\Programs\Downloaded.whatever")

compiler.Compile(pathtosaveEXE, src) 

With this method you can easily add not just variables, complete functions, subs can be added with this.

Use this code wherever you want.

Peace 🤝


* - IAmNotHere - Oct 29, 2014

Thank you Maember for this.

Code
Imports ProjectName.compile

I don't think this is needed for the example source you are sharing.
I have created a few builders myself and, as far as I know the compiler class is for compiling the executable only and does not need to be added to the executable for running the compiled executable.

And thanks for the ms links too. I saw a few, for me unknown, compiler options. Where among the /addmodule compiler option. I was looking for something like this in the past.


* - BerryP - Oct 29, 2014

(Oct 29, 2014 11:03 AM)IAmNotHere Wrote:  Thank you Maember for this.

Code
Imports ProjectName.compile

I don't think this is needed for the example source you are sharing.
I have created a few builders myself and, as far as I know the compiler class is for compiling the executable only and does not need to be added to the executable for running the compiled executable.

And thanks for the ms links too. I saw a few, for me unknown, compiler options. Where among the /addmodule compiler option. I was looking for something like this in the past.
Sorry, dont want to insult you as a coder but its just that we dont have to write "compiler.compile("","")" but "compile("","")" (i never wrote "Imports ProjectName.compile", I wrote "Imports ProjectName.compiler" :o)
But maybe I just missunderstood something hehe 🤫

But anyways thanks for the feedback 👍

Peace 🤝


* - IAmNotHere - Oct 29, 2014

I misunderstood you I make up from your reply. Now I see what you mean. I thought the code needed to be added to the source text, but you meant to the vb.class. My apologize for the lousy comment.🤝
I won't edit my first reply. The other readers can read my comment.

I am not a coder and therefore you can't insult me as a coder. 😏

Cool code, this code does run!
I have build a codedom folder reader myself today in same kind off way, codedom.


* - BerryP - Oct 29, 2014

(Oct 29, 2014 11:23 AM)IAmNotHere Wrote:  Cool code, this code does run!
I hope so 🤫

Thanks for the positive feedback 🤝


* - CodeAssassin - Oct 29, 2014

Where is the "tutorial" all i see is a copy and paste code block...

A tutorial teaches you something, This just teaches copy and paste.


* - n31ght0 - Oct 29, 2014

what is stub mean? i didn't undrstand


* - BerryP - Oct 29, 2014

(Oct 29, 2014 05:48 PM)sweetysuckscock Wrote:  Where is the "tutorial" all i see is a copy and paste code block...

A tutorial teaches you something, This just teaches copy and paste.

Lol ? The code is fully commentated and yes its fully copy and pasted... from myself 😧 The forum I posted it at first is just dieing atm...
If you dont understand something than go ahead and ask 🤝

"what is stub mean? i didn't undrstand"
Dont get, what you mean in detail to be honest. But the stubcode is basiclly the code raw code. In this method you store it in a string, what makes it easier to edit it. Often you have the stub in form of an assembly, what makes it hard to edit it. But the string can be edited and compiled how you want it 🎉

Peace🤝


* - Earn - Oct 29, 2014

(Oct 29, 2014 11:23 AM)IAmNotHere Wrote:  I misunderstood you I make up from your reply. Now I see what you mean. I thought the code needed to be added to the source text, but you meant to the vb.class. My apologize for the lousy comment.🤝
I won't edit my first reply. The other readers can read my comment.

I am not a coder and therefore you can't insult me as a coder. 😏

Cool code, this code does run!
I have build a codedom folder reader myself today in same kind off way, codedom.

Wow. I think this is the first time I have seen someone admit that they were wrong on HF & not flame the person that pointed it out. They even apologised. Never seen it before on HF. :P

Anyway, good tutorial OP. It should help the newer people out.


* - CodeAssassin - Oct 29, 2014

(Oct 29, 2014 06:09 PM)Maember Wrote:  Lol ? The code is fully commentated and yes its fully copy and pasted... from myself 😧 The forum I posted it at first is just dieing atm...
If you dont understand something than go ahead and ask 🤝

"what is stub mean? i didn't undrstand"
Dont get, what you mean in detail to be honest. But the stubcode is basiclly the code raw code. In this method you store it in a string, what makes it easier to edit it. Often you have the stub in form of an assembly, what makes it hard to edit it. But the string can be edited and compiled how you want it 🎉

Peace🤝

I have plenty of experience with the Codedom thankyou, I just hate when people label a Tutorial if its not, This would at best be a commented source.

I mean copy and paste with regards to the people you're "trying" to teach as per your words as a tutorial. When you make a tutorial its best to approach it as the individual has no clue what your teaching, Explain it all and expand on why we use certain functions, subs to do a job in a particular way.

Its pretty clear you only have basic knowledge about vb.net or you would not of included these....

Code
Imports System.Net
Imports System.IO
Imports System.Collections 'Basic imports (feel free to change them :) )

Where not necessary, even labelling it "basic imports" ??? (suggest you have no idea whats used for what)

Sorry to hear about your forum btw.


* - nazist - Oct 29, 2014

thx bro I was looking for something like this in the past.


* - CodeAssassin - Oct 29, 2014

(Oct 29, 2014 09:02 PM)nazist Wrote:  thx bro I was looking for something like this in the past.

You now what search is?? Their are much better codedom examples here on hf....

Just to see a few..... out of the 25+ pages of "Codedom" results...

One

Two (very detailed, actual tutorial)

Three


* - 4NTIVIRUS - Oct 30, 2014

Good, Tutorial is A one. Got you points. Looking for more tut from you side.


* - 420 Blaze It - Oct 30, 2014

Thanks for this, very good for beginners :D :D


* - Moon Rock - Oct 30, 2014

I'll have to add this to my builder source list, thanks for sharing 🙂