|
-
Jan 26th, 2009, 04:46 PM
#1
Thread Starter
Member
[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.
-
Jan 27th, 2009, 05:06 AM
#2
Thread Starter
Member
Re: [2008] Binary to Hexadecimal (String)
-
Jan 27th, 2009, 09:20 AM
#3
Re: [2008] Binary to Hexadecimal (String)
Code:
Dim s As String = "440047000028000000000000896B4685"
Dim ssub As String
ssub = StrReverse(s.Substring(0, 4))
-
Jan 27th, 2009, 04:53 PM
#4
Thread Starter
Member
Re: [2008] Binary to Hexadecimal (String)
ok the main problem now is, how would i retrieve binary data from SQL?
-
Jan 27th, 2009, 05:57 PM
#5
Thread Starter
Member
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
-
Jan 27th, 2009, 06:04 PM
#6
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:
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()
builder.Append("0x")
For i As Integer = 0 To myBytes.Length - 1
builder.AppendFormat("{0:x2}", myBytes(i))
Next
MessageBox.Show(builder.ToString())
-
Jan 27th, 2009, 07:25 PM
#7
Thread Starter
Member
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.
-
Jan 27th, 2009, 07:30 PM
#8
Re: [2008] Binary to Hexadecimal (String)
-
Jan 28th, 2009, 04:10 AM
#9
Thread Starter
Member
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.
-
Jan 28th, 2009, 09:53 AM
#10
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
 
-
Jan 28th, 2009, 10:56 AM
#11
Thread Starter
Member
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"
-
Jan 28th, 2009, 11:12 AM
#12
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?
-
Jan 28th, 2009, 11:24 AM
#13
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
 
-
Jan 28th, 2009, 12:45 PM
#14
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|