I have some security key in an application. I want to store it securly. I like to store it in a native shared library (maybe generated from some code). After that I want it to b
I will try to answer your first question here:
Signature of your application is stored in the DEX(Dalvik executable) file of your APK. DEX files have following structure:
So, this is the beginning of the header of DEX file:
So, to calk a signature of your apk, you should compute SHA-1 signature of your DEX file starting from the offset 32.
To get access to DEX file of your apk from native code, you can read process memory, which is stored in /proc/self/maps:
FILE *fp;
fp = fopen("/proc/self/maps", "r");
Each row in proc/$ID/maps file has following structure:
Here you can find a better description of proc/$ID/maps file's structure: Understanding Linux /proc/id/maps
To detect location of DEX file in process memory you should check out 'pathname' column in every row of your proc/self/maps file. When the row corresponding to DEX file will be found, you should get starting and ending addresses of the DEX file region:
while (fgets(line, 2048, fp) != NULL) {
// search for '.dex'
if (strstr(line, ".dex") != NULL) {
// get starting and ending addresses of the DEX file region
So, when you will have starting and ending addresses of your apk's bytecode, you will be able to compute signature of your apk.