Program/Android Java

루팅체크

너구리V 2012. 11. 9. 14:17

public class TestRootingCheckActivity extends Activity {
 
    public static final String ROOT_PATH = Environment.
            getExternalStorageDirectory() + "";
    public static final String ROOTING_PATH_1 = "/system/bin/su";
    public static final String ROOTING_PATH_2 = "/system/xbin/su";
    public static final String ROOTING_PATH_3 = "/system/app/SuperUser.apk";
    public static final String ROOTING_PATH_4 = "/data/data/com.noshufou.android.su";
     
    public String[] RootFilesPath = new String[]{
            ROOT_PATH + ROOTING_PATH_1 ,
            ROOT_PATH + ROOTING_PATH_2 ,
            ROOT_PATH + ROOTING_PATH_3 ,
            ROOT_PATH + ROOTING_PATH_4
    };
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         
        boolean isRootingFlag = false;
 
        try {
            Runtime.getRuntime().exec("su");
            isRootingFlag = true;
        } catch ( Exception e) {
            // Exception 나면 루팅 false;
            isRootingFlag = false;
        }
         
        if(!isRootingFlag){
            isRootingFlag = checkRootingFiles(createFiles(RootFilesPath));
        }
         
        Log.d("test", "isRootingFlag = " + isRootingFlag);
    }
 
    /**
     * 루팅파일 의심 Path를 가진 파일들을 생성 한다.
     */
    private File[] createFiles(String[] sfiles){
        File[] rootingFiles = new File[sfiles.length];
        for(int i=0 ; i < sfiles.length; i++){
            rootingFiles[i] = new File(sfiles[i]);
        }
        return rootingFiles;
    }
     
    /**
     * 루팅파일 여부를 확인 한다.
     */
    private boolean checkRootingFiles(File... file){
        boolean result = false;
        for(File f : file){
            if(f != null && f.exists() && f.isFile()){
                result = true;
                break;
            }else{
                result = false;
            }
        }
        return result;
    }
}

반응형