include binary in assets

jocalajocala USMember

I need to include an elf binary in assets and make it available for execution by adb shell. On first run the Android program needs to:

  1. copy the binary from assets to /data/data/packagename/files/binary
  2. mark binary as executable.

I've got a test program that includes the binary. I'm new to C#, can someone point to or post code to get me started?

Posts

  • jocalajocala USMember
    edited March 2015
    using System;
    using Android.App;
    using Android.Content;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Android.OS;
    using System.IO;
    
    namespace com.jocala.test
    {
        [Activity (Label = "com.jocala.test", MainLauncher = true, Icon = "@drawable/icon")]
        public class MainActivity : Activity
        {
            string filename = "busybox";
            string filepath = "/data/data/com.jocala.test/files";
    
            protected override void OnCreate (Bundle bundle)
            {
                base.OnCreate (bundle);
    
                // Set our view from the "main" layout resource
    
                SetContentView (Resource.Layout.Main);
    
                // Get our button from the layout resource,
                // and attach an event to it
    
                Button button = FindViewById<Button> (Resource.Id.myButton);
    
                button.Click += delegate {
                    button.Text = string.Format ("Installing");
                    using (Stream stream = Assets.Open (filename)) 
                    {
                        using(var fileStream = System.IO.File.Create (filepath))
                        {
                            stream.CopyTo(fileStream );
                        }
                    }
    
                };
            }
        }
    }
    

    [mono-rt] java.io.FileNotFoundException: busybox

    So, here's where I'm at; it compiles and runs, but my binary isn't copied. Thanks for any assistance!

  • jocalajocala USMember

    [mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.UnauthorizedAccessException: Access to the path '/data/data/com.jocala.test/files' is denied.

    My first run, the binary wasn't actually present. The error above is current.

  • jocalajocala USMember
        string filepath = System.Environment.GetFolderPath  (System.Environment.SpecialFolder.Personal);
    

    also gives a access denied error.

Sign In or Register to comment.