一、 简介
Pin is a dynamic binary instrumentation framework for the IA-32 and x86-64 instruction-set architectures thatenables the creation of dynamic program analysis tools.Some tools built with Pin are Intel Parallel Inspector, Intel ParallelAmplifier and Intel Parallel Advisor. The tools created using Pin,called Pintools, can be used to perform program analysis on user spaceapplications inLinux and Windows. As a dynamic binary instrumentation tool, instrumentation isperformed at run time on the compiled binary files. Thus, it requires norecompiling of source code and can support instrumenting programs thatdynamically generate code.
Pin provides a rich API that abstracts away the underlyinginstruction-set idiosyncrasies and allows context information such as registercontents to be passed to the injected code as parameters. Pin automaticallysaves and restores the registers that are overwritten by the injected code sothe application continues to work. Limited access to symbol and debug informationis available as well.
Pin was originally created as a tool for computer architectureanalysis, but its flexible API and an active community (called"Pinheads") havecreated a diverse set oftools for security, emulation and parallel program analysis.
Pin is proprietary software developed and supported by Intel and issuppliedfree of charge for non-commercial use.Pin includes thesource code for a large number ofexample instrumentation tools like basic block profilers, cachesimulators, instruction trace generators, etc. It is easy to derive new toolsusing the examples as a template.
Pin is a tool for the instrumentation ofprograms. It supports the Android*,Linux*, OSX* and Windows* operatingsystems and executables for the IA-32, Intel(R) 64 architectures.
Pin allows a tool to insert arbitrary code(written in C or C++) in arbitrary places in the executable. The code is addeddynamically while the executable is running. This also makes it possible toattach Pin to an already running process.
consists of two components:
1. A mechanismthat decides where and what code is inserted
2. The code toexecute at insertion points
These twocomponents are instrumentation and analysis code. Both components live in asingle executable, a Pintool. Pintools can be thought of as plugins that canmodify the code generation process inside Pin.
ThePintool registers instrumentation callback routines with Pin that are calledfrom Pin whenever new code needs to be generated. This instrumentation callbackroutine represents the instrumentation component. It inspects the code to begenerated, investigates its static properties, and decides if and where toinject calls to analysis functions.
Theanalysis function gathers data about the application. Pin makes sure that theinteger and floating point register state is saved and restored as necessaryand allow arguments to be passed to the functions.
The Pintool can also register notification callbackroutines for events such as thread creation or forking. These callbacks are generallyused to gather data or tool initialization or clean up.
l Pin and the Pintool control a program startingwith the very first instruction. For executables compiled with shared librariesthis implies that the execution of the dynamic loader and all shared librarieswill be visible to the Pintool.
二、 体系结构