注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

蒙奇D小豌豆的博客

蒙奇D小豌豆的学习记录

 
 
 

日志

 
 

convert an absolute address to function pointer  

2012-03-30 17:33:17|  分类: kernel |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

         How to convert an absolute address to function pointer? Maybe you feel this is a strange way to use an absolute address in function way. But sometimes it’s very useful for us. Such as in linux we can not  access the function in kernel for the Symbol reason, But we can get the function address through Sysmap file. So we can use the function in this strange way.

       1. We should know the function’s protype.

For the module_alloc example, module_alloc: it is a function that allocate some kernel memory which can excuted by kernel.  For the symbol reason, the function can’t be access in modules(.ko file).

The function protype is 
               void *module_alloc(unsigned long size),
 So we define the protype.

            typedef void *(*)( unsigned long size)   execute_alloc

       2.  Get the absolute address of the function

 root@ubuntu # cat /boot/System.map-3.1.0-rc9+ | grep module_alloc

ffffffff810376d0 T module_alloc

The address is shown above!

      3.      Convert the absolute to the function and run it

void* (*funcptr) (unsigned long size); 

 funcptr  = (execute_alloc)(0xffffffff810376d0);

Or direct way

funcptr = (void *(*)( unsigned long size))(0xffffffff810376d0); 

run it :

unsigned long size = 0x1000;

(*funcptr)(size);

  评论这张
 
阅读(340)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018