faldo Posted March 1, 2009 Posted March 1, 2009 (edited) Is there a way to make the following loop go faster? While $State=1 MemWrite($OpenProcess, $TsAddress, 'int', 2 , 1) Wend Func MemWrite($i_hProcess, $i_lpBaseAddress, $s_Type ,$v_Inject, $i_nSize) Local $hDll = DllOpen("kernel32.dll") If @error Then SetError(1) Return 0 EndIf $v_lpNumberOfBytesRead = '' Local $v_Struct = DllStructCreate ($s_Type&'[' & $i_nSize & ']') DllStructSetData ($v_Struct, 1, $v_Inject) $i_Call = DllCall($hDll, 'int', 'WriteProcessMemory', 'int', $i_hProcess, 'int', $i_lpBaseAddress, 'int', DllStructGetPtr ($v_Struct, 1), 'int', $i_nSize, 'int', $v_lpNumberOfBytesRead) If @error Then SetError(1) Return 0 EndIf $v_Struct=0 DllClose($hDll) Return $i_Call[0] EndFunc I need that MemWrite to happen at an extremely fast pase... any suggestions? Edited March 1, 2009 by faldo Check out my other scripts: RDP antihammer/blacklist generator | Phemex cryptocurrency exchange API
KaFu Posted March 1, 2009 Posted March 1, 2009 Maybe this is faster: Global $hDll = DllOpen("kernel32.dll") While $State = 1 MemWrite($OpenProcess, $TsAddress, 'int', 2, 1) WEnd DllClose($hDll) Func MemWrite($i_hProcess, $i_lpBaseAddress, $s_Type, $v_Inject, $i_nSize) If @error Then SetError(1) Return 0 EndIf $v_lpNumberOfBytesRead = '' Local $v_Struct = DllStructCreate($s_Type & '[' & $i_nSize & ']') DllStructSetData($v_Struct, 1, $v_Inject) $i_Call = DllCall($hDll, 'int', 'WriteProcessMemory', 'int', $i_hProcess, 'int', $i_lpBaseAddress, 'int', DllStructGetPtr($v_Struct, 1), 'int', $i_nSize, 'int', $v_lpNumberOfBytesRead) If @error Then SetError(1) Return 0 EndIf $v_Struct = 0 Return $i_Call[0] EndFunc ;==>MemWrite 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 (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Authenticity Posted March 1, 2009 Posted March 1, 2009 Move the DllOpen and DllClose out of the function to the header and after the loop accordingly. I don't know how faster it will be but it'd save you some unnecessary code line execution over and over... If you're calling this function always with the same $s_Type, $v_Inject, $i_nSize parameters then it'd save some time to remove them all and declare the DllStructCreate variable as a global one and...
KaFu Posted March 1, 2009 Posted March 1, 2009 If you're calling this function always with the same $s_Type, $v_Inject, $i_nSize parameters then it'd save some time to remove them all and declare the DllStructCreate variable as a global one and...My second thought 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 (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
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