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

Process execution pauses for too long while loading a comment database #2296

Closed
alex-shr opened this issue Feb 22, 2020 · 9 comments
Closed

Process execution pauses for too long while loading a comment database #2296

alex-shr opened this issue Feb 22, 2020 · 9 comments
Labels

Comments

@alex-shr
Copy link

@alex-shr alex-shr commented Feb 22, 2020

x32dbg Feb 11 2020.
Microsoft Windows [Version 10.0.18363.657]
I cann't attach x32dbg to time critical network client app (RF Online MMORPG client protected by Enigma). Comment database loading takes 6sec+ when x32dbg tries to attach to the process. During this time, the execution of the debugged application is completly suspended, which is enough to lose connection. "Attach breakpoint" option is OFF, but it does not help at all.

Is it possible to move this database loading stuff into a separate thread?

@mrexodia

This comment has been minimized.

Copy link
Member

@mrexodia mrexodia commented Feb 22, 2020

It’s not really possible, because breakpoints are also loaded at this stage and you don’t want your breakpoints to not load.

In theory it isn’t necessary for the app to be suspended though, perhaps it’s possible to move database loading to before cbCreateProcess, but I doubt this use case is common enough. Generally you can just start the program under the debugger and things should work fine.

@alex-shr

This comment has been minimized.

Copy link
Author

@alex-shr alex-shr commented Feb 22, 2020

Starting the program under the debugger is not an option. There is another app - the launcher. This application logs on to the game server, launches the main client application and transfers encrypted data to it. This procedure is time critical, and cannot be done manually.

All i need is to attach to the main process in 5 seconds max.

Can you store breakpoints data separatly from comments?

@mrexodia

This comment has been minimized.

Copy link
Member

@mrexodia mrexodia commented Feb 22, 2020

@blaquee

This comment has been minimized.

Copy link
Contributor

@blaquee blaquee commented Feb 22, 2020

Floating the idea here of “early attach” plugin execution. Then perhaps you could run something before all the necessary initialization. Just a thought

@mrexodia

This comment has been minimized.

Copy link
Member

@mrexodia mrexodia commented Feb 22, 2020

@blaquee Yeah you can already do that withCB_INITDEBUG and CB_ATTACH, which are called before the debug loop starts, but you cannot change the behavior of what happens in cbCreateProcess, which will hang the executable as long as it doesn't return.

See here for relevant code:

x64dbg/src/dbg/debugger.cpp

Lines 2694 to 2705 in 6407b2b

//call plugin callback
PLUG_CB_INITDEBUG initInfo;
initInfo.szFileName = szFileName;
plugincbcall(CB_INITDEBUG, &initInfo);
//call plugin callback (attach)
if(attach)
{
PLUG_CB_ATTACH attachInfo;
attachInfo.dwProcessId = (DWORD)pid;
plugincbcall(CB_ATTACH, &attachInfo);
}

@alex-shr From where I'm sitting this looks like an impossible scenario to cover even in theory. There is never a guarantee that events in the debug loop are processed under a certain time threshold, so even if the database loading is optimized there might be lots of reasons why cbCreateProcess takes a very long time (disk i/o for instance, or other plugins)

@alex-shr

This comment has been minimized.

Copy link
Author

@alex-shr alex-shr commented Feb 23, 2020

This code is the problem.

x64dbg/src/dbg/debugger.cpp

Lines 1371 to 1373 in 6407b2b

// Init program database
DbLoad(DbLoadSaveType::DebugData);
bDatabaseLoaded = true;

It takes 12 seconds under MSVC 2019 debugger. All other code of cbCreateProcess takes less than 0.5 second. Can you move it into debugLoopFunction before this part?

x64dbg/src/dbg/debugger.cpp

Lines 2707 to 2723 in 6407b2b

//run debug loop (returns when process debugging is stopped)
if(attach)
{
if(AttachDebugger(pid, true, fdProcessInfo, (void*)cbAttachDebugger) == false)
{
String error = stringformatinline(StringUtils::sprintf("{winerror@%d}", GetLastError()));
dprintf(QT_TRANSLATE_NOOP("DBG", "Attach to process failed! GetLastError() = %s\n"), error.c_str());
}
}
else
{
//close the process and thread handles we got back from CreateProcess, to prevent duplicating the ones we will receive in cbCreateProcess
CloseHandle(fdProcessInfo->hProcess);
CloseHandle(fdProcessInfo->hThread);
fdProcessInfo->hProcess = fdProcessInfo->hThread = nullptr;
DebugLoop();
}

@mrexodia

This comment has been minimized.

Copy link
Member

@mrexodia mrexodia commented Feb 23, 2020

It might be possible, but it's very tricky because it will no longer call CB_LOADDB from the debug thread like before which is something plugins might depend on. I will investigate if something is possible.

@mrexodia

This comment has been minimized.

Copy link
Member

@mrexodia mrexodia commented Feb 23, 2020

@alex-shr

This comment has been minimized.

Copy link
Author

@alex-shr alex-shr commented Feb 23, 2020

Many thanks!

@mrexodia mrexodia closed this in d2c62e6 Feb 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.