Metal Posted November 9, 2008 Share Posted November 9, 2008 Hi all,I need to add a null byte at the end of a string, but i donnow how to do iti tryed this:$s = 'hello'$s &= Chr(0)but failedI used search and found this, but i didn't understand the solution...can you help me please? Link to comment Share on other sites More sharing options...
ResNullius Posted November 9, 2008 Share Posted November 9, 2008 How is it failing? What are you trying to do with the results? Write to a file? Link to comment Share on other sites More sharing options...
trancexx Posted November 9, 2008 Share Posted November 9, 2008 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 Link to comment Share on other sites More sharing options...
Metal Posted November 10, 2008 Author Share Posted November 10, 2008 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 More sharing options...
rover Posted November 10, 2008 Share Posted November 10, 2008 Firstly, Welcome to the forums Metala few links to posts about nothing Nothing (VB/VBScript constant) in AutoIthttp://www.autoitscript.com/forum/index.ph...mp;#entry483555advanced 'title only' search for "Null"http://www.autoitscript.com/forum/index.ph...ighlite=%2Bnullperhaps someone with python experience will comment. I see fascists... Link to comment Share on other sites More sharing options...
JRowe Posted November 10, 2008 Share Posted November 10, 2008 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 [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 11, 2008 Share Posted November 11, 2008 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 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 More sharing options...
JRowe Posted November 11, 2008 Share Posted November 11, 2008 Ahh, I see good to know. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now