Jump to content

hex editing help


am632
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

wtfpl-badge-1.png

Link to comment
Share on other sites

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 (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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