Пример #1
0
bool DebugFrontend::InitializeBackend(const char* symbolsDirectory)
{

    if (GetIsBeingDebugged(m_processId))
    {
        MessageEvent("Error: The process cannot be debugged because it contains hooks from a previous session", MessageType_Error);
        return false;
    }

    char eventChannelName[256];
    _snprintf(eventChannelName, 256, "Decoda.Event.%x", m_processId);

    char commandChannelName[256];
    _snprintf(commandChannelName, 256, "Decoda.Command.%x", m_processId);
    
    // Setup communication channel with the process that is used to receive events
    // back to the frontend.
    if (!m_eventChannel.Create(eventChannelName))
    {
        return false;
    }

    // Setup communication channel with the process that is used to send commands
    // to the backend.
    if (!m_commandChannel.Create(commandChannelName))
    {
        return false;
    }

    // Inject our debugger DLL into the process so that we can monitor from
    // inside the process's memory space.
    if (!InjectDll(m_processId, "LuaInject.dll"))
    {
        MessageEvent("Error: LuaInject.dll could not be loaded into the process", MessageType_Error);
        return false;
    }

    // Wait for the client to connect.
    m_eventChannel.WaitForConnection();

    // Read the initialization function from the event channel.

    if (!ProcessInitialization(symbolsDirectory))
    {
        MessageEvent("Error: Backend couldn't be initialized", MessageType_Error);
        return false;
    }

    m_state = State_Running;

    // Start a new thread to handle the incoming event channel.
    DWORD threadId;
    m_eventThread = CreateThread(NULL, 0, StaticEventThreadProc, this, 0, &threadId);

    return true;

}
Пример #2
0
void wxGISStatusBar::SetMessage(const wxString& text, int i)
{
    wxCommandEvent MessageEvent( wxEVT_COMMAND_BUTTON_CLICKED ); // Keep it simple, don't give a specific event ID
    MessageEvent.SetString(text);
    MessageEvent.SetInt(i);
    wxPostEvent(this, MessageEvent);
}
Пример #3
0
void CTriggerEvent::MessageEvent(ETriggerStateType eType, uint32 uFromID, uint32 uToID, ESpecialEventType eArg1, bool bArg2)
{
	CEntityServer* pEntityFrom = CEntityServerManager::GetEntityByID(uFromID);
	CFighterDictator* pFrom = pEntityFrom ? pEntityFrom->GetFighter() : NULL;
	CEntityServer* pEntityTo = CEntityServerManager::GetEntityByID(uToID);
	CFighterDictator* pTo = pEntityTo ? pEntityTo->GetFighter() : NULL;
	MessageEvent(eType, pFrom, pTo, eArg1, bArg2);
}
Пример #4
0
void CTriggerEvent::MessageEvent(ETriggerStateType eType, uint32 uFromID, uint32 uToID, EHurtResult eArg1, bool bArg2, ESkillType eArg3, EAttackType eArg4)
{
	CEntityServer* pEntityFrom = CEntityServerManager::GetEntityByID(uFromID);
	CFighterDictator* pFrom = pEntityFrom ? pEntityFrom->GetFighter() : NULL;
	CEntityServer* pEntityTo = CEntityServerManager::GetEntityByID(uToID);
	CFighterDictator* pTo = pEntityTo ? pEntityTo->GetFighter() : NULL;
	MessageEvent(eType, pFrom, pTo, eArg1, bArg2, eArg3, eArg4);
}
Пример #5
0
void DebugFrontend::OutputError(DWORD error)
{

    char buffer[1024];
    if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buffer, 1024,  NULL))
    {
        std::string message = "Error: ";
        message += buffer;
        MessageEvent(message, MessageType_Error);
    }

}
Пример #6
0
void Hud::AddMessageEvent(char* string) {
	MessageEvent message = MessageEvent();
	message.type = MESSAGEEVENT;
	strcpy(message.string,string);
	mMessageEvents.push_back(message);
	if (mMessageEvents.size() > 9) {
		mMessageEvents.erase(mMessageEvents.begin());
	}
	if (mMessageEventCounter < 3) {
		mMessageEventCounter++;
		mMessageEventTimer = 0;
	}
}
Пример #7
0
void Hud::AddChatEvent(char* name, char* string, int team, bool isdead, bool isteamonly) {
	MessageEvent message = MessageEvent();
	message.type = CHATEVENT;
	strcpy(message.chatevent.name,name);
	strcpy(message.chatevent.string,string);
	message.chatevent.team = team;
	message.chatevent.isDead = isdead;
	message.chatevent.isTeamOnly = isteamonly;
	mMessageEvents.push_back(message);
	if (mMessageEvents.size() > 9) {
		mMessageEvents.erase(mMessageEvents.begin());
	}
	if (mMessageEventCounter < 3) {
		mMessageEventCounter++;
		mMessageEventTimer = 0;
	}
}
Пример #8
0
bool DebugFrontend::Attach(unsigned int processId, const char* symbolsDirectory)
{

    m_processId = processId;
    m_process   = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);

    if (m_process == NULL)
    {
        MessageEvent("Error: The process could not be opened", MessageType_Error);
        m_processId = 0;
        return false;
    }
    
    if (!InitializeBackend(symbolsDirectory))
    {
        CloseHandle(m_process);
        m_process   = NULL;
        m_processId = 0;
        return false;
    }

    return true;

}
Пример #9
0
bool DebugFrontend::Start(const char* command, const char* commandArguments, const char* currentDirectory, const char* symbolsDirectory, bool debug, bool startBroken)
{

    Stop(false);

    STARTUPINFO startUpInfo = { 0 };
    startUpInfo.cb = sizeof(startUpInfo);

    char commandLine[8191];
    _snprintf(commandLine, sizeof(commandLine), "\"%s\" %s", command, commandArguments);

    // If no directory was specified, then use the directory from the exe.
    
    std::string directory = TrimSpaces(currentDirectory);

    if (directory.empty())
    {
        directory = GetDirectory(command);
    }

    PROCESS_INFORMATION processInfo;

    if (debug)
    {
        if (!StartProcessAndRunToEntry(command, commandLine, directory.c_str(), processInfo))
        {
            return false;
        }
    }
    else
    {

        if (!CreateProcess(NULL, commandLine, NULL, NULL, TRUE, 0, NULL, directory.c_str(), &startUpInfo, &processInfo))
        {
            OutputError(GetLastError());
            return false;
        }

        // We're not debugging, so no need to proceed.
        CloseHandle(processInfo.hThread);
        CloseHandle(processInfo.hProcess);
        return true;
    
    }

    DWORD exitCode;

    if (GetExitCodeProcess(processInfo.hProcess, &exitCode) && exitCode != STILL_ACTIVE)
    {
        MessageEvent("The process has terminated unexpectedly", MessageType_Error);
        return false;
    }

    m_process   = processInfo.hProcess;
    m_processId = processInfo.dwProcessId;

    if (!InitializeBackend(symbolsDirectory))
    {
        Stop(true);
        return false;
    }

    if (startBroken)
    {
        Break(0);
    }

    // Now that our initialization is complete, let the process run.
    ResumeThread(processInfo.hThread);
    CloseHandle(processInfo.hThread);

    return true;

}
Пример #10
0
bool DebugFrontend::StartProcessAndRunToEntry(LPCSTR exeFileName, LPSTR commandLine, LPCSTR directory, PROCESS_INFORMATION& processInfo)
{

    STARTUPINFO startUpInfo = { 0 };
    startUpInfo.cb = sizeof(startUpInfo);

    ExeInfo info;
    if (!GetExeInfo(exeFileName, info) || info.entryPoint == 0)
    {
        MessageEvent("Error: The entry point for the application could not be located", MessageType_Error);
        return false;
    }

    if (!info.i386)
    {
        MessageEvent("Error: Debugging 64-bit applications is not supported", MessageType_Error);
        return false;
    }

    DWORD flags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;

    if (!CreateProcess(NULL, commandLine, NULL, NULL, TRUE, flags, NULL, directory, &startUpInfo, &processInfo))
    {
        OutputError(GetLastError());
        return false;
    }

    // Running to the entry point currently doesn't work for managed applications, so
    // just start it up.

    if (!info.managed)
    {

        unsigned long entryPoint = info.entryPoint;

        BYTE breakPointData;
        bool done = false;
        
        while (!done)
        {

            DEBUG_EVENT debugEvent;
            WaitForDebugEvent(&debugEvent, INFINITE);

            DWORD continueStatus = DBG_EXCEPTION_NOT_HANDLED;

            if (debugEvent.dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
            {
                if (debugEvent.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_SINGLE_STEP ||
                    debugEvent.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT)
                {

                    CONTEXT context;
                    context.ContextFlags = CONTEXT_FULL;

                    GetThreadContext(processInfo.hThread, &context);

                    if (context.Eip == entryPoint + 1)
                    {

                        // Restore the original code bytes.
                        SetBreakpoint(processInfo.hProcess, (LPVOID)entryPoint, false, &breakPointData);
                        done = true;

                        // Backup the instruction pointer so that we execute the original instruction.
                        --context.Eip;
                        SetThreadContext(processInfo.hThread, &context);

                        // Suspend the thread before we continue the debug event so that the program
                        // doesn't continue to run.
                        SuspendThread(processInfo.hThread);

                    }

                    continueStatus = DBG_CONTINUE;

                }
            }
            else if (debugEvent.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT)
            {
                done = true;
            }
            else if (debugEvent.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT)
            {
            
                // Offset the entry point by the load address of the process.
                entryPoint += reinterpret_cast<size_t>(debugEvent.u.CreateProcessInfo.lpBaseOfImage);

                // Write a break point at the entry point of the application so that we
                // will stop when we reach that point.
                SetBreakpoint(processInfo.hProcess, reinterpret_cast<void*>(entryPoint), true, &breakPointData);

                CloseHandle(debugEvent.u.CreateProcessInfo.hFile);

            }
            else if (debugEvent.dwDebugEventCode == LOAD_DLL_DEBUG_EVENT)
            {
                CloseHandle(debugEvent.u.LoadDll.hFile);
            }

            ContinueDebugEvent(debugEvent.dwProcessId, debugEvent.dwThreadId, continueStatus);
        
        }

    }

    DebugActiveProcessStop(processInfo.dwProcessId);
    return true;

}