Android - APK disassembler - android

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"

Related

How are shared libraries packed into apk?

I'm working on some script for custom build system and i need to pack some .so files in android apk (aars with native libs are not yet supported).
I've invoked ./gradlew assembleDebug --debug for the apk project that depends on aar with native libraries (.so) to get full log but did not find any .so files paths passed to aapt or any other android build tool (though i've seen .so stripping commands with ndk strip tool).
How is it done in details? Does aapt tool do it? Are there any aapt arguments for this or they should be just stored on some specific paths (eg. libs).
Yes, aapt via an invocation like aapt add -v MyApp.apk lib/armeabi/libMyLib.so.
Use aapt --list MyApp.apk to ensure that it is in the apk with that directory structure (a lib folder, an armeabi subfolder, and MyApp.apk within that).
After installing the app, look in /data/app/com.Company/android/MyApp-X/lib/arm/ for libMyLib.so to ensure it got copied.
If problems, logcat output is actually really useful, telling you the path tried, the function tried, etc.
Obviously, replace the app name, company name, and armeabi architecture to fit your projects' parameters.

Error while trying to compile android kernel in ubuntu

I'm trying to compile a Android Kernel from source and I have downloaded all the right packages to do it but for some reason I get this error:
arm-linux-androideabi-gcc: error: unrecognized command line option '-mgeneral-regs-only'
/home/livlogik/android/kernel/H901BK_L_Kernel/./Kbuild:35: recipe for target 'kernel/bounds.s' failed
make[1]: *** [kernel/bounds.s] Error 1
Makefile:858: recipe for target 'prepare0' failed
make: *** [prepare0] Error 2
I have the latest NDK and I'm using Ubuntu 15.10 64bit if this helps.
Here is where I have the NDK and kernel:
NDK ---- /home/livlogik/android/ndk/
Kernel ---- /home/livlogik/android/kernel/H901bk_L_Kernel/
If someone could help me that would be great. Sorry if this was already posted I could find a answer to it.
Thanks,
Zach
As it can be seen from build error message:
drivers/media/platform/msm/camera_v2/sensor/msm_sensor.c:20:27: fatal error: ./mh1/msm_mh1.h: No such file or directory
#include <./mh1/msm_mh1.h>
compiler just can't find msm_mh1.h file. This is because the path specified for #include directive isn't correct. Most probably it's typo: instead ./ there should be ../.
To fix that error, in drivers/media/platform/msm/camera_v2/sensor/msm_sensor.c file change this line:
#include <./mh1/msm_mh1.h>
to this line
#include "../mh1/msm_mh1.h"
After this make command should work fine. Also, kernel image file will be available at arch/arm64/boot, and it's not zImage as stated in documentation, it's actually Image.gz. Uncompressed kernel image is Image file.
Update
Answering your question in comments:
Is there any way to make it compress into a zImage?
From Documentation/arm64/booting.txt:
The AArch64 kernel does not currently provide a decompressor and
therefore requires decompression (gzip etc.) to be performed by the boot
loader if a compressed Image target (e.g. Image.gz) is used. For
bootloaders that do not implement this requirement, the uncompressed
Image target is available instead.
Basically zImage is just gzipped and self-extracted Image. So zImage file consists of program for unpacking gzip archive in the beginning, followed by gzipped Image, and when kernel is run by bootloader its unpacking itself (hense "self-extracted" term) and then start running.
...So I can make it flashable
In case of arm64, you don't have zImage, so most likely you need to use Image file (which acts in the same way, but only its size is bigger). You can create boot.img from Image file and built AFS ramdisk (using mkbootimg tool) and then just do fastboot flash boot boot.img. Refer to this documentation for example. Of course for your platform some things can be different, so try to find instructions for your platform.
You have to install the right toolchain:
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
And configure the Makefile appropriately
The wrong toolchain is at
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-android-4.9

How do I build Libgdx.so from source for Android with gdb tracing enabled?

I have setup a debug ROM on an Android device, and enabled the DDMS Native Heap in search for a libgdx memory leak.
I now have a trace, but no source code attached to follow the lead.
I downloaded libgdx source code.
How do I build it enabling gdb tracing so I can follow the code referenced by the trace ?
Update:
I built the debug .so libgdx from source
To do this, I modified the file:
libgdx/gdx/jni/build-android32.xml
Adding to the compile-natives target
I also added APP_OPTIM := debug to the Application.mk in the same folder
And added '-g' to the Android.mk file in the same folder:
LOCAL_CFLAGS := -g $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__
This, indeed, produces a dbg libgdx.so dynamic library place in
libgdx/gdx/libs/armeabi
Although I am getting closer, I still cannot get the name of the function that is loading memory.
I am using arm-linux-androideabi-addr2line and the Hex address of the function, but it prints
??
Download the Android Source and build it.
Point DDMS to the libs with debug symbols. On the command line:
export ANDROID_SYMBOLS=$ANDROID_SOURCE/out/target/product/flo/symbols/system/lib
Note that $ANDROID_SOURCE refers to the location where you built the Android source.
start DDMS from that shell
$ddms
Now you should see the native traces on ddms.
I also built libgdx from source and added $LIBGDX_SOURCE/libgdx/gdx/obj/local/armeabi/libgdx.so
to $ANDROID_SOURCE/out/target/product/flo/symbols/system/lib to see the method names for libgdx.so.
Preliminaries
You need to set the device to debug memory
adb root
adb shell setprop libc.debug.malloc 1
adb shell stop
adb shell start
The device must be rooted or with a dbg ROM.

Cross-compiling nfs-utils package for Android

I would like to add NFS support (both client and server) for my Android device. I have already built and inserted the required kernel modules (sunrpc.ko, lockd.ko, nfs.ko, exportfs.ko, nfsd.ko)
My Android phone now can act as an NFS client by mounting using Busybox. But to work as an NFS server, seems like some utilities (such as exportfs) and service daemons (portmap, nfsd, mountd, etc) are missing.
I figured I needed to install the nfs-utils package (http://nfs.sourceforge.net/).
I thought I should cross-compile it on my pc and then install it on my phone's Linux kernel. I'm not familiar with the whole cross-compiling thing. I'm trying to compile it on Ubuntu right now, and this is the command I'm using:
$ ./configure
--target=arm-linux-gnueabi
--host=arm-linux-gnueabi
--build=x86_64-linux
CC=/usr/bin/arm-linux-gnueabi-gcc
CPPFLAGS="-I/usr/arm-linux-gnueabi/include/"
CFLAGS="-nostdlib"
LDFLAGS="-Wl,-rpath-link=/usr/arm-linux-gnueabi/lib/ -L/usr/arm-linux-gnueabi/lib/"
LIBS="-lc"
This gives me the error msg:
checking for libwrap... configure: error: *** libwrap missing
config.log errors:
configure:3978: /usr/bin/arm-linux-gnueabi-gcc -V >&5
arm-linux-gnueabi-gcc: fatal error: no input files
configure:3978: /usr/bin/arm-linux-gnueabi-gcc -qversion >&5
arm-linux-gnueabi-gcc: fatal error: no input files
conftest.c:12:28: fatal error: ac_nonexistent.h: No such file or directory
conftest.c:55:28: fatal error: sys/capability.h: No such file or directory
I have the gcc-arm-linux-gnueabi package installed, but I guess there are some problems with building/linking with dependency libraries I don't really understand. Should they be cross-compiled too? How can I do that? And will I need to insert these libraries into my phone for NFS to run properly?
I'm completely new to this so any help would be greatly appreciated.
You have a dependency of tcp-wrappers which means you must first build and install tcp wrappers.
Alternatively, you can pass this option to ./configure:
--without-tcp-wrappers \
Also, you can get a complete list of options:
./configure --help

Android build PJSIP with openssl

I'm trying to build PJSIP on Android with SSL/TLS support.
I successfully built OpenSSL following this answer (without fips, as shared-.so libraries) and installed it in ~/android (which created the ~/android/ssl directory).
Now, when i do
./configure-android --with-ssl=/home/andrea/android/ssl
and look at the config.log, the first error states
<ndk-directories-and-stuff>/arm-linux-androideabi/bin/ld: warning: libdl.so, needed by /home/andrea/android/ssl/lib/libcrypto.so, not found (try using -rpath or -rpath-link)
a lot of undefined references follow.
As consequence SSL support is disabled:
aconfigure:7012: result: ** OpenSSL libraries not found, disabling SSL support **
ac_cv_header_openssl_ssl_h=yes
ac_cv_lib_ssl_SSL_library_init=no
CFLAGS=' -I/home/andrea/android/android-ndk-r8e/platforms/android-14/arch-arm/usr/include -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1 -I/home/andrea/android/ssl/include'
LDFLAGS=' -nostdlib -L/home/andrea/android/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib/ -L/home/andrea/android/ssl/lib'
ac_no_ssl=''
libssl_present=''
openssl_h_present='1'
but libdl.so exists in the ndk's directory:
<ndk-dir>/platforms/android-14/arch-arm/usr/lib/
I guess I have to tell ld where the other libraries are,
what does ld's suggestion mean?
try using -rpath or -rpath-link
I can't understand what -rpath or rpath-link are or where to apply them .
any ideas?
I successfully built PJSIP with OpenSSL. please follow the following steps:
First download openssl-android and compile it by reading ReadMe File. (Put your android-ndk to PATH and execute command ndk-build in openssl-android root) then just copy libcrypto.so and libssl.so from libs/armeabi/ folder to lib/ folder in root of openssl-android (you can create this folder). your directory structure now should be like:
openssl-android/
->apps
->crypto
->include
->jni
->lib
->libs
->...
now just execute in root directory of pjsip:
./configure-android --with-ssl=/home/your-user-name/path-to-openssl-android-dir
for confirmation that openssl is included just pipe this command to grep like:
./configure-android --with-ssl=/home/your-user-name/path-to-openssl-android-dir | grep -wi ssl
then you will see this line result: OpenSSL library found, SSL support enabled. This means, OpenSSL is now enabled for your PJSIP. Now you can continue normal.
hope this helps.

Categories

Resources