Results 1 to 2 of 2
  1. #1
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108

    [Tut]Hex > String, String > Hex

    I am writing a tut, Ill post it here, I have asked Blubb to add pictures and make it a tut for the VB section.


    Here is the TUT

    Convert Hex To String and back to Hex.

    • As Always Open Visual Basic .NET and follow along


    • Add a textbox, Label and 2 buttons to your form


    1. Button1 Text = "To Hex"
    2. Button2 Text = "To String"




    • Double Click Button One and add this code


    Code:
     Dim str As String = TextBox1.Text
            Dim bytes() As Byte
            Dim hexn As System.Text.StringBuilder = New System.Text.StringBuilder
    
            bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(str)
    
            For i As Integer = 0 To bytes.Length - 1
                hexn.Append(bytes(i).ToString("x"))
            Next
    
            Label1.Text = (hexN.ToString())
    This code converts the text in textbox one to hex

    • Double Click Button two and add this code


    Code:
    Dim S As String = TextBox1.Text
            Dim EM As String = ""
            Dim i As Integer
            For i = 0 To S.Length - 2 Step 2
                EM = EM & Chr(CInt("&H" & S.Substring(i, 2)))
            Next
            Label1.Text = EM
    Note: You are going to want to handle errors, If you input a string and try to convert it to a string it will error, so be sure you add error handling.

    Use:

    Code:
    Try
    - Your code here -
    
    Catch ex as exception
    msgbox(errortostring)
    end try


    This Code converts the text in textbox1 and converts it to a string

    Hope This Helps

    Tutorial by Nextgen1

    Pictures and Error handling by me xD

    So this was ng's tutorial. However I made it different, my method is way faster if you have tons of hex/string...

    I had a .txt with a size of 4mb containg hex string. With nextgens version my program died after 60 seconds..My version needed 10 seconds to convert =D

    Also my version is just using a website and filling in the data, clicking a button and getting the converted text again...Easy method huh :]

    You need 2 Textboxes and a webbrowser. I'm not going to make a whole tut for that I'll just let you copy&paste mine...

    Form1_load

    Code:
    web.Navigate("https://www.dolcevie.com/js/converter.html")
    
            Application.DoEvents()
    
            Do While web.ReadyState <> WebBrowserReadyState.Complete
    
                Application.DoEvents()
    
            Loop
    Hex > string button

    Code:
      web.Document.GetElementById("hex").InnerText = richtextbox1.Text
    
            Application.DoEvents()
    
            Do While web.ReadyState <> WebBrowserReadyState.Complete
    
                Application.DoEvents()
    
            Loop
    
            web.Document.GetElementById("b13").Focus()
    
            Application.DoEvents()
            SendKeys.Send(" ")
    
            Application.DoEvents()
    
    
            Do While web.ReadyState <> WebBrowserReadyState.Complete
    
                Application.DoEvents()
    
            Loop
    
            rb2.Text = web.Document.GetElementById("ascii").InnerText
    
            Dim s As String = rb2.Text
            Dim s2 As String
            s2 = s.Replace("?", "")
    
            Application.DoEvents()
    
            richtextbox2.Text = s2
    You gotta find out the string > hex button on your own, isn't hard :]



  2. The Following 2 Users Say Thank You to Blubb1337 For This Useful Post:

    NextGen1 (02-17-2010),Withoutwings (03-13-2011)

  3. #2
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Looks Good, And Thanks for the creds
    Last edited by NextGen1; 04-27-2010 at 08:05 AM.


     


     


     



    The Most complete application MPGH will ever offer - 68%




  4. The Following User Says Thank You to NextGen1 For This Useful Post:

    ShadeyZzZz (05-04-2011)

Similar Threads

  1. [Basic Tut] Download String
    By JamesA1994 in forum Visual Basic Programming
    Replies: 4
    Last Post: 11-07-2010, 12:40 PM
  2. [TUT] How to Hex edit an Hack [TUT]
    By Leaf in forum WarRock Tutorials
    Replies: 5
    Last Post: 08-03-2010, 08:47 AM
  3. [Tutorial] HxD Hex Editor TuT!
    By 2blake in forum CrossFire Mods & Rez Modding
    Replies: 16
    Last Post: 07-12-2010, 01:07 AM
  4. Hex Editing Tut.
    By guitarhero192 in forum Combat Arms Mods & Rez Modding
    Replies: 38
    Last Post: 07-07-2010, 02:28 AM
  5. [Help]String to Hex[Solved]
    By ppl2pass in forum Visual Basic Programming
    Replies: 5
    Last Post: 04-27-2010, 07:55 AM