Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Debugger Setup via plugin

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Source -> Plugin development
View previous topic :: View next topic  
Author Message
MMM-304
Expert Cheater
Reputation: 0

Joined: 17 Aug 2020
Posts: 170
Location: Milkey Way

PostPosted: Sun Jun 23, 2024 11:55 pm    Post subject: Debugger Setup via plugin Reply with quote

I am trying to setup debugger interface using plugin with c++. I am not too familiar with debugging and encountering a few problems.

1. I cannot get the context of the debug thread. Here is my OnDebugEvent.
Code:
int __stdcall OnDebugEvent(LPDEBUG_EVENT DebugEvent)
{
    brokenThreadId = NULL;
    if (!DebugEvent) return 0;
    switch (DebugEvent->dwDebugEventCode)
    {
    case EXCEPTION_DEBUG_EVENT:
    {
        volatile EXCEPTION_DEBUG_INFO& Exception = DebugEvent->u.Exception;
        logger->AddLog(string_format("ThreadID: %X - ExceptionCode: %X - ExceptionFlag: %d", DebugEvent->dwThreadId, Exception.ExceptionRecord.ExceptionCode, Exception.ExceptionRecord.ExceptionFlags));
        switch (Exception.ExceptionRecord.ExceptionCode)
        {
        case EXCEPTION_BREAKPOINT:
            break;
        case EXCEPTION_SINGLE_STEP:
        {
            brokenThreadId = DebugEvent->dwThreadId;
            isBroken = LuaAPI::debug_isBroken();
            HANDLE tHandle = OpenThread(THREAD_ALL_ACCESS, NULL, DebugEvent->dwThreadId);
            if (tHandle && tHandle != INVALID_HANDLE_VALUE)
            {
                CONTEXT context;
                ZeroMemory(&context, sizeof(CONTEXT));
                context.ContextFlags = CONTEXT_FULL;
                if (GetThreadContext(tHandle, &context))
                {
                    logger->AddLog(string_format("RBX = %p, Address: %p", context.Rbx, Exception.ExceptionRecord.ExceptionAddress)); // Incorrect value
                }
                CloseHandle(tHandle);
            }
            return 0;
        }
            break;
        default:
            break;
        }
    }
    default:
        break;
    }
    return 0;
}


I tried to store the thread ID and look up the context later, but it still gave me incorrect context.

2. Is there a plugin function to set the debugger with a specific callback c++ function? The current one "debug_setBreakpoint" does not include the callback function.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 467

Joined: 09 May 2003
Posts: 25700
Location: The netherlands

PostPosted: Mon Jun 24, 2024 2:18 am    Post subject: Reply with quote

1 Is the debugger interface set to windows or one of the others ?

2 not at the moment. Although you could invoke the lua version of debug_setBreakpoint and give it a cfunction as callback (using the lua callback mechanism)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
MMM-304
Expert Cheater
Reputation: 0

Joined: 17 Aug 2020
Posts: 170
Location: Milkey Way

PostPosted: Mon Jun 24, 2024 2:21 am    Post subject: Reply with quote

Currently im using VEH debugger

Edit:
Also there is nothing within ExceptionRecord. Is there a way to get exceptioninfo? through which context?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 467

Joined: 09 May 2003
Posts: 25700
Location: The netherlands

PostPosted: Mon Jun 24, 2024 3:58 am    Post subject: Reply with quote

right. When using any of the non-windows debugger interfaces stuff like getthreadcontext won't work as it's interface specific

for vehdebug you could try mapping the TVEHDebugSharedMem shared memory and read the context from there

the exceptioninfo should be correctish though. is the target 32 or 64 bit ? You'll need to adjust the context to the correct type

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
MMM-304
Expert Cheater
Reputation: 0

Joined: 17 Aug 2020
Posts: 170
Location: Milkey Way

PostPosted: Mon Jun 24, 2024 4:23 am    Post subject: Reply with quote

The target is 64, and an example would be appreciated, especially with respect to the plugin system

Also is there a way to know which type of debugger is selected by the user before it is even injected? I mean `debug_getCurrentDebuggerInterface` only returns value after the injection. I need to know the type before the injection
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Source -> Plugin development All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites