I would like to implement security check - signature verification of application (or dex file) to verify that unmodified application uses my shared native library (*.so) build with NDK. I would like to perform all signature checks directly in C++, without Java. Currently I found out that it is possible to access apk file here: /data/app/--1/base.apk. From apk file I guess it's possible to get contents of original dex file probably even without extraction as apk file is aligned.
- Does anyone know how to read dex file without extraction from apk?
I say original dex file because if I understand correctly (and correct me if I'm wrong) dex file is converted into ELF shared object when apk is installed - binary executable specific to architecture of device. That was the reason why I was not able to check/verify signature of *.dex file listed in /proc/self/maps (example: /data/dalvik-cache/x86/data@app@com.asdf.pkg@base.apk@classes.dex) because it's not possible to know signature at compile time because dex file will be changed.
I know the method of checking original dex file is not very secure because I think it could be bypassed on rooted device easily by replacing optimized dex file - just run dex2oat on custom dex file and place it in (/data/dalvik-cache/...).
- Is there any other better method to check if application is original from native library using plain C++? (without calling Java through JNI)