예제 #1
0
DbgHelp::~DbgHelp()
{
  try
  {
    boost::mutex::scoped_lock lock(mInstanceMutex);

    // Unload all modules loades to free memory
    if (!SymEnumerateModules64(unloadModule, this))
    {
      std::cerr << "~DbgHelp(), SymEnumerateModules64 failed, GetLastError = " <<  GetLastError();

    }

    // Let dbgHelp release resources
    if(!SymCleanup())
    {
      std::cerr << "~DbgHelp(), SymCleanup failed, GetLastError = " <<  GetLastError();
    }

    // Unload dbgHelp.dll
    ::FreeLibrary(mDbgHelp);
  }
  catch(...)
  {
    // better safe than sorry...
  }
}
예제 #2
0
const bool Symbols::EnumerateAllModulesWithSymbols()
{
    const bool bSuccess = BOOLIFY(SymEnumerateModules64(m_hProcess, SymEnumCallback, this));
    if (!bSuccess)
    {
        fprintf(stderr, "Could not enumerate symbols. Error = %X.\n",
            GetLastError());
    }

    return bSuccess;
}
예제 #3
0
prmap_t *Plmid_to_map(struct ps_prochandle *P, Lmid_t ignored, const char *cname)
{
    struct lmid_map_uc uc;

    uc.name = cname;
    uc.map = NULL;

    if ((SymEnumerateModules64(P->phandle, MyEnumerateModulesProc2, &uc) == FALSE)) {
        dprintf("SymEnumerateModules64 failed (%d): %x\n", P->pid, GetLastError());
    }

    return uc.map;
}
예제 #4
0
int Pobject_iter(struct ps_prochandle *P, proc_map_f *func, void *cd)
{
    struct object_iter_uc uc;

    uc.f = func;
    uc.cd = cd;
    uc.proc = P;

    if ((SymEnumerateModules64(P->phandle, MyEnumerateModulesProc1, &uc)) == FALSE) {
        dprintf("Pobject_iter: SymEnumerateModules64 failed %d: %d\n",
                P->pid, GetLastError());
        return -1;
    }

    return 0;
}
예제 #5
0
BOOL dbg_get_debuggee_info(HANDLE hProcess, IMAGEHLP_MODULE64* imh_mod)
{
    struct mod_loader_info  mli;
    DWORD                   opt;

    /* this will resynchronize builtin dbghelp's internal ELF module list */
    SymLoadModule(hProcess, 0, 0, 0, 0, 0);
    mli.handle  = hProcess;
    mli.imh_mod = imh_mod;
    imh_mod->SizeOfStruct = sizeof(*imh_mod);
    imh_mod->BaseOfImage = 0;
    /* this is a wine specific options to return also ELF modules in the
     * enumeration
     */
    SymSetOptions((opt = SymGetOptions()) | 0x40000000);
    SymEnumerateModules64(hProcess, mod_loader_cb, (void*)&mli);
    SymSetOptions(opt);

    return imh_mod->BaseOfImage != 0;
}
예제 #6
0
int dbg_help_client_t::init(char* path) {
    DWORD64 dwBaseAddr=0;

    int chars;
    char exe_path[MAX_PATH];
    chars = GetModuleFileName(NULL, exe_path, MAX_PATH);
    if (chars == 0) { 
        fprintf(stderr,"Could not find base path for XED executable\n");
        fflush(stderr);
        exit(1);
    }
    //fprintf(stderr,"EXE PATH %s\n", exe_path);
    char* dir = find_base_path(exe_path);
    //fprintf(stderr,"DIR      %s\n", dir);

    char* dbghelp = append3(dir,"\\","dbghelp.dll");
    //fprintf(stderr,"DBGHLP   %s\n", dbghelp);

    if (_access_s(dbghelp,4) != 0) {
        //fprintf(stderr,
        //    "WARNING: Could not find dbghelp.dll in xed.exe directory\n");
        //fflush(stderr);
        return 0;
    }    
    //fprintf(stderr,"FOUND DBGHELP\n");

    if (validate_version(dbghelp)) {
        fprintf(stderr,
            "WARNING: dbghelp.dll version is too old\n");
        fflush(stderr);
        return 0;
    }


    //FIXME: Add a version check for the dll ( ImagehlpApiVersion is NOT
    //the right thing)
        
    SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
    hProcess = GetCurrentProcess();
    
    if (SymInitialize(hProcess, NULL, FALSE))     {
        // nothing
    }
    else    {
        error = GetLastError();
        fprintf(stderr,"SymInitialize returned error : %d 0x%x\n",
                error, error);
        fflush(stderr);
        return 0;
    }


    actual_base = SymLoadModuleEx(hProcess, NULL, path, NULL, 
                                  dwBaseAddr, 0, NULL, 0);
    if (actual_base) {
        // nothing
    }
    else    {
        error = GetLastError();
        fprintf(stderr,"SymLoadModuleEx returned error : %d 0x%x\n", 
                error, error);
        fflush(stderr);
        return 0;
    }


    if (SymEnumerateModules64(hProcess, 
                        (PSYM_ENUMMODULES_CALLBACK64)enum_modules, this)) {
        // nothing
    }
    else    {
        error = GetLastError();
        fprintf(stderr,"SymEnumerateModules64 returned error : %d 0x%x\n",
               error, error);
        fflush(stderr);
        return 0;
    }

    if (SymEnumSymbols(hProcess, actual_base, 0, enum_sym, this))    {
        // nothing
    }
    else    {
        error = GetLastError();
        fprintf(stderr,"SymEnumSymbols failed: %d 0x%x\n", error, error);
        fflush(stderr);
        return 0;
    }

    make_symbol_vector(&sym_tab);
    initialized = true;
    return 1;
}