示例#1
0
func (t *Thread) writeMemory(addr uintptr, data []byte) (int, error) {
	var (
		vmData = C.LPCVOID(unsafe.Pointer(&data[0]))
		vmAddr = C.LPVOID(addr)
		length = C.SIZE_T(len(data))
		count  C.SIZE_T
	)
	ret := C.WriteProcessMemory(C.HANDLE(t.dbp.os.hProcess), vmAddr, vmData, length, &count)
	if ret == C.FALSE {
		return int(count), fmt.Errorf("could not write memory")
	}
	return int(count), nil
}
示例#2
0
func (t *Thread) readMemory(addr uintptr, size int) ([]byte, error) {
	if size == 0 {
		return nil, nil
	}
	var (
		buf    = make([]byte, size)
		vmData = C.LPVOID(unsafe.Pointer(&buf[0]))
		vmAddr = C.LPCVOID(addr)
		length = C.SIZE_T(size)
		count  C.SIZE_T
	)
	ret := C.ReadProcessMemory(C.HANDLE(t.dbp.os.hProcess), vmAddr, vmData, length, &count)
	if ret == C.FALSE {
		return nil, fmt.Errorf("could not read memory")
	}
	return buf, nil
}