Beispiel #1
0
InstFakeKill::InstFakeKill(Cfg *Func, const VarList &KilledRegs,
                           const Inst *Linked)
    : Inst(Func, Inst::FakeKill, KilledRegs.size(), NULL), Linked(Linked) {
  for (VarList::const_iterator I = KilledRegs.begin(), E = KilledRegs.end();
       I != E; ++I) {
    Variable *Var = *I;
    addSource(Var);
  }
}
Beispiel #2
0
void DataRewriter::organizeNewBss(Region* reg, unsigned char magic) {
   /**
    *
    */

   fprintf(stderr, "BSS region starts at %p\n", reg->getRegionAddr());

   VarList globals = filterVariables(reg);

   unsigned int dataSize = 0;
   unsigned int dataBase = 0;
   unsigned int dataOffset = 0;

   unsigned int rawIndex = 0;
   unsigned int rawValue = 0;

   unsigned int newRawIndex = 0;

   dataSize = reg->getRegionSize();
   dataBase = newDataBase + newDataSize;

   fprintf(stderr, "BSS base = %p\n", (void*) dataBase);

   unsigned int newBssSize = sizeof(unsigned char) * dataSize;

   oldRawBss = (unsigned char*) reg->getPtrToRawData();
   newRawBss = (unsigned char*) malloc (newBssSize);

   memcpy(newRawBss, oldRawBss, dataSize);


   for (int i = 0; i < globals.size(); i++) {
      dataOffset = globals[i]->getOffset();
      rawIndex = dataOffset - dataBase;
      // Update the relocated address mapping
      newLocs[dataOffset] = dataBase + newRawIndex;
      newRawIndex += globals[i]->getSize();
   }

   for (AddrMapping::const_iterator iter = newLocs.begin();
         iter != newLocs.end();
         ++iter) {
      fprintf(stderr, "%p -> %p\n", iter->first, iter->second);
   }

   // Causes a segfault in the mutated binary
   // 
   //if (!reg->setPtrToRawData(newRawBss, newDataSize)) {
   //   fprintf(stderr, "Unable to assign new data section.\n");
   //   exit(EXIT_FAILURE);
   //}

}
Beispiel #3
0
void DataRewriter::organizeNewData(Region* reg, unsigned char magic) {
   /**
    *
    */
   VarList globals = filterVariables(reg);

   unsigned int dataSize = 0;
   unsigned int dataBase = 0;
   unsigned int dataOffset = 0;

   unsigned int rawIndex = 0;
   unsigned int rawValue = 0;

   unsigned int newRawIndex = 0;

   dataSize = reg->getRegionSize();
   dataBase = reg->getRegionAddr();

   newDataBase = dataBase;
   newDataSize = sizeof(unsigned char) * dataSize * 2;

   oldRaw = (unsigned char*) reg->getPtrToRawData();
   newRaw = (unsigned char*) malloc (newDataSize);

   // The dso_handle bullshit
   memcpy(newRaw, oldRaw, 4);
   memset(newRaw + 4, magic, 4);
   newRawIndex += 8;

   // Pad the new data section with an extra 4 bytes between all 4 byte values.
   for (int i = 0; i < globals.size(); i++) {
      dataOffset = globals[i]->getOffset();
      rawIndex = dataOffset - dataBase;
      memcpy(newRaw + newRawIndex, oldRaw + rawIndex, 4);
      // Sanity checks, write magic values into padding
      memset(newRaw + newRawIndex + 4, magic, 4);
      // Update the relocated address mapping
      newLocs[dataOffset] = dataBase + newRawIndex;
      newRawIndex += 8;
   }

   fprintf(stderr, "NEW DATA: %p through %p\n", newDataBase, newDataBase + newDataSize);

   if (!reg->setPtrToRawData(newRaw, newDataSize)) {
      fprintf(stderr, "Unable to assign new data section.\n");
      exit(EXIT_FAILURE);
   }

}
Beispiel #4
0
 const size_t nvars( void ) const
 {
     return( m_vars.size() );
 }