Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Jai-wei opened this issue Sep 13, 2024 · 3 comments
Open

Comments

@Jai-wei
Copy link

Jai-wei commented Sep 13, 2024

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.

@luadebug
Copy link
Contributor

luadebug commented Sep 13, 2024

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()

@Jai-wei
Copy link
Author

Jai-wei commented Sep 13, 2024

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 Jai-wei closed this as completed Sep 13, 2024
@rdbo
Copy link
Owner

rdbo commented Sep 15, 2024

I'll reopen since I'll look into this

@rdbo rdbo reopened this Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants