Beispiel #1
0
HRESULT
CALLBACK
DebugExtensionInitialize(PULONG Version, PULONG Flags)
{
    IDebugClient *DebugClient = NULL;
    HRESULT Hr= S_OK;

    *Version = DEBUG_EXTENSION_VERSION(1, 0);
    *Flags = 0;

    // Connect to client
    if ((Hr = DebugCreate(__uuidof(IDebugClient),
                          (void **)&DebugClient)) != S_OK)
    {
        return Hr;
    }

    // Get the windbg-style extension APIS
    PDEBUG_CONTROL DebugControl;
    if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
                                          (void **)&DebugControl)) == S_OK)
    {
        ExtensionApis.nSize = sizeof (ExtensionApis);
        Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis);

        DebugControl->Release();
    }

    // done
    DebugClient->Release();
    return Hr;
}
void initDebugEngine(void)
{
	if ( NULL != gDebugControl )
	{
		gDebugControl->Release();
		gDebugControl = NULL;
	}
	if ( NULL != gDebugClient )
	{
		gDebugClient->Release();
		gDebugClient = NULL;
	}

	{
		HRESULT hResult = S_FALSE;
		hResult = DebugCreate( __uuidof(IDebugClient), (PVOID *)&gDebugClient );
		if ( FAILED(hResult) )
		{
			dprintf( "get IDebugClient fail\n" );
			return;
		}

		if ( NULL != gDebugClient )
		{
			hResult = gDebugClient->QueryInterface( __uuidof(IDebugControl), (PVOID *)&gDebugControl );
			if ( FAILED(hResult) )
			{
				dprintf( "get IDebugControl fail\n" );
			}
		}
	}
}
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;
}
Beispiel #4
0
Debugger::Debugger(QObject* parent)
:   QObject(parent),
    m_callbackEvent(this),
    m_watchTimer(-1),
    m_hDebuggeeProcess(0)
{
    HRESULT hr;
    hr = DebugCreate( __uuidof(IDebugClient5), reinterpret_cast<void**>(&m_pDebugClient));
    if (FAILED(hr)) m_pDebugClient = 0;
    hr = DebugCreate( __uuidof(IDebugControl4), reinterpret_cast<void**>(&m_pDebugControl));
    if (FAILED(hr)) m_pDebugControl = 0;
    hr = DebugCreate( __uuidof(IDebugSystemObjects4), reinterpret_cast<void**>(&m_pDebugSystemObjects));
    if (FAILED(hr)) m_pDebugSystemObjects = 0;
    hr = DebugCreate( __uuidof(IDebugSymbols3), reinterpret_cast<void**>(&m_pDebugSymbols));
    if (FAILED(hr)) m_pDebugSymbols = 0;
    hr = DebugCreate( __uuidof(IDebugRegisters2), reinterpret_cast<void**>(&m_pDebugRegisters));
    if (FAILED(hr)) m_pDebugRegisters = 0;

    m_pDebugClient->SetOutputCallbacks(&g_outputCallbacks);
    m_pDebugClient->SetEventCallbacks(&m_callbackEvent);
}
Beispiel #5
0
static bool getWindbgInterfaces(JNIEnv* env, jobject obj) {
  // get windbg interfaces ..

  IDebugClient* ptrIDebugClient = 0;
  if (DebugCreate(__uuidof(IDebugClient), (PVOID*) &ptrIDebugClient) != S_OK) {
     THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to create IDebugClient object!", false);
  }
  env->SetLongField(obj, ptrIDebugClient_ID, (jlong) ptrIDebugClient);

  IDebugControl* ptrIDebugControl = 0;
  if (ptrIDebugClient->QueryInterface(__uuidof(IDebugControl), (PVOID*) &ptrIDebugControl)
     != S_OK) {
     THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugControl", false);
  }
  env->SetLongField(obj, ptrIDebugControl_ID, (jlong) ptrIDebugControl);

  IDebugDataSpaces* ptrIDebugDataSpaces = 0;
  if (ptrIDebugClient->QueryInterface(__uuidof(IDebugDataSpaces), (PVOID*) &ptrIDebugDataSpaces)
     != S_OK) {
     THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugDataSpaces object!", false);
  }
  env->SetLongField(obj, ptrIDebugDataSpaces_ID, (jlong) ptrIDebugDataSpaces);

  SAOutputCallbacks* ptrIDebugOutputCallbacks = new SAOutputCallbacks();
  ptrIDebugOutputCallbacks->AddRef();
  env->SetLongField(obj, ptrIDebugOutputCallbacks_ID, (jlong) ptrIDebugOutputCallbacks);
  CHECK_EXCEPTION_(false);

  IDebugAdvanced* ptrIDebugAdvanced = 0;
  if (ptrIDebugClient->QueryInterface(__uuidof(IDebugAdvanced), (PVOID*) &ptrIDebugAdvanced)
     != S_OK) {
     THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugAdvanced object!", false);
  }
  env->SetLongField(obj, ptrIDebugAdvanced_ID, (jlong) ptrIDebugAdvanced);

  IDebugSymbols* ptrIDebugSymbols = 0;
  if (ptrIDebugClient->QueryInterface(__uuidof(IDebugSymbols), (PVOID*) &ptrIDebugSymbols)
     != S_OK) {
     THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSymbols object!", false);
  }
  env->SetLongField(obj, ptrIDebugSymbols_ID, (jlong) ptrIDebugSymbols);

  IDebugSystemObjects* ptrIDebugSystemObjects = 0;
  if (ptrIDebugClient->QueryInterface(__uuidof(IDebugSystemObjects), (PVOID*) &ptrIDebugSystemObjects)
     != S_OK) {
     THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSystemObjects object!", false);
  }
  env->SetLongField(obj, ptrIDebugSystemObjects_ID, (jlong) ptrIDebugSystemObjects);

  return true;
}
Beispiel #6
0
void* createInstance(ServiceFunc* serviceFunc) {
    DbgEngPlugin* plugin = new DbgEngPlugin;

    HRESULT hr = DebugCreate(__uuidof(IDebugClient), (void**)&plugin->debugClient);
    assert(SUCCEEDED(hr));

    hr = plugin->debugClient->SetEventCallbacks(plugin);
    assert(SUCCEEDED(hr));

    hr = plugin->debugClient->QueryInterface(__uuidof(IDebugControl), (void**)&plugin->debugControl);
    assert(SUCCEEDED(hr));

    return plugin;
}
bool FWindowsPlatformStackWalkExt::InitStackWalking()
{
	if (!FWindowsPlatformMisc::CoInitialize())
	{
		return false;
	}

	check( DebugCreate( __uuidof( IDebugClient5 ), ( void** )&Client ) == S_OK );

	check( Client->QueryInterface( __uuidof( IDebugControl4 ), ( void** )&Control ) == S_OK );
	check( Client->QueryInterface( __uuidof( IDebugSymbols3 ), ( void** )&Symbol ) == S_OK );
	check( Client->QueryInterface( __uuidof( IDebugAdvanced3 ), ( void** )&Advanced ) == S_OK );

	return true;
}
Beispiel #8
0
void
CreateInterfaces(void)
{
    SYSTEM_INFO SysInfo;
    
    // For purposes of keeping this example simple the
    // code only works on x86 machines.  There's no reason
    // that it couldn't be made to work on all processors, though.
    GetSystemInfo(&SysInfo);
    if (SysInfo.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_INTEL)
    {
        Exit(1, "This program only runs on x86 machines.\n");
    }

    // Get default version information.
    g_OsVer.dwOSVersionInfoSize = sizeof(g_OsVer);
    if (!GetVersionEx(&g_OsVer))
    {
        Exit(1, "GetVersionEx failed, %d\n", GetLastError());
    }

    HRESULT Status;

    // Start things off by getting an initial interface from
    // the engine.  This can be any engine interface but is
    // generally IDebugClient as the client interface is
    // where sessions are started.
    if ((Status = DebugCreate(__uuidof(IDebugClient),
                              (void**)&g_Client)) != S_OK)
    {
        Exit(1, "DebugCreate failed, 0x%X\n", Status);
    }

    // Query for some other interfaces that we'll need.
    if ((Status = g_Client->QueryInterface(__uuidof(IDebugControl),
                                           (void**)&g_Control)) != S_OK ||
        (Status = g_Client->QueryInterface(__uuidof(IDebugDataSpaces),
                                           (void**)&g_Data)) != S_OK ||
        (Status = g_Client->QueryInterface(__uuidof(IDebugRegisters),
                                           (void**)&g_Registers)) != S_OK ||
        (Status = g_Client->QueryInterface(__uuidof(IDebugSymbols),
                                           (void**)&g_Symbols)) != S_OK)
    {
        Exit(1, "QueryInterface failed, 0x%X\n", Status);
    }
}
Beispiel #9
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;
}
Beispiel #10
0
bool InitializeIDebug()
{
    HRESULT Hr;
    char Buffer[1024];
    IID *piidIDebugClient = (IID*)Buffer;
    Hr = IIDFromString(L"{27fe5639-8407-4f47-8364-ee118fb08ac8}", piidIDebugClient);
    if (Hr != S_OK){
        dprintf("Failed to IIDFromString 1\n");
        return false;
    }
    Hr = DebugCreate(piidIDebugClient, (void**)&pDebugClient);
    if (Hr != S_OK){
        dprintf("Failed to DebugCreate\n");
        return false;
    }

    IID *piidIDebugControl = (IID*)Buffer;
    Hr = IIDFromString(L"{5182e668-105e-416e-ad92-24ef800424ba}", piidIDebugControl);
    if (Hr != S_OK){
        dprintf("Failed to IIDFromString 2\n");
        return false;
    }
    Hr = pDebugClient->lpVtbl->QueryInterface(pDebugClient, piidIDebugControl, (void**)&pDebugControl);
    if (Hr != S_OK){
        dprintf("Failed to QueryInterface\n");
        return false;
    }

    /*
    IID *piidIDebugEventCallbacks = (IID*)Buffer;
    Hr = IIDFromString(L"{337be28b-5036-4d72-b6bf-c45fbb9f2eaa}", piidIDebugEventCallbacks);
    if (Hr != S_OK){
        dprintf("Failed to IIDFromString 3\n");
        return false;
    }
    Hr = pDebugClient->lpVtbl->QueryInterface(pDebugClient, piidIDebugEventCallbacks, (void**)&g_pDebugEventCallbacks);
    if (Hr != S_OK){
        dprintf("Failed to QueryInterface 3\n");
        return false;
    }
    */

    return true;
}
Beispiel #11
0
HRESULT
CALLBACK
DebugExtensionInitialize(PULONG Version, PULONG Flags)
{
    HRESULT hRes=S_OK;
    IDebugClient *DebugClient;
    PDEBUG_CONTROL DebugControl;

    *Version = DEBUG_EXTENSION_VERSION(EXT_MAJOR_VER, EXT_MINOR_VER);
    *Flags = 0;

    if (FAILED(hRes=DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)))
        return hRes;

    if (SUCCEEDED(hRes=DebugClient->QueryInterface(__uuidof(IDebugControl),  (void **)&DebugControl)))
    {
        // Get the windbg-style extension APIS
        ExtensionApis.nSize = sizeof (ExtensionApis);
        hRes = DebugControl->GetWindbgExtensionApis64(&ExtensionApis);
        DebugControl->Release();
        dprintf("[sync] DebugExtensionInitialize, ExtensionApis loaded\n");
    }

    DebugClient->Release();
    g_ExtClient = NULL;
    g_Synchronized = FALSE;

    g_hPollCompleteEvent = CreateEvent(NULL, true, false, NULL);
    if (g_hPollCompleteEvent == NULL)
    {
        dprintf("[sync] Command polling feature init failed\n");
        return E_FAIL;
    }

    InitializeCriticalSection(&g_CritSectPollRelease);

    if(SUCCEEDED(LoadConfigurationFile()))
        dprintf("[sync] Configuration file loaded\n       -> set HOST to %s:%s\n", g_DefaultHost, g_DefaultPort);

    return hRes;
}
//jc: this in the init routine. Runs on load.
HRESULT
CALLBACK
DebugExtensionInitialize(PULONG Version, PULONG Flags)
{
    IDebugClient *DebugClient;
    PDEBUG_CONTROL DebugControl;
    HRESULT Hr;

    *Version = DEBUG_EXTENSION_VERSION(1, 0);
    *Flags = 0;
    Hr = S_OK;

	

    if ((Hr = DebugCreate(__uuidof(IDebugClient),
                          (void **)&DebugClient)) != S_OK)
    {
        return Hr;
    }

    if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
                                  (void **)&DebugControl)) == S_OK)
    {

        //
        // Get the windbg-style extension APIS
        //
        ExtensionApis.nSize = sizeof (ExtensionApis);
        Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis);

        DebugControl->Release();

    }
	
	dprintf("[Byakugan] Successfully loaded!\n");
    DebugClient->Release();


    return (Hr);
}
void LateSymbolInfo::loadMinidump(std::wstring& dumppath, bool delete_when_done)
{
	// Method credit to http://stackoverflow.com/a/8119364/21501

	if (debugClient5 || debugControl4 || debugSymbols3)
	{
		//throw SleepyException(L"Minidump symbols already loaded.");

		// maybe the user moved a .pdb to somewhere where we can now find it?
		unloadMinidump();
	}

	IDebugClient *debugClient = NULL;

	SetLastError(0);
	comenforce(DebugCreate(__uuidof(IDebugClient), (void**)&debugClient), "DebugCreate");
	comenforce(debugClient->QueryInterface(__uuidof(IDebugClient5 ), (void**)&debugClient5 ), "QueryInterface(IDebugClient5)" );
	comenforce(debugClient->QueryInterface(__uuidof(IDebugControl4), (void**)&debugControl4), "QueryInterface(IDebugControl4)");
	comenforce(debugClient->QueryInterface(__uuidof(IDebugSymbols3), (void**)&debugSymbols3), "QueryInterface(IDebugSymbols3)");
	comenforce(debugClient5->SetOutputCallbacksWide(debugOutputCallbacks), "IDebugClient5::SetOutputCallbacksWide");
	comenforce(debugSymbols3->SetSymbolOptions(SYMOPT_UNDNAME | SYMOPT_LOAD_LINES | SYMOPT_OMAP_FIND_NEAREST | SYMOPT_AUTO_PUBLICS | SYMOPT_DEBUG), "IDebugSymbols::SetSymbolOptions");

	std::wstring sympath;
	prefs.AdjustSymbolPath(sympath, true);

	comenforce(debugSymbols3->SetSymbolPathWide(sympath.c_str()), "IDebugSymbols::SetSymbolPath");
	comenforce(debugClient5->OpenDumpFileWide(dumppath.c_str(), NULL), "IDebugClient4::OpenDumpFileWide");
	comenforce(debugControl4->WaitForEvent(0, INFINITE), "IDebugControl::WaitForEvent");

	// Since we can't just enumerate all symbols in all modules referenced by the minidump,
	// we have to keep the debugger session open and query symbols as requested by the
	// profiler GUI.

	debugClient->Release(); // but keep the other ones

	// If we are given a temporary file, clean it up later
	if (delete_when_done)
		file_to_delete = dumppath;
}
Beispiel #14
0
extern "C" HRESULT CALLBACK DebugExtensionInitialize(PULONG Version, PULONG Flags)
{
	IDebugClient *DebugClient;
	PDEBUG_CONTROL DebugControl;
	HRESULT Hr;

	*Version = DEBUG_EXTENSION_VERSION(1, 0);
	*Flags = 0;
	Hr = S_OK;

	if ((Hr = DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)) != S_OK)
	{
		return Hr;
	}
	if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),	(void **)&DebugControl)) == S_OK)
	{
		ExtensionApis.nSize = sizeof(ExtensionApis);
		Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis);
		DebugControl->Release();
	}
	DebugClient->Release();
	return Hr;
}
LLCrashLookupWindows::LLCrashLookupWindows()
	: LLCrashLookup()
	, m_pDbgClient(NULL)
	, m_pDbgControl(NULL)
	, m_pDbgSymbols(NULL)
	, m_pDbgClient4(0)
{
	CoInitialize(NULL);

	// Create the base IDebugClient object and then query it for the class instances we're interested in
	HRESULT hRes = DebugCreate(__uuidof(IDebugClient), (void**)&m_pDbgClient);
	if (SUCCEEDED(hRes))
	{
		hRes = m_pDbgClient->QueryInterface(__uuidof(IDebugControl4), (void**)&m_pDbgControl);
		if (FAILED(hRes))
			return;
		hRes = m_pDbgClient->QueryInterface(__uuidof(IDebugSymbols2), (void**)&m_pDbgSymbols);
		if (FAILED(hRes))
			return;

		m_pDbgClient->QueryInterface( __uuidof(IDebugClient4), (void**)&m_pDbgClient4 );
	}
}
Beispiel #16
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");
}
Beispiel #17
0
static void onCommand(HWND hDlg, int id, HWND /*hwndCtl*/, UINT codeNotify)
{
    if (bLoading) {
        return;
    }

    switch (id) {
    case MENU_LOAD:
        HK_openGame(0);
        break;

    case MENU_LOAD_QUICK:
        HK_quickOpenGame(0);
        break;

    case MENU_QUIT:
        HK_exitGame(0);
        break;

    case MENU_EXIT:
        StopReplay();
        AviStop();
        FBA_KailleraEnd();
        PostQuitMessage(0);

        menuSync(MENUT_ALL);
        return;

    case MENU_PAUSE:
        HK_pause(0);
        break;

    case MENU_CARTR_MOUNT:
        mountCartridge(true);
        menuSync(MENUT_FILE);
        break;

    case MENU_CARTR_UNMOUNT:
        mountCartridge(false);
        menuSync(MENUT_FILE);
        break;

    case MENU_STARTNET:
        if (!kNetGame) {
            InputSetCooperativeLevel(false, !bAlwaysProcessKey);
            audio.blank();
            SplashDestroy(1);
            StopReplay();
            AviStop();
            BurnerDrvExit();
            // load kaillera.dll
            if (FBA_KailleraInit()) {
                DoNetGame();
            }
            menuSync(MENUT_ALL);
            InputSetCooperativeLevel(false, !bAlwaysProcessKey);
        }
        break;

    case MENU_STARTREPLAY:
        HK_playRec(0);
        break;
    case MENU_STARTRECORD:
        HK_startRec(0);
        break;
    case MENU_STOPREPLAY:
        HK_stopRec(0);
        break;

    case MENU_AVISTART:
        HK_startAvi(0);
        break;
    case MENU_AVISTOP:
        HK_stopAvi(0);
        break;
    case MENU_AVIINTAUD:
        nAviIntAudio = !nAviIntAudio;
        menuSync(MENUT_FILE);
        break;

    case MENU_MEMCARD_CREATE:
        if (useDialogs() && bDrvOkay && !kNetGame
                && (BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNK_NEOGEO) {
            InputSetCooperativeLevel(false, !bAlwaysProcessKey);
            audio.blank();
            MemCardEject();
            MemCardCreate();
            MemCardInsert();
            menuSync(MENUT_FILE);
            GameInpCheckMouse();
        }
        break;
    case MENU_MEMCARD_SELECT:
        if (useDialogs() && bDrvOkay && !kNetGame
                && (BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNK_NEOGEO) {
            InputSetCooperativeLevel(false, !bAlwaysProcessKey);
            audio.blank();
            MemCardEject();
            MemCardSelect();
            MemCardInsert();
            menuSync(MENUT_FILE);
            GameInpCheckMouse();
        }
        break;
    case MENU_MEMCARD_INSERT:
        if (bDrvOkay && !kNetGame
                && (BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNK_NEOGEO) {
            MemCardInsert();
        }
        break;
    case MENU_MEMCARD_EJECT:
        if (bDrvOkay && !kNetGame
                && (BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNK_NEOGEO) {
            MemCardEject();
        }
        break;

    case MENU_MEMCARD_TOGGLE:
        if (bDrvOkay && !kNetGame
                && (BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SNK_NEOGEO) {
            MemCardToggle();
        }
        break;

    case MENU_STATE_LOAD_DIALOG:
        HK_loadStateDialog(0);
        break;
    case MENU_STATE_SAVE_DIALOG:
        HK_saveStateDialog(0);
        return;
    case MENU_STATE_PREVSLOT:
        HK_prevState(0);
        break;
    case MENU_STATE_NEXTSLOT:
        HK_nextState(0);
        break;
    case MENU_STATE_LOAD_SLOT:
        HK_loadCurState(0);
        break;
    case MENU_STATE_SAVE_SLOT:
        HK_saveCurState(0);
        break;

    case MENU_STATE_ALLRAM:
        bDrvSaveAll = !bDrvSaveAll;
        menuSync(MENUT_FILE);
        break;

    case MENU_WLOGSTART:
        audio.blank();
        waveLogStart();
        break;
    case MENU_WLOGEND:
        audio.blank();
        waveLogStop();
        break;

    case MENU_NOSTRETCH:
        bVidCorrectAspect = 0;
        bVidFullStretch = 0;
        simpleReinitScrn(false);
        menuSync(MENUT_SETTING);
        break;
    case MENU_STRETCH:
        bVidFullStretch = 1;
        bVidCorrectAspect = 0;
        simpleReinitScrn(false);
        menuSync(MENUT_SETTING);
        break;
    case MENU_ASPECT:
        bVidCorrectAspect = 1;
        bVidFullStretch = 0;
        simpleReinitScrn(false);
        menuSync(MENUT_SETTING);
        break;

    case MENU_FULL:
        HK_fullscreen(0);
        return;

    case MENU_AUTOSIZE:
        if (nWindowSize != 0) {
            nWindowSize = 0;
            simpleReinitScrn(false);
            menuSync(MENUT_SETTING);
        }
        break;
    case MENU_WINDOWSIZE1X:
        HK_windowSize(1);
        break;
    case MENU_WINDOWSIZE2X:
        HK_windowSize(2);
        break;
    case MENU_WINDOWSIZE3X:
        HK_windowSize(3);
        break;
    case MENU_WINDOWSIZE4X:
        HK_windowSize(4);
        break;
    case MENU_WINDOWSIZEMAX:
        HK_windowSizeMax(0);
        break;

    case MENU_HOTKEYS:
        MHkeysCreate(hDlg);
        break;

    case MENU_INPUT:
        HK_configPad(0);
        break;

    case MENU_DIPSW:
        HK_setDips(0);
        break;

    case MENU_SETCPUCLOCK:
        audio.blank();
        CPUClockDialog(hDlg);
        menuSync(MENUT_GAME);
        GameInpCheckMouse();
        break;
    case MENU_RESETCPUCLOCK:
        nBurnCPUSpeedAdjust = 0x0100;
        menuSync(MENUT_GAME);
        break;

    // ==> rom save
    case MENU_SAVEC:
        bsavedecryptedcs = !bsavedecryptedcs;
        menuSync(MENUT_GAME);
        break;
    case MENU_SAVEP:
        bsavedecryptedps = !bsavedecryptedps;
        menuSync(MENUT_GAME);
        break;
    case MENU_SAVES:
        bsavedecrypteds1 = !bsavedecrypteds1;
        menuSync(MENUT_GAME);
        break;
    case MENU_SAVEV:
        bsavedecryptedvs = !bsavedecryptedvs;
        menuSync(MENUT_GAME);
        break;
    case MENU_SAVEM:
        bsavedecryptedm1 = !bsavedecryptedm1;
        menuSync(MENUT_GAME);
        break;
    case MENU_SAVEXOR:
        bsavedecryptedxor = !bsavedecryptedxor;
        menuSync(MENUT_GAME);
        break;
    case MENU_SAVEDPROM:
        bsavedecryptedprom = !bsavedecryptedprom;
        menuSync(MENUT_GAME);
        break;
    // <== rom save

    case MENU_LANGUAGE_SELECT:
        if (useDialogs()) {
            if (!FBALocaliseLoad()) {
                menuReinit();
            }
        }
        break;
    case MENU_LANGUAGE_UNLOAD:
        _tcsncpy(szLanguage, _T(""), sizearray(szLanguage));
        FBALocaliseExit();
        menuReinit();
        break;

    case MENU_GAMELIST_SELECT:
        if (useDialogs()) {
            loadGamelist();
        }
        break;
    case MENU_GAMELIST_EXPORT:
        if (useDialogs()) {
            createGamelist();
        }
        break;

    case MENU_MISCDIR_EDIT:
        if (useDialogs()) {
            pathSheetCreate(hDlg);
        }
        break;
    case MENU_ROMDIR_EDIT:
        if (useDialogs()) {
            RomsDirCreate(hDlg);
        }
        break;

    case MENU_ENABLECHEAT:
        HK_cheatEditor(0);
        break;

#ifndef NO_CHEATSEARCH
    case MENU_CHEATSEARCH:
        HK_cheatSearch(0);
        break;
#endif

    // ==> simple jukebox, added by regret
    case MENU_JUKEBOX:
        if (useDialogs()) {
            jukeCreate();
            InputSetCooperativeLevel(false, !bAlwaysProcessKey);
        }
        break;
    // <== simple jukebox

    case MENU_DEBUG:
        if (useDialogs()) {
            InputSetCooperativeLevel(false, !bAlwaysProcessKey);
            DebugCreate();
        }
        break;

    case MENU_SAVESNAP: {
        HK_screenShot(0);
        break;
    }
    case MENU_SNAPFACT:
        HK_shotFactory(0);
        break;

    case MENU_SKIN_SELECT:
        if (useDialogs()) {
            if (selectSkin() == 0) {
                simpleReinitScrn(true);
            }
        }
        break;
    case MENU_SKIN_UNLOAD:
        _tcsncpy(szPlaceHolder, _T(""), sizearray(szPlaceHolder));
        simpleReinitScrn(true);
        break;

    case MENU_CLRMAMEPRO_XML:
        if (useDialogs()) {
            createDatfileWindows(1);
        }
        break;
    case MENU_CLRMAME_PRO:
        if (useDialogs()) {
            createDatfileWindows(0);
        }
        break;

    case MENU_SAVESET:
        configAppSaveXml();
        break;
    case MENU_LOADSET:
        configAppLoadXml();
        POST_INITIALISE_MESSAGE;
        break;

    case MENU_ABOUT:
        if (useDialogs()) {
            InputSetCooperativeLevel(false, !bAlwaysProcessKey);
            audio.blank();
            AboutCreate(hDlg);
            GameInpCheckMouse();
        }
        break;
    case MENU_SYSINFO:
        if (useDialogs()) {
            InputSetCooperativeLevel(false, !bAlwaysProcessKey);
            audio.blank();
            SystemInfoCreate(hDlg);
            GameInpCheckMouse();
        }
        break;

    case MENU_CONTENTS: {
        if (useDialogs()) {
            FILE* fp = _tfopen(_T("readme.txt"), _T("r"));
            if (fp) {
                fclose(fp);
                ShellExecute(NULL, _T("open"), _T("readme.txt"), NULL, NULL, SW_SHOWNORMAL);
            }
        }
        break;
    }

    case MENU_WWW_HOME:
        ShellExecute(NULL, _T("open"), _T("http://www.barryharris.me.uk/"), NULL, NULL, SW_SHOWNORMAL);
        break;
    case MENU_WWW_FORUM:
        ShellExecute(NULL, _T("open"), _T("http://neosource.1emulation.com/forums/"), NULL, NULL, SW_SHOWNORMAL);
        break;
    case MENU_WWW_FORUM1:
        ShellExecute(NULL, _T("open"), _T("http://www.egcg.com.cn/bbs/"), NULL, NULL, SW_SHOWNORMAL);
        break;

    // filters
    case MENU_SOFT_NONE:
        vidUseFilter = 0;
        nVidFilter = 0;
        VidReinit();
        menuSync(MENUT_SETTING);
        break;

    case MENU_SOFT_EPXB:
    case MENU_SOFT_EPXC:
    case MENU_SOFT_SCALE2X:
    case MENU_SOFT_SCALE3X:
    case MENU_SOFT_2XSAI:
    case MENU_SOFT_SUPER2XSAI:
    case MENU_SOFT_SUPEREAGLE:
    case MENU_SOFT_2XPMHQ:
    case MENU_SOFT_HQ2X:
    case MENU_SOFT_HQ2XS:
    case MENU_SOFT_HQ2XBOLD:
    case MENU_SOFT_HQ3X:
    case MENU_SOFT_HQ3XS:
    case MENU_SOFT_HQ3XBOLD:
    case MENU_SOFT_SCANLINE:
    case MENU_SOFT_SCANLINE50:
    case MENU_SOFT_SCANLINE25:
    case MENU_SOFT_INTERSCANLINE:
    case MENU_SOFT_INTERSCANLINE50:
    case MENU_SOFT_INTERSCANLINE25:
        vidUseFilter = 1;
        nVidFilter = id - MENU_SOFT_NONE;
        scrnSize();
        VidSwitchFilter(nVidFilter);
        menuSync(MENUT_SETTING);
        break;

    case MENU_FILTER_AUTOSIZE:
        vidForceFilterSize = !vidForceFilterSize;
        simpleReinitScrn(true);
        menuSync(MENUT_SETTING);
        break;

    // Options for blitters
    case MENU_FILTER_POINT:
        if (vidFilterLinear) {
            vidFilterLinear = 0;
            VidReinit();
            menuSync(MENUT_SETTING);
        }
        break;
    case MENU_FILTER_LINEAR:
        if (!vidFilterLinear) {
            vidFilterLinear = 1;
            VidReinit();
            menuSync(MENUT_SETTING);
        }
        break;

    case MENU_CONFIGALL:
        if (useDialogs()) {
            preferenceCreate(hDlg);
            setWindowAspect();
            menuReinit();
            simpleReinitScrn(true);
            mediaReInitAudio();
        }
        break;
    case MENU_VIDEOCONFIG:
        if (useDialogs()) {
            prefVideoCreate(hDlg);
            setWindowAspect();
            simpleReinitScrn(true);
        }
        break;
    case MENU_AUDIOCONFIG:
        if (useDialogs()) {
            prefAudioCreate(hDlg);
            mediaReInitAudio();
        }
        break;
    case MENU_MISCCONFIG:
        if (useDialogs()) {
            prefMiscCreate(hDlg);
            menuReinit();
            VidReinit();
        }
        break;

//		default:
//			printf("  * Command %i sent.\n");
    }

    if (ChatActivated()) {
        switch (codeNotify) {
        case EN_CHANGE: {
            bEditTextChanged = true;
            SendMessage(GetChatWindow(), WM_GETTEXT, (WPARAM)MAX_CHAT_SIZE + 1, (LPARAM)EditText);
            break;
        }
        case EN_KILLFOCUS: {
            ActivateChat();
            break;
        }
        case EN_MAXTEXT: {
            VidSNewShortMsg(FBALoadStringEx(IDS_NETPLAY_TOOMUCH), 0xFF3F3F);
            break;
        }
        }
    }
}
Beispiel #18
0
extern "C" HRESULT CALLBACK DebugExtensionInitialize(PULONG Version, PULONG Flags)
{
    HRESULT hRes=E_FAIL;

    if(bInitialized)
    {
        return S_OK;
    }

    //
    // Initialize the version information
    //
    *Version=DEBUG_EXTENSION_VERSION(1, 0);
    *Flags=0;

    //
    // Initialize required COM interface pointers
    //
    if(FAILED(hRes=DebugCreate(__uuidof(IDebugClient), 
                               (void**) &pDebugClient)))
    {
        return hRes;
    }

    if(FAILED(hRes=pDebugClient->QueryInterface(__uuidof(IDebugControl), (void**) &pDebugControl)))
    {
        ReleaseComPointers();
        return hRes;
    }

    //
    // Initialize WinDbg extension data
    //
    ExtensionApis.nSize=sizeof(ExtensionApis);
    hRes=pDebugControl->GetWindbgExtensionApis64(&ExtensionApis);

    if(FAILED((hRes=pDebugClient->QueryInterface(__uuidof(IDebugDataSpaces), (void**) &pDataSpaces))))
    {
        dprintf( "Failed to get required COM interface\n");
        ReleaseComPointers();
        return hRes;
    }
       
    if(FAILED(hRes=pDebugClient->QueryInterface(__uuidof(IDebugSymbols), (void**) &pSymbols)))
    {
        dprintf( "Failed to get required COM interface\n");
        ReleaseComPointers();
        return hRes;
    }

    if(FAILED(hRes=pDebugClient->QueryInterface(__uuidof(IDebugSymbols3), (void**) &pSymbols3)))
    {
        dprintf( "Failed to get required COM interface\n");
        ReleaseComPointers();        
        return hRes;
    }

    //
    // Initialize type information
    //
    if(FAILED(hRes=pSymbols->GetModuleByModuleName("11bstree", 
                                                   0, 
                                                   NULL, 
                                                   &pBase)))
    {
        dprintf("Failed to get module information for bstree.exe\n");
        ReleaseComPointers();        
        return hRes;
    }
    if(FAILED(hRes=pSymbols3->GetTypeId(pBase, 
                                        "CBinaryTree::_TreeNode",    
                                        &pNodeIndex)))
    {
        dprintf("Failed to get type id\n");
        ReleaseComPointers();        
        return hRes;
    }
    if(FAILED(hRes=pSymbols->GetTypeSize(pBase, 
                                         pNodeIndex, 
                                         &pSize)))
    {
        dprintf("Failed to get type size\n");
        ReleaseComPointers();        
        return hRes;
    }

    if(FAILED(hRes=pSymbols->GetFieldOffset(pBase, 
                                            pNodeIndex, 
                                            "pLeftChild", 
                                            &ulLeftOffset)))
    {
        dprintf("Failed to get left child offset\n");			
        ReleaseComPointers();        
        return hRes;
    }

    if(FAILED(hRes=pSymbols->GetFieldOffset(pBase, 
                                            pNodeIndex, 
                                            "pRightChild", 
                                            &ulRightOffset)))
    {
        dprintf("Failed to get right child offset\n");			
        ReleaseComPointers();        
        return hRes;
    }

    if(FAILED(hRes=pSymbols->GetFieldOffset(pBase, 
                                            pNodeIndex, 
                                            "data", 
                                            &ulDataOffset)))
    {
        dprintf("Failed to get data offset\n");			
        ReleaseComPointers();        
        return hRes;
    }

    bInitialized=TRUE;
    hRes=S_OK;

    return hRes;
}
Beispiel #19
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;
}
Beispiel #20
0
HRESULT
CALLBACK
DebugExtensionInitialize(PULONG Version, PULONG Flags)
{
    IDebugClient *DebugClient;
    PDEBUG_CONTROL DebugControl;
    HRESULT Hr;

    *Version = DEBUG_EXTENSION_VERSION(1, 0);
    *Flags = 0;

    if (g_Initialized)
    {
        return S_OK;
    }
    g_Initialized = true;

    if ((Hr = DebugCreate(__uuidof(IDebugClient),
                          (void **)&DebugClient)) != S_OK)
    {
        return Hr;
    }
    if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
                                              (void **)&DebugControl)) != S_OK)
    {
        return Hr;
    }

    ExtensionApis.nSize = sizeof (ExtensionApis);
    if ((Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis)) != S_OK)
    {
        return Hr;
    }
    
    // Fixes the "Unable to read dynamic function table entries" error messages by disabling the WinDbg security
    // feature that prevents the loading of unknown out of proc tack walkers.
    DebugControl->Execute(DEBUG_OUTCTL_IGNORE, ".settings set EngineInitialization.VerifyFunctionTableCallbacks=false", 
        DEBUG_EXECUTE_NOT_LOGGED | DEBUG_EXECUTE_NO_REPEAT);

    ExtQuery(DebugClient);
    if (IsMiniDumpFileNODAC())
    {
        ExtOut (
            "----------------------------------------------------------------------------\n"
            "The user dump currently examined is a minidump. Consequently, only a subset\n"
            "of sos.dll functionality will be available. If needed, attaching to the live\n"
            "process or debugging a full dump will allow access to sos.dll's full feature\n"
            "set.\n"
            "To create a full user dump use the command: .dump /ma <filename>\n"
            "----------------------------------------------------------------------------\n");
    }
    ExtRelease();
    
    OnUnloadTask::Register(CleanupEventCallbacks);
    g_pCallbacksClient = DebugClient;
    EventCallbacks* pCallbacksObj = new EventCallbacks(DebugClient);
    IDebugEventCallbacks* pCallbacks = NULL;
    pCallbacksObj->QueryInterface(__uuidof(IDebugEventCallbacks), (void**)&pCallbacks);
    pCallbacksObj->Release();

    if(FAILED(Hr = g_pCallbacksClient->SetEventCallbacks(pCallbacks)))
    {
        ExtOut ("SOS: Failed to register callback events\n");
        pCallbacks->Release();
        return Hr;
    }
    pCallbacks->Release();

#ifndef _ARM_
    // Make sure we do not tear down the debugger when a security function fails
    // Since we link statically against CRT this will only affect the SOS module.
    _set_invalid_parameter_handler(_SOS_invalid_parameter);
#endif
    
    DebugControl->Release();
    return S_OK;
}