RoderickRM Posted March 14, 2013 Share Posted March 14, 2013 (edited) I've used code submitted earlier on this forum: #Include <EditConstants.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> Global $sFile, $hFile, $iSize, $sData, $tData, $iRead $sFile = @WindowsDir & '\regedit.exe' $iSize = FileGetSize($sFile) $tData = DllStructCreate('byte[' & $iSize & ']') $hFile = _WinAPI_CreateFile($sFile, 2, 2, 2) _WinAPI_ReadFile($hFile, DllStructGetPtr($tData), $iSize, $iRead) _WinAPI_CloseHandle($hFile) MsgBox(0, '', Hex(DllStructGetData($tData, 1, 1), 2) & Hex(DllStructGetData($tData, 1, 2), 2) & ' (' & Chr(DllStructGetData($tData, 1, 1)) & Chr(DllStructGetData($tData, 1, 2)) & ') - signature for EXE fies.') $sData = '' For $i = 1 To $iSize $sData &= Hex(DllStructGetData($tData, 1, $i), 2) If Mod($i, 16) = 0 Then $sData &= @CRLF Else $sData &= ' ' EndIf Next $sData = StringTrimRight($sData, 2) Global $Edit GUICreate('MyGUI', 422, 526) $Edit = GUICtrlCreateEdit('', 10, 10, 402, 506, BitOR($ES_READONLY, $WS_VSCROLL, $WS_HSCROLL)) GUICtrlSetFont(-1, 8.5, 400, 0, 'Courier') GUICtrlSetData($Edit, $sData) GUISetState() Do Until GUIGetMsg() = -3 and it's working great! But I need to get the data in reversed order therefore I used $sData = Hex(DllStructGetData($tData, 1, $i), 2) & $sData It is working, but obviously it's painfully slow. Does anyone have any ideas how to make the process quicker. I'd really gratefull. Edited March 14, 2013 by RoderickRM Link to comment Share on other sites More sharing options...
KaFu Posted March 14, 2013 Share Posted March 14, 2013 (edited) Maybe not exactly what you're looking for, but a hell of a lot faster ... function originally posted by trancexx Edit:Looking at the function CryptBinaryToString the output can tweaked to look more like your original one by using different dwFlags (only that there are two spaces right in the middle)... *test*test*, example #4 replaces those manually to mimic your example exactly... and , for me it's even faster than example #3 because parsing that data to the edit controls takes less time.expandcollapse popup#include <EditConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $sFile, $hFile, $iSize, $sData, $tData, $iRead $sFile = @WindowsDir & '\regedit.exe' $iSize = FileGetSize($sFile) $tData = DllStructCreate('byte[' & $iSize & ']') $hFile = _WinAPI_CreateFile($sFile, 2, 2, 2) _WinAPI_ReadFile($hFile, DllStructGetPtr($tData), $iSize, $iRead) _WinAPI_CloseHandle($hFile) MsgBox(0, '', Hex(DllStructGetData($tData, 1, 1), 2) & Hex(DllStructGetData($tData, 1, 2), 2) & ' (' & Chr(DllStructGetData($tData, 1, 1)) & Chr(DllStructGetData($tData, 1, 2)) & ') - signature for EXE fies.') $sData = '' $timer = TimerInit() For $i = 1 To $iSize $sData &= Hex(DllStructGetData($tData, 1, $i), 2) If Mod($i, 16) = 0 Then $sData &= @CRLF Else $sData &= ' ' EndIf Next $sData = StringTrimRight($sData, 2) GUICreate('1) DllStructGetData()', 422, 526) $Edit = GUICtrlCreateEdit('', 10, 10, 402, 506, BitOR($ES_READONLY, $WS_VSCROLL, $WS_HSCROLL)) GUICtrlSetFont(-1, 8.5, 400, 0, 'Courier') GUICtrlSetData($Edit, $sData) GUISetState() ConsoleWrite("1) " & TimerDiff($timer) & @CRLF) $timer = TimerInit() $sData = _HexEncode(DllStructGetData($tData, 1)) GUICreate('2) CryptBinaryToString - 0x0000000b', 422, 526) $Edit2 = GUICtrlCreateEdit('', 10, 10, 402, 506, BitOR($ES_READONLY, $WS_VSCROLL, $WS_HSCROLL)) GUICtrlSetFont(-1, 8.5, 400, 0, 'Courier') GUICtrlSetData($Edit2, $sData) GUISetState() ConsoleWrite("2) " & TimerDiff($timer) & @CRLF) $timer = TimerInit() $sData = _HexEncode(DllStructGetData($tData, 1), 0x00000004) GUICreate('3) CryptBinaryToString - 0x00000004', 422, 526) $Edit3 = GUICtrlCreateEdit('', 10, 10, 402, 506, BitOR($ES_READONLY, $WS_VSCROLL, $WS_HSCROLL)) GUICtrlSetFont(-1, 8.5, 400, 0, 'Courier') GUICtrlSetData($Edit3, $sData) GUISetState() ConsoleWrite("3) " & TimerDiff($timer) & @CRLF) $timer = TimerInit() $sData = _HexEncode(DllStructGetData($tData, 1), 0x00000004) GUICreate('4) CryptBinaryToString - 0x00000004 + StringReplace()', 422, 526) $Edit4 = GUICtrlCreateEdit('', 10, 10, 402, 506, BitOR($ES_READONLY, $WS_VSCROLL, $WS_HSCROLL)) GUICtrlSetFont(-1, 8.5, 400, 0, 'Courier') GUICtrlSetData($Edit4, StringReplace($sData, " ", " ", 0, 2)) GUISetState() ConsoleWrite("4) " & TimerDiff($timer) & @CRLF) Do Until GUIGetMsg() = -3 Func _HexEncode($bInput, $iFlags = 0x0000000b) ; CryptBinaryToString function (Windows) ; http://msdn.microsoft.com/en-us/library/windows/desktop/aa379887%28v=vs.85%29.aspx Local $tInput = DllStructCreate("byte[" & BinaryLen($bInput) & "]") DllStructSetData($tInput, 1, $bInput) Local $a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($tInput), _ "dword", DllStructGetSize($tInput), _ "dword", $iFlags, _ "ptr", 0, _ "dword*", 0) If @error Or Not $a_iCall[0] Then Return SetError(1, 0, "") EndIf Local $iSize = $a_iCall[5] Local $tOut = DllStructCreate("char[" & $iSize & "]") $a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($tInput), _ "dword", DllStructGetSize($tInput), _ "dword", $iFlags, _ "ptr", DllStructGetPtr($tOut), _ "dword*", $iSize) If @error Or Not $a_iCall[0] Then Return SetError(2, 0, "") EndIf Return SetError(0, 0, DllStructGetData($tOut, 1)) EndFunc ;==>_HexEncode Edited March 14, 2013 by KaFu Xandy and mLipok 2 Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
RoderickRM Posted March 14, 2013 Author Share Posted March 14, 2013 Your example #4 is brilliant. It's the fastest for me too. But is there a way to display the data in reversed order, from the end of the file? Link to comment Share on other sites More sharing options...
RoderickRM Posted March 15, 2013 Author Share Posted March 15, 2013 Forgot about _StringReverse. That's working fine I really appreciate your help. Xandy 1 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