Jump to content

Debugging question


Steve8402
 Share

Recommended Posts

I am a newbie to autoit and am trying to figure out how to debug my scripts as they run. Is there an option somewhere to show what the script is doing as it steps through its functions?

The reason I would like to debug my script is that when I do a string comparison in an if statement from what I can tell the variable is somehow being reset to null.

$line = FileReadLine($file1)
$text = StringMid($line, 12,18)
MsgBox(0,"temp", $text)
    If $text = "ReadProcessMemory" Then
            MsgBox(0,"test","read process mem")
            ClearLog()
            StartBotting()
            $inside = 1
    Endif

I have set up the first MsgBox to display the contents of $text and it outputs the proper text. I then do a comparison of the $text variable to "ReadProcessMemory" and at that point the script does not enter the If statement. When I place this section of code into a loop the second time that the first MsgBox is displayed the contents of the MsgBox is blank.

Also if I set my comparison to:

If $text = "" Then
    ...
    ...
EndIf

It will enter the If statement.

If anyone can offer some help, or tell me how to better debug the scripts that would be really helpful.

Link to comment
Share on other sites

Have you gotten Scite yet? get it (Link in sig i think)

They have a debug msgbox thing, you gotta work with it to get it to do what you want.

Anyway, to test the contents of a variable, whenever you would use it, call a msgbox like this

Msgbox("$*YourVar* =, $YourVar)

If its a blank msgbox, then yes, you string has been set to null

Link to comment
Share on other sites

Have you gotten Scite yet? get it (Link in sig i think)

They have a debug msgbox thing, you gotta work with it to get it to do what you want.

Anyway, to test the contents of a variable, whenever you would use it, call a msgbox like this

Msgbox("$*YourVar* =, $YourVar)

If its a blank msgbox, then yes, you string has been set to null

Thanks for the advice.

Do you have any idea why it could be resetting the variable though?

Link to comment
Share on other sites

Not without a code/specified variable

but provide me with that and i'd be happy to help :)

Here is a snippet of what I am doing. If you create a file called Test.log in the directory you run the script from and place some text in it you should be able to run this code and see the problem.

$file1 = FileOpen("Test.log", 0)
While 1
$line = FileReadLine($file1)
$text = StringMid($line, 12,18)
MsgBox(0, $text, $text)
WEnd
Link to comment
Share on other sites

Here is a snippet of what I am doing. If you create a file called Test.log in the directory you run the script from and place some text in it you should be able to run this code and see the problem.

$file1 = FileOpen("Test.log", 0)
While 1
$line = FileReadLine($file1)
$text = StringMid($line, 12,18)
MsgBox(0, $text, $text)
WEnd
Is the line read from $file1 less than 12 characters long? If so, then the StringMid() function will return an empty string, since you told it to start at the 12th character. In the first post you were comparing it to "ReadProcessMemory", which is only 17 characters long, yet your StringMid() selects 18 characters to compare with. There may be a trailing non-printable character in your $text string, like a space, @CRLF, etc., which would cause it not to match.

You could make your StringMid match the search string length automaticaly:

$SearchStr = "ReadProcessMemory"
$SearchLen = StrLen($SearchStr)
$file1 = FileOpen("Test.log", 0)
While 1
     $line = FileReadLine($file1)
     $text = StringMid($line, 12, $SearchLen)
     If $text = $SearchStr Then MsgBox(64, "Match", "String match: " & $text)
WEndoÝ÷ Øíív¶!j¶µêé¢È¬¶*'É趷¬   â~'ܨ¹Ê.Øî²Û¬zêåoÝ÷ ØKÞ'â¶f­µê춭ÖÞjÛa{]­ÈZ­§-z´­®)à"t­®f²²Ø¥·jÈ­«­¢+ØÀÌØíMÉ¡MÑÈôÅÕ½ÐíIAɽÍÍ5µ½ÉäÅÕ½Ðì(ÀÌØí¥±Äô¥±=Á¸ ÅÕ½ÐíQÍй±½ÅÕ½Ðì°À¤)]¡¥±Ä(ÀÌØí±¥¹ô¥±I1¥¹ ÀÌØí¥±Ä¤(%MÑÉ¥¹%¹MÑÈ ÀÌØí±¥¹°ÀÌØíMÉ¡MÑȤôÄÈQ¡¸5Í   ½à ØаÅÕ½Ðí5Ñ ÅÕ½Ðì°ÅÕ½ÐíMÑÉ¥¹µÑ èÅÕ½ÐìµÀìÀÌØí±¥¹¤)]¹

Lots of options... :)

Edited by PsaltyDS
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

Is the line read from $file1 less than 12 characters long? If so, then the StringMid() function will return an empty string, since you told it to start at the 12th character. In the first post you were comparing it to "ReadProcessMemory", which is only 17 characters long, yet your StringMid() selects 18 characters to compare with. There may be a trailing non-printable character in your $text string, like a space, @CRLF, etc., which would cause it not to match.

You could make your StringMid match the search string length automaticaly:

$SearchStr = "ReadProcessMemory"
$SearchLen = StrLen($SearchStr)
$file1 = FileOpen("Test.log", 0)
While 1
     $line = FileReadLine($file1)
     $text = StringMid($line, 12, $SearchLen)
     If $text = $SearchStr Then MsgBox(64, "Match", "String match: " & $text)
WEndoÝ÷ Øíív¶!j¶µêé¢È¬¶*'É趷¬   â~'ܨ¹Ê.Øî²Û¬zêåoÝ÷ ØKÞ'â¶f­µê춭ÖÞjÛa{]­ÈZ­§-z´­®)à"t­®f²²Ø¥·jÈ­«­¢+ØÀÌØíMÉ¡MÑÈôÅÕ½ÐíIAɽÍÍ5µ½ÉäÅÕ½Ðì(ÀÌØí¥±Äô¥±=Á¸ ÅÕ½ÐíQÍй±½ÅÕ½Ðì°À¤)]¡¥±Ä(ÀÌØí±¥¹ô¥±I1¥¹ ÀÌØí¥±Ä¤(%MÑÉ¥¹%¹MÑÈ ÀÌØí±¥¹°ÀÌØíMÉ¡MÑȤôÄÈQ¡¸5Í   ½à ØаÅÕ½Ðí5Ñ ÅÕ½Ðì°ÅÕ½ÐíMÑÉ¥¹µÑ èÅÕ½ÐìµÀìÀÌØí±¥¹¤)]¹

Lots of options... :)

The 12th character is significant because of a timestamp which is placed in the log file. The reason I chose 18 character lenght is when I used the MsgBox to display the contents of the variable it was cutting off the last character (the 'y'). I will try this by setting the $SearchStr variable and see if that works.

Link to comment
Share on other sites

OK this is what I have tried with the same result:

$file1 = FileOpen("Test.log", 0)
$searchStr = "ReadProcessMemory"
$searchLen = StringLen($searchStr)
While 1
$line = FileReadLine($file1)
$text = StringMid($line, 12,$searchLen)
MsgBox(0, $text, $text)
WEnd

Once again the variable is displaying only "ReadProcessMemor" when it is shown in the MsgBox the first time through the loop. The second time and all subsequent times through the loop the MsgBox displays nothing.

Link to comment
Share on other sites

OK this is what I have tried with the same result:

$file1 = FileOpen("Test.log", 0)
$searchStr = "ReadProcessMemory"
$searchLen = StringLen($searchStr)
While 1
$line = FileReadLine($file1)
$text = StringMid($line, 12,$searchLen)
MsgBox(0, $text, $text)
WEnd

Once again the variable is displaying only "ReadProcessMemor" when it is shown in the MsgBox the first time through the loop. The second time and all subsequent times through the loop the MsgBox displays nothing.

Could you post about a three line sample of Test.log for us? It would really help to be able to look at that line format. The only reason I see for that data mangling is that the string "ReadProcessMemory" actually starts at character 13 and you are catching a LEADING extra character: "_ReadProcessMemor". One way to test that would be change your debug MsgBox to:

MsgBox(0, "Debug", "=" & $text & "=")

Then the equals signs will clearly show if there are other characters in there.

I've use a lot of String*() functions, and they don't just lose count like that. Do you get a different result using StringInStr() examples instead?

:)

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

Could you post about a three line sample of Test.log for us? It would really help to be able to look at that line format. The only reason I see for that data mangling is that the string "ReadProcessMemory" actually starts at character 13 and you are catching a LEADING extra character: "_ReadProcessMemor". One way to test that would be change your debug MsgBox to:

MsgBox(0, "Debug", "=" & $text & "=")

Then the equals signs will clearly show if there are other characters in there.

I've use a lot of String*() functions, and they don't just lose count like that. Do you get a different result using StringInStr() examples instead?

:)

I will give StringInStr a try. The file that I am pulling this from just has some sample data which is in the exact format of the real file. The sample is below.

xx:xx:xx xx ReadProcessMemory

The xx:xx:xx is a time stamp, the next xx is either AM/PM.

Thanks for the help btw I appreciate it.

Link to comment
Share on other sites

I will give StringInStr a try. The file that I am pulling this from just has some sample data which is in the exact format of the real file. The sample is below.

The xx:xx:xx is a time stamp, the next xx is either AM/PM.

Thanks for the help btw I appreciate it.

Welllll... :)

xx times 3 = 6

plus two times ":" colons for seperators = 8

plus a space = 9

plus xx for am/pm = 11

plus another space = 12

makes "ReadProcessMemory" start at... 13!

:P

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

Welllll... :)

xx times 3 = 6

plus two times ":" colons for seperators = 8

plus a space = 9

plus xx for am/pm = 11

plus another space = 12

makes "ReadProcessMemory" start at... 13!

:P

OK this is exactly what I have in the script right now with 13 as the start position. The problem is not really what it reads the first time through the loop but when it goes through the loop again it clears the variable.

$file1 = FileOpen("Test.log", 0)
While 1
$line = FileReadLine($file1)
$text = StringMid($line, 13,17)
MsgBox(0, $text, $text)
WEnd

Could you try loading that in a script with the Test.log file containing the same thing I posted earlier and tell me if you get the same result? Or does your MsgBox show "ReadProcessMemory" each time it goes through the loop?

Link to comment
Share on other sites

I finally got it working.... I added a FileOpen and FileClose inside the loop and that appears to of fixed the problem.

Thanks for the help.

The problem with that is you will read the first line over and over.

I'm not on a Windows box right now, but will test it when I get to one (some time tomorrow).

Cheers!

:)

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

I tested it with the following code, loosely based on your OP:

; Test1.au3
$file1 = FileOpen(@ScriptDir & "\Test1.log", 0) ; 0=readonly
While 1
    $line = FileReadLine($file1)
    If @error Then ExitLoop
    $text = StringMid($line, 13, 17)
    ; MsgBox(64, "Debug", "$text ==>" & $text & "<==")
    If $text = "ReadProcessMemory" Then
        Trigger($line)
    EndIf
WEnd
FileClose($file1)

Func Trigger($sData)
    MsgBox(64, "Trigger()", "Function Trigger() was called: " & $sData, 3)
EndFunc   ;==>Trigger

And the following contents in Test1.log:

CODE
12:01:01 AM ReadProcessMemory 1234567890ABCDEFGHIJ

01:01:01 AM ReadProcessMemory 1234567890ABCDEFGHI

02:01:01 AM DifferentMessage 1234567890ABCDEFGH

03:01:01 AM ReadProcessMemory 1234567890ABCDEFG

04:01:01 AM ReadProcessMemory 1234567890ABCDEF

05:01:01 AM DifferentMessage 1234567890ABCDE

06:01:01 AM ReadProcessMemory 1234567890ABCD

07:01:01 AM ReadProcessMemory 1234567890ABC

08:01:01 AM DifferentMessage 1234567890AB

09:01:01 AM ReadProcessMemory 1234567890A

10:01:01 AM ReadProcessMemory 1234567890

11:01:01 AM DifferentMessage 123456789

12:01:01 PM ReadProcessMemory 12345678

01:01:01 PM ReadProcessMemory 1234567

02:01:01 PM DifferentMessage 123456

03:01:01 PM ReadProcessMemory 12345

04:01:01 PM ReadProcessMemory 1234

05:01:01 PM DifferentMessage 123

06:01:01 PM ReadProcessMemory 12

07:01:01 PM ReadProcessMemory 1

08:01:01 PM DifferentMessage

09:01:01 PM ReadProcessMemory ABCDEFGHIJ0123456789

10:01:01 PM ReadProcessMemory ABCDEFGHIJ012345678

11:01:01 PM DifferentMessage ABCDEFGHIJ01234567

It has no problem reading the whole file, detecting every instance of "ReadProcessMemory", and ignoring the other lines.

:)

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...