Skrip Posted November 15, 2008 Share Posted November 15, 2008 (edited) How can you open a file, and search a specific address (3Eh) for specific text?I need to search for 'Photoshop' at 3Eh. How can I do this?---$hFile = FileOpen("C:\Documents and Settings\Admin\My Documents\My Pictures\tyler.png", BitOR(16, 0)) $read = FileRead($hFile) #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 447, 193, 125) $Edit1 = GUICtrlCreateEdit("", 0, 0, 617, 433) GUICtrlSetData(-1, "Edit1") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Edit1, BinaryToString($read)) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndIt is a PNG file. The code above only returns ‰PNG Edited November 15, 2008 by Firestorm [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] Link to comment Share on other sites More sharing options...
Mobius Posted November 15, 2008 Share Posted November 15, 2008 (edited) 3eh would equate to 63 bytes from the start of the file, and since you know the length of the data you are searching for,this might work.$hFile = FileOpen("C:\Documents and Settings\Admin\My Documents\My Pictures\tyler.png", BitOR(16, 0)) $read = FileRead($hFile) ;#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 447, 193, 125) $Edit1 = GUICtrlCreateEdit("", 0, 0, 617, 433) GUICtrlSetData(-1, "Edit1") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Edit1, StringMid(BinaryToString($read),63,9)) ; Byte start and length While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 ; $GUI_EVENT_CLOSE Exit EndSwitch WEndoÝ÷ ÚÚaz¹¶¶âÖ§vÈhÂØ^¦"¶*'jëh×6$p = Int(StringInStr($read,"50686f746f73686f70",2) /2) IF $p THEN GUICtrlSetData($Edit1, StringMid(BinaryToString($read),$p,9) &" At "& Hex($p,2))Vlad Edited November 15, 2008 by Mobius Link to comment Share on other sites More sharing options...
rasim Posted November 15, 2008 Share Posted November 15, 2008 (edited) FirestormExample:;Creating the text file with a string "Hello world!" $hFile = FileOpen(@ScriptDir & "\~test.txt", 2) FileWrite($hFile, "Hello world!") FileClose($hFile) ;Open file in binary mode $hFile = FileOpen(@ScriptDir & "\~test.txt", 16) $sRead = FileRead($hFile) ;Search the ANSI "w" char For $i = 1 To BinaryLen($sRead) $var = BinaryMid($sRead, $i, 1) If BinaryToString($var) = "w" Then MsgBox(0, "Found", StringFormat("Binary(in HEX represent): %s\nString: %s\nOffset: %s", $var, BinaryToString($var), $i)) ExitLoop EndIf Next FileClose($hFile) FileDelete(@ScriptDir & "\~test.txt")Note!Searching the binary data in the string mode very slowly procedure. For quick searching use a buffer created through a DllStructCreate() function.Also you can find more examples from my little tools Edited November 15, 2008 by rasim Link to comment Share on other sites More sharing options...
Skrip Posted November 15, 2008 Author Share Posted November 15, 2008 They both work quite well. Thank you. [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] 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