Jump to content
Sign in to follow this  
am632

hex editing help

Recommended Posts

am632

Hi I have searched around but cant really find what im looking for - its a very simple idea.

I have a file which I can open in a hex editor - goto an offset which I already know and I want to change the value.

I want a script which I can pre-specify a file and offset and an editbox which I can type in a new two-digit figure which will be the value I want to change.

How can I do this? The gui isnt a problem - i just cant really find much info regards hex editing. the reason I want this is to save me opening the file in a hex editor and searching for the offset everytime I want to change it 'cos its time consuming.

can anyone offer any help in the correct direction please?

thanks

Share this post


Link to post
Share on other sites
FireFox

Hi,

This is simple, open the file in "binary" mode and then edit the offset you want (with File or String funcs)

$hFile = FileOpen("myfile.ext", 16) ;binary mode + read

$hexRead = FileRead($hFile)

FileClose($hFile)

$hexEdited = ... ;process the file

$hFile = FileOpen("myfile.ext", 18) ;binary mode + write
FileWrite($hFile, Binary($hexEdited))
FileClose($hFile)

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Malkey

Expanding of FireFox's example, here is an example using a function that will HexEdit or binary edit a file.

Local $sFileName = "myfile.ext"
Local $iOffSet   = 4     ; No. of bytes from beginning of file.
Local $iNewBinaryValue = "38"    ; "0x38393938" ; Binary values, or, ASCII hexadeciminal values with, or, without the leading "0x"

Local $Ret = _FileHexEdit($sFileName, $iOffSet, $iNewBinaryValue)
If @error Then
Switch $Ret
Case -1
MsgBox(0, "Error", 'Unable to open file: "' & $sFileName & '"')
Case 1
MsgBox(0, "Error", 'Offset out of bounds')
EndSwitch
Else
ConsoleWrite(FileRead($sFileName) & @LF)
EndIf


Func _FileHexEdit($sFileName, $iOffSet, $sHexNew)
If StringLeft($sHexNew, 2) == "0x" Then $sHexNew = StringTrimLeft($sHexNew, 2)
Local $sEndFile = ""
Local $hFile = FileOpen($sFileName, 16) ;binary mode + read
If $hFile = -1 Then Return SetError(1, 0, -1) ; If error opening file

Local $iFileSize = FileGetSize($sFileName)
If $iOffSet < 1 Or $iOffSet > $iFileSize Then Return SetError(1, 0, 1) ; Check offset size

Local $sBeginFile = FileRead($hFile, $iOffSet - 1) ; Read file from start to $iOffSet -1
If ($iOffSet - 1) + (StringLen($sHexNew) / 2) < $iFileSize Then ; Can not set file pointer beyond EOF.
FileSetPos($hFile, ($iOffSet - 1) + (StringLen($sHexNew) / 2), 0) ; 0 = $FILE_BEGIN) ; Set file pointer to (($iOffSet-1) + No. of bytes in $sHexNew)
$sEndFile = FileRead($hFile) ; Read rest of the file from file pointer to EOF.
EndIf
FileClose($hFile)

Local $hexEdited = ($sBeginFile & $sHexNew & StringTrimLeft($sEndFile, 2)) ; Concatenate beginning of file & $sHexNew & end part of file
If StringLeft($hexEdited, 2) <> "0x" Then $hexEdited = "0x" & $hexEdited ; When offset = 1 there is no leading "0x"

$hFile = FileOpen($sFileName, 18) ;binary mode + write
FileWrite($hFile, Binary($hexEdited))
FileClose($hFile)
Return SetError(0, 0, 1)
EndFunc ;==>_FileHexEdit
  • Like 1

Share this post


Link to post
Share on other sites
am632

Hi, thanks guys for these examples - sorry I havnt replied earlier, just been bit busy but will check these out 2nite hopefully when I get a spare bit of time.

Thanks a lot

Share this post


Link to post
Share on other sites
water

Why do you want to hex edit a file at all? What kind of file (exe ...) do you need to edit?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Mobius

Why do you want to hex edit a file at all? What kind of file (exe ...) do you need to edit?

How is that even relevant, the users reasons are their own, or else they surely would have provided this information would they not.

Is the use of a hex editor suddenly taboo, you are probably right in your assumption but who cares, they recieved the help and support they needed.

Vlad

Share this post


Link to post
Share on other sites
water

It is relevant. If you have read the forum rules you will know that a few things are forbidden here.

I ask to see if the user has a legitimate reason for what he wants to do.

The user just describes what he wants to do but not why. That's why I ask.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Mobius

Let the moderators do their jobs and stop lecturing.

were the support indufficient the op would probably have provided more information that would have led us to understand its intent anyway.

Vlad

Share this post


Link to post
Share on other sites
water

Let the moderators do their jobs and stop lecturing.

Don't try to tell me what I have to do or not!

I'm doing the moderators job (a small part of) because if I feel that a thread is not legitimate I report it to the moderators and let them decide what to do.

BTW: Why do you feel the urge to jump in anyway?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Mobius

Its an open forum Dude, my reasons are even less your business than the ops reasons.

Now, I am off to do something constructive with my day, I suggest you do similar.

Vlad

Share this post


Link to post
Share on other sites
water

It's my business as soon as you question what I do and how I do it on this forum!

Off for something constructive (as you suggested)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
czardas

The fact is that information can be put to either good and bad use. This forum is full of such information, and so is the internet. We try to avoid helping anyone who has bad intentions, and it's a fair question to ask for more details about any thread in Help and Support. However, I think it's bad form to automatically asume malicious intent simply because a question is in some way vague.

Once asked I think it is important that the user responds by providing further information, or else a valid reason for not doing so. It then boils down to a moderator's decision, which should always be final.

  • Like 3

Share this post


Link to post
Share on other sites
FireFox

yup, and editing a file is not going to help him automating a game, nor cracking a file...

  • Like 1

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Melba23

Hi all,

If you have suspicions about a question, please just report it so that a Mod can take a look. Entering into public spats as above is unneccessary and unedifying. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×