/****************************************************************** * module_get_debug * * get the debug information from a module: * - if the module's type is deferred, then force loading of debug info (and return * the module itself) * - if the module has no debug info and has an ELF container, then return the ELF * container (and also force the ELF container's debug info loading if deferred) * - otherwise return the module itself if it has some debug info */ BOOL module_get_debug(struct module_pair* pair) { IMAGEHLP_DEFERRED_SYMBOL_LOADW64 idslW64; if (!pair->requested) return FALSE; /* for a PE builtin, always get info from container */ if (!(pair->effective = module_get_container(pair->pcs, pair->requested))) pair->effective = pair->requested; /* if deferred, force loading */ if (pair->effective->module.SymType == SymDeferred) { BOOL ret; if (pair->effective->is_virtual) ret = FALSE; else switch (pair->effective->type) { #ifndef DBGHELP_STATIC_LIB case DMT_ELF: ret = elf_load_debug_info(pair->effective); break; #endif case DMT_PE: idslW64.SizeOfStruct = sizeof(idslW64); idslW64.BaseOfImage = pair->effective->module.BaseOfImage; idslW64.CheckSum = pair->effective->module.CheckSum; idslW64.TimeDateStamp = pair->effective->module.TimeDateStamp; memcpy(idslW64.FileName, pair->effective->module.ImageName, sizeof(pair->effective->module.ImageName)); idslW64.Reparse = FALSE; idslW64.hFile = INVALID_HANDLE_VALUE; pcs_callback(pair->pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idslW64); ret = pe_load_debug_info(pair->pcs, pair->effective); pcs_callback(pair->pcs, ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE, &idslW64); break; #ifndef DBGHELP_STATIC_LIB case DMT_MACHO: ret = macho_load_debug_info(pair->effective); break; #endif default: ret = FALSE; break; } if (!ret) pair->effective->module.SymType = SymNone; assert(pair->effective->module.SymType != SymDeferred); pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts; } return pair->effective->module.SymType != SymNone; }
/****************************************************************** * module_get_debug * * get the debug information from a module: * - if the module's type is deferred, then force loading of debug info (and return * the module itself) * - if the module has no debug info and has an ELF container, then return the ELF * container (and also force the ELF container's debug info loading if deferred) * - otherwise return the module itself if it has some debug info */ BOOL module_get_debug(const struct process* pcs, struct module_pair* pair) { IMAGEHLP_DEFERRED_SYMBOL_LOAD64 idsl64; if (!pair->requested) return FALSE; /* for a PE builtin, always get info from container */ if (!(pair->effective = module_get_container(pcs, pair->requested))) pair->effective = pair->requested; /* if deferred, force loading */ if (pair->effective->module.SymType == SymDeferred) { BOOL ret; if (pair->effective->is_virtual) ret = FALSE; else switch (pair->effective->type) { case DMT_ELF: ret = elf_load_debug_info(pair->effective, NULL); break; case DMT_PE: idsl64.SizeOfStruct = sizeof(idsl64); idsl64.BaseOfImage = pair->effective->module.BaseOfImage; idsl64.CheckSum = pair->effective->module.CheckSum; idsl64.TimeDateStamp = pair->effective->module.TimeDateStamp; strcpy(idsl64.FileName, pair->effective->module.ImageName); idsl64.Reparse = FALSE; idsl64.hFile = INVALID_HANDLE_VALUE; pcs_callback(pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idsl64); ret = pe_load_debug_info(pcs, pair->effective); pcs_callback(pcs, ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE, &idsl64); break; default: ret = FALSE; break; } if (!ret) pair->effective->module.SymType = SymNone; assert(pair->effective->module.SymType != SymDeferred); module_compute_num_syms(pair->effective); } return pair->effective->module.SymType != SymNone; }