2014-09-14 3 views
0

내 개인 안드로이드 애플 리케이션에 팔을 미리 컴파일 된 이진을 첨부하려고 내 머리를 부수고있다.안드로이드 애플 리케이션에 이진 첨부

괜찮 으면 내 앱에 대해 알려드립니다. 내 gprs 통신으로 인해 iptables 규칙을 수정해야합니다. 그것은 안드로이드에 대한 원격 제어이며, 내 로봇의 트래픽 대신 모든 트래픽을 거부하면 더 나은 결과를 얻습니다. 난 내 로봇의 제어를 마친 후 규칙을 복원하려는 때문에

는 그래서 난

것은 내가 '이다 ..하지만 - 저장 -restore 지원과 내 사이 애 노젠 모드의 버전 11의 iptables과의 iptables를 컴파일 내가 구글에서 많은 검색을 해왔다. 그리고 나는 'res'최상위 디렉토리에 'raw'디렉토리를 생성하는 것으로 보이는 droidwall을 발견했다. 그리고 일단 설치되면 adb 쉘에서 'app_bin'폴더 안쪽에서 볼 수있다./data/data의 경로. 하지만 내 애플 리케이션을 설치할 때, 그 dirs 만든 내가 어떤 이상한 경로에서 바이너리를 볼 수 없습니다 ... 정말, 아주 드문 경우입니까? 내가 네트워크에있는 모든 문서 ...

덕분에 많이

은 당신이 도움이 희망을 찾을 수 없습니다.

abel.

./src/com :

EDIT (수 sollution)는

나는 bin 디렉토리에, 그것은 APK 자원에서 복사 할 것으로 보인다 android_firewall 프로젝트의 코드를 다운로드 한 /jtschohl/androidfirewall/Api.java : 최종 문자열 app_iptables = dir + "/ iptables_armv5"; ./src/com/jtschohl/androidfirewall/Api.java : // iptables_armv5를 확인하십시오. ./src/com/jtschohl/androidfirewall/Api.java : File file = new File (ctx.getDir ("bin", 0) , "iptables_armv5"); ./src/com/jtschohl/androidfirewall/Api.java : copyRawFile (ctx, R.raw.iptables_armv5, file, "755");

나는 시도 할 것이다. 뉴스를 계속 ...

답변

0

예, 이것은 해결책입니다. 폴더 이름 "app _ % {TYPE}"은 getDir (% {TYPE}, MODE_PRIVATE) 함수를 호출하여 반환 된 폴더 이름입니다.

그래서 다음 코드를 수행하여 원하는 기능 :

private static void copyRawFile(Context ctx, int resid, File file, String mode) throws IOException, InterruptedException { 
      final String abspath = file.getAbsolutePath(); 
      // Write the iptables binary 
      final FileOutputStream out = new FileOutputStream(file); 
      final InputStream is = ctx.getResources().openRawResource(resid); 
      byte buf[] = new byte[1024]; 
      int len; 
      while ((len = is.read(buf)) > 0) { 
       out.write(buf, 0, len); 
      } 
      out.close(); 
      is.close(); 
      // Change the permissions 
      Runtime.getRuntime().exec("chmod " + mode + " " + abspath).waitFor(); 
     } 

     private boolean assertBinaries(Context ctx, boolean showErrors) { 
      try { 
       File file = new File(ctx.getDir("bin", MODE_PRIVATE), "xtables_multi"); 
       if (!file.exists()) { 
        copyRawFile(ctx, R.raw.xtables_multi, file, "755"); 
       } 
       file = new File(ctx.getDir("bin", MODE_PRIVATE), "iptables_new.sh"); 
       if (!file.exists()) { 
        copyRawFile(ctx, R.raw.iptables_new, file, "755"); 
       } 
      } catch(Exception e) { 
       if (showErrors) { 
        alert(ctx, R.string.error_assertbinaries + " " + e); 
       } 
       return false; 
      } 
     return true; 
     } 

     public static void alert(Context ctx, CharSequence msg) { 
      if (ctx != null) { 
       Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show(); 
      } 
     } 

희망 도움이

환호; 아벨.

관련 문제