Jump to content

FileOpen - Exe, change Hexcode


peet
 Share

Recommended Posts

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
Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 9 months later...

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]

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