Jump to content
Sign in to follow this  
Metal

Null byte

Recommended Posts

Metal

Hi all,

I need to add a null byte at the end of a string, but i donnow how to do it

i tryed this:

$s = 'hello'

$s &= Chr(0)

but failed

I used search and found this, but i didn't understand the solution...

can you help me please?

Share this post


Link to post
Share on other sites
ResNullius

How is it failing?

What are you trying to do with the results?

Write to a file?

Share this post


Link to post
Share on other sites
trancexx

I don't see a problem.

@Metal; you should really use more words explaining.

I guess what you want is null terminated string. But that is only my assumption.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Metal

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

Share this post


Link to post
Share on other sites
JRowe

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:

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
JRowe

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.