Jump to content

Recommended Posts

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]

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

wtfpl-badge-1.png

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
Posted

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]

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...