Intel Pin cannot detect memcmp or strcmp

86 Views Asked by At

I am trying to write a pintool that analyzes the return values of memcmp and strcmp in applications. First I wrote a routine trace pintool that lists all of the routines that are executed. My sample code is very simple and just uses memcmp to compare a fixed string to a user-supplied string. However, I noticed that my pintool never reports memcmp. I also tried for strcmp and had the same problem.

Here is where things get weird. As a sanity check, I wrote another pintool that supposedly prints every routine in every image, even those that are not executed. Here is the code for the Image instrumentation:

VOID Image(IMG img, VOID* v)
{
    const char* img_name = IMG_Name(img).c_str();

    for(SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec))
    {
        const char* sec_name = SEC_Name(sec).c_str();

        for(RTN rtn = SEC_RtnHead(sec); RTN_Valid(rtn); rtn = RTN_Next(rtn))
        {
            const char* rtn_name = RTN_Name(rtn).c_str();
            
            printf("%s -- %s -- %s\n", img_name, sec_name, rtn_name);
        }
    }
}

This prints out lots of routines like stat, mkdir, memcpy, etc...but no memcmp or strcmp! Does anybody know what is going on here?

1

There are 1 best solutions below

1
On BEST ANSWER

You should initialize pintools with IFUNC_SYMBOLS (see from the documentation SYMBOL_INFO_MODE) :

Using your code with :

int main(INT32 argc, CHAR* argv[])
{
    if (PIN_Init(argc, argv)) return 0;
    PIN_InitSymbolsAlt(SYMBOL_INFO_MODE(UINT32(IFUNC_SYMBOLS) | UINT32(DEBUG_OR_EXPORT_SYMBOLS)));
    IMG_AddInstrumentFunction(Image, 0);
    PIN_StartProgram();    
    return 0;
}

print memcmp & strcmp