Results 1 to 14 of 14

Thread: [2008] Binary to Hexadecimal (String)

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    51

    [2008] Binary to Hexadecimal (String)

    So the server I am running has a database of players equipment, I am trying to write a program to see if they are hacking by comparing the item requirement with the stats the player has, to do this I need to convert the varbinary(512) column from the SQL Database too a Hexadecimal string, then from that string remove certain parts of it.

    Example:
    This is the hexadecimal code for an item:
    Code:
    0x440047000028000000000000896B4685
    the part I need is "4400" numbers (Position 3,4,5,6 from start) I then need to flip these backwards so it reads "0044". I then will compare this itemIDX with a list of items I have set aside that people mainly use this hack for.

    So the main things I need help with, are converting varbinary(512) to hexadecimal and then making my program bring a list of accountID's up who are using the hack, here is how the databases are set out:

    Account:
    Contains account data ONLY
    Game:
    Contains the Character and Equipment DB

    i need to compare the equipmentDB, then return the CharacterID from the equipmentID, compare that ID with the CharacterID in CharacterDB, then extract the accountID then return the account name from the accountDB

    I don't know how the binary is split up from item too item, although I would imagine, it isn't, i would have thought it just goes onto the next item when the item ends.
    Although, all the items start with hex string "0x" so this may be the separator!

    If somone knows a set of SQLQuerys this would also help, thanks a lot!

    -02goswej
    Last edited by 02goswej; Jan 26th, 2009 at 04:50 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    51

    Re: [2008] Binary to Hexadecimal (String)

    Anyone :S?

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] Binary to Hexadecimal (String)

    Code:
            Dim s As String = "440047000028000000000000896B4685"
            Dim ssub As String
            ssub = StrReverse(s.Substring(0, 4))
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    51

    Re: [2008] Binary to Hexadecimal (String)

    ok the main problem now is, how would i retrieve binary data from SQL?

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    51

    Re: [2008] Binary to Hexadecimal (String)

    Ok, i am having this problem:

    I can retrieve the binary array from SQL but in the list box is shows up as "Byte[]Array" i want this to show the actual bytes so i can convert it into hexadecimal!

    some one help

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Binary to Hexadecimal (String)

    You are probably adding the entire array object to the ListBox, which in turn will call its ToString method when it displays it...which will give you a string containing the type name.

    You need to do something like this:
    VB.NET Code:
    1. Dim myBytes() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
    2.         Dim builder As New System.Text.StringBuilder()
    3.         builder.Append("0x")
    4.         For i As Integer = 0 To myBytes.Length - 1
    5.             builder.AppendFormat("{0:x2}", myBytes(i))
    6.         Next
    7.         MessageBox.Show(builder.ToString())
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    51

    Re: [2008] Binary to Hexadecimal (String)

    How would i now convert this into hexadecimal (if it already isnt?)
    Also, how would i insert some kind of splitter between each records (each record is 32 characters long, so every 32 characters insert a space or somthing)
    Last edited by 02goswej; Jan 27th, 2009 at 07:32 PM.

  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Binary to Hexadecimal (String)

    Did you try my code?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    51

    Re: [2008] Binary to Hexadecimal (String)

    Yup, works fine (thanks a lot ^.^)
    Thing i need to do is add a seperator between each value (As at the minute im just getting a BIG BLOCK of numbers with a few letters here and there)

    Somthing just like add a space every 32 characters
    Last edited by 02goswej; Jan 28th, 2009 at 09:48 AM.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Binary to Hexadecimal (String)

    Is it ALWAYS every 32 characters, or is there some character indicating the end of a row?
    My usual boring signature: Nothing

  11. #11

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    51

    Re: [2008] Binary to Hexadecimal (String)

    Well at the minute, ive hit a snag before i can continue:

    My character is wearing 2 items (for testing) and they have ID's of "809"

    This is the feedback im getting from my characters equipment data:



    As you can see it's incorrect!, it works with some items, but i dont know...Is it jumbled up or is it just "weird" it seems to be repetetive therfore i know its getting the same item data twice, although i dont know why the itemID shows up with some items and not others. It there a possibility that it has been moved around in the process?

    my code for fetching the data:

    Code:
     Dim DBIP As String = "<IP>" 'Database IP
        Dim UID As String = "sa"      'Database UID
        Dim PWD As String = "<password>"     'Database UID Password
     Dim s As String
            myconnection = New SqlClient.SqlConnection("server=" & DBIP & ";uid=" & UID & ";pwd=" & PWD & ";database='GameDB'")
            Try
                myconnection.Open()
                mycommand = New SqlClient.SqlCommand("Select * from game_equipment_table", myconnection)
                dr = mycommand.ExecuteReader
                While dr.Read
                    LstChName.Items.Add(dr.GetValue(0).ToString)
                    Dim myBytes() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
                    Dim builder As New System.Text.StringBuilder()
                    myBytes = dr.GetValue(1)
                    For i As Integer = 0 To myBytes.Length - 1
                        builder.AppendFormat("{0:x2}", myBytes(i))
                    Next
                    lstAccount.Items.Add(builder.ToString())
                End While
                dr.Close()
                myconnection.Close()
            Catch ex As Exception
            End Try
    that's the code to connect to the database, recieve the code, then change the code to what i have in the screenshot (This is just the data from one of my characters using item id "809"

  12. #12
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Binary to Hexadecimal (String)

    Well..
    You are fetching a byte array from the database, and you're expecting the value 809 to pop up somewhere, but a byte can not be larger than 255, so you will never see a value larger than that if you're dealing with bytes only.

    Numbers that are larger than 255 are made up of several bytes in memory. In the case of 809 it consists of 41 and 3.
    41 and 3 in hexadecimal would be: 2903
    Can you find 2903 somewhere in your chunk of hexadecimal values?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Binary to Hexadecimal (String)

    To add to what Athiest has said, Windows comes with a calculator that does Decimal to Hex conversions. When you have it set to decimal, type in 809, then switch to Hex, you get 329. Since every two characters in hex make up each byte, the 329 should be read as 03 and 29, but which order they will show up in your array is not necessarily the same as you would read them. The first byte is first (29) while the second byte is second (03), hence 2903.
    My usual boring signature: Nothing

  14. #14

    Thread Starter
    Member
    Join Date
    Jan 2009
    Posts
    51

    Re: [2008] Binary to Hexadecimal (String)

    Ah i see, thanks so i can just make it check for either "2903" or "0329" and ittl give me the same result ?

    if so, how would i check through the first 4 characters, then skip to 30-34, 64-68,98-102 and so... (the first 4 character (what i need) occur, then a string of 29 other characters that are usless too me, then the next items 4 characters come up)

    Example (May not be correct!)
    29030D000004000000000D00000000F829030C000004000000000E00000000F882E0010000041B00001001000000000009E
    although in this case the hex string "82E0" is far too big for an item id (Either way its over 30000)
    so the above in red is the data i need, how would i extract it and check it against a set of numbers i already have
    Last edited by 02goswej; Jan 28th, 2009 at 01:31 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width