使用反编译后的so文件
来源:互联网 发布:有哪些社交软件 编辑:程序博客网 时间:2024/05/22 03:25
本文主要整理来之网络,用于记录学习的知识
1、编译别人的apk文件后,获取到so文件后
比如
- static {
- try {
- System.loadLibrary("NativeExampleActivity");
- } catch (Throwable t) {
- }
- }
- public native int addFunction(int a, int b);
- public native String getString(String name);
虽然知道了这两个native函数,但是我们还不能直接使用,因为这两个native函数在so库里面的真实函数名不是addFunction和getString,它在native函数名之前还有包名,所以必须使用nm命令,查看so库里面的函数名。
nm -A libNativeExampleActivity.so
或者
nm -D libNativeExampleActivity.so
这样我们看到so库里的主要信息:
Java_org_natives_example_NativeExampleActivity_addFunction
Java_org_natives_example_NativeExampleActivity_getString
3、新建一个android 项目
- package so.hello;
- import android.app.Activity;
- import android.os.Bundle;
- public class SoHelloActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- static {
- try {
- System.loadLibrary("soHello");
- } catch (Throwable t) {
- }
- }
- public native int addFunction1(int a, int b);
- public native String getString1(String name);
- }
- /* DO NOT EDIT THIS FILE - it is machine generated */
- #include <jni.h>
- /* Header for class so_hello_SoHelloActivity */
- #ifndef _Included_so_hello_SoHelloActivity
- #define _Included_so_hello_SoHelloActivity
- #ifdef __cplusplus
- extern "C" {
- #endif
- /*
- * Class: so_hello_SoHelloActivity
- * Method: addFunction1
- * Signature: (II)I
- */
- JNIEXPORT jint JNICALL Java_so_hello_SoHelloActivity_addFunction1
- (JNIEnv *, jobject, jint, jint);
- /*
- * Class: so_hello_SoHelloActivity
- * Method: getString1
- * Signature: (Ljava/lang/String;)Ljava/lang/String;
- */
- JNIEXPORT jstring JNICALL Java_so_hello_SoHelloActivity_getString1
- (JNIEnv *, jobject, jstring);
- #ifdef __cplusplus
- }
- #endif
- #endif
6、写一个so_hello_SoHelloActivity.cpp文件
- #include "so_hello_SoHelloActivity.h"
- #include <stdlib.h>
- #include <fcntl.h>
- #include <android/log.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include <dlfcn.h>
- void *filehandle = NULL;
- jint (*addFunc)(JNIEnv *,jobject,jint,jint) = NULL;
- jstring (*getStringFunc)(JNIEnv *, jobject, jstring) = NULL;
- JNIEXPORT jint JNICALL Java_so_hello_SoHelloActivity_addFunction1
- (JNIEnv *env, jobject obj, jint a, jint b);
- {
- jint mun = 0;
- //事先把libNativeExampleActivity放到root/system/lib/目录下
- filehandle = dlopen("/system/lib/libNativeExampleActivity.so", RTLD_LAZY);
- if(filehandle)
- {
- addFunc = (jint (*)(JNIEnv *,jobject,jint,jint))dlsym(filehandle, "Java_org_natives_example_NativeExampleActivity_addFunction");
- if(addFunc)
- mun = addFunc(env, obj, a, b);
- dlclose(filehandle);
- filehandle = NULL;
- }
- return mun
- }
- /*
- * Class: so_hello_SoHelloActivity
- * Method: getString1
- * Signature: (Ljava/lang/String;)Ljava/lang/String;
- */
- JNIEXPORT jstring JNICALL Java_so_hello_SoHelloActivity_getString1
- (JNIEnv *, jobject, jstring name)
- {
- jstring mun = 0;
- //事先把libNativeExampleActivity放到root/system/lib/目录下
- filehandle = dlopen("/system/lib/libNativeExampleActivity.so", RTLD_LAZY);
- if(filehandle)
- {
- getStringFunc = (jstring (*)(JNIEnv *,jobject,jstring))dlsym(filehandle, "Java_org_natives_example_NativeExampleActivity_getString");
- if(getStringFunc)
- {
- mun = getStringFunc(env, obj, name);
- }
- dlclose(filehandle);
- filehandle = NULL;
- }
- return mun
- }
- LOCAL_PATH := $(call my-dir)
- include $(CLEAR_VARS)
- LOCAL_LDLIBS := -llog
- LOCAL_C_INCLUDES += system/core/include/cutils
- LOCAL_SHARED_LIBRARIES := \
- libdl \
- libcutils
- LOCAL_PRELINK_MODULE := false
- LOCAL_MODULE := libsoHello
- LOCAL_MODULE_TAGS := optional
- LOCAL_SRC_FILES := so_hello_SoHelloActivity.cpp
- LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
- include $(BUILD_SHARED_LIBRARY)
使用mm命令编译so_hello_SoHelloActivity.cpp,便可以生成libsoHello.so库。
综述:
这里主要使用了dlopen、dlsym、dlclose三个函数来加载so库:
void *filehandle = NULL;
jint (*addFunc)(JNIEnv *,jobject,jint,jint) = NULL;
jint mun = 0
//事先把libNativeExampleActivity放到root/system/lib/目录下
filehandle = dlopen("/system/lib/libNativeExampleActivity.so", RTLD_LAZY);
if(filehandle)
{
addFunc = (jint (*)(JNIEnv *,jobject,jint,jint))dlsym(filehandle, "Java_org_natives_example_NativeExampleActivity_addFunction");
if(addFunc)
mun = addFunc(env, obj, a, b);
dlclose(filehandle);
filehandle = NULL;
}
- 使用反编译后的so文件
- so文件的使用
- 反编译后的数组使用解析
- 简单的使用so文件
- gcc生成.so文件及.so文件的使用
- opencore音频输出文件编译后对应的so文件
- 除去反编译后的java文件的乱码
- 恢复Reflector反编译后资源文件的办法
- 恢复Reflector反编译后资源文件的办法
- apk反编译后修改文件的几个注意点
- 恢复Reflector反编译后资源文件的方法
- 恢复Reflector反编译后资源文件的办法
- 剔除java反编译文件后的无效注释信息
- Spring加载加密后的文件,防止反编译
- 恢复Reflector反编译后资源文件的办法
- 使用apktool反编译apk的XML文件
- 使用apktool反编译apk的XML文件
- 使用自己定义的so文件
- Java中Synchronized的用法
- 水题生成器
- redis
- 为什么?为什么?为什么WA啊!洛谷 [USACO1.1]贪婪的送礼者{已AC}
- 【JavaSE学习笔记】多线程02_Lock,死锁,等待唤醒机制,线程组和线程池,Timer定时器
- 使用反编译后的so文件
- react-native 下编写工具、Public类
- 栈和队列(习题)
- Python 实现爬取图片
- Generous Kefa
- C# 向MySQL数据库存储及读取图片、音乐等文件
- myeclipse中web项目出现红色叹号解决方案
- malloc/free和new/delete
- 【离散化+并查集】POJ_1733_Parity game