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

Callbacks are not thread safe #52

Open
owerosu opened this issue Jul 14, 2020 · 1 comment
Open

Callbacks are not thread safe #52

owerosu opened this issue Jul 14, 2020 · 1 comment

Comments

@owerosu
Copy link

owerosu commented Jul 14, 2020

Hello,
Callbacks registered there https://github.com/x64dbg/x64dbgpy/blob/v25/py.cpp#L810 are not thread safe and will produce random memory corruptions if an user script is running at the same time. We can't run python from two different threads at the exact same time.

Trigger the random corruption:
Dummy program to debug:
int crash(int a,int b) { int sum = 0; for (int i = 0; i < 0xFFFFFF; i++) sum += a + b; return sum; }

Dummy script:

`import x64dbgpy

def loop():
print("inside loop")
x64dbgpy.pluginsdk.Run()

def outloop():
print("loop finished")
x64dbgpy.pluginsdk.Run()

x64dbgpy.Breakpoint.add(0x140001036,loop)
x64dbgpy.Breakpoint.add(0x140001048,outloop)
x64dbgpy.pluginsdk.Run()`

corruption

Then enjoy random memory corruptions, you may need to run several times to crash or reload binary etc ...

So we need to use GIL lock related functions or maybe use async functions like PyThreadState_SetAsyncExc/Py_AddPendingCall.

@mrexodia
Copy link
Member

Yeah, the current codebase is not great. The https://github.com/x64dbg/x64dbgpy/tree/v25/scriptapi project uses pybind11, which can work around these threading issues but it's currently not in development. Please join the x64dbg chat to discuss if you would like to collaborate on it.

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

2 participants