security - Process.execute() on android - android

Given i have compiled linux exe file in my resources/raw directory.
Can i execute it using Process.execute("./resources/raw/filename") or i have to have special permissions (like ROOT or smth) ?

Firstly, How did you compile the executable? I hope you've used a Cross-Compiler.
And Yes, you can execute applications...No special rights required.
I haven't tried that method, (Process.execute()) But i can Confirm Runtime.getRuntime().exec("/path/a.out"); works.... :)
When you execute it, the application will have the same privilege level as your application (non-root)...unless you rooted the device.

Related

A question about the permissiones of files generated after the APK installation

I know that some directories(e.g. /data/data/{package}/lib) will be generated after APK installation.I want to know whether the permissions(e.g.-rwxr-xr-x) of these directories and files in them can be set at the code level before APK installation?Or is the permission of the files generated during installation granted by the Android system during installation and the permissions cannot be set in advance?How can I do to implement it if the permissions of the generated file can be set in advance?
The files in data/data/package/ are always private to your application. No other process can read or write them (except the system, of course). And there's no way to override those permissions at install time. You probably could at runtime, but I'm not sure why you'd want to.

openalpr on android - path to config and runtime_data

I want to use open alpr (automatic licences plate recognition) library in my android project. I compiled everything successfully and now it is time to use open alpr in app but...
to create Alpr class object properly I have to provide path to config file and path to runtime_data folder which contains some mandatory files needed by open alpr (ocr and trained data).
I tried something like:
Alpr alpr = new Alpr("eu", "android_assets/alpr.conf", "android_assets/runtime_data");
but Alpr.isLoaded() returns false which means that config or runtime_data have not been found.
Path to assets folder in project is: src/main/assets.
Can someone explain to me how path to "runtime_data" directory and "alpr.conf"
should looks to be visible by open alpr?
Thanks in advance.
I am not familiar with the specific library, but on newer Android devices (Android 6 and up), you can not rely on your application files residing under /data/data/your.package.name
The actual library name still includes the package name of your app, but also has some identifier appended to it in base64 format.
This identifier is unique per installation, and it will change if you uninstall and reinstall the app on the same device.
So, if your library needs to use a configuration file with a path to some other files, there are 2 options:
The right way:
Get the real address of your application files folder using Context.getFilesDir().
Unpack you files from the assets folder of the APK on the device using AssetManager.
Programmatically rewrite your configuration file with the path returned by getFilesDir().
The "hacky" but simpler way:
Use public storage to unpack your files.
You will need to add WRITE_EXTERNAL_STORAGE permission to your app, and unpack the assets files to the external storage.
For backwards compatibility this will be available under /sdcard folder on most Android devices, even with the latest Android version.
The second method is not recommended since using /sdcard directly is deprecated and strongly discouraged by Google.
Also, not all Android devices have /sdcard link to their public storage, but this is the only way to avoid dynamically editing the configuration file after installation.
Important note before you start implementing those steps. This library supports only arm CPU architecture. Good news is, most probably, your physical device is using arm architecture but to make sure just double-check it before implemting those steps.
I've recompiled this library to a new wrapper library. In original library, you need to manually configure openalpr.conf file and edit its content with correct path to your data directory. Manual configuration is cumbersome because since Android 5 multiple user accounts is supported and we can't simply hardcode data directory as /data/data/com.your.packagename/..... Because every user gets their symlink to data directory as /data/user/0/com.your.packagename/..... All those manual steps are gone in recompiled wrapper library.
Implementation
Add this in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency into app module:
dependencies {
...
implementation 'com.github.mecoFarid:openalpr:1.0.0'
}
And you're done. Please check this sample app to get started with UI.
Troubleshooting:
If your target sdk is targetSdkVersion >= 24 and you're running your app on a device with Android API 24+ you'll get following error:
android.os.FileUriExposedException: file:///storage/emulated/0/OpenALPR/2019-09-21-01-32-13.jpg exposed beyond app through ClipData.Item.getUri()
To solve this error: you can add following lines into onCreate() of your Activity as a workaround or you may use this thread for offical solution:
if(Build.VERSION.SDK_INT>=24){
try{
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
}catch(Exception e){
e.printStackTrace();
}
}
TEST:
You can use this image to test your app.
"/data/data/yourpackagename" + File.separatorChar + "runtime_data"
+ File.separatorChar + "openalpr.conf";

QPython - Reading a file

I have installed QPython in my Android mobile.
I written a statement in the QEdit to read a text file from the below path
/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt
I used the below statement
fob=open('/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt','r')
fob.read()
If I run the statement, it is throwing error as:
IOError:[Errno 2] No such file or directory: '/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt'
1|uo_a116#cancro:/ $
Is the above statement correct?
fob=open('File1.txt','r')
Is not working in version 1.0.4.
fout=open('File2.txt','w')
Was working on version 0.9.6, but is not working in 1.0.4.
The "error" is Read only file system.
It looks like restrictions in the (new 1.0.4) file system library. I post a mail to the editor, but no answer at this time.
For testing, try to write absolute path to your files pointing, for example, to sdcard (/sdcard/out.txt).
I had problems on this versions (>=1.0.4) because launch process of script changes and execution directory is not the same as script directory.
I had to change my scripts to point to absolute paths.
It was tested with qpython developer.
Check this link:
https://github.com/qpython-android/qpython.org/issues/48
You can also try as simple as:
fob=open('File1.txt','r')
fob.read()
Just if the script is in the same folder of the file.
You can change the current working directory to path with script before read file:
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))

Where to I place the OBB file to test Android Expansion Pack Files (OBB) on my Nexus 4?

I'm trying to test the Expansion Pack Files (OBB) In Android following the guide here:
http://developer.android.com/google/play/expansion-files.html
I'm in the step where I need to test my app on my Nexus 4.
I generated my .obb file with jobb and adb-pushed it in the device in this location:
/mnt/shell/emulated/0/Android/obb/my.package/main.1.my.package.obb
When the app run it doesn't find the file.
Method:
Helpers.doesFileExist(context, fileName, xf.mFileSize, false)
return false for my file.
I debugged and found out it is looking for the file in:
/storage/emulated/0/Android/obb/my.package/main.1.my.package.obb
Specifically this is the path returned by:
Helpers.generateSaveFileName(c, fileName)
The /storage/emulated/0, returned by Environment.getExternalStorageDirectory() doesn't exist browsing the device with adb shell.
But it DOES at runtime, inside the app, I also checked what it contains: it contains almost the same things I found in /mnt/shell/emulated/0, it contains the Android/obb dir, which is empty.
How I found out the path /mnt/shell/emulated/0/Android/obb/my.package/main.1.my.package.obb where I placed my obb file:
$ adb shell
$ ls -ld sdcard
lrwxrwxrwx root root 2013-10-16 17:34 sdcard -> /storage/emulated/legacy
$ ls -ld /storage/emulated/legacy
lrwxrwxrwx root root 2013-10-16 17:34 legacy -> /mnt/shell/emulated/0
And inside that I already found the Android/obb directory, empty.
So the question is: where should I put my obb file for it to be in the right position at runtime?
I did everything said there:
created a draft application in the Market to get the public key
generated a random array of 20 byte (salt)
integrated play_licensing/library and play_apk_expansion/download_library
wrote my Service / Receiver
did the check using the Helpers etc.. exactly like the documentation say.
I suppose everything works but I can't just yet release on Play Store! I need to test locally and I'll have the need to change my obb file pretty often in this initial phase of development.
I can't test on the Emulator because I use 3D and device camera.
Since Android 4.2 multi users support have been added.
To support that Android mount an emulated disk for each users acting as a sandbox layer around the actual filesystem: this let Android handle gracefully either sharing of files between users either personal files.
Long story short:
/storage/emulated
is the emulated filesystem.
if you enter that directory from adb shell you may see a
/storage/emulated/obb
directory. Sometimes it doesn't show up, for some reason (see below for what to do if this happen)
It's not in /Android/obb but that's the right directory where to place your app package / obb file!
If you don't see that directory try looking in:
/mnt/shell/emulated/obb
You should be able to put your file there.
It will be correctly picked up at runtime ending at the
/storage/emulated/0/Android/obb/my.package/main.1.my.package.obb
path.
I think the Android documentation should explain this.
(I answer my own question because I found out how to solve it while writing it.)
For me the correct location is : mnt/sdcard/Android/obb/nameofyourpackage/
NOT "/mnt/shell"

Access to permission files

I am trying to connect a zwave device to android tv box.
For that I need to edit handheld_core_hardware.xml file situated in /system/etc/permissions, but I can't do that since it is a read only file.
Can somebody tell me any trick by which I can edit the file?
You cannot access that file without root (superuser) permissions.
Every files located in /data or /system dirs are protected and you can read or write it only with root permissions.
Try something different or your app will run only on rooted devices.
Read more about that :
http://en.wikipedia.org/wiki/Android_rooting
http://www.androidcentral.com/root

Categories

Resources