pintool 간단한 문제 풀이
Pintool은 인텔에서 만든, 동적으로 바이너리를 삽입 할 수 있게 하는 DBI 프로그램입니다.
https://software.intel.com/en-us/articles/pin-a-dynamic-binary-instrumentation-tool 에서 다운받을수있고, 메뉴얼를 보거나 핀툴안에 있는 메뉴얼예제를 보면서 공부하면 됩니다.
핀툴 실행방법
./pin.sh -t [핀툴.so] -- [프로그램]
간단한 핀툴문제.
출제자 - jinmo123
내용을 보면, 입력을 하고 해당입력된 값이 저 if문의 조건에 다 맞아야 풀리는 문제이다.
이거를 손수 손으로 할수는 있긴하지만, if문의 양이 한 어마어마 하게 많다.
그러므로 핀툴을 사용하면 쉽게 풀수있다.
핀툴을 이용하여 저기 있는 xor,cmp에 있는 오퍼랜드를 긁어와서 둘이 xor 해주면 된다.
잘보면, xor을 안하고 cmp을 하는 경우가 있기 때문에,
xor,cmp의 오퍼랜드를 서로 xor 하고 나서는 긁어온 xor를 저장하는 변수는 꼭 0으로 초기화 해줘야 된다.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <iostream> #include <fstream> #include <pin.H> #define start 0x08048310 #define end 0x08048F20 using namespace std; int result_xor,result_cmp; void y0ubat(INS ins,void* v) { char result; ADDRINT address = INS_Address(ins); if( address >= start && address <= end) { switch(INS_Opcode(ins)) { case XED_ICLASS_XOR: result_xor = INS_OperandImmediate(ins,1); break; case XED_ICLASS_CMP: result_cmp = INS_OperandImmediate(ins,1); result = result_cmp^result_xor; cout << result << endl; result_xor = 0; break; } INS_Delete(ins); } } int main(int argc,char *argv[]) { if(PIN_Init(argc,argv)) return -1; INS_AddInstrumentFunction(y0ubat,0); PIN_StartProgram(); return 0; } | cs |
https://software.intel.com/sites/landingpage/pintool/docs/71313/Pin/html/modules.html
여기 메뉴얼을 보면 영어로 설명 되어 있다. 간략하게 1줄,2줄로 설명 되어 있어서, 영어를 잘못해두 뭘 하는 함수인지 알수있다.
INS_Address(ins) - 현재 인트럭션의 주소를 가져 옵니다.
INS_Opcode(ins) - 현재 인트력션의 오피코드를 가져옵니다.
INS_OperandImmediate(ins,n) - 현재 인트럭션의 n번째 오퍼랜드를 가져옵니다.