Jump to content

Null byte


Metal
 Share

Recommended Posts

i'm sorry, but i'm not good with english

i'm creating a client for a chat service. I have to send to the server a package containing some information to login in the chat service. The structure of the package is this (python language):

auth = byte2(0x90)
                auth += byte2(56)
                auth += byte2(1)
                auth += byte2(32)
                auth += bytestr(str(usr_data[0])+"\0", 24);
                auth += bytestr(str(usr_data[1])+"\0", 24);

byte2(), bytestr() are functions created by the developer, usr_data[0] is the username and usr_data[1] is the password.

After username and after password i've to add a null byte (null byte in python is "\0"), but i don't now how to add a null byte in autoit language. I tryed to use

&Chr(0)

instead of

+"\0"

but it fails. Is it a problem of the syntax i used or whatelse? C'ouse in this way it fails. What's the syntax for 'null byte' in autoit?

ps: i hope that explaination is better; sorry me for my bad english

Link to comment
Share on other sites

You'll want to use the Binary() function, to convert your data to binary, then add a 0 to the end. For example,

$test= Binary("test")

0x74657374 is the result; It's the hex version of the binary data representing the string "test."

In order to add a null to the end of your data, then, simply concatenate:

$testWithNull = Binary($test) & Binary(Chr(0))

Thus, the data being sent to is now: 0x7465737400. Hopefully that works :mellow:

Link to comment
Share on other sites

You'll want to use the Binary() function, to convert your data to binary, then add a 0 to the end. For example,

$test= Binary("test")

0x74657374 is the result; It's the hex version of the binary data representing the string "test."

In order to add a null to the end of your data, then, simply concatenate:

$testWithNull = Binary($test) & Binary(Chr(0))

Thus, the data being sent to is now: 0x7465737400. Hopefully that works :mellow:

You've got the right idea, but the Binary() function won't stop reading the input string when it hits a null, as most other AutoIt functions will. So you don't have to append the nulls with separate calls to Binary(Chr(0)):
$test = "test" & Chr(0) & Chr(0) & "x"
ConsoleWrite("Debug:  $test = " & $test & @LF)
$testWithNull = Binary($test)
ConsoleWrite("Debug:  $testWithNull = " & $testWithNull & @LF)

Output:

>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Temp\Test_1.au3"   
Debug:  $test = testDebug:  $testWithNull = 0x74657374000078
+>09:39:43 AutoIT3.exe ended.rc:0

Note the ConsoleWrite() function stops reading the string at the first null it hits, but the Binary() function gets them all.

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...