Popular Post ptrex Posted December 26, 2020 Popular Post Share Posted December 26, 2020 (edited) HEX Editor COM Control You can find the HEX Editor GUI example based on this ActiveX control https://www.codeproject.com/Articles/1384/Hex-Editor-OCX-Control It was a challenge to make it all work, but due the Lars his bright solution the final piece of the puzzle was in place. See here where all the magic is happening ! I made 2 slight optimizations : 1. No need for an external VBScript 2. No need to register the OCX control on Windows PREQUISITES : 1. Download the HexEdit.ocx see attached. And put it is your script folder (No registration needed ! ) 2. Download IRunningObjectTable.au3 3. Run this script expandcollapse popup; https://www.codeproject.com/Articles/1384/Hex-Editor-OCX-Control #AutoIt3Wrapper_UseX64=N ;~ Opt("WinTitleMatchMode", 2) #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <FileConstants.au3> #include "IRunningObjectTable.au3" #include <Array.au3> ; Initialize COM error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Global $hFileOD Global $hFile Global $hActiveX ; Load ActiveX module $hActiveX = DllOpen(@ScriptDir & "\HexEdit.ocx") ; Object identifiers Global Const $sCLSID = "{2E93307E-777D-49E4-886A-D5B04470796A}" Global Const $sIID = Default ; Create a simple GUI for our output Local $hHexEdit = GUICreate ( "Hex Editor", 1000, 580,(@DesktopWidth-1000)/2, (@DesktopHeight-580)/2 ) Local $idButton_About = GUICtrlCreateButton("About", 100, 10, 85, 25) Local $idButton_FileOpen = GUICtrlCreateButton("FileOpen", 10, 10, 85, 25) GUICtrlCreateGroup("Columns", 790, 40, 190, 90) Local $idInput = GUICtrlCreateInput("20", 800, 80, 60, 25) GUICtrlCreateUpdown($idInput) $sInput = GUICtrlRead($idInput) Local $idButton_Auto = GUICtrlCreateButton("Auto", 880, 80, 75, 25) GUICtrlCreateGroup("Address", 790, 180, 190, 90) Local $idAscii = GUICtrlCreateCheckbox("Address", 800, 180, 185, 25) Local $idAddress1 = GUICtrlCreateRadio("WORD", 800, 210, 120, 20) Local $idAddress2 = GUICtrlCreateRadio("DWORD", 800, 235, 120, 20) GUICtrlSetState($idAddress1, $GUI_CHECKED) GUICtrlCreateGroup("Data", 790, 280, 190, 90) Local $idData1 = GUICtrlCreateRadio("BYTE", 800, 300, 120, 20) Local $idData2 = GUICtrlCreateRadio("WORD", 800, 320, 120, 20) Local $idData3 = GUICtrlCreateRadio("DWORD", 800, 340, 120, 20) GUICtrlSetState($idData1, $GUI_CHECKED) Local $idAscii = GUICtrlCreateCheckbox("Show ASCII", 800, 400, 185, 25) GUICtrlSetState(-1, 1) Local $idInvert = GUICtrlCreateCheckbox("Invert Color", 800, 430, 185, 25) Local $idLabel = GUICtrlCreateLabel("Modified : ", 800, 540, 185, 25) ; Create Com Object ;~ Local $oHexEdit = ObjCreate("HEXEDIT.HexEditCtrl.1") Local $oHexEdit = ObjCreate($sCLSID, $sIID, $hActiveX) If IsObj($oHexEdit) = 0 Then MsgBox(48, "Error", "Could not create the object, Common problem ActiveX not registered.") ConsoleWrite(IsObj($oHexEdit) & @CRLF) Exit EndIf $oHexEdit.Appearance = 1 $oHexEdit.AllowChangeSize = 0 $oHexEdit.BackColor = 0x000000 $oHexEdit.ForeColor = 0xffffff $oHexEdit.Fontheight = 16 $oHexEdit.Columns = Int($sInput) $GUIActiveX = GUICtrlCreateObj ($oHexEdit, 10, 40, 750, 520) GUICtrlSetResizing ( $GUIActiveX, $GUI_DOCKAUTO) GUICtrlSetData($idLabel, "Modified ; " & $oHexEdit.DataModified) ; Show GUI GUISetState () ; Loop GUI While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_PRIMARYDOWN GUICtrlSetData($idLabel, "Modified ; " & $oHexEdit.DataModified) If $oHexEdit.DataModified = True Then GUICtrlSetColor($idLabel, $COLOR_RED) EndIf Case $idButton_About $oHexEdit.AboutBox() Case $idButton_Auto $oHexEdit.Columns = 0 Case $idInput $oHexEdit.Columns = GUICtrlRead($idInput) Case $idAscii If BitAND(GUICtrlRead($idAscii), $GUI_CHECKED) = $GUI_CHECKED Then $oHexEdit.ShowAscii = 1 Else $oHexEdit.ShowAscii = 0 EndIf Case $idInvert If BitAND(GUICtrlRead($idInvert), $GUI_CHECKED) = $GUI_CHECKED Then $oHexEdit.BackColor = 0xffffff $oHexEdit.ForeColor = 0x000000 Else $oHexEdit.BackColor = 0x000000 $oHexEdit.ForeColor = 0xffffff EndIf Case $idButton_FileOpen Set_Data(GetFile()) If BitAND(GUICtrlRead($idAddress1), $GUI_CHECKED) = $GUI_CHECKED Then $oHexEdit.DigitsInAddress = 4 EndIf If BitAND(GUICtrlRead($idAddress2), $GUI_CHECKED) = $GUI_CHECKED Then $oHexEdit.DigitsInAddress = 8 EndIf If BitAND(GUICtrlRead($idData1), $GUI_CHECKED) = $GUI_CHECKED Then $oHexEdit.DigitsInData = 2 EndIf If BitAND(GUICtrlRead($idData2), $GUI_CHECKED) = $GUI_CHECKED Then $oHexEdit.DigitsInData = 4 EndIf If BitAND(GUICtrlRead($idData2), $GUI_CHECKED) = $GUI_CHECKED Then $oHexEdit.DigitsInData = 8 EndIf EndSwitch WEnd ; Function File Open Func GetFile() $hFileOD = FileOpenDialog("Select EXE File", @ScriptDir & "\", "EXE (*.exe)") $hFileOpen = FileOpen($hFileOD, 16) If $hFileOpen = -1 Then MsgBox(48, "Error", "Unable to open file, or no file selected !!") Else ; Read the contents of the file using the handle returned by FileOpen. Local $sFileRead = FileRead($hFileOpen) Return $sFileRead EndIf ; Close the handle returned by FileOpen. FileClose($hFileOpen) EndFunc Func Set_Data($dBinary) ; https://www.autoitscript.com/forum/topic/202618-implementing-irunningobjecttable-interface/?do=findComment&comment=1471171 Local $sDictionaryData = "DictionaryData" ROT_RegisterObject( Default, $sDictionaryData ) ; Default => Object = Dictionary object Local $oROTobj = ObjGet( $sDictionaryData ) ; Dictionary object $oROTobj( "oHexEdit" ) = $oHexEdit $oROTobj( "dBinary" ) = $dBinary Local $code= 'Dim oROTobj, oHexEdit, dBinary' $code=$code & @CRLF & 'Set oROTobj = GetObject( "DictionaryData" )' $code=$code & @CRLF & 'Set oHexEdit = oROTobj( "oHexEdit" )' $code=$code & @CRLF & 'dBinary = oROTobj( "dBinary" )' $code=$code & @CRLF & 'oHexEdit.SetData dBinary, 0' Local $vbs = ObjCreate("ScriptControl") $vbs.language="vbscript" $vbs.addcode($code) ;~ ROT_Revoke($oROTobj) EndFunc ; COM Error Handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"AutoItCOM","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) Endfunc Enjoy !! PS : I did not implement the write back to file yet. Feel free to add this if needed. HexEdit.zip Edited January 4, 2021 by ptrex Danyfirex, Professor_Bernd, LarsJ and 3 others 4 2 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Dan_555 Posted December 26, 2020 Share Posted December 26, 2020 Ahem, for the prerequisites, the #include "IRunningObjectTable.au3" is needed too. After a bit of search, i found it in the Attachment following the here post (the ObjectMethods.7z ) Some of my script sourcecode Link to comment Share on other sites More sharing options...
ptrex Posted December 26, 2020 Author Share Posted December 26, 2020 Dan_555 updated the frst post. Thanks Dan_555 1 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
LarsJ Posted January 3, 2021 Share Posted January 3, 2021 ptrex, You should definitely make it possible to view and edit AutoIt binary data directly in this visual control and return modified data. $dBin = Binary("abc") $dBin should appear as "61 62 63" in the control. If you change 3 to 4, and return the modified data you get $dBin = Binary("abd") Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
ptrex Posted January 4, 2021 Author Share Posted January 4, 2021 (edited) Hi Lars, Editing binary code is available out of the box. 1. Open the application and read an EXE file. 2. When you see the binary appear in the control, double click any byte you want to change and change it. Writing back the modified value is still a mistery to me at the moment. Once you have changed the binary data it is captured in the COM control. And I am not sure how to access the object in the ROT., since there is no GETDATA method available ? PS : Thanks again for this genius IRunningObjectTable solution ! Now we have a real use case for your iRunningObjectTable as well. Edited January 4, 2021 by ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Gianni Posted January 5, 2021 Share Posted January 5, 2021 any chances to use the ocx published here (https://github.com/dzzie/hexed)? it seems to be read/write able. Thanks Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
ptrex Posted January 5, 2021 Author Share Posted January 5, 2021 @Chimp Thanks for the tip ! I will give it a try when I see some time available. Gianni 1 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now