Jump to content
Tuts 4 You

Using dUP2's search 'n' replace patch engine in AutoIt3


Zeffy

Recommended Posts

Posted

Hello, for the last few days I have been trying to figure out how to use diablo2oo2's dUP2 SNR patch engine in a scripting language called autoit, the way you call Dll's from autoit is as follows

DllCall ( "dll", "return type", "function" [, type1, param1 [, type n, param n]] )

I don't understand ASM very well, and since the examples are only in ASM, I'm having quite a difficult time translating it to autoit, and I was hoping someone could help me figure out how to call it, Thanks.

Posted (edited)

SearchAndReplace PROTO _targetadress:dword,\
_searchpattern:dword,\
_searchmask:dword,\
_replacepattern:dword,\
_replacemask:dword,\
_patternsize:dword,
_searchsize:dword,
_patchnumber:dword;Could possibly translate to:DllCall ( 'snr_patchengine.dll', 'int', 'SearchAndReplace', 'int_ptr',$targetadress,'int_ptr',$searchpattern,'int_ptr',$searchmask,'int_ptr',$replacepattern,'int_ptr',$replacemask,'int',patternsize,'int',searchsize,'int',patchnumber)

I know nothing of AutoIt, having never used it, but a 2 second Google search for 'AutoIt DllCall' yields hits. Instead of expecting people to spoonfeed you your answers, do some work yourself and be prepared to actually have to give some effort. Check out this page and it may explain the syntax properly for you (it has examples there with Win32 API).

HR,

Ghadni

Edited by ghandi
Posted

If you didn't see it, I posted how to use DllCall in my post. I wasn't asking how to use DllCall, I just didn't know how to use it with the SnR PatchEngine, because I don't know ASM so I couldn't interpret the ASM example.

Thanks for your help, anyway.

Posted

In case you didn't read my post, i didn't show 'how to use DllCall' but 'how to use DllCall with snr_patchengine.dll'.

If you understood how to use DllCall, then you wouldn't have needed anyone to explain it to you, because like all good things Assembler, every parameter passed on the stack is a DWORD (even for 64 bit values, its passed as 2x DWORD pushed to the stack or passed in two registers). Knowing the syntax and conversions from Win32 (read: Programming languages, not scripting.) to AutoIt would have made this a 2 second job.

The page i got the information from, via the Google search, also contains the following information:

DllCall is great. But it can be tricky to use. Here are some syntax notes geared towards using the Windows API. When you manage to get DllCall to work with a new api then please post the syntax you used and the MSDN API syntax so that others may benefit. I'll merge all the posts into this one.

Windows API

All the Windows API details you need can be found by searching at MSDN Library

Common Datatypes

AutoIt has a single datatype - the variant. A variant can hold HWNDs (window handles), integers (32 and 64bit), floating point numbers (doubles). Windows API calls take many different sorts of datatypes and in the DllCall function you must work out which type to use for conversion.

Complete list of Windows Datatypes

Windows Datatype = DllCall Type

BOOL = "int"

COLORREF = "int"

DWORD = "int"

HANDLE = "ptr"

HDC = "ptr"

HFILE = "int"

HFONT = "ptr"

HICON = "ptr"

HINSTANCE = "ptr"

HKEY = "ptr"

HMENU = "ptr"

HMODILE = "ptr"

HWND = "hwnd"

INT = "int"

LONG = "long"

LPARAM = "long"

LPCTSTR = "str" ("wstr" if a UNICODE function)

LPINT = "int_ptr"

LPLONG = "long_ptr"

UINT = "int"

ULONG = "long"

WPARAM = "int"

API List

Here is a list of API functions that have been used successfully in AutoIt and their respective DllCall syntax.

GetAsyncKeyState - DllCall("user32.dll", "int", "GetAsyncKeyState", "int", $hexKey)

GetTickCount - DllCall("kernel32.dll", "long", "GetTickCount")

MessageBeep - DllCall ("user32.dll", "int", "MessageBeep", "int", 0xFFFFFFFF)

MessageBox - DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "text", "str", "title", "int", 0)

PrintUI /? - DllCall("printui.dll", "none", "PrintUIEntryW", "hwnd", 0, "ptr", 0, "wstr", "/?", "int", @SW_SHOWNORMAL)

This post has been edited by Jon: 30 December 2004 - 12:50 PM

AutoIt Forum:
/>http://www.autoitscript.com/forum/index.php

Source Page:
/>http://www.autoitscript.com/forum/index.php?showtopic=7072

Now, i reiterate, if you had taken the time to perform a Google search yourself, you would have found this information because it was the very first hit i got! Take the time to read the above information and if anything is unclear, consider the possiblility of using perhaps the AutoIt forum for asking an AutoIt related question. Just me, but i'd sort of hope that the 'official' sites would contain either information or links to said information which would enable you to learn and use the product to its full potential?

Personally i'd ask RCE related questions on the RCE forum and AutoIt related questions (unless its RCE related also) on an AutoIt forum, i could be backwards in thinking this though. :)

HR,

Ghandi

Posted

In case you didn't read my post, i didn't show 'how to use DllCall' but 'how to use DllCall with snr_patchengine.dll'.

If you understood how to use DllCall, then you wouldn't have needed anyone to explain it to you, because like all good things Assembler, every parameter passed on the stack is a DWORD (even for 64 bit values, its passed as 2x DWORD pushed to the stack or passed in two registers). Knowing the syntax and conversions from Win32 (read: Programming languages, not scripting.) to AutoIt would have made this a 2 second job.

The page i got the information from, via the Google search, also contains the following information:

AutoIt Forum:
/>http://www.autoitscript.com/forum/index.php

Source Page:
/>http://www.autoitscript.com/forum/index.php?showtopic=7072

Now, i reiterate, if you had taken the time to perform a Google search yourself, you would have found this information because it was the very first hit i got! Take the time to read the above information and if anything is unclear, consider the possiblility of using perhaps the AutoIt forum for asking an AutoIt related question. Just me, but i'd sort of hope that the 'official' sites would contain either information or links to said information which would enable you to learn and use the product to its full potential?

Personally i'd ask RCE related questions on the RCE forum and AutoIt related questions (unless its RCE related also) on an AutoIt forum, i could be backwards in thinking this though. :)

HR,

Ghandi

Alright, thanks for explaining that, I thought I knew how to use DllCall pretty well put I guess not, sorry to have taken your time.

The reason I posted this here instead of on AutoIt's forums is it had to do with patching, and I figured people here would better understand how to use snr_patchengine.dll. Also, a couple more questions: I couldnt find how to specify a file to patch in the example code, and how would I format the search/replace pattern in the dllcall? (In autoit hex is specified as 0x000000 instead of 000000h, but would that change anything?)

Thanks, again I'm sorry to have taken your time.

Posted

The SnR dll doesn't handle loading the file, etc. It is the search and replace function which you can use in your own programs/scripts. You need to handle the file i/o, i'd imagine that it could be done similar to the ways its done via assembled/compiled languages:

* Get the filename in some fashion, such as an OpenFileDialog call or even an edit control which the user enters the filename in.

or

* Store the filename internally.

* Open a handle to the file, you can use any file I/O API. I use CreateFile, feel free to investigate and choose your own though.

* CreateFileMapping and MapViewOfFile to map an instance of the file into memory so you can perform direct checksumming/patching/flushing before freeing the map and closing the file map object returned by CreateFileMapping then the file handle.

or

* GetFileSize, allocate memory (a few API here too), ReadFile, CloseHandle. Then you can perform the same checksumming & patching before replacing/overwriting the original file. CopyFile, DeleteFile, CreateFile, WriteFile, CloseHandle will facilitate this, or you can skip the DeleteFile and use the appropriate flags to truncate the existing original file so you can overwrite it. Heck, you can skip this and simply overwrite it because the file pointer will be at 0 so it will overwrite the file byte for byte except for your patch.

Based on this information if you were confident in your AutoIt knowledge (and if AutoIt allows direct manipulation of bytes), you might attempt converting the search and replace routine into AutoIt scripting so you could simply read in the file, perform your snr and then save results if succesful. As i know nothing about AutoIt, it could be that i'm just having a pipedream and accidentally blowing smoke up your ***, so you might want to check if you can do the byte-wise manipulations with AutoIt.

No need to apologize for taking time, i only said what i said because of your rebuttal. I meant no criticism of your knowledge or ability, as i said i know nothing about AutoIt as i have never used it, but I try to help where i can rather than hinder people and all of the RCE forums are based around community and helping (its how they survive[d]).

The following is from another forum, it deals more with processes rather than files, but it shows more usage of DllCall (and i thought it might be useful for an AutoIt project like a loader or such), here is the link so you can see the site/comments also:


/>http://www.elitepvpers.de/forum/eo-guides-templates/134188-auto-guide-programming-2.html


below are a set of functions for manipulating memory, lets face it, pixel bots can only go so far, after that you need to actually start to manipulate memory, reading values, writing values back etc, these functions will do that for you. Credit is given to those who wrote these functions. i will not put these in code blocks because the forums eat the variable declarations.#include-once
#region _Mem()
;================================================= =====================
; AutoIt Version: 3.1.127 (beta)
; Language: English
; Platform: All Windows
; Author: Nomad
; Requirements:
; These functions will only work with beta. If you place this
; script in your include folder, you can use these functions
; just as any other function, as long as you put
; "#include <Memory.au3>" in your script (or w/e you name it).
;================================================= =====================
; Credits:
; wOuter:
; These functions are based on his original _Mem() functions.
; They are easier to use and comprehend, IMO. These functions
; are in no way a direct copy of his functions. His functions
; only provided a foundation from which these evolved. The
; biggest changes were made made to _MemRead() and _MemWrite().
; You also no longer need to use _MemCreate() before using
; _MemWrite().
;================================================= =====================
; Additional:
; I've never used _MemRev(), _MemAlloc(), _MemFree(), or _MemText()
; So I did not attempt to revise them in any way and they are not
; included in this script.
;
; Please remember to credit accordingly for any use of these UDF's.
;================================================= =====================
;================================================= =====================
; Function Name: _MemOpen()
;
; Description: Opens the process specified by the Process ID and
; returns the necessary Dll information for reading
; from it's memory.
;
; Parameters:
; $Pid = The Process ID of the program you want to open.
;
; $InheritHandle = [optional] If this value is TRUE, processes
; created by this process will inherit the
; handle. Otherwise, the processes do not
; inherit this handle. Most users will not
; need to alter this parameter.
;
; Returns:
; On Success: Returns an array containing the .dll and an open handle
; to the specified process.
; On Failure: Returns 0 and sets error to 1
;================================================= =====================
Func _MemOpen($Pid, $InheritHandle = 0x1F0FFF)Local $Dll[2] = [DllOpen('kernel32.dll')]
Local $OpenProcess = DllCall($Dll[0], 'int', 'OpenProcess', 'int', $InheritHandle, 'int', 0, 'int', $Pid)If @Error Then
DllClose($Dll[0])
SetError(1)
Return 0
EndIf$Dll[1] = $OpenProcess[0]Return $DllEndFunc;================================================= =====================
; Function Name: _MemRead()
;
; Description: Reads the value located in the memory address
; specified by the $Address parameter. You must open
; the process first with _MemOpen()
;
; Parameters:
; $Address = The memory address you want to read from.
; It must be in hex format (0x00000000).
;
; $Dll = The necessary Dll information which is an array returned
; from _MemOpen().
;
; $Type = [optional] The "Type" of value you intend to read.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. For example, if you want to read a
; word that is 15 characters in length, you would use
; 'char[15]' since a 'char' is 8 bits (1 byte) in size.
;
; Additional:
; Values returned are in Decimal format, unless specified as a
; 'char' type, then they are returned in ASCII format.
;
; Returns:
; On Success: Returns the value located at the specified address
; On Failure: Returns 0 and sets error to 1
;================================================= =====================
Func _MemRead($Address, $Dll, $Type = 'dword')If Not IsArray($Dll) Then
SetError(1)
Return 0
EndIfLocal $LpBuffer = DllStructCreate($Type)DllCall($Dll[0], 'int', 'ReadProcessMemory', 'int', $Dll[1], 'int', $Address, 'ptr', DllStructGetPtr($LpBuffer), 'int', DllStructGetSize($LpBuffer), 'int', '')If Not @Error Then
$Value = DllStructGetData($LpBuffer, 1)
Return $Value
Else
SetError(1)
Return 0
EndIfEndFunc;================================================= =====================
; Function Name: _MemWrite()
;
; Description: Writes data to the specified memory address
;
; Parameters:
; $Address = The memory address which you want to write to.
; Must be in hex format (0x00000000).
;
; $Dll = The necessary Dll information which is an array returned
; from _MemOpen().
;
; $Value = The information you want to write.
;
; $Type = [optional] The "Type" of value you intend to write.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. If you want to write a 'char' type,
; you will use 'char[15]' if it's 15 characters in
; length.
;
; Returns:
; On Success: Returns 1
; On Failure: Returns 0 and sets error to 1
;================================================= =====================
Func _MemWrite($Address, $Dll, $Value, $Type = 'dword')If Not IsArray($Dll) Then
SetError(1)
Return 0
EndIfLocal $LpBuffer = DllStructCreate($Type)
DllStructSetData($LpBuffer, 1, $Value, 1)DllCall($Dll[0], 'int', 'WriteProcessMemory', 'int', $Dll[1], 'int', $Address, 'ptr', DllStructGetPtr($LpBuffer), 'int', DllStructGetSize($LpBuffer), 'int', '')If Not @Error Then
Return 1
Else
SetError(1)
Return 0
EndIfEndFunc;================================================= =====================
; Function Name: _MemClose()
;
; Description: Closes the process which was opened using _MemOpen().
;
; Parameters:
; $Dll = The necessary Dll information which is an array returned
; from _MemOpen().
;
; Returns:
; On Success: Returns 1
; On Failure: Returns 0 and sets error to 1
;================================================= =====================
Func _MemClose($Dll)If Not IsArray($Dll) Then
SetError(1)
Return 0
EndIfDllCall($Dll[0], 'int', 'CloseHandle', 'int', $Dll[1])
If Not @Error Then
DllClose($Dll[0])
Return 1
Else
DllClose($Dll[0])
SetError(1)
Return 0
EndIfEndFunc
#endregion

Best of luck.

HR,

Ghandi

Posted

Yes, I tried using the FileOpen(), FileRead(), and StringReplace() with a Hex to String conversion, but I couldnt get it working, so I thought I'd try using the SnR dll. I'll try what you said. Thanks again

  • 4 years later...
Posted

I can't download 


dup.search.and.replace.patchengine.sourcecode.rar


  • 1 year later...
Posted
Quote

Code 1 (include dll on script):
 

ConsoleWrite("-   OUT: " & _BinarySearchAndReplace("001122330033221100", "00", "99") & @CRLF)
ConsoleWrite("! Error: " & @error & @CRLF)


ConsoleWrite("-   OUT: " & _BinarySearchAndReplace("001122330033221100", "00??", "0066") & @CRLF)
ConsoleWrite("! Error: " & @error & @CRLF)


ConsoleWrite("-   OUT: " & _BinarySearchAndReplace("001122330033221100", "33??33", "55??77") & @CRLF)
ConsoleWrite("! Error: " & @error & @CRLF)


ConsoleWrite("-   OUT: " & _BinarySearchAndReplace("001122330033221100", "0033??11", "77332?66") & @CRLF)
ConsoleWrite("! Error: " & @error & @CRLF)

Func _BinarySearchAndReplace($sStringHex, $sSearch, $sReplace)
    If (StringLeft($sStringHex, 2) = "0x") Then $sStringHex = StringTrimLeft($sStringHex, 2)
    If (StringLen($sStringHex) = 0) Or (StringLen($sSearch) = 0) Then Return SetError(-1, 0, $sStringHex);Not think to replace
    If @AutoItX64 Then Return SetError(1, 0, $sStringHex);Dll only for 32-bit
    ;--------------------------------------------------------- Begin create temp dll
    Local $sBinaryDll = '4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000C00000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A240000000000000071D4F7DB35B5998835B5998835B59988C9958B8834B59988BBAA8A8834B599885269636835B59988000000000000000000000000000000000000000000000000504500004C010300E8B694560000000000000000E0000E210B01050C00020000000400000000000000100000001000000020000000000010001000000002000004000000000000000400000000000000004000000004000000000000020000000000100000100000000010000010000000000000100000000020000057000000000000000000000000000000000000000000000000000000000000000000000000300000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
    $sBinaryDll &= '2E74657874000000B7000000001000000002000000040000000000000000000000000000200000602E7264617461000057000000002000000002000000060000000000000000000000000000400000402E72656C6F6300000C00000000300000000200000008000000000000000000000000000040000042000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
    $sBinaryDll &= '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000558BECB801000000C9C20C008D642400558BEC83C4F860C645FF00C745F8000000008B7D088B750C8B55108B5D1C33C9EB2C8BC103C33B45207773515657528BCB85C97420803A017408ACAE750A4249EBEF47464249EBE95A5F5E5947413B4D2075CFEB49FF45F85A5F5E8B452483F8FF74093945F874045947EBB68B75148B551833C9EB0D803A017404ACAAEB02474642413BCB75EFC645FF0159837D24FF750C2BFB47418B750C8B5510EB84610FB645FFC9C2200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
    $sBinaryDll &= '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E8B694560000000032200000010000000100000001000000282000002C20000030200000101000004620000000004456545F5061746368456E67696E652E646C6C00536561726368416E645265706C616365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
    $sBinaryDll &= '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
    $sBinaryDll &= '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
    Local $sDllFilePath = @TempDir & "\~PE32.dll"
    FileDelete($sDllFilePath)
    Local $hOpenDll = FileOpen($sDllFilePath, 2 + 8 + 16)
    FileWrite($sDllFilePath, Binary('0x' & $sBinaryDll))
    FileClose($hOpenDll)
    If Not FileExists($sDllFilePath) Then Return SetError(-1, 0, $sStringHex);Can not write temp Dll
    ;----------------------------------------------------------- End Cceate temp dll
    ConsoleWrite("+   -IN: " & $sStringHex & @CRLF)
    Local $taStrPtr = DllStructCreate("char Data[" & StringLen($sStringHex) & "]")
    $taStrPtr.Data = $sStringHex
    Local $spStrPtr = DllStructCreate("byte[" & StringLen($sSearch) & "]")
    Local $smStrPtr = DllStructCreate("byte[" & StringLen($sSearch) & "]")
    Local $aStr = StringSplit($sSearch, "")
    For $i = 1 To $aStr[0]
        DllStructSetData($spStrPtr, 1, Asc($aStr[$i]), $i)
        DllStructSetData($smStrPtr, 1, $aStr[$i] = "?" ? 1 : 0, $i);avoid a
    Next
    Local $rpStrPtr = DllStructCreate("byte[" & StringLen($sReplace) & "]")
    Local $tmStrPtr = DllStructCreate("byte[" & StringLen($sReplace) & "]")
    Local $aStr = StringSplit($sReplace, "")
    For $i = 1 To $aStr[0]
        DllStructSetData($rpStrPtr, 1, Asc($aStr[$i]), $i)
        DllStructSetData($tmStrPtr, 1, $aStr[$i] = "?" ? 1 : 0, $i);avoid a
    Next
    Local $_TargetAdress = DllStructGetPtr($taStrPtr)
    Local $_SearchPattern = DllStructGetPtr($spStrPtr)
    Local $_SearchMask = DllStructGetPtr($smStrPtr)
    Local $_ReplacePattern = DllStructGetPtr($rpStrPtr)
    Local $_ReplaceMask = DllStructGetPtr($tmStrPtr)
    Local $_PatternSize = DllStructGetSize($rpStrPtr)
    Local $_SearchSize = DllStructGetSize($taStrPtr)
    Local $aRep = DllCall($sDllFilePath, 'BYTE', 'SearchAndReplace', 'DWORD', $_TargetAdress, 'DWORD', $_SearchPattern, 'DWORD', $_SearchMask, 'DWORD', $_ReplacePattern, 'DWORD', $_ReplaceMask, 'DWORD', $_PatternSize, 'DWORD', $_SearchSize, 'DWORD', -1)
    If @error Or (Not IsArray($aRep)) Then Return SetError(@error, 0, 0)
    $sReplace = "0x" & $taStrPtr.Data
    FileDelete($sDllFilePath)
    Return SetError(@error, 0, $sReplace)
EndFunc   ;==>_BinarySearchAndReplace

Code 2: 

 

ConsoleWrite("-   OUT: " & _BinarySearchAndReplace("001122330033221100", "00", "99") & @CRLF)
ConsoleWrite("! Error: " & @error & @CRLF)


ConsoleWrite("-   OUT: " & _BinarySearchAndReplace("001122330033221100", "00??", "0066") & @CRLF)
ConsoleWrite("! Error: " & @error & @CRLF)


ConsoleWrite("-   OUT: " & _BinarySearchAndReplace("001122330033221100", "33??33", "55??77") & @CRLF)
ConsoleWrite("! Error: " & @error & @CRLF)


ConsoleWrite("-   OUT: " & _BinarySearchAndReplace("001122330033221100", "0033??11", "77332?66") & @CRLF)
ConsoleWrite("! Error: " & @error & @CRLF)

Func _BinarySearchAndReplace($sStringHex, $sSearch, $sReplace)
    If (StringLeft($sStringHex, 2) = "0x") Then $sStringHex = StringTrimLeft($sStringHex, 2)
    If (StringLen($sStringHex) = 0) Or (StringLen($sSearch) = 0) Then Return SetError(-1, 0, $sStringHex);Not think to replace
    If @AutoItX64 Then Return SetError(1, 0, $sStringHex);Dll only for 32-bit
    ConsoleWrite("+   -IN: " & $sStringHex & @CRLF)
    Local $taStrPtr = DllStructCreate("char Data[" & StringLen($sStringHex) & "]")
    $taStrPtr.Data = $sStringHex
    Local $spStrPtr = DllStructCreate("byte[" & StringLen($sSearch) & "]")
    Local $smStrPtr = DllStructCreate("byte[" & StringLen($sSearch) & "]")
    Local $aStr = StringSplit($sSearch, "")
    For $i = 1 To $aStr[0]
        DllStructSetData($spStrPtr, 1, Asc($aStr[$i]), $i)
        DllStructSetData($smStrPtr, 1, $aStr[$i] = "?" ? 1 : 0, $i);avoid a
    Next
    Local $rpStrPtr = DllStructCreate("byte[" & StringLen($sReplace) & "]")
    Local $tmStrPtr = DllStructCreate("byte[" & StringLen($sReplace) & "]")
    Local $aStr = StringSplit($sReplace, "")
    For $i = 1 To $aStr[0]
        DllStructSetData($rpStrPtr, 1, Asc($aStr[$i]), $i)
        DllStructSetData($tmStrPtr, 1, $aStr[$i] = "?" ? 1 : 0, $i);avoid a
    Next
    Local $_TargetAdress = DllStructGetPtr($taStrPtr)
    Local $_SearchPattern = DllStructGetPtr($spStrPtr)
    Local $_SearchMask = DllStructGetPtr($smStrPtr)
    Local $_ReplacePattern = DllStructGetPtr($rpStrPtr)
    Local $_ReplaceMask = DllStructGetPtr($tmStrPtr)
    Local $_PatternSize = DllStructGetSize($rpStrPtr)
    Local $_SearchSize = DllStructGetSize($taStrPtr)
    Local $aRep = DllCall('DVT_PatchEngine.dll', 'BYTE', 'SearchAndReplace', 'DWORD', $_TargetAdress, 'DWORD', $_SearchPattern, 'DWORD', $_SearchMask, 'DWORD', $_ReplacePattern, 'DWORD', $_ReplaceMask, 'DWORD', $_PatternSize, 'DWORD', $_SearchSize, 'DWORD', -1)
    If @error Or (Not IsArray($aRep)) Then Return SetError(@error, 0, 0)
    $sReplace = "0x" & $taStrPtr.Data
    Return SetError(@error, 0, $sReplace)
EndFunc   ;==>_BinarySearchAndReplace

snr.dup.search.and.replace.patchengine.sourcecode.src.zip

  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...