cat dlopen.c

#include <stdio.h>
#include <dlfcn.h>int main(int argc, char *argv)
{int index = -1;void *handle;int (*get_index)(int);int ret = -1;// 获取handlehandle = dlopen("./liba.so", RTLD_NOW);if (handle == NULL) {printf("dlopen error!:%s\n", dlerror());return -1;}//获取函数,get_card_index为so中的实现函数,get_index指向该函数;get_index = dlsym(handle, "get_card_index");if (get_index == NULL) {printf("dlsym error!\n");dlclose(handle);return -1;}ret = get_index(index);printf("ret:%d\n", ret);// 关闭该handledlclose(handle);return 0;
}

cat test.c

int get_card_index(int num)
{return 123;
}

cat test.h

int get_car_index(int num);

编译和执行过程

syli@lishengyu-pc:~/work/tmp$ gcc -fPIC -shared -o liba.so test.c
syli@lishengyu-pc:~/work/tmp$ gcc dlopen.c -ldl
syli@lishengyu-pc:~/work/tmp$ ./a.out
ret:123

dlopen函数使用示例相关推荐

  1. 【Android 逆向】Android 进程注入工具开发 ( 注入代码分析 | 获取 linker 中的 dlopen 函数地址 并 通过 远程调用 执行该函数 )

    文章目录 一.dlopen 函数简介 二.获取 目标进程 linker 中的 dlopen 函数地址 三.远程调用 目标进程 linker 中的 dlopen 函数 一.dlopen 函数简介 dlo ...

  2. 【Android 逆向】Android 进程注入工具开发 ( EIP 寄存器指向 dlopen 函数 | ESP 寄存器指向栈内存 | 调试程序收回目标进程控制权 )

    文章目录 一.EIP 寄存器指向 dlopen 函数 二.ESP 寄存器指向栈内存 三.调试程序收回目标进程控制权 一.EIP 寄存器指向 dlopen 函数 代码段中 , 一般都有 dlopen 函 ...

  3. php指定长度 分割整形,php指定长度分割字符串str_split函数用法示例

    本文实例讲述了php指定长度分割字符串str_split函数用法.分享给大家供大家参考,具体如下: 示例1:$str = 'abcdefgh'; $arr = str_split($str,2); 运 ...

  4. android 禁用dlsym_Android 7.0 dlopen 函数分析

    1. 说明 Android 7.0 后使用 dlopen 函数无法获取 soinfo 对应,因此也无法使用 dlsym 函数去调用第三方的 so 内的函数.这里给出 dlopen() 函数的源码分析. ...

  5. getdate函数_PHP getdate()函数与示例

    getdate函数 PHP getdate()函数 (PHP getdate() function) getdate() function is used to get the local date/ ...

  6. 安卓log.e函数打印示例_log1p()函数以及C ++中的示例

    安卓log.e函数打印示例 C ++ log1p()函数 (C++ log1p() function) log1p() function is a library function of cmath ...

  7. gettimeofday_PHP gettimeofday()函数与示例

    gettimeofday PHP gettimeofday()函数 (PHP gettimeofday() function) gettimeofday() function is used to g ...

  8. dir函数_PHP dir()函数与示例

    dir函数 PHP dir()函数 (PHP dir() function) dir() function is an instance of the directory class, it is u ...

  9. PHP rewinddir()函数与示例

    PHP rewinddir()函数 (PHP rewinddir() function) rewinddir() function is used to rewind/reset the direct ...

最新文章

  1. 网站站内优化新方案,SEO运营人员值得一看
  2. 倒序查询_mysql大表分页查询翻页优化方案
  3. C语言矩阵N*N旋转的算法(附完整源码)
  4. 双指针 - 四数之和
  5. 深入浅出MFC文档/视图架构之文档模板
  6. sql server 按照日期自动生成单据编号的函数
  7. WinCE 6.0中断驱动程序分析
  8. 大数据之-Hadoop之HDFS的API操作_文件IO流_上传_案例---大数据之hadoop工作笔记0063
  9. 采用Locust对grpc协议进行压测
  10. 网络编程基础(Socket ServerSocket)
  11. 如何将MBR分区转换成GPT分区
  12. 中国广电5G套餐价格实惠,但是又没有预期那么便宜
  13. 利用python进行数据处理
  14. H5 页面适配所有 iPhone 和安卓机型的六个技巧
  15. 电脑连接热点无internet访问权限_电脑连接无线网,显示无网络访问权限
  16. 物联网+人工智能:发那科、思科、罗克韦尔自动化联合推出FIELD system
  17. java swfupload 302_swfupload Upload Error 302 错误解决办法
  18. 51 nod 1625 夹克爷发红包【贪心、二进制枚举】
  19. PMP 考试一定要报培训班吗?
  20. Java面试java基础,重庆java哪家培训班好

热门文章

  1. [MemTest太慢? 来试试这个压力更大吧!]分享一个快速测试内存超频出错的软件-TM5(和国外大佬的极限自定义配置)
  2. 轮廓中对踵点/旋转卡壳
  3. C++ opencv批量修改图片大小
  4. 如何在window10系统上简单快捷下载b站视频
  5. 金蝶K3物料计量单位后台调整SQL语句
  6. 分频器设计(三)小数分频
  7. 单片机四线步进电机驱动 PROTEUS 和51单片机教程(附仿真文件+源代码)
  8. 操作系统——存储器管理(连续分配存储管理方式)
  9. Winform控件开发(1)——Label(史上最全)
  10. 冯登国院士:关键信息基础设施安全保护的三个视角