Smali - Decompiling/[Modifying]/Compiling
アプリケーションコードを変更して隠された情報にアクセスすることが興味深い場合があります(おそらくよく難読化されたパスワードやフラグ)。その後、APKを逆コンパイルしてコードを変更し、再コンパイルすることが興味深いかもしれません。
オペコードリファレンス: http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html
早い方法
Visual Studio CodeとAPKLab拡張機能を使用すると、自動的に逆コンパイル、変更、再コンパイル、アプリケーションの署名とインストールを実行せずに行うことができます。
このタスクを大幅に簡略化するスクリプトもう一つはhttps://github.com/ax/apk.shです。
APKを逆コンパイルする
APKToolを使用すると、smaliコードとリソースにアクセスできます:
If apktool gives you any error, try installing the latest version
Some interesting files you should look are:
res/values/strings.xml (and all xmls inside res/values/*)
AndroidManifest.xml
Any file with extension .sqlite or .db
If apktool
has problems decoding the application take a look to https://ibotpeaches.github.io/Apktool/documentation/#framework-files or try using the argument -r
(Do not decode resources). Then, if the problem was in a resource and not in the source code, you won't have the problem (you won't also decompile the resources).
Change smali code
You can change instructions, change the value of some variables or add new instructions. I change the Smali code using VS Code, you then install the smalise extension and the editor will tell you if any instruction is incorrect. Some examples can be found here:
Or you can check below some Smali changes explained.
Recompile the APK
After modifying the code you can recompile the code using:
それはdistフォルダーの中に新しいAPKをコンパイルします。
もしapktoolがエラーを出したら、最新バージョンをインストールしてみてください。
新しいAPKに署名する
その後、キーを生成する必要があります(パスワードとランダムに入力できる情報が求められます):
最後に、新しいAPKに署名を付けます:
新しいアプリケーションの最適化
zipalignは、Androidアプリケーション(APK)ファイルに重要な最適化を提供するアーカイブ整列ツールです。こちらで詳細を確認。
新しいAPKに署名する(再び?)
もしjarsignerの代わりにapksignerを使用したい場合は、zipalignを適用した後にapkに署名する必要があります。ただし、jarsigner(zipalignの前)またはaspsigner(zipalignの後)でアプリケーションに署名する必要があるのは1回だけであることに注意してください。
Smaliの変更
次のHello World Javaコードについて:
Smaliコードは次のようになります:
軽微な変更
関数内の変数の初期値を変更する
一部の変数は、関数の冒頭で const オペコードを使用して定義されています。これらの値を変更したり、新しいものを定義したりできます:
基本的な操作
大きな変更
ロギング
Recommendations:
If you are going to use declared variables inside the function (declared v0,v1,v2...) put these lines between the .local <number> and the declarations of the variables (const v0, 0x1)
If you want to put the logging code in the middle of the code of a function:
Add 2 to the number of declared variables: Ex: from .locals 10 to .locals 12
The new variables should be the next numbers of the already declared variables (in this example should be v10 and v11, remember that it starts in v0).
Change the code of the logging function and use v10 and v11 instead of v5 and v1.
Toasting
Remember to add 3 to the number of .locals at the beginning of the function.
This code is prepared to be inserted in the middle of a function (change the number of the variables as necessary). It will take the value of this.o, transform it to String and them make a toast with its value.
Last updated