Tools, Tutorials & Resources Various tools to help you develop your hacks can be found here.

Draconius GO
Reply
 
Thread Tools
  #1    
Old June 14th, 2013 (12:20 PM). Edited June 18th, 2013 by Akiba.
Akiba's Avatar
Akiba Akiba is offline
  • Crystal Tier
 
Join Date: Mar 2011
Location: in a gap
Age: 18
Gender: Female
Nature: Brave
Posts: 4,268
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, 182 views) (Save to Dropbox)
__________________
Reply With Quote

Relevant Advertising!

  #2    
Old June 16th, 2013 (4:06 PM). Edited June 16th, 2013 by DarkPsychic.
DarkPsychic's Avatar
DarkPsychic DarkPsychic is offline
     
    Join Date: Jul 2012
    Location: CO
    Gender: Male
    Nature: Timid
    Posts: 133
    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.
    Reply With Quote
      #3    
    Old June 16th, 2013 (9:03 PM).
    Akiba's Avatar
    Akiba Akiba is offline
    • Crystal Tier
     
    Join Date: Mar 2011
    Location: in a gap
    Age: 18
    Gender: Female
    Nature: Brave
    Posts: 4,268
    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 (9:37 PM).
    Incineroar's Avatar
    Incineroar Incineroar is offline
    the spirit of the fighter
    • Moderator
    • Platinum Tier
    • Developer
     
    Join Date: May 2009
    Location: Iki Town
    Age: 22
    Gender: Male
    Nature: Brave
    Posts: 13,592
    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?
    __________________
    Reply With Quote
      #5    
    Old June 16th, 2013 (9:58 PM).
    Akiba's Avatar
    Akiba Akiba is offline
    • Crystal Tier
     
    Join Date: Mar 2011
    Location: in a gap
    Age: 18
    Gender: Female
    Nature: Brave
    Posts: 4,268
    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 (9:23 PM).
    DarkPsychic's Avatar
    DarkPsychic DarkPsychic is offline
       
      Join Date: Jul 2012
      Location: CO
      Gender: Male
      Nature: Timid
      Posts: 133
      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).
      Akiba's Avatar
      Akiba Akiba is offline
      • Crystal Tier
       
      Join Date: Mar 2011
      Location: in a gap
      Age: 18
      Gender: Female
      Nature: Brave
      Posts: 4,268
      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 (1:02 AM).
      DarkPsychic's Avatar
      DarkPsychic DarkPsychic is offline
         
        Join Date: Jul 2012
        Location: CO
        Gender: Male
        Nature: Timid
        Posts: 133
        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 (4:51 AM).
        PokeBunny's Avatar
        PokeBunny PokeBunny is offline
        Pokemon Game Maker
           
          Join Date: Aug 2012
          Location: South Africa
          Age: 18
          Gender: Male
          Nature: Serious
          Posts: 34
          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 (2:45 AM).
          Kakarot1212's Avatar
          Kakarot1212 Kakarot1212 is offline
          Resident Programmer
             
            Join Date: Oct 2013
            Location: Phillipines
            Gender: Male
            Nature: Adamant
            Posts: 553
            Hmm.. Nice tut!
            Bad thing i dont have any knowledge on VB.NET yet.
            Am still learning java, though.
            __________________
            Reply With Quote
              #11    
            Old December 20th, 2013 (12:47 PM).
            haven1433 haven1433 is offline
            Modder / Programmer
               
              Join Date: Oct 2013
              Gender: Male
              Posts: 7
              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
                #12    
              Old August 16th, 2015 (5:01 PM).
              ConradoPSA ConradoPSA is offline
                 
                Join Date: Aug 2015
                Posts: 2
                The file is being saved totally corrupted

                Please, help-me, contact-me in the skype: ConradoP.S.A
                I'm brazilian, sorry the inglish.
                Reply With Quote
                  #13    
                Old August 17th, 2015 (12:52 AM).
                Graykis23390's Avatar
                Graykis23390 Graykis23390 is offline
                Graykis Jiang
                   
                  Join Date: Jul 2015
                  Location: Hongkong
                  Gender: Male
                  Nature: Calm
                  Posts: 49
                  Wow!creating tool by oneself is cool!
                  __________________
                  Never giving up!
                  Reply With Quote
                    #14    
                  Old August 17th, 2015 (5:50 AM).
                  Akiba's Avatar
                  Akiba Akiba is offline
                  • Crystal Tier
                   
                  Join Date: Mar 2011
                  Location: in a gap
                  Age: 18
                  Gender: Female
                  Nature: Brave
                  Posts: 4,268
                  lmao I was such a noob when I was 13.

                  VB.NET shouldn't be used at all, I'm going to write a tutorial series on modern hacking tools real soon.
                  __________________
                  Reply With Quote
                    #15    
                  Old August 17th, 2015 (5:56 PM).
                  ConradoPSA ConradoPSA is offline
                     
                    Join Date: Aug 2015
                    Posts: 2
                    13 years? You can be anything, but not noob. Excellent tool even if not 100%, congratulations!! ^-^
                    Reply With Quote
                      #16    
                    Old August 17th, 2015 (6:43 PM).
                    Akiba's Avatar
                    Akiba Akiba is offline
                    • Crystal Tier
                     
                    Join Date: Mar 2011
                    Location: in a gap
                    Age: 18
                    Gender: Female
                    Nature: Brave
                    Posts: 4,268
                    I'm flying back from Japan in a few hours.

                    I'll probably write a bunch of tutorials and deprecate all these old ones lol
                    __________________
                    Reply With Quote
                      #17    
                    Old August 17th, 2015 (8:54 PM).
                    Nick Nick is offline
                    Banned
                       
                      Join Date: Nov 2009
                      Age: 19
                      Posts: 5,220
                      Quote:
                      Originally Posted by Akiba View Post
                      I'm flying back from Japan in a few hours.

                      I'll probably write a bunch of tutorials and deprecate all these old ones lol
                      I'd really appreciate it if, at some point when it's possible, you wrote a tutorial demonstrating effective use of standard PokéScript, using Lapis as an assembler. And of course one for Sapphire for the folks who use in-built editors! :P
                      Reply With Quote
                        #18    
                      Old August 17th, 2015 (9:02 PM).
                      Akiba's Avatar
                      Akiba Akiba is offline
                      • Crystal Tier
                       
                      Join Date: Mar 2011
                      Location: in a gap
                      Age: 18
                      Gender: Female
                      Nature: Brave
                      Posts: 4,268
                      I took a look at Lapis a while ago, it's pretty cool.

                      My new ecosystem is essentially a collection of orthogonal npm packages that operate on ROMs with buffers and streams. I'd be interested in porting it to JS.

                      Joexv just sent me the source for his Hex Helper, I'm reimplementing it in a Unixy way.
                      __________________
                      Reply With Quote
                        #19    
                      Old August 17th, 2015 (9:25 PM).
                      Nick Nick is offline
                      Banned
                         
                        Join Date: Nov 2009
                        Age: 19
                        Posts: 5,220
                        Quote:
                        Originally Posted by Akiba View Post
                        I took a look at Lapis a while ago, it's pretty cool.

                        My new ecosystem is essentially a collection of orthogonal npm packages that operate on ROMs with buffers and streams. I'd be interested in porting it to JS.


                        You make good tutorials. I'd like to see one of the first how-tos for this program and its standard to be done properly. :p
                        Reply With Quote
                          #20    
                        Old August 17th, 2015 (10:24 PM). Edited August 18th, 2015 by Spherical Ice.
                        Akiba's Avatar
                        Akiba Akiba is offline
                        • Crystal Tier
                         
                        Join Date: Mar 2011
                        Location: in a gap
                        Age: 18
                        Gender: Female
                        Nature: Brave
                        Posts: 4,268
                        Nothing else to do at the airport so I just went ahead and wrote a little article. Hope y'all like it.

                        http://www.pokecommunity.com/showthread.php?t=354188
                        __________________
                        Reply With Quote
                          #21    
                        Old February 24th, 2017 (12:13 PM).
                        majdimohammad majdimohammad is offline
                           
                          Join Date: Feb 2017
                          Gender: Male
                          Posts: 1
                          Any how i can get new link for the simplehex source code?
                          Reply With Quote
                          Reply

                          Quick Reply

                          Join the conversation!

                          Create an account to post a reply in this thread, participate in other discussions, and more!

                          Create a PokéCommunity Account

                          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

                          Forum Jump


                          All times are GMT -8. The time now is 8:38 PM.