• Welcome to Valhalla Legends Archive.
 

Why do you do this?

Started by BaDDBLooD, August 29, 2004, 11:31 PM

Previous topic - Next topic

BaDDBLooD

I am don't understand when your parsing certain things you need to use code like:

Val("&h" & HexConverter(StrReverse(Data)))
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

shadypalm88

#1
Quote from: BaDDBLooD on August 29, 2004, 11:31 PMI am don't understand when your parsing certain things you need to use code like:

Val("&h" & HexConverter(StrReverse(Data)))
I'm not sure what HexConverter is, but this is how you turn hexadecimal strings, e.g. AF, into actual numbers.  For example, this is how my bot gets the version byte for a product:
Public Function GetVersionByte(Product As bnProduct) As Long
   GetVersionByte = CLng("&H" & GetSetting("VerByte", ClientKeyToStr(Product)))
End Function
(bnProduct is an Enum of Battle.Net products, ClientKeyToStr turns one of those values into a stat code.)

This gets the version byte from the configuration file, which will be a 2-character string, such as C9.  &H is prepended to that, which makes VB evaluate is as &HC9.

BaDDBLooD

I mean like, in lot's of bots

People use the function strToHex



Public Function StrToHex(ByVal String1 As String) As String
Dim strTemp As String, strReturn As String, i As Long

For i = 1 To Len(String1)
   strTemp = Hex(Asc(Mid(String1, i, 1)))
   If Len(strTemp) = 1 Then strTemp = "0" & strTemp
   strReturn = strReturn & strTemp
Next i
StrToHex = strReturn
End Function



To get the ServerKey from 0x50

Why?
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

shadypalm88

#3
Quote from: BaDDBLooD on August 30, 2004, 12:21 AM
I mean like, in lot's of bots
People use the function strToHex
{code removed}
To get the ServerKey from 0x50
Why?
You might use that to display the server key, but I can't think of any good reason why you need it to get the key.  Unless they do something truly insane and stupid like:
Dim ServerKey As Long
[...]
ServerKey = Val("&H" & StrToHex(Mid(PacketData, 9, 4)))
If you're seeing that in "lot's of bots", well, IMO, that's a ridiculously stupid way to get an integer value out of a packet.

If you're not using an incoming packet parser (I do, so I'm just making this up, it's not tested code), something like this is more efficient:
Dim ServerKey As Long
[...]
CopyMemory ServerKey, ByVal Mid(PacketData, 9, 4), 4
Or even better, if you store packet data in a byte array instead of a string:

Dim ServerKey As Long
[...]
CopyMemory ServerKey, PacketData(8), 4

BaDDBLooD

Actually in the bot i am looking at:



ServerToken = Val("&h" & StrToHex(StrReverse(Mid(Data, 9, 4))))



That makes no Sence to me.  Why don't you just use GetDWORD
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

shadypalm88

Quote from: BaDDBLooD on August 30, 2004, 01:00 AMThat makes no Sence to me.  Why don't you just use GetDWORD
You should just use GetDWORD.  It doesn't make any sense to you because it's a very stupid way of doing it.

BaDDBLooD

#6
Could you explain it in more detail?

EDIT: I'd like to learn =)
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

shadypalm88

Quote from: BaDDBLooD on August 30, 2004, 01:03 AMCould you explain it in more detail?
Explain what in more detail?

BaDDBLooD

#8
Explain How that works.  Even if it is Stupid.

EDIT: Could we talk on aim?
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

shadypalm88

Quote from: BaDDBLooD on August 30, 2004, 01:07 AMExplain How that works.  Even if it is Stupid.
Oh.  Sure.  I'll break it down, moving from the inside out.

ServerToken = Val("&h" & StrToHex(StrReverse(Mid(Data, 9, 4))))

Mid(Data, 9, 4) - Extracts the raw bytes of the server token from the packet.
StrReverse() - Reverses the byte order.
StrToHex() - Gets the hex string from the raw bytes.  So, if the actual bytes (in hex) of the server token were CC 5B 58 30, StrToHex() will generate a string containing the characters "30585BCC".  (Remember, it was reversed.)
"&H" & - Adds the &H hex-delimiter to the beginning of the string.  Now the string would read "&H30585BCC"
Val() - Val reads a string that contains a number and returns the value of the number inside the string.  In this case, it reads the string and recognizes it as a number in base-16 (hexadecimal).  It then returns the actual value of the number.  So before you had the string "&H30585BCC", now you have the number &H30585BCC, which is the server token.

All these steps for just one value.  That's what makes it stupid.  Hopefully my explanation made sense. ;)

BaDDBLooD

This is what Copy Memory Does?
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

shadypalm88

Quote from: BaDDBLooD on August 30, 2004, 01:27 AMThis is what Copy Memory Does?
No.  Copy memory just, well, copies the memory.
Quote from: shadypalm88 on August 30, 2004, 12:57 AMDim ServerKey As Long
[...]
CopyMemory ServerKey, ByVal Mid(PacketData, 9, 4), 4
This takes the 4 bytes from the packet that represent the server token, and copies it to the variable called ServerKey.  No conversion takes place, as opposed to the "stupid" method where the server token is extracted, reversed, converted to human-readable format, and then converted back into machine-readable format.

BaDDBLooD

#12
Ok.  Still a little shady on how copy memory works.  Why you have to use it to "Copy" the memory.  I Don't see why you can't do Variable = Data.

EDIT: I heard from UserLoser that Copy Memory "Reverse's"?
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

shadypalm88

#13
Quote from: BaDDBLooD on August 30, 2004, 01:37 AMOk.  Still a little shady on how copy memory works.  Why you have to use it to "Copy" the memory.  I Don't see why you can't do Variable = Data.
While this is possible in other languages, it is not directly possible in Visual Basic.  Other languages support "typecasts".  If this were possible in VB you could do something like:Dim ServerToken As Long
[...]
ServerToken = (Long) Mid$(PacketData, 9, 4)
That code means "Take 4 bytes out of string PacketData starting with byte # 9, treat it as a Long and store it in ServerToken."  But like I said, this isn't possible in VB.  Using CopyMemory is a workaround for this problem.  Using the other, "stupid" method is another workaround, although it's slower, longer, and messier.

Quote from: BaDDBLooD on August 30, 2004, 01:37 AMEDIT: I heard from UserLoser that Copy Memory "Reverse's"?
I don't think so.  If it did, the value that ended up in ServerToken would be incorrect.

BaDDBLooD

#14
Well like when relating to Clan packets.

I was sending my Tag as NonNTSTring StrReverse(Tag)

i than realized that it said "dword" so my tag was 3 bytes..  He said use Copy memory to make it Four, you don't need to have strReverse.
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.