Skip to content

Instantly share code, notes, and snippets.

@realoriginal
Created September 28, 2025 00:55
Show Gist options
  • Select an option

  • Save realoriginal/8131707a68de4f3fe0e85e82fa899408 to your computer and use it in GitHub Desktop.

Select an option

Save realoriginal/8131707a68de4f3fe0e85e82fa899408 to your computer and use it in GitHub Desktop.
Updated IntelPIN with some fixes for the newer versions of PIN. Original from https://gist.github.com/mrexodia/f61fead0108603d04b2ca0ab045e0952
# Website: https://software.intel.com/content/www/us/en/develop/articles/pin-a-binary-instrumentation-tool-downloads.html
# License: https://software.intel.com/sites/landingpage/pintool/pinlicense.txt
# This snippet: https://gist.github.com/mrexodia/f61fead0108603d04b2ca0ab045e0952
# TODO: lunix support
# Thanks to Francesco for showing me this method
CPMAddPackage(
NAME IntelPIN
VERSION 3.31
URL https://software.intel.com/sites/landingpage/pintool/downloads/pin-external-3.31-98869-gfa6f126a8-msvc-windows.zip
DOWNLOAD_ONLY ON
)
if(IntelPIN_ADDED)
# Automatically detect the subfolder in the zip
file(GLOB PIN_DIR LIST_DIRECTORIES true ${IntelPIN_SOURCE_DIR})
# Loosely based on ${PIN_DIR}/source/tools/Config/makefile.win.config
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PIN_EXE "${PIN_DIR}/intel64/bin/pin${CMAKE_EXECUTABLE_SUFFIX}")
else()
set(PIN_EXE "${PIN_DIR}/ia32/bin/pin${CMAKE_EXECUTABLE_SUFFIX}")
endif()
string(REGEX REPLACE "/" "\\\\" PIN_EXE ${PIN_EXE})
add_library(IntelPIN INTERFACE)
target_include_directories(IntelPIN INTERFACE
${PIN_DIR}/source/include/pin
${PIN_DIR}/source/include/pin/gen
${PIN_DIR}/extras/components/include
${PIN_DIR}/extras/stlport/include
${PIN_DIR}/extras
${PIN_DIR}/extras/libstdc++/include
${PIN_DIR}/extras/crt/include
${PIN_DIR}/extras/crt
${PIN_DIR}/extras/crt/include/kernel/uapi
${PIN_DIR}/extras/crt/include/kernel/uapi/asm-x86
)
target_link_libraries(IntelPIN INTERFACE
pin
xed
pinipc
pincrt
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
target_link_options(IntelPIN INTERFACE /NODEFAULTLIB /EXPORT:main /BASE:0xC5000000 /ENTRY:Ptrace_DllMainCRTStartup /IGNORE:4210 /IGNORE:4281)
else()
target_link_options(IntelPIN INTERFACE /NODEFAULTLIB /EXPORT:main /BASE:0x55000000 /ENTRY:Ptrace_DllMainCRTStartup@12 /IGNORE:4210 /IGNORE:4281 /SAFESEH:NO)
endif()
target_compile_options(IntelPIN INTERFACE /GR- /GS- /EHs- /EHa- /fp:strict /Oi- /FIinclude/msvc_compat.h /wd5208)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
target_include_directories(IntelPIN INTERFACE
${PIN_DIR}/extras/xed-intel64/include/xed
${PIN_DIR}/extras/crt/include/arch-x86_64
)
target_link_directories(IntelPIN INTERFACE
${PIN_DIR}/intel64/lib
${PIN_DIR}/intel64/runtime/pincrt
${PIN_DIR}/extras/xed-intel64/lib
)
target_compile_definitions(IntelPIN INTERFACE
TARGET_IA32E
HOST_IA32E
TARGET_WINDOWS
__PIN__=1
PIN_CRT=1
__LP64__
_WINDOWS_H_PATH_=../um # dirty hack
)
target_link_libraries(IntelPIN INTERFACE
ntdll
kernel32
${PIN_DIR}/intel64/runtime/pincrt/crtbeginS.obj
)
else()
target_include_directories(IntelPIN INTERFACE
${PIN_DIR}/extras/xed-ia32/include/xed
${PIN_DIR}/extras/crt/include/arch-x86
)
target_link_directories(IntelPIN INTERFACE
${PIN_DIR}/ia32/lib
${PIN_DIR}/ia32/runtime/pincrt
${PIN_DIR}/extras/xed-ia32/lib
)
target_compile_definitions(IntelPIN INTERFACE
TARGET_IA32
HOST_IA32
TARGET_WINDOWS
__PIN__=1
PIN_CRT=1
__i386__
_WINDOWS_H_PATH_=../um # dirty hack
)
target_link_libraries(IntelPIN INTERFACE
ntdll
kernel32
${PIN_DIR}/ia32/runtime/pincrt/crtbeginS.obj
)
endif()
# Create a static library InstLib that is used in a lot of example pintools
file(GLOB InstLib_SOURCES
"${PIN_DIR}/source/tools/InstLib/*.cpp"
"${PIN_DIR}/source/tools/InstLib/*.H"
)
add_library(InstLib STATIC EXCLUDE_FROM_ALL ${InstLib_SOURCES})
target_include_directories(InstLib PUBLIC "${PIN_DIR}/source/tools/InstLib")
target_link_libraries(InstLib PUBLIC IntelPIN)
function(add_pintool target)
add_library(${target} SHARED ${ARGN})
target_link_libraries(${target} PRIVATE IntelPIN)
endfunction()
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment