标签:for blog 链接 ref x86 lan .so std printf
编译参考文章
http://blog.csdn.net/john_1984/article/details/12622215
一、编写soLoader主文件
soLoader.c内容:
#include <stdio.h> typedef int (*MAIN_FN)(int,char**); int main(int argc,char* argv[]){ printf("hello so!\n"); int ret = dlopen("/data/local/xxx.so"); if (ret==0) { printf("file not found!\n"); } void* pfn = dlsym(ret,"main"); if (pfn==NULL) { printf("method \"main\" not found!\n"); } ((MAIN_FN)pfn)(argc,argv); printf("result: %x\n",ret); }
二、编译o文件
E:\Documents\Android\sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin>arm-linux-androideabi-gcc.exe --sysroot=E:\Documents\Android\sdk\ndk-bundle\platforms\android-19\arch-arm -o E:\VMShare\Work\Andriod\antidebug\soLoader\jni\soLoader.o -c E:\VMShare\Work\Andriod\antidebug\soLoader\jni\soLoader.c
三、链接o文件为elf文件
E:\Documents\Android\sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin>arm-linux-androideabi-gcc.exe --sysroot=E:\Documents\Android\sdk\ndk-bundle\platforms\android-19\arch-arm -o E:\VMShare\Work\Andriod\antidebug\soLoader\jni\soLoader E:\VMShare\Work\Andriod\antidebug\soLoader\jni\soLoader.o
或者直接编译链接(二,三命令合并):
E:\Documents\Android\sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin>arm-linux-androideabi-gcc.exe --sysroot=E:\Documents\Android\sdk\ndk-bundle\platforms\android-19\arch-arm -o E:\VMShare\Work\Andriod\antidebug\soLoader\jni\soLoader E:\VMShare\Work\Andriod\antidebug\soLoader\jni\soLoader.c
四、push到手机,执行
//pc端命令
E:\VMShare\Work\Andriod\antidebug\soLoader\jni>adb push soLoader /data/local/tmp
//adb shell shell@hammerhead:/data/local/tmp # chmod 775 soLoader shell@hammerhead:/data/local/tmp # ./soLoader hello so! file not found! method "main" not found! [1] + Stopped (signal) ./soLoader shell@hammerhead:/data/local/tmp # ls
标签:for blog 链接 ref x86 lan .so std printf
原文地址:http://www.cnblogs.com/xunbu7/p/6974207.html