Frida の使い方 (超基礎編)

バイナリ計装ツール (Binary instrumentation tool) の Frida について, 基礎的な使い方のお勉強

そもそもバイナリ計装とは?

Binary Instrumentation is a technique used in computer science to measure task memory access patterns, which helps predict performance degradation due to contention for CPU caches.

Frida とは

インストール

pip install frida-tools
        

用語

フッキング

プロセスへのアタッチとスクリプトのロード

frida-ps
        
frida -p $PROCESS

frida -n $NAME
        

frida-trace を用いた Windows バイナリの解析

frida-trace -n $NAME -i $API_NAME
        
frida-trace -f $NAME -i $API_NAME
        

handlers の編集

/*
 * Auto-generated by Frida. Please modify to match the signature of Sleep.
 * This stub is currently auto-generated from manpages when available.
 *
 * For full API reference, see: https://frida.re/docs/javascript-api/
 */

defineHandler({
  onEnter(log, args, state) {
    log('Sleep()');
  },

  onLeave(log, retval, state) {
  }
});
        
/*
 * Auto-generated by Frida. Please modify to match the signature of Sleep.
 * This stub is currently auto-generated from manpages when available.
 *
 * For full API reference, see: https://frida.re/docs/javascript-api/
 */

defineHandler({
  onEnter(log, args, state) {
    log('Sleep()');
    args[0] = ptr(0);
    console.log("sleep modified!");
  },

  onLeave(log, retval, state) {
  }
});