Beispiel #1
0
int main( int argc, char *argv[] ) {

  if ( PIN_Init( argc, argv ) ) {
    return Usage();
  }
  PIN_InitSymbols();

  initRcdcSim();

  IMG_AddInstrumentFunction( instrumentImage, NULL );
  TRACE_AddInstrumentFunction( instrumentTrace, NULL );
  cerr << " Before this function\n";
  //INS_AddInstrumentFunction(Instruction, 0);
  cerr << " After this function\n";

  PIN_AddThreadStartFunction( threadBegin, NULL );
  PIN_AddThreadFiniFunction( threadEnd, NULL );

  PIN_AddContextChangeFunction( beforeSignal, NULL );
  PIN_AddSyscallEntryFunction( beforeSyscall, NULL );
  PIN_AddSyscallExitFunction( afterSyscall, NULL );

  PIN_AddFiniUnlockedFunction( pinFini, NULL );

  if ( !CODECACHE_ChangeMaxInsPerTrace( 4096 * 1024 ) ) {
    fprintf( stderr, "TLSProf::CODECACHE_ChangeMaxInsPerTrace failed.\n" );
  }

  THREADID tid = PIN_SpawnInternalThread( ioThread, NULL, 0, &s_IOThreadId );
  assert( tid != INVALID_THREADID );

  PIN_StartProgram();
  return 0;
}
int main(int argc, char **argv)
{
    PIN_Init(argc,argv);
    INS_AddInstrumentFunction(insCallback, 0);

    intTid = PIN_SpawnInternalThread(doPause, 0, 0, 0);
    ASSERT(intTid != INVALID_THREADID, "Fail to spawn internal thread");

    PIN_StartProgram();
    return 0;
}
int main(int argc, char *argv[])
{
    // Initialize PIN library. Print help message if -h(elp) is specified
    // in the command line or the command line is invalid 
    if(PIN_Init(argc,argv))
        return Usage();
    
    /// Instrumentations
    // Register function to be called to instrument traces
    TRACE_AddInstrumentFunction(trace_instrumentation, 0);

    // Register function to be called when the application exits
    PIN_AddFiniFunction(this_is_the_end, 0);
    
    // Register function to be called when a module is loaded
    IMG_AddInstrumentFunction(image_instrumentation, 0);

    /// Other stuffs
    // This routine will be called if the sleeping_thread calls PIN_Detach() (when the time is out)
    PIN_AddDetachFunction(pin_is_detached, 0);

    // Run a thread that will wait for the time out
    PIN_SpawnInternalThread(
        sleeping_thread,
        0,
        0,
        NULL
    );

    // If we are in a wow64 process we must blacklist manually the JMP FAR: stub
    // from being instrumented (each time a syscall is called, it will be instrumented for *nothing*)
    // Its address is in FS:[0xC0] on Windows 7
    ADDRINT wow64stub = __readfsdword(0xC0);
    modules_blacklisted.insert(
        std::make_pair(
            std::string("wow64stub"),
            std::make_pair(
                wow64stub,
                wow64stub
            )
        )
    );

    /// FIRE IN THE HOLE
    // Start the program, never returns
    PIN_StartProgram();
    
    return 0;
}
Beispiel #4
0
Thread::State Thread::start (size_t stack_size)
{
  // Prevent multiple threads from calling this routine at the same
  // time and causing a race condition.
  Write_Guard <RW_Mutex> guard (this->rw_mutex_);

  // Make sure the thread is not already started.
  if (this->state_ == STARTED || this->state_ == RUNNING)
    return this->state_;
  
  // We can start the thread.
  this->thr_id_ = PIN_SpawnInternalThread (&Thread::__thr_run, this, stack_size, &this->thr_uid_);
  this->state_ = this->thr_id_ != INVALID_THREADID ? STARTED : ERROR;
  
  return this->state_;
}
Beispiel #5
0
int pintoolInit()
{ 
    int returnValue = INIT_ERROR;

    // option du pintool('taint' ou 'checkscore')    
    g_option = KOption.Value();
    
    /**** OPTION TAINT ***/
    if ("taint" == g_option)
    {
        returnValue = OPTION_TAINT;

        // instanciation des classes globales : marquage mémoire et formule SMT2
        pTmgrGlobal   = new TaintManager_Global;
        g_pFormula    = new TranslateIR;
        if (!pTmgrGlobal || !g_pFormula)  return (INIT_ERROR);

        /*** RECUPERATION DES ARGUMENTS DE LA LIGNE DE COMMANDE ***/
        // 1) si pipe => ouverture, sinon récupération de l'option 'input'
        g_nopipe = KNoPipe.Value();
        if (!g_nopipe)
        {
            // erreur si pipe ne peut pas être ouvert
            if (EXIT_FAILURE == openPipe()) return (INIT_ERROR);
            // récupération de l'entrée étudiée via le pipe
            g_inputFile = readFromPipe();
            if (g_inputFile.empty()) return (INIT_ERROR);
        }
        else
        {
            // si pas de pipe, nom de l'entrée passée par ligne de commande
            g_inputFile = KInputFile.Value();    
            // l'écriture des resultats (formule SMT2) se fera dans un fichier
            // donc récupérer le handle du fichier qui sera utilisé
            std::string formulaFile(g_inputFile + "_formula.smt2");
            g_hPipe = WINDOWS::CreateFile(
                formulaFile.c_str(), // nom du fichier 
                GENERIC_WRITE, // acces en ecriture
                0,             // pas de partage 
                nullptr,       // attributs de sécurité par défaut
                CREATE_ALWAYS, // écrasement du précédent fichier, si existant
                0,             // attributs par défaut
                nullptr);	   // pas de modèle

            if ((HANDLE)(WINDOWS::LONG_PTR) (-1) == g_hPipe)  return (INIT_ERROR);
        }

        // 2) mode verbeux : création des fichiers de log
        g_verbose = KVerbose.Value();
        if (g_verbose)
        {
            // création et ouverture du fichier de log dessasemblage
            std::string logfile(g_inputFile + "_asm.log");
            g_debug.open(logfile); 

            // création et ouverture du fichier de log de marquage
            std::string taintfile(g_inputFile + "_taint.log");
            g_taint.open(taintfile);
            if (!g_taint.good() || !g_debug.good()) return (INIT_ERROR);

            // stockage de l'heure du top départ pour statistiques
            g_timeBegin = clock();
        }

        // 4) intervalles d'octets source à marquer, si option présente
        if (!KBytes.Value().empty())  pTmgrGlobal->setBytesToTaint(KBytes.Value());

        // 5) nombre maximal de contraintes ((0 si aucune)
        g_maxConstraints = KMaxConstr.Value();
        
        // 6) type d'OS hote (déterminé par le programme appelant)
        g_osType = static_cast<OSTYPE>(KOsType.Value());
        // détermination des numéros de syscalls à monitorer (dépend de l'OS)
        if (HOST_UNKNOWN == g_osType) return (INIT_ERROR);
        else SYSCALLS::defineSyscallsNumbers(g_osType);
            
        // initialisation de variable globale indiquant le départ de l'instrumentation
        // est mise à vrai par la partie syscalls lorsque les premières données
        // marquées sont créées (= lecture dans l'entrée)
        g_beginInstrumentationOfInstructions = false;

        // création des clefs pour les TLS, pas de fonction de destruction
        g_tlsKeyTaint       = PIN_CreateThreadDataKey(nullptr);
        g_tlsKeySyscallData = PIN_CreateThreadDataKey(nullptr);
    }
    else if ("checkscore" == g_option) // option....checkscore :)   
    {
        // erreur si pipe ne peut pas être ouvert
        if (EXIT_FAILURE == openPipe()) return (INIT_ERROR);
        returnValue = OPTION_CHECKSCORE;
    }
    else return (INIT_ERROR); // option inconnue : erreur

    /**** DERNIERES INITIALISATIONS COMMUNES AUX DEUX OPTIONS **/

    // Initialisation des verrous pour le multithreading
    PIN_InitLock(&g_lock);
  
    // temps maximal d'exécution (valable en 'taint' et en 'checkscore')
    g_maxTime = KMaxTime.Value();
    // si non nul, création d'un thread interne au pintool : 
    // sert à la surveillance du temps maximal d'execution 
    if (g_maxTime)
    {
        THREADID tid = PIN_SpawnInternalThread(maxTimeThread, nullptr, 0, nullptr);
        if (INVALID_THREADID == tid)   return (INIT_ERROR);  
    }

    return (returnValue); // option choisie (taint ou checkScore), ou erreur d'init
} // pintoolInit()
Beispiel #6
0
void Scheduler::startWatchdogThread() {
    PIN_SpawnInternalThread(threadTrampoline, this, 64*1024, nullptr);
}