This is a piece of V1 code, I want to convert it to V2
How to use this class RemoteBuffer? Help me
Code: Select all
hSci := ControlGetHwnd('Scintilla2', 'ahk_class SciTEWindow')
sciOutputHwnd:=WinGetPID(hSci)
str:="xxxx"
n := VarSetCapacity(data, StrPut(str, "UTF-8"))
StrPut(str, &data, n, sciOutputCP)
SendMessage 0xC2, % true, % &data,, ahk_id %sciOutputHwnd% ; EM_REPLACESEL
class RemoteBuffer
{
__New(PID, size) {
static flags := (PROCESS_VM_OPERATION := 0x8) | (PROCESS_VM_WRITE := 0x20) | (PROCESS_VM_READ := 0x10)
, Params := ['UInt', MEM_COMMIT := 0x1000, 'UInt', PAGE_READWRITE := 0x4, 'Ptr']
if !this.hProc := DllCall('OpenProcess', 'UInt', flags, 'Int', 0, 'UInt', PID, 'Ptr')
throw OSError('Can`'t open remote process PID = ' . PID . '`nA_LastError: ' . A_LastError, 'RemoteBuffer.__New')
if !this.ptr := DllCall('VirtualAllocEx', 'Ptr', this.hProc, 'Ptr', 0, 'Ptr', size, Params*) {
DllCall('CloseHandle', 'Ptr', this.hProc)
throw OSError('Can`'t allocate memory in remote process PID = ' . PID . '`nA_LastError: ' . A_LastError, 'RemoteBuffer.__New')
}
}
__Delete() {
DllCall('VirtualFreeEx', 'Ptr', this.hProc, 'Ptr', this.ptr, 'UInt', 0, 'UInt', MEM_RELEASE := 0x8000)
DllCall('CloseHandle', 'Ptr', this.hProc)
}
Read(BufObj, offset := 0) {
if !DllCall('ReadProcessMemory', 'Ptr', this.hProc, 'Ptr', this.ptr + offset, 'Ptr', BufObj, 'Ptr', BufObj.Size, 'PtrP', &bytesRead := 0)
throw OSError('Can`'t read data from remote buffer`nA_LastError: ' . A_LastError, 'RemoteBuffer.Read')
return bytesRead
}
Write(BufObj, offset := 0) {
if !res := DllCall('WriteProcessMemory', 'Ptr', this.hProc, 'Ptr', this.ptr + offset, 'Ptr', BufObj, 'Ptr', BufObj.Size, 'PtrP', &bytesWritten := 0)
throw OSError('Can`'t write data to remote buffer`nA_LastError: ' . A_LastError, 'RemoteBuffer.Write')
return bytesWritten
}
}