`
zhangjia328
  • 浏览: 17883 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

IDA Pro Plug-in 学习笔记

阅读更多

1、            IDA Pro中的segment结构与PE文件中节区的对应关系

           IDA Pro的反汇编后,PE文件中的.code节区(存放代码的节区)对应IDA Pro中名为_textsegment(code segment), .rdata节区(只读数据节区)中的导入表部分对应IDA Pro中名为_idatasegment, .radata节区中自定义的数据部分对应IDA Pro中名为_rdatasegment(data segment).

           实际上,PE文件中的导入表在反汇编的结果中并不对应实际的segment,因为该段的type值为SEG_XTRN( this segments contain no instructions or data and are not declared as 'segments' in the disassembly), IDA Pro在自己的数据库中为导入表定义一个段(逻辑上的)是为了分析的方便,因为导入表中每个dwordPE文件装载到内存中后存放的是相应导入函数的入口地址,IDA Pro模拟PE文件装载的过程,分析出了这些导入函数的信息,并用这些函数的信息(包括函数名,参数列表)为相应的入口地址命名(效果相当于存储单元的变量名),从而给分析带来了方便。

 

2 如何得到段名

           segment_t中有name数据项,但该数据项是uval_t类型,实际中存放的一个很大数值(现在还不清楚该数值代表的意义),所以,得到一个segment的名称只能调用get_segm_name()函数,该函数返回一个诸如.text的字符串,函数原型为:idaman char *ida_export get_segm_name(const segment_t *s)

 

3IDA Pro SDK中的字符串函数

(1)IDA Pro SDK中等同strstr()的函数:

idaman char *ida_export stristr(const char *s1,const char *s2)

s1中寻找匹配s2的子串,并返回第一个匹配的子串的指针,若无匹配的子串,返回NULL

(2)IDA Pro中替换strcpy的函数:

idaman char *ida_export qstrncpy(char *dst, const char *src, size_t dstsize);

 

4IDA Pro SDK 的头文件中涉及I/O的函数的命名都是在标准C库相应的函数名前加一个前缀q, 其原因为(摘自IDAPro SDK4.8 include\fpro.h)

       This file contains q.. counterparts of FILE* functions from Clib. The only difference is that they set 'qerrno' variable too. You should not use C standard I/O functions in your modules. The reason: Borland keep FILE * information local to a DLL so if you open a file in the plugin and pass the handle to the kernel, the kernel will not be able to use it.

 

5IDA Pro SDK中的字符函数

(1)   int isalnum(int ch)

说明:isalnum()函数的原型在ctype.h,使TC库中的函数。如果函数isalnum()的参数是字母表中的一个字母(大写或小写)或是一个数字,则函数将返回非零值,如果不是一个字母或数字,则返回零。

 

6IDA Pro SDK中的与用户交互的函数

(1)   弹出地址输入对话框的函数:askaddr()

           这是一个内置函数,实际上是调用相应的callui()函数:

callui(ui_askaddr, addr, format, va)

 

7IDA Pro SDK中关于寄存器的函数

(1)从寄存器中取值的函数

get_reg_val(): read a register value from the current thread

 

8Trace event debugger event notifications的区别

(1)  Trace 有三种类型: Function tracing, Instruction tracing and Breakpoint (otherwise known as read/write/execute) tracing.  When writing plug-ins, an additional form of tracing is available: Step tracing. Step tracing is a low level form of tracing that allows you to build your own tracing mechanism on top of it, utilising event notifications (see section 4.5) to inform your plug-in of each instruction that is executed.      

       Trace运行的机制:A "trace event" is generated and stored in a buffer when a trace occurs, and what triggers the generation of a trace event depends on the type of tracing you have enabled, however it's worth

noting that step tracing will not generate trace events, but event notifications instead.

All the different trace event types along with the corresponding tev_type_t enum value are as follows: (which is defined in dbg.hpp.)

Trace Type               Event Type

Funciton call and return    tev_call and tev_ret

instruction                tev_insn

          Breakpiont                tev_bpt

       All trace events are stored in a circular buffer, so it never fills up, but old trace events will be overwritten if the buffer is too small. Each trace event is represented by the tev_info_t struct.

       Based on the bpt_t struct described in section 4.4.3, a breakpoint trace is the same as a normal breakpoint but has the BPT_TRACE flag set on the flags member. Optionally, the condition buffer member could have an IDC command to run at each breakpoint.

       可见,Trace的机制是先在plug-inenable某些类型的trace, 然后在plug-in中有一个不断检测存放trace eventbuffer的函数,并根据trace event的类型进行相应的处理。

(2)  Debugger Event Notifications中的HignLevel Event Notifications中,有一种Event Notifications: dbg_trace(defined in [dbg_notifications_t] enum).

即在每个instruction was executed 后,Debugger 会产生 dag_trace类型的 Event notifications 这种类型的 Event Notifications需要处理器的step trace的支持。实际上这就是(1)中提到的Step tracing 它不同于Trace event, 因为它的运行机制是Event Notifications的运行机制,即在plug-inIDAP_init()函数中先对接受的Event 进行注册,同时注册处理该Event Notifications的回调函数,在运行过程中,一旦IDA产生了相应的Event Notification,则自动调用相应的回调函数。

(3)由以上分析,可以看到Trace的机制 Event Notifications的机制是不同的,而且所处理的情况也是不同的,Trace可以对函数的入口出口、指令、断点进行跟踪,而Event Notifications的机制则类似于windows的消息处理,可以处理很多事件。 其实,step traceing 严格来说,不属于trace的范,也不属于Event Notifications的范围,因为,在实现step traceing之前,必须先enable该类型的traceing(调用enable_step_trace()request_enable_step_trace()),但该step traceing 并不产生 trace event, 而是产生Event Notifications,即处理的机制与Event Notifications相同。

 

9IDA Plug-inIDAP_init()被调用的时间

IDAP_init()IDA is loading the first file for disassembly 时别调用。而IDAP_run()须由用户通过Edit->Plugins menu或通过插件的热键调用。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics