・ このブログの記事(テキスト・画像)について

2011年12月4日日曜日

【Android】Androidのapkをデコンパイルやeclipseへデバック用にプロジェクトを読み込みしてみる。

もし、自分のプロジェクトを紛失して、apkのみしか無い場合の事を考えて、プロジェクト作成できるか、ちょっと調べてみました。


ただ・・・・いろいろありますが2通りあることがわかりました。


1.環境
WindowsXP
Android開発環境
著作権上問題のないAndroidnoapkファイル
 ecilpse環境
apktooldex2jarをダウンロード (dex2.jarについては後日)
003SH 端末



2.apktoolを使う
何ができるか試してみました。

2.1 このツールでapkからeclipse用のプロジェクトは作成できるか?
apkファイルからeclipseへプロジェクト作成をし、実行して端末へインストールできるかしらべました。ついでに、デバックモードへapkを書き換えられるかも調査しました。
->結論::実行して端末へインストールは、できました。しかし、エラーで落ちますw
準備

apktoolの詳細はこのサイトに載っています。
コマンドプロンプト起動
デコンパイル対象ファイルへコマンド実行
このコマンドによって、展開後、デバックモードで再度ビルドを行う




buildフォルダが再ビルドによって生成


次にeclipseで、新規作成->Androidプロジェクトを選択


EclipseからAndroidプロジェクトを選択

先ほどのパスを設定して完了する。
Eclipseへプロジェクトとして生成は完了しました ^^
プロジェクトが読み込まれました。
 AndroidManifest.xmlもバッチリ見えます。
EclipseからHelloWorldプロジェクトを実行する。


003shにロックオンし、実行する。

android端末へインストールはできました。が・・・・
エラーが出てAPKが起動できてない。
HelloworldプロジェクトをEclipseから直接実行した場合エラーがでる。
 ムキー!!

ちょっとwikiを読むと
 ・・・・・・・・・・・・・・・・・・・・・・下記wikiから抜粋・・・・・・・・・・・・・・・・・・・・・・

Specific instructions

Above informations are enough to debug smali code using apktool, but if you aren't familiar with DDMS and Java debugging, then you probably still don't know, how to do it. Below are simple instructions for doing it using Netbeans.
  1. Decode apk in debug mode: $ apktool d -d app.apk out
  2. Build new apk in debug mode: $ apktool b -d out
  3. Sign, install and run new apk.
  4. In Netbeans add new Java Project with Existing Sources, select "out" directory as project root and "smali" subdirectory as sources dir.
  5. Run DDMS, find your application on a list and click it. Note port information in last column - it should be something like "86xx / 8700".
  6. In Netbeans: Debug -> Attach Debugger -> select JPDA and set Port to 8700 (or whatever you saw in previous step). Rest of fields should be ok, click "Ok".
  7. Debugging session should start: you will see some info in a log and debugging buttons will show up in top panel.
  8. Set breakpoint. You must select line with some instruction, you can't set breakpoint on lines starting with ".", ":" or "#".
  9. Trigger some action in application. If you run at breakpoint, then thread should stop and you will be able to debug step by step, watch variables, etc.
You could also watch this video:


I tried to use Eclipse, but seems it forbids to add breakpoint on uknown (commented out) line :-/ I workarounded this and added breakpoint, then I was able to debug normally, but you should treat apktool debuging as unworkable on Eclipse - at least until someone will find some solution.


ううーんapktoolは、Eclipse用ではなく、 Netbeans用でデバックできるっぽい。。
 Netbeansで試せば、デバックモードに書き換えができるのかな・・・・・・・
次回の課題にします ><


0 件のコメント:

コメントを投稿