Sign in to follow this  
Followers 0
peet

FileOpen - Exe, change Hexcode

4 posts in this topic

#1 ·  Posted (edited)

Hi =)

I often need to edit some of my files with a hex-editor, so I tried to make it a little easier with AutoIt.

Cheap .txt files work like a charm but if try to read .exe files, FileOpen refuses to read them.

I just get the first two or three characters.

$myFile = "..."
FileOpen($myFile, 16)
$fileContent = FileRead($myFile,FileGetSize($myFile))
FileClose($myFile)

ConsoleWrite($fileContent & @CRLF)
Edited by peet

Share this post


Link to post
Share on other sites



Hi and Welcome to the forums!

The third character is a NULL, and ConsoleWrite() uses that to signal end of line or something. If you use lets say BinaryLen() you will see that everything is there.

ConsoleWrite(@AutoItExe & @CRLF)

$handle = FileOpen(@AutoItExe, 16)
$fileContent = FileRead($handle)
FileClose($handle)

ConsoleWrite(BinaryLen($fileContent) & @CRLF)

Also 2 things:

1. Use the autoit tags instead of code tags, gets more easy to read that way.

2. Your usage of the File*() funcs make no sense. See helpfile.

Share this post


Link to post
Share on other sites

Yey I finally made it work ;)

ConsoleWrite(@AutoItExe & @CRLF)
;Specify your file:
$datei = "..."
;find this Hexcode:
$findeHex = "..."
;replace it whith this:
$ersetzeMit = "..."

;Open the file in binary mode (16)
$dateiLesen = FileOpen($datei, 16)
$dateiInhalt = FileRead($dateiLesen)
FileClose($dateiLesen)

;ConsoleWrite($dateiInhalt & @CRLF)

$dateiInhalt = StringReplace($dateiInhalt, $findeHex, $ersetzeMit)

;Mode 2, too create a new modified file
$dateiErsetzen = FileOpen($datei, 2)
FileWrite($dateiErsetzen, Binary($dateiInhalt))
FileClose($dateiErsetzen)

;ConsoleWrite($dateiInhalt & @CRLF)

Now I'm going to make a nice interface.

Thanks for the advice, to look at my File* functions.

Share this post


Link to post
Share on other sites

Yey I finally made it work :ph34r:

ConsoleWrite(@AutoItExe & @CRLF)
;Specify your file:
$datei = "..."
;find this Hexcode:
$findeHex = "..."
;replace it whith this:
$ersetzeMit = "..."

;Open the file in binary mode (16)
$dateiLesen = FileOpen($datei, 16)
$dateiInhalt = FileRead($dateiLesen)
FileClose($dateiLesen)

;ConsoleWrite($dateiInhalt & @CRLF)

$dateiInhalt = StringReplace($dateiInhalt, $findeHex, $ersetzeMit)

;Mode 2, too create a new modified file
$dateiErsetzen = FileOpen($datei, 2)
FileWrite($dateiErsetzen, Binary($dateiInhalt))
FileClose($dateiErsetzen)

;ConsoleWrite($dateiInhalt & @CRLF)

Now I'm going to make a nice interface.

Thanks for the advice, to look at my File* functions.

OMG! OMG! OMG!

You are awesome, thanks a million!!! ;):alien::huh2:


#include<god.h>_asm //don't look!!![spoiler]x DB "aby'y DB 'GOD'tmp DB ? MOV CX,3 LEA SI, y LEA DI, tmp REP MOVSB LEA SI, x LEA DI, y REP MOVSB LEA SI, tmp LEA DI, x REP MOVSB MOV AH,09 MOV DX, OFFSET x INT 21h MOV DX, OFFSET y INT 21h[/spoiler]

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