The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > ROM Hacking > Tools, Tutorials & Resources
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Tools, Tutorials & Resources Various tools to help you develop your hacks can be found here.
New threads in this forum are to be approved by a moderator before they are displayed.


Reply
 
Thread Tools
  #1    
Old June 14th, 2013, 12:20 PM
Synchronous's Avatar
Synchronous
Hacking is moving to the cloud.
Community Supporter
 
Join Date: Mar 2011
Location: エルキア
Age: 15
Gender: Male
Nature: Quiet
Introduction

Hello all. Darthatron made a tutorial several years back on creating a Hex Editor and related hacking tools in VB6. The thread can be found here. As you all know, VB6 is run in Win16, which means that it can only be run on Win16 or Win32 machines. A very small amount of people use Win16 machines anymore, and this leaves Win64 developers at a loss. So my purpose is to create a tutorial using the new VB.NET, which is standardized and maintains support from Microsoft. The source code can be found at the bottom of the page.

Resources

All you need is an IDE (Integrated Development Environment) that can work with VB.NET.

If you already have Microsoft Visual Studio, that's wonderful.

Otherwise, for a much more lightweight yet almost equally effective IDE, you can get Sharpdevelop, which has a virtually identical layout. It can be found in my signature, or here.

I will be demonstrating in Microsoft Visual Studio.

Step 1: Create and Prepare Your Project.

In your IDE, go to File->New->Project in MSVS or File->New->Solution in #Dev.

Select the settings in the following pictures.

Spoiler:



Spoiler:



Rename your form and application text to Main.vb and Main, respectively. I do this just because using Form1 is a bad programming habit. Naming in the project will be optional.

Create a Button, name it 'open_button', change the text property to 'Open File...', and create a Rich Text Box, and name it 'hex_richtextbox'.

Spoiler:



Double-click on 'open_button' in the designer to create an event. We will use this in the next step.

Create an Open File Dialog, and name it 'open_openfiledialog'. This is the dialog that we will use to browse for a file.

Spoiler:



Go into Main.vb where your event was created.

At the very top, type 'Imports System.IO'. This will make our code easier to understand by reducing text needed to type.

Under Public Class Main, type 'Dim hexString as String'. This will declare the string that we are going to use to display our hex values.

Now your preparations are ready.

Step 2: Programming the Application

Your Main.vb should now look like this.

Spoiler:



Under the Click Event, type this.

Spoiler:
If open_openfiledialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
Using file As New IO.FileStream(open_openfiledialog.FileName, IO.FileMode.Open)
Dim value As Integer = file.ReadByte()

Do Until value = -1
hexString = hexString & (value.ToString("X2"))

value = file.ReadByte()
Loop
End Using
hex_richtextbox.Text = hexString
End If


Explanation:

Spoiler:
If open_openfiledialog.ShowDialog() = Windows.Forms.DialogResult.OK Then

This combines several things into one line. First, it creates an instance of our dialog that browses for a file. Then, it checks to see whether the OK button was clicked or not.


Using file As New IO.FileStream(open_openfiledialog.FileName, IO.FileMode.Open)

This is a using statement. It creates a little space to work in, and defines 'file' as something that the program can open and access. All variables used inside are disposed afterwards, so it's less memory-intensive.


Dim value As Integer = file.ReadByte()

This defines 'value' as a datum that can contain bytes that are read.


Do Until value = -1
hexString = hexString & (value.ToString("X2"))
value = file.ReadByte()
Loop

This whole loop reads a byte, concatenates (adds) its value onto the string that will be displayed, and loops until it reaches the end of the file.


End Using

This disposes our little virtual workspace.


hex_richtextbox.Text = hexString

This assigns the text property of our 'hex_richtextbox' to the value of 'hexString'. In other words, it shows 'hexString' in it.


End If

This ends our if statement, so that we can proceed onto the next segment of code.


This code reads the Hex from the selected file, and displays it in the textbox.

Your code should now look like this.

Spoiler:



Now, your program can read the hex from a file!

Click on the green arrow to compile your program.

Spoiler:



Part 3: Allowing only Hex Values to be Entered

This step is short and sweet.

Go to the designer, and click on the Rich Text Box once.
Click on the Lightning button; this is where all possible events for that control are found.

Double-click on the KeyPress event.

Spoiler:



Under the event sub, type this.

Spoiler:
If (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57) Or (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 70) Or (Asc(e.KeyChar) >= 97 And Asc(e.KeyChar) <= 102) Or (Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 16) Then
e.Handled = False
Else
e.Handled = True
End If


Explanation:

Spoiler:
If (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57) Or (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 70) Or (Asc(e.KeyChar) >= 97 And Asc(e.KeyChar) <= 102) Or (Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 16) Then

This executes whatever is in the conditional block if the condition is true, in this case, where the key pressed is equivalent to hex values that would be entered. Each key on the keyboard has an ASCII value that is in turn, processed by the computer, save for the arrow keys and some others. Those keys have their own detection methods.


e.Handled = False

This means that whatever key is pressed, it is ignored.


Else

This will execute the next block of code if the conditional is not met, nor any subconditionals (which in this case we d not have).


e.Handled = True

This will accept the key that is pressed.


End If

This will end our if statement, allowing the next block of code to be executed.


Your code should look like this.

Spoiler:



Now your textbox only accepts Hex characters.

Part 4: Saving your File

Now increase the size of your form to accommodate a Save button.

Create a Button called 'save_button' and change the text property to 'Save File...'.

Create a Save File Dialog and name it 'save_savefiledialog'.

Spoiler:



Create an event for 'save_button' the same way you did for 'open_button'.

Under the Save event, type this.

Spoiler:
Try
If save_savefiledialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim fs As New IO.FileStream(save_savefiledialog.FileName, IO.FileMode.Create)

For x As Integer = 0 To hexString.Length - 1 Step 8
Dim ui As UInt32
ui = Convert.ToUInt32(hexString.Substring(x, 8), 16)
Dim b() As Byte = BitConverter.GetBytes(ui)
fs.Write(b, 0, b.Length)
Next
fs.Close()
End If
Catch

End Try


Explanation:

Spoiler:
Try

This will try to execute the next block of code, and return an error if something happens. If an exception is created, the program will not crash.


If save_savefiledialog.ShowDialog() = Windows.Forms.DialogResult.OK Then

This is very similar to the dialog for opening files, showing it first, and proceeding if the OK button was pressed.


Dim fs As New IO.FileStream(save_savefiledialog.FileName, IO.FileMode.Create)

This will create a filestream to save the bytes to. It is set on creation mode, which is used in other programs equivalent to the 'Save As' function.


For x As Integer = 0 To hexString.Length - 1 Step 8

This will increment the variable 'x' by eight each time the loop goes through. I will explain why in the next line of code.


Dim ui As UInt32

UInt32 is a variable type for 32-bit integers. The maximum number of characters it can store is eight, which is why we use them to our maximum advantage, and increment our index 'x' by eight each time. We have defined 'ui' as a UInt32 data value.


ui = Convert.ToUInt32(hexString.Substring(x, 8), 16)

This converts the variable to a hex value that is ready to be converted to a byte.


Dim b() As Byte = BitConverter.GetBytes(ui)

This converts ui into a series of bytes, and assigns it to the array of b().


fs.Write(b, 0, b.Length)

This concatenates 'b' onto the file.


Next

This is the loop footer.


fs.Close()

This closes the filestream. If this statement is not included, then nothing else will be able to access it until it is closed, which can only be done forcefully.


End If

This ends our if statement to move on the the next instructions.


Catch

This will execute the block of code that it contains only if the above code within the try region failed. If it failed, then it would do nothing, as we did not add any instructions within the catch region. Usually, an error message would be put here.


End Try

This ends our try statement, as an if statement is ended.


This will save the file, and do nothing if it fails.

Your code should look like this.

Spoiler:



Go back up to your open_button event, and wrap it in a [Try, Catch, End Try], so that the program doesn't crash if another program is using it.

Your program is now done.

Hope this helps to start the foundation for one of the next revolutionary hacking tools.

If you could not follow the tutorial, the source code can be found in the attachments.

Regards,
~Tosaka
Attached Files
File Type: zip SimpleHex.zip‎ (67.5 KB, 111 views) (Save to Dropbox)
__________________

Last edited by Synchronous; June 18th, 2013 at 12:43 AM. Reason: Added line-by-line explanations for code o.o
Reply With Quote
  #2    
Old June 16th, 2013, 04:06 PM
DarkPsychic's Avatar
DarkPsychic
 
Join Date: Jul 2012
Gender: Male
Never mind I figured It out... You should really keep doing tutorials on VB.Net as I would love to learn how to make tools.

Last edited by DarkPsychic; June 16th, 2013 at 06:57 PM.
Reply With Quote
  #3    
Old June 16th, 2013, 09:03 PM
Synchronous's Avatar
Synchronous
Hacking is moving to the cloud.
Community Supporter
 
Join Date: Mar 2011
Location: エルキア
Age: 15
Gender: Male
Nature: Quiet
Quote:
Originally Posted by DarkPsychic View Post
Never mind I figured It out... You should really keep doing tutorials on VB.Net as I would love to learn how to make tools.
You're very welcome. I'll be sure to make more programming tutorials. Source code will be included each time.
__________________
Reply With Quote
  #4    
Old June 16th, 2013, 09:37 PM
Team Fail's Avatar
Team Fail
The fine line between in|sanity
Community Supporter
 
Join Date: May 2009
Age: 19
Gender: Male
Nature: Brave
One thing I'd recommend you do is put additional spoilers to explain what each chunk of code does. I know a bit of VB.NET (I know more C# though...) but I didn't quite get all of it.

Also, I was thinking on making a tutorial for people to make C#-oriented programs, if I can get off my lazy butt and do it. Would you be fine with it, seeing as you're covering one of the other Microsoft-oriented languages?
__________________

Pairs:
Kevin, Echidna
Follow me on Twitter! @TeamFail
Alt 1, リザードン
Miiverse
Pokémon Hackers Online
Alt 2: Jack Cayman



[04:20.39] <@GoGo> I WILL INSERT WITH PLEASURE
[04:20.45] <@GoGo> shut it Bela

[05:41.55] <Team_Fail> Blue Spider is interesting, but #MEHMasterRace
[05:42.20] <diegoisawesome> Team_Fail: Sounds like a bunch of unmotivated people that still want to try to take over the world
Reply With Quote
  #5    
Old June 16th, 2013, 09:58 PM
Synchronous's Avatar
Synchronous
Hacking is moving to the cloud.
Community Supporter
 
Join Date: Mar 2011
Location: エルキア
Age: 15
Gender: Male
Nature: Quiet
Quote:
Originally Posted by Team Fail View Post
One thing I'd recommend you do is put additional spoilers to explain what each chunk of code does. I know a bit of VB.NET (I know more C# though...) but I didn't quite get all of it.

Also, I was thinking on making a tutorial for people to make C#-oriented programs, if I can get off my lazy butt and do it. Would you be fine with it, seeing as you're covering one of the other Microsoft-oriented languages?
I know C# and VB.NET exactly the same -- after all, they are exactly the same in structure, libraries, and effect. However, VB.NET is easier to deal with in that brackets are intimidating to some people.
This website is a great VB.NET to C# and vice-verso converter tool. #Dev also has a feature in which it can convert an entire project to and fro VB.NET and C#.

I'll add some more spoilers, sure.
__________________
Reply With Quote
  #6    
Old June 17th, 2013, 09:23 PM
DarkPsychic's Avatar
DarkPsychic
 
Join Date: Jul 2012
Gender: Male
Quote:
Originally Posted by DeltaSalamence View Post
You're very welcome. I'll be sure to make more programming tutorials. Source code will be included each time.
Now a great tutorial (if not to complicated) would be some kind of simple inserting of an asm code into a fire red rom. Like a small tool that adds jpans saveblock patch and give one the option to add the flag extension and the var extension hack. I am new to programming so I do like the idea of additional spoilers to explain what each chunk of code does. And any good video tutorials or pdf tutorials you may know about to teach me the ins and outs of programming. VB.net seems to be very beginner friendly, I tried learning RGSS-Ruby Game Scripting System so I could make a ABS-Action Battle System for Pokémon Essentials but no one was willing to help, and I had no clue where to start as most of the rmxp scripts don't work with Pokémon Essentials. Any way I will learn how (Eventually) to program so all my ideas can be brought to life.

P.S
Thank you for taking your time to Educate us who have trouble with the learning curve of programming. I do have to say if there is any way possible to go over the little details that most don't pay any mind to.. I only say this because I just learned how to use setvar and compare commands in xse and that is only because no one ever really went into detail about these commands ( not to say A lot of others ).
Reply With Quote
  #7    
Old June 18th, 2013, 12:46 AM
Synchronous's Avatar
Synchronous
Hacking is moving to the cloud.
Community Supporter
 
Join Date: Mar 2011
Location: エルキア
Age: 15
Gender: Male
Nature: Quiet
Quote:
Originally Posted by DarkPsychic View Post
Now a great tutorial (if not to complicated) would be some kind of simple inserting of an asm code into a fire red rom. Like a small tool that adds jpans saveblock patch and give one the option to add the flag extension and the var extension hack. I am new to programming so I do like the idea of additional spoilers to explain what each chunk of code does. And any good video tutorials or pdf tutorials you may know about to teach me the ins and outs of programming. VB.net seems to be very beginner friendly, I tried learning RGSS-Ruby Game Scripting System so I could make a ABS-Action Battle System for Pokémon Essentials but no one was willing to help, and I had no clue where to start as most of the rmxp scripts don't work with Pokémon Essentials. Any way I will learn how (Eventually) to program so all my ideas can be brought to life.

P.S
Thank you for taking your time to Educate us who have trouble with the learning curve of programming. I do have to say if there is any way possible to go over the little details that most don't pay any mind to.. I only say this because I just learned how to use setvar and compare commands in xse and that is only because no one ever really went into detail about these commands ( not to say A lot of others ).
Ideas? Make sure you don't lose them. Meanwhile, I'd be happy to program some of them myself.
__________________
Reply With Quote
  #8    
Old June 19th, 2013, 01:02 AM
DarkPsychic's Avatar
DarkPsychic
 
Join Date: Jul 2012
Gender: Male
I shall never lose my ideas.. I am learning VB.net 2010 as we speak. I've decided to make a windows application that finds the sum of the first and last digit of a number. This great tutorial made me finally decide on what language to learn (VB.net) and I see that C#,Python and Ruby all seem to be very compatible with one another.

PS. if you can give me some advice on making a Action battle system- for my pokemon abs game it would be much appreciated. I would like to learn how to code it in VB then I can translate it in to Ruby later on when I need it.
Reply With Quote
  #9    
Old September 30th, 2013, 04:51 AM
PokeBunny's Avatar
PokeBunny
Pokemon Game Maker
 
Join Date: Aug 2012
Location: South Africa
Age: 14
Gender: Male
Nature: Serious
I'm a bit confused, as I have never use VB before... VB .NET is different from the IDE right? So I go and download both of them?
__________________
special POKeBUNNY

The Pokemon Game Developer
If you are wondering why I'm taking long to make Pokemon Hot Red and Cold Blue... It's because I barely get computer time. Be patient (I'm not!.

My SoundCloud!!!!!!!!!
Reply With Quote
  #10    
Old November 30th, 2013, 02:45 AM
Kakarot1212's Avatar
Kakarot1212
Awesome as always...
 
Join Date: Oct 2013
Location: Phillipines
Age: 16
Gender: Male
Nature: Naughty
Hmm.. Nice tut!
Bad thing i dont have any knowledge on VB.NET yet.
Am still learning java, though.
__________________

楓 弘詩
“ Programs must be written for people
to read, and only incidentally for
machines to execute. ”
Pair Pair | Facebook | Showdown | PHO | Twitter
| The Prediction Game |
Reply With Quote
  #11    
Old December 20th, 2013, 12:47 PM
haven1433
Modder / Programmer
 
Join Date: Oct 2013
Gender: Male
Thanks for making this! I've been considering making a poke-specific hex editor that lets you follow pointers, and lets you see when a section of code is being pointed to. This is great for getting started!
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 04:54 PM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.