home ホーム search 検索 -  login ログイン  | reload edit datainfo version cmd icon diff delete  | help ヘルプ

技術/Android/DebuggerDetection

技術/Android/DebuggerDetection

技術 / Android / DebuggerDetection
id: 992 所有者: msakamoto-sf    作成日: 2011-06-26 19:56:21
カテゴリ: Android 

デバッガが接続されているか確認したい時に。

元ネタ:

デバッグ可能な設定になっているかチェック

boolean isDebuggable = (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
if ( isDebuggable )
  // ...

ただし Context.getAppliccationInfo() は API Level 4 以上。

現在デバッガが接続されているかチェック

boolean debugConn = Debug.isDebuggerConnected();

サンプル

package test.android;
 
import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.os.Debug;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
 
public class Main extends Activity {
    Button btnCheckManifest;
    Button btnCheckConnected;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        btnCheckManifest = (Button) findViewById(R.id.main_btn_check_manifest);
        btnCheckConnected = (Button) findViewById(R.id.main_btn_check_connected);
 
        btnCheckManifest.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isDebuggable = (0 != 
                    (Main.this.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
                if (isDebuggable) {
                    Toast.makeText(Main.this, "Debuggable", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(Main.this, "NOT Debuggable", Toast.LENGTH_SHORT).show();
                }
            }
        });
 
        btnCheckConnected.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean debugConn = Debug.isDebuggerConnected();
                if (debugConn) {
                    Toast.makeText(Main.this, "Debugger Conected", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(Main.this, "Debugger NOT Conected", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}

ちなみに

これらを使って「デバッガが接続されている端末上では、逆解析されたくないので実行を停止する」テクニックを使っても無意味なので注意すること。
調査不足なので詳細は書けないが、誰でも入手できるソフトウェアで逆解析は比較的容易になりつつある。
恐らく近い将来、このレベルの"AntiDebug"技術は易々と回避されるようになるだろう(或いは、既にそうなっているか)。



プレーンテキスト形式でダウンロード
現在のバージョン : 1
更新者: msakamoto-sf
更新日: 2011-06-26 19:56:49
md5:39e28faa046ed8ca9c012748a7129b4b
sha1:0344b600ed54bdd97e334c54655e0c251f18f75c
コメント
コメントを投稿するにはログインして下さい。