Sign in to follow this  
Followers 0
Skrip

ASCII - Binary Search

4 posts in this topic

#1 ·  Posted (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?

Posted Image

---

$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
WEnd

It is a PNG file. The code above only returns

‰PNG
Edited 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]

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Mobius

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Firestorm

Example:

;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 :mellow:

Edited by rasim

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
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
Sign in to follow this  
Followers 0