libmem icon indicating copy to clipboard operation
libmem copied to clipboard

`set_memory_ex`:TypeError function takes exactly 3 arguments (4 given)

Open Jai-wei opened this issue 1 year ago • 3 comments

Language:python 3.11 Code:

proc = find_process("notepad++.exe")
new_me = alloc_memory_ex(proc, 1024, PROT_XRW)
set_memory_ex(proc, new_me , b"\x00", 10)

// ERROR 👇
set_memory_ex(proc, new_me , b"\x00", 10)
TypeError: function takes exactly 3 arguments (4 given)

I'm not sure why this error occurs. The set_memory_ex function should have passed in 4 parameters.

Jai-wei avatar Sep 13 '24 06:09 Jai-wei

I understand that it might be defined wrong way and it should be fixed. You can try using this for now:

>>> help(libmem.write_memory_ex)
Help on function write_memory_ex in module libmem:

write_memory_ex(process: libmem.lm_process_t, dest: int, source: bytearray) -> bool
    Write memory to a remote process

So your solution would look like that:

import libmem
import traceback

try:
    proc = libmem.find_process("notepad++.exe")
    print(f"Process found = {proc}")
    # Allocate memory
    new_me = libmem.alloc_memory_ex(proc, 1024, libmem.PROT_XRW)
    print(f"Allocated memory in remote process address = {new_me:016x}")
    # Try to write memory
    try:
        res = libmem.write_memory_ex(proc, new_me, bytearray(b"\x00" * 10))
        print("Memory written successfully:", res)
    except Exception as e:
        print("An error occurred while writing memory: ")
        traceback.print_exc()


except Exception as e:
    print("An error occurred: ")
    traceback.print_exc()

luadebug avatar Sep 13 '24 14:09 luadebug

OK, I have completed the code using the write_memory_ex function correctly. Thank you very much for your patient answer, very detailed, thank you!

Jai-wei avatar Sep 13 '24 15:09 Jai-wei

I'll reopen since I'll look into this

rdbo avatar Sep 15 '24 22:09 rdbo