その後のその後

iOSエンジニア 堤 修一のブログ github.com/shu223

otoolでバイナリの内容をいろいろと調べる方法

new BSDライセンスについて調べていたら、こちらの有名な事件に関してのまとめ記事に行き当たり、


NatsuLion for iPhone クローン (略) から学んだこととかまとめ


その中でこんな記述がありました。

今回の場合は、まず、Twitterville が見た目上ソックリであっても、中身まで NatsuLion for iPhone のソースを使ったと示せないので、バイナリを otool してシンボルを全て比較するという手法を取りました。


へーそういうものがあるのか、とotoolの使い方などを調べてみました。

使い方

バイナリ(〜.app)のあるフォルダへ移動し、ターミナルから以下のように実行します。

otool -l {アプリ名}.app/{アプリ名}


バイナリのある場所は、Xcode4を使用しているのであれば、~/Library/Developer/Xcode/DerivedData から下を探せば見つかります。


また、AppStoreからダウンロードしたアプリを解析したい場合は、~/Music/iTunes/Mobile Applications/ 配下に {アプリ名}.ipa ファイルがあるので、こちらの拡張子を.zipに変更し、解凍すれば.appのバイナリが取り出せます。


otoolを使うとわかることその1:使用しているフレームワークの一覧

こんな感じで使用しているフレームワークの情報がわかります。

cmd LC_LOAD_DYLIB
cmdsize 88
name /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (offset 24)
time stamp 2 Thu Jan 1 09:00:02 1970
current version 600.0.0
compatibility version 64.0.0

otoolを使うとわかることその2:暗号化されたデータの情報

  • cryptoff:暗号化されたデータの開始位置(ファイル先頭からのオフセット)
  • cryptsize:暗号化されたデータの長さ
  • cryptid:暗号化されたデータの有無。0であればなし。

この情報を使って何かできてしまうようです・・・
AppStore Application Hack Guide

その他のオプション

オプションを変えれば上記以外にもいろいろな情報がとれそうです。

-a Display the archive header, if the file is an archive.
-S Display the contents of the `__.SYMDEF' file, if the file is an archive.
-f Display the universal headers.
-h Display the Mach header.
-l Display the load commands.
-L Display the names and version numbers of the shared libraries that the object file uses. As
well as the shared library ID if the file is a shared library.
-D Display just install name of a shared library.
-s segname sectname
Display the contents of the section (segname,sectname). If the -v flag is specified, the sec-
tion is displayed as its type, unless the type is zero (the section header flags). Also the
sections (__OBJC,__protocol), (__OBJC,__string_object) and (__OBJC,__runtime_setup) are dis-
played symbolically if the -v flag is specified.
-t Display the contents of the (__TEXT,__text) section. With the -v flag, this disassembles the
text. And with -V, it also symbolically disassembles the operands.
-d Display the contents of the (__DATA,__data) section.
-o Display the contents of the __OBJC segment used by the Objective-C run-time system.
-r Display the relocation entries.
-c Display the argument strings (argv and envp) from a core file.
-I Display the indirect symbol table.
-T Display the table of contents for a dynamically linked shared library.
-R Display the reference table of a dynamically linked shared library.
-M Display the module table of a dynamically linked shared library.
-H Display the two-level namespace hints table.