| Code instrumentation is the act of modifying the code of an existing application by inserting new code statements and modifying or deleting existing ones.Code instrumentation is a powerful mechanism for understanding and modifying program behaviors. It is employed in various fields, including software design, development, testing, debugging, tracing, access control, performance evaluation, distributed computing and aspect-oriented programming. In this paper, we do research on the methods of dynamic code instrumentation in Windows system and its application on software tracing and troubleshooting. Based on Detours library provided by Microsoft Research and Dbghlp API, we present a new solution for the Win32 API tracing and implement a prototype for the solution. It can generate the trace code automatically for any specified Win32 functions without touching the source code. |