libmem
libmem copied to clipboard
`set_memory_ex`:TypeError function takes exactly 3 arguments (4 given)
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.
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()
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!
I'll reopen since I'll look into this