IDA动态调试之生成so文件

本文详细介绍了如何在Android Studio(AS)中利用IDA进行动态调试,包括配置MainActivity.java,生成JNI头文件,编写C程序,配置NDK与C++编译选项,解决Lambda语法不支持问题,以及链接库设置。此外,还提供了JNI开发流程、布局UI创建和Android反编译进阶资源链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.配置MainActivity.java

package xiziyunqi.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

// Used to load the 'native-lib' library on application startup.

static {
    System.loadLibrary("totoc");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Example of a call to a native method
    findViewById(R.id.button).setOnClickListener((v)->{
            boolean res = isEquals("123456");
            Log.i("jw", "res:" + res);
    });
}

/**
 * A native method that is implemented by the 'totoc' native library,
 * which is packaged with this application.
 */
private native boolean isEquals(String str);

}

2.生成头文件
第一步:
cd 到app\src\main(工作路径,在次路径下生成jni文件夹)
第二步,执行:
javah -d jni -classpath C:\Users\BFS039\AppData\Local\Android\sdk\extras\android\m2repository\com\android\support\appcompat-v7\26.0.0-alpha1\appcompat-v7-26.0.0-alpha1-sources.jar;….\build\intermediates\classes\debug xiziyunqi.myapplication.MainActivity
注意:
appcompat-v7-26.0.0-alpha1-sources.jar后要有分号

….\build\intermediates\classes\debug(进入到生成class类文件的目录)

xiziyunqi.myapplication.MainActivity(对目录下的该类文件执行javah产生头文件到工作路径)

如果提示找不到类文件(在-classpath加上sdk/…/android.jar)

3.根据头文件对函数的声明补全c程序

4.配置
1配置ndk
ndk {
moduleName “totoc”
abiFilters “armeabi”,”armeabi-v7a”,”x86”
}
2C++的编译配置
Put this part in build.gradle(Module:app) above buildTypes{}

sourceSets {
main {
jni.srcDirs = []
}
}

出现的问题
1.不支持Lambda语法(gradle编译)
解决办法:
在app目录的build.gradle中加上:
Android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
jackOptions {
enabled true
}
2.如果默认勾选了include C++
在cmakelist下做相应更改
#Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
native-lib

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         # Associated headers in the same location as their source
         # file are automatically included.
         src/main/cpp/native-lib.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
log-lib

          # Specifies the name of the NDK library that
          # you want CMake to locate.
          log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
native-lib

                   # Links the target library to the log library
                   # included in the NDK.
                   ${log-lib} )

3布局UI的路径
这里写图片描述

参考网址:
1.布局UI:
https://developer.android.com/studio/write/layout-editor.html
2.AS添加按钮:
http://blog.youkuaiyun.com/mghhz816210/article/details/51673558
3.JNI开发流程:
http://www.jianshu.com/p/e18ee69a8ba1
4.拓展:
http://www.wjdiankong.cn/android%E9%80%86%E5%90%91%E4%B9%8B%E6%97%85-%E5%8A%A8%E6%80%81%E6%96%B9%E5%BC%8F%E7%A0%B4%E8%A7%A3apk%E8%BF%9B%E9%98%B6%E7%AF%87ida%E8%B0%83%E8%AF%95so%E6%BA%90%E7%A0%81/

https://www.52pojie.cn/thread-579531-1-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值