从ndk编译,说到so文件结构以及ida导入、导出函数

2023-05-16

一、背景

一直以来对ndk的编译链接所依赖的文件没有完成弄明白,还有ida的导入、导出函数与dynsym section之间的关系是什么?

 

二、ndk编译所依赖的文件

1、我们一般在Application.mk中指定所需要的平台版本和编译后so的架构。

APP_PLATFORM := android-21
APP_ABI := armeabi-v7a

这个android-21对应什么呢?这是android ndk的根目录。

这里指定的编译so时,链接时需要的so文件,如果指定了android-21,那么链接时就到这个目录下寻找so。

2、下面看下Android.mk

LOCAL_PATH := $(call my-dir)
  
include $(CLEAR_VARS)  
  
LOCAL_MODULE    := lesson2
  
LOCAL_SRC_FILES := Lesson2.cpp MyTest.cpp module.c

LOCAL_LDLIBS    := -llog -ldl -lmediandk -lGLESv2

LOCAL_CPPFLAGS += -O3

LOCAL_CFLAGS += -fvisibility=hidden
        
include $(BUILD_SHARED_LIBRARY)

-lmediandk在链接时会使用android-ndk-r21/platforms/android-21/arch-arm/usr/lib/libmediandk.so

-lGLESv2在链接时会使用android-ndk-r21/platforms/android-21/arch-arm/usr/lib/libGLESv2.so

3、Lesson2.cpp

#include <media/NdkMediaDrm.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

在使用函数的地方还需要包含头文件,这些头文件在哪呢?

android-ndk-r21/sysroot/usr/include

4、使用的交叉编译工具

android-ndk-r21/toolchains/llvm/prebuilt/darwin-x86_64/bin

 

三、ida中Exports、Imports与dynsym之间的关系

arm-linux-androideabi-readelf -s liblesson2.so

Symbol table '.dynsym' contains 61 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_atexit@LIBC (2)
     2: 00000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_finalize@LIBC (2)
     3: 00000000     0 FUNC    GLOBAL DEFAULT  UND AMediaDrm_createByUUID
     4: 00000000     0 FUNC    GLOBAL DEFAULT  UND dladdr@LIBC (3)
     5: 00000000     0 FUNC    GLOBAL DEFAULT  UND AMediaDrm_getPropertyByte
     6: 00000000     0 FUNC    GLOBAL DEFAULT  UND snprintf@LIBC (2)
     7: 00000000     0 FUNC    GLOBAL DEFAULT  UND _Znwj@LIBC_O (4)
     8: 00000000     0 FUNC    GLOBAL DEFAULT  UND __android_log_print
     9: 00000000     0 FUNC    GLOBAL DEFAULT  UND __stack_chk_fail@LIBC (2)
    10: 00000000     0 OBJECT  GLOBAL DEFAULT  UND __stack_chk_guard@LIBC (2)
    11: 00000000     0 FUNC    GLOBAL DEFAULT  UND __vsprintf_chk@LIBC (2)
    12: 00000000     0 FUNC    GLOBAL DEFAULT  UND gettimeofday@LIBC (2)
    13: 00000000     0 FUNC    GLOBAL DEFAULT  UND localtime@LIBC (2)
    14: 00000000     0 FUNC    GLOBAL DEFAULT  UND stat@LIBC (2)
    15: 00000000     0 FUNC    GLOBAL DEFAULT  UND strftime@LIBC (2)
    16: 00000000     0 FUNC    GLOBAL DEFAULT  UND time@LIBC (2)
    17: 00000000     0 FUNC    GLOBAL DEFAULT  UND vsnprintf@LIBC (2)
    18: 00000000     0 OBJECT  GLOBAL DEFAULT  UND __sF@LIBC (2)
    19: 00000000     0 FUNC    GLOBAL DEFAULT  UND abort@LIBC (2)
    20: 00000000     0 FUNC    GLOBAL DEFAULT  UND fflush@LIBC (2)
    21: 00000000     0 FUNC    GLOBAL DEFAULT  UND fprintf@LIBC (2)
    22: 00000000     0 FUNC    GLOBAL DEFAULT  UND __aeabi_memclr
    23: 00000000     0 FUNC    GLOBAL DEFAULT  UND __aeabi_memcpy
    24: 00000000     0 FUNC    GLOBAL DEFAULT  UND __gnu_Unwind_Find_exidx
    25: 00001e15    72 FUNC    GLOBAL DEFAULT   13 unw_set_reg
    26: 00001ed1     6 FUNC    GLOBAL DEFAULT   13 unw_step
    27: 00001f0d    28 FUNC    GLOBAL DEFAULT   13 unw_get_proc_name
    28: 00001f3b    12 FUNC    GLOBAL DEFAULT   13 unw_is_signal_frame
    29: 00001a75     8 FUNC    GLOBAL DEFAULT   13 __aeabi_unwind_cpp_pr0
    30: 00001abd   160 FUNC    GLOBAL DEFAULT   13 _Unwind_RaiseException
    31: 00001ed7    32 FUNC    GLOBAL DEFAULT   13 unw_get_proc_info
    32: 00001345   312 FUNC    GLOBAL DEFAULT   13 Java_com_example_ndkrever
    33: 00001aad     8 FUNC    GLOBAL DEFAULT   13 __aeabi_unwind_cpp_pr1
    34: 00001519    72 FUNC    GLOBAL DEFAULT   13 decode_eht_entry
    35: 00005004     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
    36: 00001ab5     8 FUNC    GLOBAL DEFAULT   13 __aeabi_unwind_cpp_pr2
    37: 00001d99    72 FUNC    GLOBAL DEFAULT   13 unw_init_local
    38: 00005005     0 NOTYPE  GLOBAL DEFAULT  ABS _end
    39: 00001e5d    56 FUNC    GLOBAL DEFAULT   13 unw_get_fpreg
    40: 0000147d    36 FUNC    GLOBAL DEFAULT   13 JNI_OnLoad
    41: 00005004     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
    42: 00001d15    52 FUNC    GLOBAL DEFAULT   13 _Unwind_GetRegionStart
    43: 00001561   616 FUNC    GLOBAL DEFAULT   13 _Unwind_VRS_Interpret
    44: 00001de1    52 FUNC    GLOBAL DEFAULT   13 unw_get_reg
    45: 00001925   336 FUNC    GLOBAL DEFAULT   13 _Unwind_VRS_Pop
    46: 00001875   176 FUNC    GLOBAL DEFAULT   13 _Unwind_VRS_Set
    47: 00001ef9    20 FUNC    GLOBAL DEFAULT   13 unw_resume
    48: 00001f47     6 FUNC    GLOBAL DEFAULT   13 unw_save_vfp_as_X
    49: 00001f35     6 FUNC    GLOBAL DEFAULT   13 unw_regname
    50: 00001231    80 FUNC    GLOBAL DEFAULT   13 _Z4testv
    51: 00001d49    12 FUNC    GLOBAL DEFAULT   13 _Unwind_DeleteException
    52: 00001d55    18 FUNC    GLOBAL DEFAULT   13 __gnu_unwind_frame
    53: 00001c75     2 FUNC    GLOBAL DEFAULT   13 _Unwind_Complete
    54: 00001d68     0 FUNC    GLOBAL DEFAULT   13 unw_getcontext
    55: 00001e95    60 FUNC    GLOBAL DEFAULT   13 unw_set_fpreg
    56: 00001f29    12 FUNC    GLOBAL DEFAULT   13 unw_is_fpreg
    57: 00001ce1    52 FUNC    GLOBAL DEFAULT   13 _Unwind_GetLanguageSpecif
    58: 00001c79   104 FUNC    GLOBAL DEFAULT   13 _Unwind_Resume
    59: 000017c9   172 FUNC    GLOBAL DEFAULT   13 _Unwind_VRS_Get
    60: 00005000     4 OBJECT  GLOBAL DEFAULT   21 unw_local_addr_space

ida Imports

ida Exports

ida Imports对应到dynsym,就是那些Value为00000000的符号。

ida Exports对应到dynsym,就是那些Value不为00000000的符号(个别_end没有放到ida的Exports中)。

使用arm-linux-androideabi-nm -D liblesson2.so,可以更加清楚和完整的看到函数名,和dynsym是一一对应的。

         U AMediaDrm_createByUUID
         U AMediaDrm_getPropertyByteArray
0000147c T JNI_OnLoad
00001344 T Java_com_example_ndkreverse2_Lesson2_main
00001c74 T _Unwind_Complete
00001d48 T _Unwind_DeleteException
00001ce0 T _Unwind_GetLanguageSpecificData
00001d14 T _Unwind_GetRegionStart
00001abc T _Unwind_RaiseException
00001c78 T _Unwind_Resume
000017c8 T _Unwind_VRS_Get
00001560 T _Unwind_VRS_Interpret
00001924 T _Unwind_VRS_Pop
00001874 T _Unwind_VRS_Set
00001230 T _Z4testv
         U _Znwj
         U __aeabi_memclr
         U __aeabi_memcpy
00001a74 T __aeabi_unwind_cpp_pr0
00001aac T __aeabi_unwind_cpp_pr1
00001ab4 T __aeabi_unwind_cpp_pr2
         U __android_log_print
00005004 A __bss_start
         U __cxa_atexit
         U __cxa_finalize
         U __gnu_Unwind_Find_exidx
00001d54 T __gnu_unwind_frame
         U __sF
         U __stack_chk_fail
         U __stack_chk_guard
         U __vsprintf_chk
00005004 A _edata
00005005 A _end
         U abort
00001518 T decode_eht_entry
         U dladdr
         U fflush
         U fprintf
         U gettimeofday
         U localtime
         U snprintf
         U stat
         U strftime
         U time
00001e5c T unw_get_fpreg
00001ed6 T unw_get_proc_info
00001f0c T unw_get_proc_name
00001de0 T unw_get_reg
00001d68 T unw_getcontext
00001d98 T unw_init_local
00001f28 T unw_is_fpreg
00001f3a T unw_is_signal_frame
00005000 D unw_local_addr_space
00001f34 T unw_regname
00001ef8 T unw_resume
00001f46 T unw_save_vfp_as_X
00001e94 T unw_set_fpreg
00001e14 T unw_set_reg
00001ed0 T unw_step
         U vsnprintf

这里面的U对应到ida的Imports里面,其他对应到ida的Exports里面。

注意有些大型的so,使用arm-linux-androideabi-nm -D 获取的信息是有重复的。比如_edata,__bss_start是重复的。还有些函数地址有两个名字,ida会智能标记上两个名字,但在ida Exports里面只有一份,这就是为什么arm-linux-androideabi-nm -D获取的行数大于ida Exports的原因。

 

四、so中.rel.dyn、.rel.plt、.plt、.got表

.rel.dyn、.rel.plt

00004f68  00000216 R_ARM_JUMP_SLOT   00000000   __cxa_finalize@LIBC
00004f6c  00000116 R_ARM_JUMP_SLOT   00000000   __cxa_atexit@LIBC
00004f70  00000e16 R_ARM_JUMP_SLOT   00000000   stat@LIBC
00004f74  00000816 R_ARM_JUMP_SLOT   00000000   __android_log_print
00004f78  00000916 R_ARM_JUMP_SLOT   00000000   __stack_chk_fail@LIBC

got表

在dlopen so时,会找到android_log_print的虚拟地址,然后根据.rel.dyn、.rel.plt提示的位置,写入got表。

在程序调用android_log_print是,首先会调用.plt,在.plt中得到刚才写入了got表中android_log_print的虚拟地址。然后跳转执行。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从ndk编译,说到so文件结构以及ida导入、导出函数 的相关文章

  • #VMware#ESXI ESXI如何修改管理IP

    目录 一 修改方法 1 进入硬件管理平台 2 登录虚拟控制台 二 实际操作 1 在主界面按 F2 并输入控制台界面root的密码 xff0c 进入设置界面 2 找到 configure Management Network 选项并按 Ent
  • #华为 #usg USG6000双链路透明部署实验(一)

    目录 一 实验背景 二 实验环境 三 实验步骤 1 在所有交换机创建对应vlan 2 在核心交换机创建网关 xff0c 所有的网段IP都是254 网段是10 10 10 0 24 10 10 13 0 24 3 配置接入交换机的管理IP x
  • #VMware#ESXI 修改主机的控制台HTTP/HTTPS端口

    目录 一 开启SSH服务 二 修改控制台的默认端口 1 关闭防火墙的情境下 xff1a 1 1 远程进入ESXI的后台 xff0c 修改HTTP端口配置文件 1 2 关闭ESXI防火墙 1 3 重启服务器 2 不关闭防火墙的情景下 xff1
  • #ESXI #Centos 业务服务器故障如何恢复盘

    一 环境描述 有一台centos7的业务服务器 xff0c 因为操作人员重大失误 xff0c 导致业务服务器宕机 xff0c 由于未做备份与快照 xff0c 无法进行恢复 xff0c 考虑通过将硬盘挂载在其他虚拟机上重新获取数据 设备环境为
  • pikachu 靶场搭建

    一 准备环境 1 搭建环境 win 10phpstudypikachu 2 下载链接 win10自行寻找资源 pickchu靶机下载地址 xff1a https github com zhuifengshaonianhanlu pikach
  • virtualbox命令行启动虚拟机和关闭虚拟机和虚拟机关闭防火墙

    查看virtualbox正在运行的虚拟机命令 VBoxManage list runningvms 根据查到的虚拟机 ip 号 使用后台命令启动虚拟机的方法 xff1a VBoxManage startvm ip 使用后台命令关闭虚拟机的方
  • android studio 最新3.0 kotlin与databinding 结合使用报错。

    最近android studio 3 0更新 xff0c 迫不及待将项目中的代码向kotlin转 其中转到有databinding的时候遇到报错 xff1a Unresolved reference databinding 找到网上解决办法
  • AS--›Android Studio内存大小设置和插件推荐(2021-1-14更新)

    调整AS的占用内存 多开工程毫无压力 AS 3 5 的版本 已经支持通过设置界面修改内存大小了 但是 旧方法依旧有效 文章目录 Windows修改方法MAC修改方法插件推荐 ignore A Search with GithubTransl
  • android Camera预览界面拉伸问题解决

    问题现象 项目中的扫一扫界面打开以后 xff0c 扫描二维码的界面显示的二维码被拉伸 xff0c 图片如下 xff1a 问题原因 通常 xff0c 拍照预览页面的视图拉伸主要与下面两个因素有关 xff1a Surfaceview的大小Cam
  • 什么是 AOP,AOP 的作用是什么?

    分析 amp 回答 AOP的介绍 AOP全称 xff08 Aspect Oriented Programming xff09 面向切片编程的简称 AOP面向方面编程基于IoC xff0c 是对OOP的有益补充 xff1b AOP利用一种称为
  • Ubuntu图形界面卡死的解决方法

    转到字符界面 xff1a Ctrl 43 Alt 43 F1 查看进程 xff1a ps t tty7 找到Xorg进程的PID号xxx xff0c 如992 杀死进程Xorg xff1a kill xxx xff08 这里是kill 99
  • 笔记本电脑电源指示灯亮但是黑屏开不了机(或者成功开机之后发现很卡顿)的解决方法

    问题描述 本人电脑是联想拯救者Y7000P xff0c 性能如下 近期遇到一个问题 xff0c 笔记本电脑开机的之后 xff0c 突然出现卡顿 xff0c 不管是打开浏览器还是打开软件 xff0c 都要等上几秒钟 xff0c 连刷新都要等一
  • windows下的WSL开发环境配置以及相关工具、插件

    最近在自己的X1上捣鼓Django框架的编程 xff0c windows环境使用起来确实让人痛苦 xff0c 因此决定还是在Linux系统下进行Django框架的编程 xff0c 跟朋友交流了一下 xff0c 最终敲定了以下方案并把中间使用
  • 最全spring框架工作流程

    Spring执行流程 xff1a 用户发起请求到前端控制器 xff08 DispatcherServlet xff09 xff0c 该控制器会过滤出哪些请求可以访问Servlet 哪些不能访问 就是url pattern的作用 xff0c
  • python多线程爬虫教学,清晰易懂。

    首先需要知道什么是多线程 xff0c 多线程的作用 首先举个例子 xff0c 并发和并行 xff1a 并发 xff1a 并发 xff0c 在操作系统中 xff0c 是指一个时间段中有几个程序都处于已启动运行到运行完毕之间 xff0c 且这几
  • ubuntu 下ethtool安装

    1 xff0c 下载安装包 xff1a ethtool 2 6 37 tar xff0c 将其放入自己的路径下 xff0c 解压 xff1a tar xvf ethtool 2 6 37 tar 2 cd ethtool 2 6 37 执行
  • 第四章_表达式_4.9 sizeof 运算符

    4 9 sizeof 运算符 4 9 sizeof 运算符 4 9 sizeof 运算符 sizeof运算符返回一条表达式或一个类型名字所占的字节数 sizeof运算符满足右结合律 xff0c 其所得的值是一个size t类型的常量表达式
  • 初探ViewBinding

    视图访问的方式有常用的findViewById xff0c ButterKnife等多种方式 xff0c 这些方式的各方面对比如下 如上图所示 xff0c 在简明 编译安全和编译速度上都各有优势 xff0c 那么有没有一种方式可以一石 34
  • Kotlin--›Android 超轻,超好用,超简洁,超超超级RecyclerView分割线ItemDecoration封装

    需求分析 如图所示的 101 共2人 这一行 顶部有 一块白色区域 可以当做是分割线101 共2人 这一行 底部有一个很细的分割线 差不多撑满了一行人物信息 这一行 首次出现时 只有底部有分割线 而且还是 非撑满一行的效果人物信息 这一行
  • Linux系统网络配置详解

    1 当一台Linux虚拟机刚创建完成是无法上网 xff0c 所以需要我们去配置网络 2 右击虚拟界面 xff0c 点击打开终端 3 查看虚拟机的网关 xff08 1 xff09 点击VMware Workstation左上角的编辑 xff0

随机推荐