Beispiel #1
0
bool DysectAPI::CodeLocation::findSymbol(SymtabAPI::Symtab* symtab, string name, string libName, vector<DysectAPI::CodeLocation*>& symbols, bool isRegex) {
  assert(symtab != 0);

  bool exit = false;
  vector<SymtabAPI::Symbol *> symtabSymbols;
  vector<SymtabAPI::Symbol *> foundSymtabSymbols;
  set<pair<Dyninst::Address, string> > lOffsets;

  foundSymtabSymbols.clear();
  symtabSymbols.clear();

  // XXX: Include class specialization!
  if (name[0] == '~') {
    name.erase(0, 1);
    exit = true;
  }
  string symbolExpr = string(name);
  symbolExpr.append("<*>");
  //boost::regex expression(symbolExpr);

  if(!symtab->findSymbol(foundSymtabSymbols, name, SymtabAPI::Symbol::ST_FUNCTION, anyName, isRegex) && !isRegex) {

    // Try to search for template specialization
    symtab->findSymbol(foundSymtabSymbols, symbolExpr, SymtabAPI::Symbol::ST_FUNCTION, anyName, true);
  }

  if(foundSymtabSymbols.empty()) {
    //return Err::verbose(false, "No symbols found for '%s'", name.c_str());
    return false;
  }


  for(int i = 0; i < foundSymtabSymbols.size(); i++) {
    DysectAPI::CodeLocation* dsym = new DysectAPI::CodeLocation();
    dsym->libName = libName;

    SymtabAPI::Symbol* ssym = foundSymtabSymbols[i];

    string* str = new string(ssym->getPrettyName());
    Dyninst::Address offset = ssym->getOffset();
    if (exit == true) //TODO: This may not work if code optimized (i.e. MPI functions)
      offset = offset + ssym->getSize() - 1; // this is computing the exit!

    if(lOffsets.find(pair<Dyninst::Address, string> (offset, *str)) != lOffsets.end()) {
      continue;
    }
    lOffsets.insert(pair<Dyninst::Address, string> (offset, *str));

    dsym->offsets.insert(pair<Dyninst::Address, string*>(offset, str));

    symbols.push_back(dsym);
  }

  return true;
}
Beispiel #2
0
bool DysectAPI::CodeLocation::findSymbol(SymtabAPI::Symtab* symtab, string name, string libName, vector<DysectAPI::CodeLocation*>& symbols, bool isRegex) {
  assert(symtab != 0);

  vector<SymtabAPI::Symbol *> symtabSymbols;
  vector<SymtabAPI::Symbol *> foundSymtabSymbols;
  vector<Dyninst::Address> lOffsets;

  foundSymtabSymbols.clear();
  symtabSymbols.clear();

  // XXX: Include class specialization!
  string symbolExpr = string(name);
  symbolExpr.append("<*>");
  //boost::regex expression(symbolExpr);
  
  if(!symtab->findSymbol(foundSymtabSymbols, name, SymtabAPI::Symbol::ST_FUNCTION, anyName, isRegex) && !isRegex) {

    // Try to search for template specialization
    symtab->findSymbol(foundSymtabSymbols, symbolExpr, SymtabAPI::Symbol::ST_FUNCTION, anyName, true);
  }

  if(foundSymtabSymbols.empty()) {
    //return Err::verbose(false, "No symbols found for '%s'", name.c_str());
    return false;
  }


  for(int i = 0; i < foundSymtabSymbols.size(); i++) {
    DysectAPI::CodeLocation* dsym = new DysectAPI::CodeLocation();
    dsym->libName = libName;

    SymtabAPI::Symbol* ssym = foundSymtabSymbols[i];

    string* str = new string(ssym->getPrettyName());
    Dyninst::Address offset = ssym->getOffset();

    // XXX: Search for pair instead of plain offset
    if(dsym->offsets.find(offset) != dsym->offsets.end()) {
      continue;
    }

    dsym->offsets.insert(pair<Dyninst::Address, string*>(offset, str));

    symbols.push_back(dsym);
  }
  
  return true;
}
Beispiel #3
0
std::pair<bool, Address> IA_IAPI::getCFT() const
{
   if(validCFT) return cachedCFT;
    Expression::Ptr callTarget = curInsn().getControlFlowTarget();
	if (!callTarget) return make_pair(false, 0);
       // FIXME: templated bind(),dammit!
    callTarget->bind(thePC[_isrc->getArch()].get(), Result(s64, current));
    parsing_printf("%s[%d]: binding PC %s in %s to 0x%x...", FILE__, __LINE__,
                   thePC[_isrc->getArch()]->format(curInsn().getArch()).c_str(), curInsn().format().c_str(), current);

    Result actualTarget = callTarget->eval();
#if defined(os_vxworks)

    int reloc_target = current;
#if defined(arch_x86)
    ++reloc_target;
#endif

    if (actualTarget.convert<Address>() == reloc_target) {
        // We have a zero offset branch.  Consider relocation information.
        SymtabCodeRegion *scr = dynamic_cast<SymtabCodeRegion *>(_cr);
        SymtabCodeSource *scs = dynamic_cast<SymtabCodeSource *>(_obj->cs());

        if (!scr && scs) {
            set<CodeRegion *> regions;
            assert( scs->findRegions(reloc_target, regions) == 1 );
            scr = dynamic_cast<SymtabCodeRegion *>(*regions.begin());
        }

        SymtabAPI::Symbol *sym = NULL;
        if (scr) {
            std::vector<SymtabAPI::relocationEntry> relocs =
                scr->symRegion()->getRelocations();

            for (unsigned i = 0; i < relocs.size(); ++i) {
                if (relocs[i].rel_addr() == reloc_target) {
                    sym = relocs[i].getDynSym();
                    if (sym && sym->getOffset()) {
                        parsing_printf(" <reloc hit> ");
                        actualTarget = Result(s64, sym->getOffset());
                    }
                    break;
                }
            }
        }

        if (sym && sym->getOffset() == 0) {
            // VxWorks external call.
            // Need some external means to find the target.
            Address found;
            const std::string &sym_name = sym->getMangledName();
            if (wtxFindFunction(sym_name.c_str(), 0x0, found)) {
                parsing_printf(" <wtx search hit> ");
                actualTarget = Result(s64, found);

                // We've effectively found a plt call.  Update linkage table.
                _obj->cs()->linkage()[found] = sym_name;

            } else {
                parsing_printf(" <wtx fail %s> ", sym_name.c_str());
                actualTarget.defined = false;
            }
        }
    }
#endif

    if(actualTarget.defined)
    {
       cachedCFT = std::make_pair(true, actualTarget.convert<Address>());
       parsing_printf("SUCCESS (CFT=0x%x)\n", cachedCFT.second);
    }
    else
    {
       cachedCFT = std::make_pair(false, 0); 
        parsing_printf("FAIL (CFT=0x%x), callTarget exp: %s\n",
                       cachedCFT.second,callTarget->format(curInsn().getArch()).c_str());
    }
    validCFT = true;

    if(isLinkerStub()) {
        parsing_printf("Linker stub detected: Correcting CFT.  (CFT=0x%x)\n",
                       cachedCFT.second);
    }

    return cachedCFT;
}