Jump to content

Using AutoIt like a Hex-Editor


Recommended Posts

Hi AutoIt-Community,

i found this nifty little scripting language some days ago and i love it :whistle:

Anyway i've got a little problem while trying to get my script working.

I'm trying to read hexed data from an non-autoit .exe-File and replace this hex data with something else what is also in hex.

;So my first idea was reading the whole file..
$ahandle = FileOpen("C:\myexe.exe", 0)
$hex = Hex(BinaryString(FileRead($handle)))
FileClose($handle)

;... then using StringReplace to replace the hex searching for with another hexvalue ...
StringReplace($hex, "376869746530322E626E70", "0000000000000000000000")

; .. and then writing the new hex into a file called myexe_new.exe
$bhandle = FileOpen("C:\myexe_new.exe", 2)
FileWrite($bhandle, BinaryString($hex))
FileClose($bhandle)

Ok, this doesn't works as it was supposed to.

So, my question now is: is there some other - maybe better or at least working - way to do this or otherwise is there a way to fix my script? What did I wrong? Or is there even an existing script in these forums for this which i havn't found?

Thank you for reading and helping!

Link to comment
Share on other sites

  • Moderators

Hi AutoIt-Community,

i found this nifty little scripting language some days ago and i love it :P

Anyway i've got a little problem while trying to get my script working.

I'm trying to read hexed data from an non-autoit .exe-File and replace this hex data with something else what is also in hex.

;So my first idea was reading the whole file..
$ahandle = FileOpen("C:\myexe.exe", 0)
$hex = Hex(BinaryString(FileRead($handle)))
FileClose($handle)

;... then using StringReplace to replace the hex searching for with another hexvalue ...
StringReplace($hex, "376869746530322E626E70", "0000000000000000000000")

; .. and then writing the new hex into a file called myexe_new.exe
$bhandle = FileOpen("C:\myexe_new.exe", 2)
FileWrite($bhandle, BinaryString($hex))
FileClose($bhandle)

Ok, this doesn't works as it was supposed to.

So, my question now is: is there some other - maybe better or at least working - way to do this or otherwise is there a way to fix my script? What did I wrong? Or is there even an existing script in these forums for this which i havn't found?

Thank you for reading and helping!

Walk us through this as if we don't know what you are talking about step by step of what you are attempting and wish the outcome to be :whistle:

In addition, it's always best to provide all the tools necessary to help you efficiently.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Okay, i'll try to explain it a bit more detailed :whistle:

I've got this Exe-File, let's call it myexe.exe

Posted Image

I need to edit this file like in a hex-editor.

Posted Image

In Example, i know the file contains the hex-string "376869746530322E626E70" and now i want to replace this string with another hex-string which is "0000000000000000000000".

Posted Image

Finally i want to save the edited file where the mentioned strings were replaced as myexe_new.exe.

I don't want to automate the application, i want to edit the file with autoit commands.

My english is not the best i guess.. I hope i could at least explain it well.

(the editor used on the pics is called xvi32)

Edited by Devjunk
Link to comment
Share on other sites

  • Moderators

I've only been successful with AutoIt and this if I am able to un-pack it first... do the editing... then repack it... Larry and The Kandie Man have written "patchers" though that I'm sure since they go through the binary would be able to do it more successfully. I believe Larry even posted in the Examples forum.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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