i am getting SElinux policies error while trying to execute native binary - android

i am trying to execute native binary which i packaged with my app but getting: avc: denied { execute_no_trans } error in log
i was trying to execute that native binary using ProcessBuilder:
ProcessBuilder processBuilder = new ProcessBuilder(binaryPath);
Process process = processBuilder.start();
the native binary depends on libc++_shared.so, here is ldd output:
ldd /data/data/com.example.app/files/binary
linux-vdso.so.1 =>[vdso](0x7c22710000)
libc.so =>/apex/com.android.runtime/lib64/bionic/libc.so (0x7c20137000)
libc++_shared.so =>/data/data/com.termux/files/usr/lib/libc++_shared.so (0x7c1c032000)
libdl.so =>/apex/com.android.runtime/lib64/bionic/libdl.so (0x7c21240000)
libm.so =>/apex/com.android.runtime/lib64/bionic/libm.so (0x7c21280000)
after seeing this i thought libc++_shared.so is in different app private directory and my app was trying to call it that's why i was getting SElinux error as a security mechanism, then i also packaged libc++_shared.so with my app as assets and extracted at app first run in the same directory as binary and set LD_LIBRARY_PATH environment variable to "./" :
Map<String, String> env = processBuilder.environment();
env.put("LD_LIBRARY_PATH","./");
but again i got same error, i need help to understand how can i run native shared binary which i packed in APK with its shared library .so file.

Related

Compilation Python 3.6.5 static binary for arm32 fail

I'm trying, on Debian 9.4 x64, to compiling static Python binaries for arm32.
I have initialy:
downloaded the "Gzipped source tarball" source file from:
https://www.python.org/downloads/release/python-365/
extracted source files in: /python3.6.5/
downloaded and extract "binutils-gold-2.29.1-16.1.armv7hl.rpm" by cmd line:
rpm -qlp /python3.6.5/binutils-gold-2.29.1-16.1.armv7hl.rpm
try to compile the binary with this following command:
./configure --build=arm --prefix="$PWD"/out LDFLAGS="-static -static-libgcc -Wl,--unresolved-symbols=ignore-all -Wl,--export-dynamic" CPPFLAGS=-static CXXFLAGS=-static CFLAGS="-Os -static" LDFLAGS=-static LD=ld.gold
And i get this errors:
/usr/bin/ld: BFD assertion (GNU Binutils for Debian) 2.28 as failed ../../bfd/elflink.c:14098
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.28 internal error, aborting at ../../bfd/elf64-x86-64.c:6137 in elf_x86_64_finish_dynamic_symbol
/usr/bin/ld: Thanks to report this anomaly.
collect2: error: ld returned 1 exit status
Makefile:561 : the recipe for the "python" target has failed
-make: *** [python] Error 1
I'm trying to find how i could fix this error, but unfortunatly the support webpage on Python website isn't helpfull (https://wiki.python.org/moin/BuildStatically).
Finally, I would like to compile Python 3.6.5 for all processor platforms on which Android can run (arm32, aarm64, x86_x64, mips, mipsx64,...), to ultimately get a single binary file (i will repeat tasks for all other archs when i will have done with arm32).
So one file for each architectures cited, not multiple files/folders.
In a static way to avoid any dependencies with external libraries.
I chose to carry out the build operations, but if other less hazardous and simpler solutions exist i am taker.
NB: all cmd line has been made through LXTerminal on root session by default.
Thanks by advance for help.

ADB shell permission issues with python scripts: /data/local/tmp/iperf not found [duplicate]

root#hammerhead:/data/local # ./HelloWorld
tmp-mksh: ./HelloWorld: No such file or directory
Hello!
I compiled using gcc on Linux Deploy, which as I understand downloads Ubuntu and chroots into the environment. The file runs fine inside of this chroot environment.
As I understand this error is given when the file doesn't match the architecture of the machine. But it is running on the same machine! Does anyone know why this may be happening?
File permissions, ownership and context:
-rwxrwxrwx root root u:object_r:system_data_file:s0 HelloWorld
Id output:
uid=0(root) gid=0(root) context=u:r:init:s0
Using /system/bin/sh
/system/bin/sh: ./Helloworld: No such file or directory
Trying to execute a non existant file:
/system/bin/sh: ./test: not found
You should compile your binary with gcc '-static' key. If you don't do that, you binary will need dynamic linker ld.so that doesn't exist on Android (but definitely exists inside your chroot!). This implies that strange error message "No such file or directory".

Android: cannot execute file compiled through Linux Deploy on the same phone

root#hammerhead:/data/local # ./HelloWorld
tmp-mksh: ./HelloWorld: No such file or directory
Hello!
I compiled using gcc on Linux Deploy, which as I understand downloads Ubuntu and chroots into the environment. The file runs fine inside of this chroot environment.
As I understand this error is given when the file doesn't match the architecture of the machine. But it is running on the same machine! Does anyone know why this may be happening?
File permissions, ownership and context:
-rwxrwxrwx root root u:object_r:system_data_file:s0 HelloWorld
Id output:
uid=0(root) gid=0(root) context=u:r:init:s0
Using /system/bin/sh
/system/bin/sh: ./Helloworld: No such file or directory
Trying to execute a non existant file:
/system/bin/sh: ./test: not found
You should compile your binary with gcc '-static' key. If you don't do that, you binary will need dynamic linker ld.so that doesn't exist on Android (but definitely exists inside your chroot!). This implies that strange error message "No such file or directory".

Android NDK - Building Limbo Android returns fatal error: config.h: No such file or directory

I'm trying to rebuild Limbo Android. I'm on Linux Mint.
All I changed was android-config.mak NDK_ROOT, exported variables NDK_ROOT. I've also exported NDK_MODULE_PATH to /home/pathtoandroidndk/sources, as per README instructions.
From terminal I do cd limbo-android/jni and then make.
Building returns this error:
jni/glib/glib/./libcharset/localcharset.c:22:20: fatal error: config.h: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs-debug/glib-2.0/./libcharset/localcharset.o] Error 1
make: Leaving directory `/home/me/limbo-android'
I've tried modifing Android.mk following instructions from Android NDK - Additional Include Directories and Unable to find header files - Android NDK, without success.
I came to conclusion that each module inside limbo-android needs it's own config.h file, while libcharset does not have one.
How do I solve this error? Is there a generic config.h (the one from NDK maybe?)
NOTE: I can build it without any problems on Windows 8.1 using mingw.

Android - APK disassembler

I'm trying to get the assembler code executed for an APK. It can be extracted dynamically like gdb dissas or statically like objdump.
I tried with gdb without any exit.
APKs are actually just archives, similar to a JAR.
Within an APK you will find a number of files with application metadata (such as a manifest and certificate information), along with resource files and source files. The source code within an APK are also not Assembly files; they are DEX files for the Dalvik VM.
You will not find Assembly in an APK.
Solved using GDB.
Emulator:
gdbserver :5039 --attach pid
PC:
adb forward tcp:5039 tcp:5039
gdb
=> target remote 127.0.0.1:5039
Now in gdb we can see asm with "layout asm" or EIB ass using "x/i 0xEIB"

Categories

Resources