コード例 #1
0
ファイル: heap_tracer.py プロジェクト: jkrshnmenon/PIN
    rtn = pin.RTN_FindByName(img, 'memcpy')
    if pin.RTN_Valid(rtn):
        pin.RTN_Open(rtn)
        pin.RTN_InsertCall(pin.IPOINT_BEFORE, 'memcpy', rtn, 1, memcpy)
        pin.RTN_Close(rtn)


def exiting():
    f.close()
    print "In use chunks"
    if len(in_use.keys()) < 1:
        print "\n[+]Empty list"
    else:
        for keys in in_use.keys():
            print "{} : {}".format(hex(keys), in_use[keys])
    print "Freed chunks"
    if len(free_list.keys()) < 1:
        print "\n[+]Empty list"
    else:
        for keys in free_list.keys():
            print "{} : {}".format(hex(keys), free_list[keys])


if __name__ == "__main__":
    try:
        pin.IMG_AddInstrumentFunction(img_handler)
        pin.AddFiniFunction(exiting)
    except KeyboardInterrupt:
        exiting()
コード例 #2
0
    if pin.INS_IsMemoryWrite(ins):
        pin.INS_InsertCall(pin.IPOINT_BEFORE, ins, handle_write)

def image_load(img):
    rtn = pin.RTN_FindByName(img, "realloc")
    if pin.RTN_Valid(rtn):
        pin.RTN_Open(rtn)
        pin.RTN_InsertCall(pin.IPOINT_BEFORE, "realloc", rtn, 3, realloc_before)
        pin.RTN_InsertCall(pin.IPOINT_AFTER, "realloc", rtn, 3, realloc_after)
        pin.RTN_Close(rtn)

    rtn = pin.RTN_FindByName(img, "malloc")
    if pin.RTN_Valid(rtn):
        pin.RTN_Open(rtn)
        pin.RTN_InsertCall(pin.IPOINT_BEFORE, "malloc", rtn, 1, malloc_before)
        pin.RTN_InsertCall(pin.IPOINT_AFTER, "malloc", rtn, 1, malloc_after)
        pin.RTN_Close(rtn)

    rtn = pin.RTN_FindByName(img, "free")
    if pin.RTN_Valid(rtn):
        pin.RTN_Open(rtn)
        pin.RTN_InsertCall(pin.IPOINT_BEFORE, "free", rtn, 1, free)
        pin.RTN_Close(rtn)

def exiting():
    global allocations

pin.IMG_AddInstrumentFunction(image_load)
pin.INS_AddInstrumentFunction(ins_test)
pin.AddFiniFunction(exiting)
コード例 #3
0
import pin


def load(img):
    if pin.IMG_IsMainExecutable(img):
        print "Main executable loaded %s at %s" % (
            pin.IMG_Name(img), hex(pin.IMG_StartAddress(img)))
    else:
        print "Loaded %s at %s" % (pin.IMG_Name(img),
                                   hex(pin.IMG_StartAddress(img)))

    img_type = pin.IMG_Type(img)
    if img_type == pin.IMG_TYPE_STATIC:
        print "IMG_TYPE_STATIC"
    elif img_type == pin.IMG_TYPE_SHARED:
        print "IMG_TYPE_SHARED"
    elif img_type == pin.IMG_TYPE_SHAREDLIB:
        print "IMG_TYPE_SHAREDLIB"
    elif img_type == pin.IMG_TYPE_RELOCATABLE:
        print "IMG_TYPE_RELOCATABLE"
    else:
        print "unknown type"


def unload(img):
    print "Unloaded %s" % (pin.IMG_Name(img))


pin.IMG_AddInstrumentFunction(load)
pin.IMG_AddUnloadFunction(unload)