首页
社区
课程
招聘
[求助]关于va中native hook的偏移量计算方式
发表于: 2018-5-10 19:27 3351

[求助]关于va中native hook的偏移量计算方式

2018-5-10 19:27
3351





void mark() {
// Do nothing
};


图一可以看到patchEnv.native_offset是由java定义的一个native方法 在这个文件中定义了个mark方法 这个native方法到mark方法的offset为什么能代表所有native方法的一个偏移 hook其他native方法可以直接去使用这个offset 能有人解释一下这是什么原理吗 或者给个内存结构 还有就是为什么offset每次+4 且不能大于100?

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 1
支持
分享
最新回复 (2)
雪    币: 32
活跃值: (1020)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
class  ArtMethod  {
public:
       
        //  Field  order  required  by  test  "ValidateFieldOrderOfJavaCppUnionClasses".
        //  The  class  we  are  a  part  of.
        uint32_t  declaring_class_;
        //  Short  cuts  to  declaring_class_->dex_cache_  member  for  fast  compiled  code  access.
        uint32_t  dex_cache_resolved_methods_;
        //  Short  cuts  to  declaring_class_->dex_cache_  member  for  fast  compiled  code  access.
        uint32_t  dex_cache_resolved_types_;
        //  Access  flags;  low  16  bits  are  defined  by  spec.
        uint32_t  access_flags_;
        /*  Dex  file  fields.  The  defining  dex  file  is  available  via  declaring_class_->dex_cache_  */
        //  Offset  to  the  CodeItem.
        uint32_t  dex_code_item_offset_;
        //  Index  into  method_ids  of  the  dex  file  associated  with  this  method.
        uint32_t  dex_method_index_;
        /*  End  of  dex  file  fields.  */
        //  Entry  within  a  dispatch  table  for  this  method.  For  static/direct  methods  the  index  is  into
        //  the  declaringClass.directMethods,  for  virtual  methods  the  vtable  and  for  interface  methods  the
        //  ifTable.
        uint32_t  method_index_;
        //  Fake  padding  field  gets  inserted  here.
        //  Must  be  the  last  fields  in  the  method.
        //  PACKED(4)  is  necessary  for  the  correctness  of
        //  RoundUp(OFFSETOF_MEMBER(ArtMethod,  ptr_sized_fields_),  pointer_size).
        struct  PtrSizedFields  {
                //  Method  dispatch  from  the  interpreter  invokes  this  pointer  which  may  cause  a  bridge  into
                //  compiled  code.
                void*  entry_point_from_interpreter_;
                //  Pointer  to  JNI  function  registered  to  this  method,  or  a  function  to  resolve  the  JNI  function.
                void*  entry_point_from_jni_;
                //  Method  dispatch  from  quick  compiled  code  invokes  this  pointer  which  may  cause  bridging  into
                //  the  interpreter.
                void*  entry_point_from_quick_compiled_code_;
        }  ptr_sized_fields_;
};

这个是  ArtMethod的结构体,看到  entry_point_from_jni_  那个成员了吗?当JNI方法注册好了的时候,entry_point_from_jni_  这个字段的值就是那个native方法的函数指针。VA的做法就是从  ArtMethod开头往后搜索内存,搜到  那个已知的指针的值的时候,就代表找到了对应的偏移。

所有ArtMethod都是用这个结构表示的,因此这个偏移在同一个系统上,是固定不变的。至于为什么  +4,字节对齐的原因。为什么不能大于100,因为ArtMethod结构体不可能有这么大,超过这么多还没搜到表示搜不到没必要搜了。
2018-5-11 12:06
0
雪    币: 169
活跃值: (38)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
@twsxtd  谢谢!感激不尽
2018-5-14 10:28
0
游客
登录 | 注册 方可回帖
返回
//