am632 Posted October 3, 2012 Share Posted October 3, 2012 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 More sharing options...
FireFox Posted October 3, 2012 Share Posted October 3, 2012 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 More sharing options...
Malkey Posted October 4, 2012 Share Posted October 4, 2012 Expanding of FireFox's example, here is an example using a function that will HexEdit or binary edit a file.expandcollapse popupLocal $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 FireFox 1 Link to comment Share on other sites More sharing options...
am632 Posted October 8, 2012 Author Share Posted October 8, 2012 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 Link to comment Share on other sites More sharing options...
water Posted October 8, 2012 Share Posted October 8, 2012 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 More sharing options...
Mobius Posted October 9, 2012 Share Posted October 9, 2012 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 Link to comment Share on other sites More sharing options...
water Posted October 9, 2012 Share Posted October 9, 2012 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 More sharing options...
Mobius Posted October 9, 2012 Share Posted October 9, 2012 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 Link to comment Share on other sites More sharing options...
water Posted October 9, 2012 Share Posted October 9, 2012 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 More sharing options...
Mobius Posted October 9, 2012 Share Posted October 9, 2012 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 Link to comment Share on other sites More sharing options...
water Posted October 9, 2012 Share Posted October 9, 2012 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 More sharing options...
czardas Posted October 9, 2012 Share Posted October 9, 2012 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. Mechaflash, FireFox and water 3 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
FireFox Posted October 9, 2012 Share Posted October 9, 2012 yup, and editing a file is not going to help him automating a game, nor cracking a file... czardas 1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 9, 2012 Moderators Share Posted October 9, 2012 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts