Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How do you convert an EXE to binary string? [VB.NET]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Tue Jan 27, 2009 5:08 pm    Post subject: How do you convert an EXE to binary string? [VB.NET] Reply with quote

How do you convert an EXE to binary string in vb.net? And how do you convert binary string to an EXE. I want to do this so I store my exe in my program and then create it and run it. I will offer SOME REPS!
_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
b6ooy
Grandmaster Cheater
Reputation: 0

Joined: 21 Sep 2006
Posts: 653

PostPosted: Tue Jan 27, 2009 5:29 pm    Post subject: Reply with quote

Lol ...
what are you going to do with 0 and 1 ?
the only way i think is reading each 4 bytes from the Exe file and convert them to binary then store the binary code in a file .
and it will be x8 the Exe size because 1 byte = 8 bits .
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Tue Jan 27, 2009 5:31 pm    Post subject: Reply with quote

b6ooy wrote:
Lol ...
what are you going to do with 0 and 1 ?
the only way i thing is reading each 4 bytes from the Exe file and convert them to binary then store the binary code in a file .
and it will be x8 the Exe size because 1 byte = 8 bits .


Can you write me the code to convert an exe to 4byte, and then back?

I want it to store the bytes in a file, then I will encrypt them and then read the 4bytes, unencrypt them and convert it back to an exe then save it?

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Tue Jan 27, 2009 5:34 pm    Post subject: Reply with quote

i dont know VB.NET at ALL!! im serious... but i can offer you a solution

open Olly
goto very top of code select whole code
right click and select Edit Binary click the ctrl-A ctrl-C

goto vb.net paste it in there

the use BinaryReader/and BinaryWriter

here a example i found..for reader

Code:

Public Shared Sub Main
        Dim fs As System.IO.FileStream
        Dim r As System.IO.BinaryReader
        Dim buffer(100) As Char
        Dim mylength As Long
        fs = New System.IO.FileStream("test.txt", IO.FileMode.OpenOrCreate)
        r = New System.IO.BinaryReader(fs)
        mylength = fs.Length
        If mylength > 100 Then
            mylength = 100
        End If
        r.Read(buffer, 0, mylength)
        //Console.WriteLine(buffer) pass the string to Writer Here..maybe.. ;)
        r.Close()
        fs.Close()
    End Sub


and heres a example for Writer

Code:

Public Shared Sub Main
        Dim fs As System.IO.FileStream
        Dim w As System.IO.BinaryWriter
        Dim buffer As String
        Dim c As Char
        c = Chr(9)

        fs = New System.IO.FileStream("test.exe", IO.FileMode.OpenOrCreate)
        w = New System.IO.BinaryWriter(fs)

        w.Seek(0, System.IO.SeekOrigin.Begin)

        w.Write("writing data via BinaryWriter")
        w.Close()
        fs.Close()
    End Sub
Back to top
View user's profile Send private message MSN Messenger
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Tue Jan 27, 2009 6:05 pm    Post subject: Reply with quote

BanMe wrote:
i dont know VB.NET at ALL!! im serious... but i can offer you a solution

open Olly
goto very top of code select whole code
right click and select Edit Binary click the ctrl-A ctrl-C

goto vb.net paste it in there

the use BinaryReader/and BinaryWriter

here a example i found..for reader

Code:

Public Shared Sub Main
        Dim fs As System.IO.FileStream
        Dim r As System.IO.BinaryReader
        Dim buffer(100) As Char
        Dim mylength As Long
        fs = New System.IO.FileStream("test.txt", IO.FileMode.OpenOrCreate)
        r = New System.IO.BinaryReader(fs)
        mylength = fs.Length
        If mylength > 100 Then
            mylength = 100
        End If
        r.Read(buffer, 0, mylength)
        //Console.WriteLine(buffer) pass the string to Writer Here..maybe.. ;)
        r.Close()
        fs.Close()
    End Sub


and heres a example for Writer

Code:

Public Shared Sub Main
        Dim fs As System.IO.FileStream
        Dim w As System.IO.BinaryWriter
        Dim buffer As String
        Dim c As Char
        c = Chr(9)

        fs = New System.IO.FileStream("test.exe", IO.FileMode.OpenOrCreate)
        w = New System.IO.BinaryWriter(fs)

        w.Seek(0, System.IO.SeekOrigin.Begin)

        w.Write("writing data via BinaryWriter")
        w.Close()
        fs.Close()
    End Sub


Wait does it just write 1 line or the whole thing?

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Tue Jan 27, 2009 7:06 pm    Post subject: Reply with quote

i dont know vb.net but i am a good linguist Smile

so based on my analysis of words (and code knowledge)

i would say it reads a 100 bytes on the reader.. and on the Write it Seeks the begining of the file (SeekOrigin) and writes to it.

you will have to modify all this behavior...

i would suggest using ImageMapAndLoad and using the structure along with Binary Reader to allocate a buffer of ImageSize and pass fs FileStream to Writer ..

Regards BanMe
Back to top
View user's profile Send private message MSN Messenger
FerrisBuellerYourMyHero
Master Cheater
Reputation: 0

Joined: 14 Feb 2007
Posts: 401
Location: Inside your <kernel>

PostPosted: Wed Jan 28, 2009 2:20 am    Post subject: Reply with quote

b6ooy wrote:
Lol ...
what are you going to do with 0 and 1 ?
the only way i think is reading each 4 bytes from the Exe file and convert them to binary then store the binary code in a file .
and it will be x8 the Exe size because 1 byte = 8 bits .


Your idea is wrong, and your math is wrong...

Why would you read it 4 bytes at a time? Not every executable is exactly dividable by four bytes. I would read 1 byte at a time... You can't change a dword array into a different type of array in the middle of it. Stick with a byte array... But actually read is the wrong word... I read the whole file at once, then work with each byte individually...

convert the exe file into binary? The exe is already binary, he's trying to convert the binary into a STRING which describes the binary so that he can embed the binary in his application.

Yes 8 bits == 1 byte, but that doesn't make the resulting string be 8x the size? how did you come up with that?

Say you have one binary byte for example... lets say

01

now the value of that byte is 1, it is in binary form, now if you write that into a text file, save it, then open up the text file in a hex editor it will look like:

30 31

that is the binary data of the string...

30 represents a string 0

31 represents a string 1

so your string representation of your binary will be 2x the size of just the binary plus your languages syntax to define the byte array...

Now I don't code in VB.NET, but I have made this sorta thing in C++... In C++ I define my byte arrays as:

Code:

unsigned char BinaryData[3] = {0x4D, 0x5A, 0x90};


where between the []brackets is the size of your binary in bytes, and between the {}brackets is where the string formatted binary goes. 0x to represent that its in hex...

So I'm not sure how you define a byte array in VB.net but I looked it up and is this maybe it?

Code:

Dim BinaryData(3) as Byte = {&H4D, &H5A, &H90}


Would that work? I guess in VB you can't do 0x, so you do &H instead...

Well anyway you just put that array into your source code, then once you build your program, the BINARY will be embedded within it. Its only in string format in your source, when you compile, its stored as binary... You can then just dump the binary out to a file and do anything you want with it after. In your case its an exe so you'd probably run it! It is going to increase your executable size though, by the size of the binary your embedding in it obviously...

I have already made an application like this, all I had to do was add the ability for vb.net hopefully that's the right way you define arrays in vb.net...

It works very simply, you run it and type a file path, I usually just put the file in the same folder as it so you just type a file name instead of a long path... Then it will now ask you whether you want to create a C++ array or a VB.net array!

type 1 for c++ or 2 for vb.net and hit enter...

I tested it with a numbers.txt which just contained "123456789" because using an actual exe would be too big of a string It wouldn't of let me post it here if I tried...

Here's what the C++ array comes out as... I know this ones right because I've used this app before to embed things in my programs...

Code:

// FerrisSoft
// Source File: numbers.txt
//        Size: 9 / 0x00000009 bytes
//<--
unsigned char BinaryData[9] =
{
   0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
};
//-->


This is how the VB.NET one comes out... ' is comment in vb i think...

Code:

' FerrisSoft
' Source File: numbers.txt
'        Size: 9 / 0x00000009 bytes
'<--
Dim BinaryData(9) as Byte =
{
   &H31, &H32, &H33, &H34, &H35, &H36, &H37, &H38, &H39
}
'-->


So try it and see if it works...

http://www.java2s.com/Code/VB/File-Directory/UseBinaryWritertostoreinformationintoabinaryfile.htm

That should help you with writing the binary to a file ^^


It was created in C++ because I'm not a VB person so you'll have to deal with that! Source Code + Binary Executable attached...



The Extension 'zip' was deactivated by an board admin, therefore this Attachment is not displayed.


_________________
You know, life moves pretty fast. If you don't stop and look around once in a while, You could miss it!

Back to top
View user's profile Send private message MSN Messenger
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Wed Jan 28, 2009 3:38 pm    Post subject: Reply with quote

Ahh thanks! Pwus rep.

EDIT: Can someone convert this project?

_________________
CEF will always stay alive.


Last edited by Jorg hi on Thu Jan 29, 2009 4:50 pm; edited 1 time in total
Back to top
View user's profile Send private message
Stupidfunny
Newbie cheater
Reputation: 0

Joined: 14 Jan 2007
Posts: 20
Location: Christchurch, New Zealand

PostPosted: Thu Jan 29, 2009 4:27 pm    Post subject: Reply with quote

In addition to converting a EXE to a byte array, does anyone know how to dynamically embed stuff like this or adding a resource at runtime?
Back to top
View user's profile Send private message MSN Messenger
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Thu Jan 29, 2009 4:49 pm    Post subject: Reply with quote

Adding a resource at runtime? Well to add a control in VB.NET, for current form do...

Put this code after you declare your class.

Code:

    Public textbox1 As New TextBox With {.Location = New Drawing.Point(0, 0), .size = New Drawing.Size(100, 20), .Parent = Me, .Text = "WOW WOW WOW!"}


I don't know how to add events at runtime so I do this to clear it,
modify it to your own needs 0.0

Code:

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        textbox1.Text = ""
    End Sub


You can keep on doing this but it would be hard to keep track of the textbox names.

_________________
CEF will always stay alive.
Back to top
View user's profile Send private message
Stupidfunny
Newbie cheater
Reputation: 0

Joined: 14 Jan 2007
Posts: 20
Location: Christchurch, New Zealand

PostPosted: Wed Feb 04, 2009 11:28 pm    Post subject: Reply with quote

What I mean by resource is like a embedded exe file, any ideas?

EDIT:
No need to tell me about basic stuff though, VB .NET is my primary programming language.

EDIT2:
To add events:

Code:
Public WithEvents textbox1 As New TextBox With {.Location = New Drawing.Point(0, 0), .size = New Drawing.Size(100, 20), .Parent = Me, .Text = "WOW WOW WOW!"}


EDIT3:
nvm about the question, not a simple way to do it...
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites