Be myself :: Pin 기본 API살펴보기

달력

42024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

메뉴얼을 참고하면 처음 다음과 같은 말이 있다.


Conceptually, instrumentation consists of two components:

  • A mechanism that decides where and what code is inserted(instrumentation)

  • The code to execute at insertion points(analysis code)

즉 어디서 code 를 삽입할지 결정하는 메커니즘( 크게 4가지 메커니즘이 존재한다)과 그 code를 정의하는 부분이 필요하다.

위의 4가지 메커니즘을 보면 다음과 같다.

  • Trace Instrumentation: pintool processes one trace at a time by starting from the current instruction and ending with an unconditional branch (including calls and returns), which can be completed by using the TRACE_AddInstrumentFunction API call.
  • Instruction Instrumentation: pintool processes one instruction at a time, which can be completed by using the INS_AddInstrumentFunction API call.
  • Image Instrumentation: pintool processes an entire image where Pin can iterate over program sections, routines in a section or instructions in a routine. You can insert additional instructions before/after the routine is executed or before/after an instruction is executed. Here you have to use IMG_AddInstrumentFunction API call.
  • Routine Instrumentation: pintool processes one routine where Pin can iterate over instructions of a routine. Additional instructions can be inserted before/after routine execution or before/after instruction execution. Here you have to use RTN_AddInstrumentFunction API call.

  • There are a couple of callback functions that you can use with the pin framework and are presented below:

    • TRACE_AddInstrumentFunction: directly corresponds with the Trace Instrumentation Mode
    • INC_AddInstrumentFunction: directly corresponds with the Instruction Instrumentation Mode
    • IMG_AddInstrumentFunction: directly corresponds with the Image Instrumentation Mode
    • RTN_AddInstrumentFunction: directly corresponds with the Routine Instrumentation Mode
    • PIN_AddFiniFunction
    • PIN_AddDetachFunction
    (출처: http://resources.infosecinstitute.com/pin-dynamic-binary-instrumentation-framework/)

각각 부분을 간략히 설명하겠다.

1. TRACE부분은 BBL(Basic block: a single entrace, single exit sequence of instructions) 의 상위 개념인데 BBL은 간단하게 생각해서 어떤 분기문( if, goto ,call 등)에 의해 프로그램의 흐름이 바뀌었을 때 그 한 단락을 의미하고 TRACE는 처음 시작부분에서 끝날때 까지의 BBL 들의 연속된 리스트라고 생각하면 된다. 그림으로 보면 다음과 같다.





2. INS 같은 경우는 말 그대로 한 instruction에 대해 검사하는 것이다.


3. IMG 는 한 이미지가 로딩됬을때 호출되는 callback 함수로, 각종 라이브러리등이 로드될 때 호출된다.


4. RTN은 루틴단위로 호출된다.(하나의 함수단위로 호출된다고 생각하면 쉽다.)


따라서 위의 4개의 callback 함수로 어디서 code를 삽입할지 결정했다면, BBL_InsertCall이나 INS_InserCall, RTN_InsertCall 등으로 본인이 수행하고자 하는 코드를 등록하면 된다.

각각 예제가 궁금하신 분들은 메뉴얼 페이지에 잘 나와있으니 살펴보시라.

메뉴얼 페이지 : 메뉴얼

'Analysis' 카테고리의 다른 글

PinTool을 이용한 Instruction 추적하기, 간단한 ctf 풀이  (0) 2016.01.30
[smt solver]z3py 튜토리얼  (0) 2015.08.06
Pin tool 기본세팅  (1) 2015.07.17
Posted by flack3r
|