Example #1
0
void
CALLBACK
DebugExtensionNotify(ULONG Notify, ULONG64 Argument)
{
    UNREFERENCED_PARAMETER(Argument);

    //
    // The first time we actually connect to a target
    //
	/*
	 *New debugger extensions get new debugger interfaces by calling
	 *DebugCreate(__uuidof (IDebugClient), &DebugClient))
	 *DebugClient->QueryInterface(_uuidof(Interface_you_want)
	*/ 
    if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected))
    {
        IDebugClient *DebugClient;
        HRESULT Hr;
        PDEBUG_CONTROL DebugControl;

        if ((Hr = DebugCreate(__uuidof(IDebugClient),
                              (void **)&DebugClient)) == S_OK)
        {
            //
            // Get the architecture type.
            //

            if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
                                       (void **)&DebugControl)) == S_OK)
            {
				//jc:QueryInterface must fill in DebugControl
                if ((Hr = DebugControl->GetActualProcessorType(
                                             &TargetMachine)) == S_OK)
                {
                    Connected = TRUE;
                }


                DebugControl->Release();
            }

            DebugClient->Release();
        }
    }


    if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE)
    {
        Connected = FALSE;
        TargetMachine = 0;
    }

    return;
}
Example #2
0
void
CALLBACK
DebugExtensionNotify(ULONG Notify, ULONG64 Argument)
{
    static BOOL    Connected;

    UNREFERENCED_PARAMETER(Argument);

    // The first time we actually connect to a target
    if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected))
    {
        IDebugClient *DebugClient = NULL;
        HRESULT Hr;
        PDEBUG_CONTROL DebugControl = NULL;

        if ((Hr = DebugCreate(__uuidof(IDebugClient),
                              (void **)&DebugClient)) == S_OK)
        {
            //
            // Get the architecture type.
            //
            if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
                                                  (void **)&DebugControl)) == S_OK)
            {
                ULONG   TargetMachine;
                if ((Hr = DebugControl->GetActualProcessorType(
                              &TargetMachine)) == S_OK)
                {
                    Connected = TRUE;
                }

                //NotifyOnTargetAccessible(DebugControl);
                DebugControl->Release();
            }

            DebugClient->Release();
        }
    }

    // The target is gone
    if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE)
        Connected = FALSE;

    return;
}
Example #3
0
void
CALLBACK
DebugExtensionNotify(ULONG Notify, ULONG64 /*Argument*/)
{
    //
    // The first time we actually connect to a target, get the page size
    //

    if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected))
    {
        IDebugClient *DebugClient;
        PDEBUG_DATA_SPACES DebugDataSpaces;
        PDEBUG_CONTROL DebugControl;
        HRESULT Hr;
        ULONG64 Page;

        if ((Hr = DebugCreate(__uuidof(IDebugClient),
                              (void **)&DebugClient)) == S_OK)
        {
            //
            // Get the page size and PAE enable flag
            //

            if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugDataSpaces),
                                       (void **)&DebugDataSpaces)) == S_OK)
            {
                if ((Hr = DebugDataSpaces->ReadDebuggerData(
                    DEBUG_DATA_MmPageSize, &Page,
                    sizeof(Page), NULL)) == S_OK)
                {
                    PageSize = (ULONG)(ULONG_PTR)Page;
                }

                DebugDataSpaces->Release();
            }
            //
            // Get the architecture type.
            //

            if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
                                                  (void **)&DebugControl)) == S_OK)
            {
                if ((Hr = DebugControl->GetActualProcessorType(
                    &TargetMachine)) == S_OK)
                {
                    Connected = TRUE;
                }
                ULONG Qualifier;
                if ((Hr = DebugControl->GetDebuggeeType(&g_TargetClass, &Qualifier)) == S_OK)
                {
                }

                DebugControl->Release();
            }

            DebugClient->Release();
        }
    }


    if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE)
    {
        Connected = FALSE;
        PageSize = 0;
        TargetMachine = 0;
    }

    return;
}
Example #4
0
//--------------------------------------------------------------------------------------
VOID WDBGAPI WinDbgExtensionDllInit(
    PWINDBG_EXTENSION_APIS lpExtensionApis, 
    USHORT usMajorVersion, USHORT usMinorVersion)
{
    if (g_RefCount > 0)
    {
        // extension is allready initialized
        return;
    }

    HRESULT Hr = DebugCreate(__uuidof(IDebugClient), (void **)&g_Client);
    if (Hr != S_OK)
    {
        MessageBoxA(0, "DebugCreate() fails", __FUNCTION__, MB_ICONERROR);
        return;
    }

    Hr = g_Client->QueryInterface(__uuidof(IDebugControl), (void **)&g_Control);
    if (Hr != S_OK)
    {    
        MessageBoxA(
            0, 
            "DebugClient::QueryInterface(IDebugControl) fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }

    ULONG TargetMachine = 0;
    Hr = g_Control->GetActualProcessorType(&TargetMachine);
    if (Hr == S_OK)
    {                                                     
        switch (TargetMachine)
        {
        case IMAGE_FILE_MACHINE_I386:
            
            g_bIs64 = FALSE;
            g_RegPtrType = DEBUG_VALUE_INT32;
            break;


        case IMAGE_FILE_MACHINE_AMD64:

            g_bIs64 = TRUE;
            g_RegPtrType = DEBUG_VALUE_INT64;
            break;

        default:

            MessageBoxA(
                0, 
                "Target architecture is not supported", 
                __FUNCTION__, MB_ICONERROR
            );

            ExitProcess(0);

            break;
        }
    }
    else
    {
        MessageBoxA(
            0, 
            "DebugControl::GetActualProcessorType() fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }

    Hr = g_Client->QueryInterface(__uuidof(IDebugSymbols3), (void **)&g_Symbols);
    if (Hr != S_OK)
    {    
        MessageBoxA(
            0, 
            "DebugClient::QueryInterface(IDebugSymbols3) fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }

    Hr = g_Client->QueryInterface(__uuidof(IDebugSystemObjects), (void **)&g_SystemObjects);
    if (Hr != S_OK)
    {    
        MessageBoxA(
            0, 
            "DebugClient::QueryInterface(IDebugSystemObjects) fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }

    Hr = g_Client->QueryInterface(__uuidof(IDebugRegisters), (void **)&g_Registers);
    if (Hr != S_OK)
    {    
        MessageBoxA(
            0, 
            "DebugClient::QueryInterface(IDebugRegisters) fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }

    Hr = g_Client->QueryInterface(__uuidof(IDebugDataSpaces), (void **)&g_DataSpaces);
    if (Hr != S_OK)
    {    
        MessageBoxA(
            0, 
            "DebugClient::QueryInterface(IDebugDataSpaces) fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }

    char *lpszEip = "eip", *lpszEax = "eax", *lpszEcx = "ecx";
    if (g_bIs64)
    {
        // use 64-bit registers for parameter and return value
        lpszEip = "rip";
        lpszEax = "rax";
        lpszEcx = "rcx";
    }

    // Find the register index for eip/rip
    Hr = g_Registers->GetIndexByName(lpszEip, &g_EipIndex);
    if (Hr != S_OK)
    {
        MessageBoxA(
            0, 
            "DebugRegisters::GetIndexByName() fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }    

    // Find the register index for eax/rax
    Hr = g_Registers->GetIndexByName(lpszEax, &g_EaxIndex);
    if (Hr != S_OK)
    {
        MessageBoxA(
            0, 
            "DebugRegisters::GetIndexByName() fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }    

    // Find the register index for ecx/rcx
    Hr = g_Registers->GetIndexByName(lpszEcx, &g_EcxIndex);
    if (Hr != S_OK)
    {
        MessageBoxA(
            0, 
            "DebugRegisters::GetIndexByName() fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }

    // Find the register index for edx
    Hr = g_Registers->GetIndexByName("edx", &g_EdxIndex);
    if (Hr != S_OK)
    {
        MessageBoxA(
            0, 
            "DebugRegisters::GetIndexByName() fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }

    // Register our event callbacks.
    Hr = g_Client->SetEventCallbacks(&g_EventCb);
    if (Hr != S_OK)
    {
        MessageBoxA(
            0, 
            "DebugClient::SetEventCallbacks() fails", 
            __FUNCTION__, MB_ICONERROR
        );

        ExitProcess(0);
    }

    ExtOut("<col fg=\"srckw\">" __FUNCTION__"(): Initialized (x64: %s)</col>\n", g_bIs64 ? "Yes" : "No");
}