Hardware Breakpoints



  • Hi,

    #include <iostream>
    #include <Windows.h>
    using namespace std;
    
    void Function1(){// EIP änderung wird ignoriert, eip kommt wieder auf Function1 und breakt erneut
    }
    
    void Function2(){
    }
    
    void Detoured(){
      cout << "Detoured\n";
    }
    
    LONG WINAPI MyUnhandlerExceptionFilter(EXCEPTION_POINTERS* pExceptionInfo)
    {
    	if(pExceptionInfo->ExceptionRecord->ExceptionCode!=EXCEPTION_SINGLE_STEP)
    	{
    		return EXCEPTION_CONTINUE_SEARCH;
     	}
    
    	if(pExceptionInfo->ExceptionRecord->ExceptionAddress==Function1)
    	{
        cout << "Broken at f1";
        pExceptionInfo->ContextRecord->Eip=reinterpret_cast<unsigned long>(Detoured);
    		return EXCEPTION_CONTINUE_EXECUTION;
    	}
    
    	return EXCEPTION_CONTINUE_SEARCH;
    }
    
    int main(int argc, char* argv[])
    {
    
      PVOID pHandler = AddVectoredExceptionHandler(0xDEADBEEF,MyUnhandlerExceptionFilter);
    
    	CONTEXT Context;
    	Context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
    	GetThreadContext(GetCurrentThread(), &Context);
    	Context.Dr0=reinterpret_cast<DWORD>(Function1);
    	Context.Dr1=reinterpret_cast<DWORD>(Function2);
    	Context.Dr7=(1<<0)|(1<<2);
    	SetThreadContext(GetCurrentThread(), &Context);
    
      Function1();
      Function2();
    
      return 0;
    }
    //---------------------------------------------------------------------------
    

    fährt ürgentwie in ne schleife, aber ich versteh nicht ganz wieso



  • Contex.Dr7 = (1<<0)|(1<<2);
    

    du hast bloß 2 Breakpoints gesetzt und nicht 4.
    Ob das allerdings dein Problem löst weiß ich nicht.

    greetz KN4CK3R



  • nicht direkt 🙂

    --edit: er scheint die eip änderungen komplett zu ignorieren und immer wieder an der gleichen stelle zu "breaken"



  • Wie machen hier weiter... es ist (komischerweise) genau das gleiche Thema... hab Ihr was miteinander zu tun?
    http://www.c-plusplus.net/forum/viewtopic-var-p-is-1825538.html#1825538


Anmelden zum Antworten