0

i am breaking my brain trying to attach an arm pre-compiled binary to my private android app.

if you don't mind, i tell you about my app. it just needs to modify iptables rules because of my gprs communication with my robot. it is a remote control for android, and i get better results if i deny all traffic instead my robot's one.

so i compiled an iptables with my cyanogenmod's version 11 iptables, but with -save -restore support, since i want to restore the rules after finishing the control of my robot..

the thing is that i've been searching in google for a lot of while, and i just found droidwall which seems to only create a 'raw' directory into the 'res' top dir, and once installed, i can see on adb shell the folder 'app_bin' inside /data/data's path. but when i do install my app, with those dirs createds i can not see even the binary in some strange path... really, is this a very rare case? I don't find any documentation on the network...

thanks a lot,

hope you find it helpful.

abel.

EDIT (possible sollution)

I've downloaded the code from android_firewall project, where it seems to be copying from the apk resource, to the bin directory:

./src/com/jtschohl/androidfirewall/Api.java: final String app_iptables = dir + "/iptables_armv5"; ./src/com/jtschohl/androidfirewall/Api.java: // Check 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");

I am going to try. Keep on news...

Puffy
  • 401
  • 6
  • 13

1 Answers1

0

Yes, this is the sollution. The folder name "app_%{TYPE}" is the one returned by the calling of the function getDir(%{TYPE}, MODE_PRIVATE);

So the following code, does the desired functionality:

   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();
           }
       }

Hope that helps,

cheers; Abel.

Puffy
  • 401
  • 6
  • 13