Search code examples
x86instrumentationintel-pindynamic-analysis

Pin: instrument a specified shared library


I am performing some simple instrumentation task on an executable file and its related shared libraries, recording all the executed instructions in the main file as well as the shared libraries.

However, Pin always throw

Pin is out of memory: MmapChecked 

During the instrumentation. Since I am working on a 32-bit system, every time it reaches to around 3G memory consumption, the instrumentation process will crash.

I would like to work on this 32-bit system, since there are quite a lot of shared libraries on this platform. On the other hand, because actually I am only interested in one shared library, so I am thinking to find a way to only record the executed instructions inside the main executable as well as that special library.

However, I have no idea whether/how to do that. Right now before instrumentation, my setting is:

PIN_LockClient();
IMG img = IMG_FindByAddress(INS_Address(ins));
PIN_UnlockClient();

// if (IMG_Valid(img) && IMG_IsMainExecutable(img)){
if (IMG_Valid(img)) {           <--------------------- this line
    INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)insCallBack,
                   IARG_BOOL,
                   IARG_ADDRINT, INS_Address(ins),
                   IARG_PTR, new string(INS_Disassemble(ins)),
                   IARG_CONTEXT,
                   IARG_ADDRINT, INS_NextAddress(ins),
                   IARG_END);

}

As you can see, I didn't check whether I am instrumenting the main executable or not, which means I should be able to instrument all the libraries.

My test platform is 32-bit x86 Ubuntu 14.04. And the test target is 32-bit ELF binary code.

So my question is: given my situation, should I configure to only instrument my interested library in order to overcome the memory exception? If so, how can I do that?


Solution

  • Use IMG_Name to get the file name as pin sees it and compare it to the shared object of interest. InstLib provides a drop-in implementation of this but it's easy to do on your own.