faldo Posted March 1, 2009 Share 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 Link to comment Share on other sites More sharing options...
KaFu Posted March 1, 2009 Share 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 (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Authenticity Posted March 1, 2009 Share 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... Link to comment Share on other sites More sharing options...
KaFu Posted March 1, 2009 Share 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 (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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