LoginSignup
0
5

More than 1 year has passed since last update.

Android の Apk リバースエンジニアリング

Posted at

警告
リバースエンジニアリングは知的財産権に関連しますので注意して下さい。

バイナリ形式のAndroidアプリパッケージ(.apk)をリバースエンジニアリングを使って判読可能なテキストファイル(ソースコード)に変換します。

用途により使用するツールを使い分けます。

(1) Manifest.xmlなどの設定ファイルを参照

  • Apktool (classファイルをデコンパイルした結果はsmali形式となります。)

(2) ソースコード(.Java)を参照

  • dex2jar
  • JD(Java Decompiler)

■ apkファイルの構成

  • AndroidManifest.xml
  • META-INF(署名ファイル)
  • res(画像等のリソース)
  • classes.dex(プログラム)
  • resources.arsc(言語等のリソース)


C:\StudioProjects\Hoge\app\build\outputs\apk\debug\app-debug.apk

Androidアプリパッケージ(.apk)は、zip 形式で圧縮されています。
拡張子を zip に変更すると、Windows でも解凍できます。

C:\StudioProjects\Hoge\app\build\outputs\apk\debug\app-debug

app-debug
├── AndroidManifest.xml          (バイナリ形式)
├── classes.dex                  (クラスファイル)
├── META-INF
│   ├── android.arch.core_runtime.version

・・・

■ Apktool

Androidアプリ用のリバースエンジニアリングツールです。
リソースをほぼオリジナルの形式にデコードし、変更を加えた後でそれらを再構築することができます。
ファイル構造のようなプロジェクトやapkの構築などの反復的なタスクの自動化などのために、アプリの操作も簡単になります。

違法コピーやその他の違法な使用を目的としたものではありません 。
ローカライズ、機能の追加、カスタムプラットフォームのサポート、アプリケーションの分析などに使用できます。

特徴

  • ほぼ元の形式にresources.arscをclasses.dex ( resources.arsc 、 classes.dex 、 9.png. 、 classes.dexを含む)
  • デコードされたリソースをバイナリAPK / JARに再構築
  • フレームワークリソースに依存するAPKの整理と処理
  • Smaliのデバッグ(IdeaSmaliのために2.1.0で削除されました )
  • 繰り返し作業を支援する

使用方法

C:\Downloads>java -jar apktool_2.4.0.jar
Apktool v2.4.0 - a tool for reengineering Android apk files
with smali v2.2.6 and baksmali v2.2.6
Copyright 2014 Ryszard Wi?niewski <brut.alll@gmail.com>
Updated by Connor Tumbleson <connor.tumbleson@gmail.com>

usage: apktool                                                                          使用法:apktool
 -advance,--advanced   prints advance information.                                      事前情報を印刷します。
 -version,--version    prints the version then exits                                    バージョンを表示して終了する
usage: apktool if|install-framework [options] <framework.apk>                           使用方法:apktool if | install-framework [options] <framework.apk>
 -p,--frame-path <dir>   Stores framework files into <dir>.                             フレームワークファイルを<dir>に格納します。
 -t,--tag <tag>          Tag frameworks using <tag>.                                    <tag>を使ってフレームワークにタグを付けます。
usage: apktool d[ecode] [options] <file_apk>                                            使用方法:apktool d [ecode] [options] <file_apk>
 -f,--force              Force delete destination directory.                            宛先ディレクトリを強制削除します。
 -o,--output <dir>       The name of folder that gets written. Default is apk.out       書き込まれるフォルダの名前。 デフォルトはapk.outです。
 -p,--frame-path <dir>   Uses framework files located in <dir>.                         <dir>にあるフレームワークファイルを使用します。
 -r,--no-res             Do not decode resources.                                       リソースをデコードしません。
 -s,--no-src             Do not decode sources.                                         ソースをデコードしません。
 -t,--frame-tag <tag>    Uses framework files tagged by <tag>.                          <tag>でタグ付けされたフレームワークファイルを使用します。
usage: apktool b[uild] [options] <app_path>                                             使用方法:apktool b [uild] [options] <app_path>
 -f,--force-all          Skip changes detection and build all files.                    変更の検出をスキップしてすべてのファイルをビルドします。
 -o,--output <dir>       The name of apk that gets written. Default is dist/name.apk    書き込まれるapkの名前。 デフォルトはdist / name.apkです。
 -p,--frame-path <dir>   Uses framework files located in <dir>.                         <dir>にあるフレームワークファイルを使用します。

For additional info, see: http://ibotpeaches.github.io/Apktool/                         追加情報については、http://ibotpeaches.github.io/Apktool/を参照してください。
For smali/baksmali info, see: https://github.com/JesusFreke/smali                       smali / baksmaliについては、https://github.com/JesusFreke/smaliを参照してください。

使用例

 C:\StudioProjects\Hoge\app\build\outputs\apk\debug のディレクトリ

2022/06/16  07:41    <DIR>          .
2022/06/16  07:41    <DIR>          ..
2022/06/16  07:41         2,101,995 app-debug.apk
2022/06/16  07:41               228 output.json
               2 個のファイル           2,102,223 バイト
               2 個のディレクトリ  20,727,513,088 バイトの空き領域

C:\StudioProjects\Hoge\app\build\outputs\apk\debug>java -jar C:\Downloads\apktool_2.4.0.jar d app-debug.apk
I: Using Apktool 2.4.0 on app-debug.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
S: WARNING: Could not write to (C:\AppData\Local\apktool\framework), using C:\AppData\Local\Temp\ instead...
S: Please be aware this is a volatile directory and frameworks could go missing, please utilize --frame-path if the default storage directory is unavailable
I: Loading resource table from file: C:\AppData\Local\Temp\1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...

■ dex2jar

Androidの.dexファイルとjavaの.classファイルを操作するためのツール
https://sourceforge.net/projects/dex2jar/

C:\Downloads\dex2jar-2.0\d2j-dex2jar.bat

C:\StudioProjects\Hoge\app\build\outputs\apk\debug\app-debug>C:\Downloads\dex2jar-2.0\d2j-dex2jar.bat
d2j-dex2jar -- convert dex to jar
usage: d2j-dex2jar [options] <file0> [file1 ... fileN]
options:
 -d,--debug-info              translate debug info
 -e,--exception-file <file>   detail exception file, default is $current_dir/[fi
                              le-name]-error.zip
 -f,--force                   force overwrite
 -h,--help                    Print this help message
 -n,--not-handle-exception    not handle any exception throwed by dex2jar
 -nc,--no-code
 -o,--output <out-jar-file>   output .jar file, default is $current_dir/[file-na
                              me]-dex2jar.jar
 -os,--optmize-synchronized   optmize-synchronized
 -p,--print-ir                print ir to Syste.out
 -r,--reuse-reg               reuse regiter while generate java .class file
 -s                           same with --topological-sort/-ts
 -ts,--topological-sort       sort block by topological, that will generate more
                               readable code, default enabled
version: reader-2.0, translator-2.0, ir-2.0
C:\StudioProjects\Hoge\app\build\outputs\apk\debug\app-debug>C:\Downloads\dex2jar-2.0\d2j-dex2jar.bat classes.dex
dex2jar classes.dex -> .\classes-dex2jar.jar
Detail Error Information in File .\classes-error.zip
Please report this file to http://code.google.com/p/dex2jar/issues/entry if possible.

■ JD(Java Decompiler)

JD Project
http://java-decompiler.github.io/

0
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
5