[转载]IDA简易教程
<P>作者:www.datarescue.com<BR>信息来源:看雪学院</P><P>IDA简易教程<BR>作者:<A href="http://www.datarescue.com">www.datarescue.com</A><BR> <A href="mailto:winroot@126.com">mailto:winroot@126.com</A></P>
<P>2004-11-20 初步翻译完成,希望大家指正错误,谢谢!</P>
<P style="MARGIN-TOP: 2px">我的鸟语太差大概翻译了一下,大家凑合着能看懂就行了:-)有些地方用自己理解的意思改写了一下!</P>
<P style="MARGIN-TOP: 2px">本文的主要内容就是讲如何用IDA来辅助识别各种类型的数据.</P>
<P style="MARGIN-TOP: 2px">版权信息:所有版权归原文作者所有,如许转载清保持文章完整性。</P>
<P style="MARGIN-TOP: 2px"><A name=索引><FONT color=#ff0000>索引</FONT></A></P>
<P style="MARGIN-TOP: 2px"><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第一节:C语言的小程序">1 第一节:C语言的小程序</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第二节:基本类型的识别">2 第二节:基本类型的识别</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第三节:操作数格式">3 第三节:操作数格式</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第四节:字符和字符串的操作">4 第四节:字符和字符串的操作</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第五节:数组">5 第五节:数组</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第六节:枚举类型">6 第六节:枚举类型</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第七节:Bit-fields(位域)">7 第七节:Bit-fields(位域)</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第八节:结构体">8 第八节:结构体</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第九节:结构变量和结构数组">9 第九节:结构变量和结构数组</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第十节:联合体和结构体中的结构体">10 第十节:联合体和结构体中的结构体</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第十一节:可变的结构体">11 第十一节:可变的结构体</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第十二节:结构体偏移">12 第十二节:结构体偏移</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第十三节:联合体偏移量">13 第十三节:联合体偏移量</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第十四节:地址偏移量">14 第十四节:地址偏移量</A><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#第十五节:最终逆向结果">15 第十五节:最终逆向结果</A><BR><BR><BR><A href="file:///F:/My%20web/practise/IDA简易教程.htm#附录">附录</A></P>
<P style="MARGIN-TOP: 2px"> </P>
<P style="MARGIN-TOP: 2px"><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman; mso-bidi-font-family: Times New Roman; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><A name=第一节:C语言的小程序>第一节:C语言的小程序</A></SPAN></P>
<P style="MARGIN-TOP: 2px"><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">为了演示</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">IDA</SPAN><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">的功能先写一段小程序。(代码在附录)<A href="file:///F:/My%20web/practise/IDA简易教程.files/data.exe">程序在此</A> <A href="file:///F:/My%20web/practise/IDA简易教程.files/data.CPP">源代码</A></SPAN></P>
<P><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman; mso-bidi-font-family: Times New Roman; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">程序执行结果:</SPAN></P>
<P><FONT face="Courier New" color=#0000ff size=1>CUSTOMERS:<BR>CUSTOMER 0001: Peter (m)<BR>CUSTOMER 0002: John (m)<BR>CUSTOMER 0003: Mary (f)<BR><BR>PRODUCTS:<BR>PRODUCT 0001: BOOK: IDA QuickStart Guide<BR>PRODUCT 0002: SOFTWARE: IDA Pro: PC; WINDOWS DOS; DISASSEMBLY<BR>PRODUCT 0003: SOFTWARE: PhotoRescue: PC MAC; WINDOWS OS-X; RECOVERY<BR>PRODUCT 0004: SOFTWARE: aCrypt: PC; WINDOWS; CRYPTOGRAPHY</FONT></P>
<P><FONT face="Courier New" color=#0000ff size=1> </FONT><A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引"><FONT color=#0000ff>TOP</FONT></A></P>
<P><FONT face="Courier New" size=1>----------------------------------------------------------------------</FONT></P>
<P><A name=第二节:基本类型的识别>第二节:基本类型的识别</A></P>
<P><FONT size=2>用IDA分析我们前面的程序,我们会发现下图的类型</FONT></P>
<P><IMG height=91 src="http://www.pediy.com/practise/IDA.files/dbdwdd.gif" width=427 border=0></P>
<P><FONT size=2>只要按"D"我们就可以任意转换这些不确定的类型.可以变成byte,word,dword(db,dw,dd)。</FONT></P>
<P><FONT size=2>当然你也可以设置更多的数据转换类型:</FONT></P>
<P><FONT size=2>选择“<I>Options</I>”菜单的“<I>Setup data types</I>”命令就可以设置了</FONT></P>
<P><IMG height=361 src="http://www.pediy.com/practise/IDA.files/datatypedlg.gif" width=392 border=0></P>
<P><FONT size=2>值得注意的是:你在数据转换的时候,它是依据数据自身的结构来转换的。我们按“D”的时候,</FONT></P>
<P><FONT size=2>如果下一个字节已经被你转换过,你的本次转换,IDA将会提示让你确认。</FONT></P>
<P><IMG height=256 src="http://www.pediy.com/practise/IDA.files/autoundef.gif" width=449 border=0></P>
<P><FONT size=2>注:如果你想改变这种默认设置可以在“<I>Options</I>”菜单“<I>Convert already defined bytes</I>”命令里设置</FONT></P>
<P><IMG height=370 src="http://www.pediy.com/practise/IDA.files/autoundefopt.gif" width=475 border=0></P>
<P><FONT size=2><B>撤销你的所有转换按“U”键。</B></FONT></P>
<P> <A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引">TOP</A></P>
<P><FONT size=2>-------------------------------------------------------------------------------------</FONT></P>
<P><A name=第三节:操作数格式>第三节:操作数格式</A></P>
<P><FONT size=2>数据类型自定义转换后,被操作过的数据(就是你按过“D”的)的进制IDA也是可以自定义转变的,</FONT></P>
<P><FONT size=2>通过在“<I>Operands</I>”工具栏的“<I>Number</I>”命令我们可以随意转换数字的进制</FONT></P>
<P><IMG height=192 src="http://www.pediy.com/practise/IDA.files/opnumber.gif" width=371 border=0></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><FONT size=2>最下面的“Toggle leading point”就是填补数据前的空位为0(就是说如果当前数据未占满数据格式的所有位高位用0来填补)</FONT></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><IMG height=211 src="http://www.pediy.com/practise/IDA.files/opzero.gif" width=569 border=0></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left> </P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left> </P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><FONT size=2>IDA还可以转换数据的标志位(就是正负)具体操作如下图:</FONT></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><IMG height=226 src="http://www.pediy.com/practise/IDA.files/opsignnot.gif" width=466 border=0></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left> </P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><FONT size=2>最后呢~~如果这些转换你还不满意(够BT)当然你还可以自定义数据进制如图:</FONT></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><IMG height=367 src="http://www.pediy.com/practise/IDA.files/opmanual.gif" width=527 border=0></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引"> TOP</A></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left>-----------------------------------------------------------------------------------------</P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><A name=第四节:字符和字符串的操作>第四节:字符和字符串的操作</A></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left> </P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><FONT size=2>作者又说话了:很多程序都是包含字符串的,一些被操作过的数据(就是你按过“D”的)可以转化为</FONT></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><FONT size=2>字符,使用的命令就在“<I>Operands</I>”工具栏上</FONT></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left><IMG height=242 src="http://www.pediy.com/practise/IDA.files/opchar.gif" width=372 border=0></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; LINE-HEIGHT: 100%" align=left> </P>
<P><FONT size=2>由于编程语言的不同造成字符串也有不同的格式,当然IDA就支持所有的格式了。</FONT></P>
<P><FONT size=2>IDA在转化后会在地址添加一个名字。因为我们的程序是c的所以就找到c的字符串。具体操作如图:</FONT></P>
<P><IMG height=265 src="http://www.pediy.com/practise/IDA.files/string.gif" width=378 border=0></P>
<P><FONT size=2>如果不是C写的程序怎么办呢?我们可以在“<I>Options</I>”菜单“<I>ASCII string style</I>”命令中设置。</FONT></P>
<P><FONT size=2>允许你修改其它类型为默认设置,使用默认设置的快捷键是“A”,或者自定义一种类型可以使用不常用的终止字符。</FONT></P>
<P><IMG height=410 src="http://www.pediy.com/practise/IDA.files/stringopt.gif" width=460 border=0></P>
<P><A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引"> TOP</A></P>
<P>--------------------------------------------------------------------------</P>
<P><A name=第五节:数组>第五节:数组</A></P>
<P><FONT size=2>在c中,ASCII字符串被认为是字符数组,IDA是如何处理数组的呢?<BR>我们用最常用命令来定义数组中的第一个元素,设置第一个元素类型为byte,格式为char,然后点击“*”号键(或者“Edition ”工具栏的“Array”命令)来创建数组。这时弹出一个对话框,可以设置很多变量。</FONT></P>
<P><IMG height=401 src="http://www.pediy.com/practise/IDA.files/array1.gif" width=618 border=0></P>
<P><FONT size=2>你可以定义数组一行的显示个数,还可以使用“Element width”来设置他们之间的宽度。<BR>使用“Use dup construct ”选项可以合并连贯的相似字节,“ Display index ”选项可以像注释一样显示数组的下标。<BR><BR>例如我们设置一个有64个元素的数组,一行有8个元素,每个元素之间的宽度为4,不选取“dup constructs”,选取“Display index ”,我们就可以得到下面的数组。</FONT></P>
<P><IMG height=199 src="http://www.pediy.com/practise/IDA.files/array2.gif" width=615 border=0></P>
<P><FONT size=2>当IDA遇到未被识别的字节他会用红色的高亮显示。</FONT></P>
<P><FONT size=2><BR>当然你也可以选择一个范围来创建数组,IDA会自适应的设定。</FONT></P>
<P><IMG height=406 src="http://www.pediy.com/practise/IDA.files/array3.gif" width=620 border=0></P>
<P><A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引"> TOP</A></P>
<P>------------------------------------------------------------------------------------</P>
<P><A name=第六节:枚举类型>第六节:枚举类型</A></P>
<P><FONT size=2>还记得我们在C程序中定义的product_category_t 类型吗?<BR>让我们用IDA的“Enumerations”来定义一下。<BR><BR>首先,我们打开“Enumerations”窗口来创建一个新的枚举类型</FONT></P>
<P><IMG height=464 src="http://www.pediy.com/practise/IDA.files/enumadd.gif" width=712 border=0></P>
<P> </P>
<P><FONT size=2>我们输入我们的枚举类型值</FONT></P>
<P><IMG height=376 src="http://www.pediy.com/practise/IDA.files/enumaddmember.gif" width=709 border=0></P>
<P> </P>
<P><FONT size=2>在check_product()函数,我们可以用枚举类型重新定义一些操作数。<BR>右键点击在数值上,就会弹出一个菜单,选择“Symbolic constant”。<BR>IDA就会自动列举枚举值,用以匹配当前的数值。</FONT></P>
<P><IMG height=221 src="http://www.pediy.com/practise/IDA.files/enumapply.gif" width=788 border=0></P>
<P> </P>
<P><FONT size=2>操作完成,我们就会得到下面的结果:</FONT></P>
<P><IMG height=221 src="http://www.pediy.com/practise/IDA.files/enumapply.gif" width=788 border=0></P>
<P><A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引"> TOP</A></P>
<P>-----------------------------------------------------------------------------------------------------</P>
<P><A name=第七节:Bit-fields(位域)>第七节:Bit-fields(位域)</A></P>
<P><FONT color=#ff0000 size=2>BTW:Bit-fields,我的理解就是在结构体中的位标志。太菜!希望高手指正!</FONT></P>
<P><FONT size=2>现在,我们来定义一下在software_info_t 结构中的bitfields。<BR>IDA的观点就是,bitefields是一种特殊的枚举类型。<BR>我们可以选择在枚举类型创造窗口中的“Bitfield”选项。</FONT></P>
<P><IMG height=398 src="http://www.pediy.com/practise/IDA.files/bfadd.gif" width=337 border=0></P>
<P><FONT size=2>还记得我们曾经在我们的程序中建立了两种不同类型的bitfields ,<BR>plateform和os包含了一种隐藏的模式:用来包含组合模式(用逻辑或来操作) 。因为一种产品可以同时在几种plateforms和OS的组合。另一方面,category bitfield 中每一个数字表示一种类别:一种产品每次只能属于一种类别。<BR>在IDA中一种指定的模式,bitfield只能包含一个值。所以在描述plateform 和category bitfields时为了显示组合模式,我们必须创建一个小的bitfields,每个值的一个bit.</FONT></P>
<P><IMG height=283 src="http://www.pediy.com/practise/IDA.files/bfaddmember1.gif" width=721 border=0></P>
<P><FONT size=2>现在我们开始创建category bitfield。mask值为0x3 (2 bits).我们指定一个名字、一个值、还有bitfield mask。我们还需要定义mask的名字:这个我们不用IDA自动生成的,IDA有一个内存助手可以帮助生成。</FONT></P>
<P><IMG height=283 src="http://www.pediy.com/practise/IDA.files/bfaddmember2.gif" width=721 border=0></P>
<P><FONT size=2>当所有的bitfields被输入,我们就会得到下面的结果:</FONT></P>
<P><IMG height=248 src="http://www.pediy.com/practise/IDA.files/bf.gif" width=384 border=0></P>
<P><FONT size=2>用Operands 工具栏上的Enum member命令就可以定义我们程序中的Enum member数据</FONT></P>
<P><IMG height=368 src="http://www.pediy.com/practise/IDA.files/bfapply.gif" width=788 border=0></P>
<P> <A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引">TOP</A></P>
<P>---------------------------------------------------------------------------------------------------------</P>
<P><A name=第八节:结构体>第八节:结构体</A></P>
<P><FONT size=2>我们的程序当中包含了很多结构体。现在让我们来在IDA中描述一下结构体,<BR>看看是怎么提高汇编代码的可读性。<BR>第一步,我们必须打开Structures 窗口,来创建一个新的结构体类型。</FONT></P>
<P><IMG height=394 src="http://www.pediy.com/practise/IDA.files/stradd.gif" width=788 border=0></P>
<P><FONT size=2>结构体的成员是一汇编的模式定义的。让我们来定义software_t 结构中的第一个成员。<BR>一直按“D”知道它变成“dd”意思就是这个成员的值为 dword类型。<BR>把它的格式定义为我们以前定义好的software_info_t 枚举类型,然后我们用Rename命令输入一个适当的名字:info</FONT></P>
<P><IMG height=243 src="http://www.pediy.com/practise/IDA.files/straddmember1.gif" width=568 border=0></P>
<P><FONT size=2>开始定义第二个成员,这次使用ASCII命令(按“A”),在这个环节<BR>IDA会弹出一个专用对话框用来设定字符串的大小</FONT></P>
<P><IMG height=364 src="http://www.pediy.com/practise/IDA.files/straddmember2.gif" width=692 border=0></P>
<P><FONT size=2>我们还可以从已经分析好的数据中来建立结构体。<BR>举个例子:假设我们选择了一块数据正好是和我们的customer_t结构体的数据格式一样,我们就可以用IDA的“Create struct from data ”命令来创建结构体</FONT></P>
<P><IMG height=364 src="http://www.pediy.com/practise/IDA.files/strfromdata.gif" width=761 border=0></P>
<P> </P>
<P><FONT size=2>一旦使用了这个命令,IDA就会在Structures窗口创建一个相对应的结构体<BR>我们使用“A”键来修改name成员的长度为32bytes(和我们源代码中定义的一样),然后再给结构体一个好听的名字。</FONT><BR><BR><FONT size=2><BR>我们拿这些结构体有什么用呢?IDA提供给我们两种方法:<BR>·Apply structure types to initialized data in the program.<BR>·Convert operands as offsets inside structures.<BR>我们将在下面的教程当中来介绍这两种方法</FONT></P>
<P> <A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引">TOP</A></P>
<P><FONT size=2>---------------------------------------------------------------------------------------------------------------------</FONT></P>
<P><A name=第九节:结构变量和结构数组>第九节:结构变量和结构数组</A></P>
<P><FONT size=2>现在让我们用来customer_t结构体整理另外一个客户信息John。<BR>把鼠标指针放在我们定义的结构体的第一个自己上面,然后使用Struct var命令。</FONT></P>
<P><IMG height=368 src="http://www.pediy.com/practise/IDA.files/strapply.gif" width=788 border=0></P>
<P><FONT size=2>这样我们就得到了一个新的结构体变量。IDA会自动在结构体成员的后面加上变量名的。</FONT></P>
<P><IMG height=137 src="http://www.pediy.com/practise/IDA.files/strapplied.gif" width=750 border=0></P>
<P> </P>
<P><FONT size=2>通过我们的源码,我们知道有一个包含个4元素的customers数组,我们先前把<BR>Peter和John都定义为 customer_t 结构体了。现在取消对Join结构变量的定义,然后在Peter结构上按“*”键创建我们的customer数组,这样IDA就弹出一个数组设置框他会自动检测出来我们要创建的数组最大数是4。</FONT></P>
<P><IMG height=396 src="http://www.pediy.com/practise/IDA.files/strarray1.gif" width=730 border=0></P>
<P><FONT size=2>下来我们就看到创建好的数组了,剩下的就是改一下数组的名字。</FONT></P>
<P><IMG height=242 src="http://www.pediy.com/practise/IDA.files/strarray2.gif" width=615 border=0></P>
<P> <A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引">TOP</A></P>
<P>-------------------------------------------------------------------------------------------------------</P>
<P><A name=第十节:联合体和结构体中的结构体>第十节:联合体和结构体中的结构体</A></P>
<P><FONT size=2>IDA中可以像定义标准结构体那样来定义联合体。<BR>让我们来试着定义product_u 这个联合体吧。<BR>book_t和software_t这两个结构体我们已经定义过了。<BR>IDA认为联合体就是一种特别的结构体:因此我们打开Structures窗口,运行Add struct type命令,在对话框中我们选择创建Create union 选项。</FONT></P>
<P><IMG height=394 src="http://www.pediy.com/practise/IDA.files/unionadd.gif" width=607 border=0></P>
<P><FONT size=2>我们可以使用IDA常用的命令来创建联合体成员,分别添加一个book_t 结构体类型的book和一个software_t 结构体的software联合体成员</FONT></P>
<P><IMG height=352 src="http://www.pediy.com/practise/IDA.files/unionadded.gif" width=485 border=0></P>
<P><FONT size=2>当然结构体也可以嵌套一个结构体。事实上,我们刚才做的例子就实现了。<BR>记住IDA认为联合体只不过是一种特殊的结构体</FONT></P>
<P><IMG height=181 src="http://www.pediy.com/practise/IDA.files/unionhint.gif" width=687 border=0></P>
<P> <A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引">TOP</A></P>
<P>----------------------------------------------------------------------------------------------</P>
<P><A name=第十一节:可变的结构体>第十一节:可变的结构体</A></P>
<P><FONT size=2>我们还记得有一个softwares_t 结构体。结构体softs 的长度是不确定的。<BR>在汇编中,我们必须创建一个大小可变的结构体~。这种结构体创建的时候和普通的一样,仅仅最后一个元素定义的数组元素个数为0。</FONT></P>
<P><IMG height=392 src="http://www.pediy.com/practise/IDA.files/varstr1.gif" width=715 border=0></P>
<P> </P>
<P><FONT size=2>既然IDA不能计算出这种结构体的大小,我们就必须通过选择结构体的区域,来定义大小。</FONT></P>
<P><IMG height=275 src="http://www.pediy.com/practise/IDA.files/varstr2.gif" width=788 border=0></P>
<P><FONT size=2>我们可以看到所有的类型IDA用注释模式来显示成员名称</FONT></P>
<P><IMG height=154 src="http://www.pediy.com/practise/IDA.files/varstr3.gif" width=720 border=0></P>
<P> <A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引">TOP</A></P>
<P>----------------------------------------------------------------------------------------------------</P>
<P><A name=第十二节:结构体偏移>第十二节:结构体偏移</A></P>
<P><FONT size=2>现在我们知道如何定义联合体和结构体了。现在我们来将一些操作数指向他们原本指向的结构体。</FONT></P>
<P><FONT size=2><BR>在print_customer() 函数中,我们知道他只有一个指向customer_t结构体的参数。EAX寄存器初始化这个指针的值,使他指向customer_t 结构体。因此我们推断所有的[EAX+....]都是指向customer_t结构体成员的偏移。</FONT></P>
<P><IMG height=330 src="http://www.pediy.com/practise/IDA.files/stroff1.gif" width=572 border=0></P>
<P><FONT size=2>我们开始重新定义这些结构体变量的偏移,你右击在他们上面IDA会自动给你提供偏移的信息。</FONT></P>
<P><IMG height=330 src="http://www.pediy.com/practise/IDA.files/stroff2.gif" width=786 border=0></P>
<P><FONT size=2>当我们把所有的偏移量都整理一下的话,汇编代码马上就变得清晰易懂了。</FONT></P>
<P><IMG height=330 src="http://www.pediy.com/practise/IDA.files/stroff3.gif" width=575 border=0></P>
<P><FONT size=2>print_software()函数呢就是另外一个例子:EBX在初始化的时候指向了software_t 及构体。注意EBX寄存器在整个函数中都有应用(一个一个替换会累死的)。不要紧张,IDA会使用一次操作就能替换全部。<BR>做法如下:<BR>选择整个函数的代码,然后选在Operands工具栏上的Offset (struct) 命令。</FONT></P>
<P><IMG height=400 src="http://www.pediy.com/practise/IDA.files/stroff4.gif" width=788 border=0></P>
<P><FONT size=2>弹出Structure offsets窗口。然我们在列表中选择EBX寄存器。<BR>左边树形视图显示了在IDA中定义的所有结构。<BR>右边就显示与EBX有关系的所有操作。如果我们选择了左边的一个结构,<BR>IDA就会自动改变被选择代码中与结构体有关的偏移量。<BR>树视图前面不同的符号表示经过计算后的状态。对号就表示完全匹配,相反就是不完全匹配。在我们的操作中正好完全匹配。</FONT></P>
<P><IMG height=324 src="http://www.pediy.com/practise/IDA.files/stroffdlg1.gif" width=788 border=0></P>
<P><FONT size=2>确定以后,我们就得到了下面的结果:</FONT></P>
<P><IMG height=315 src="http://www.pediy.com/practise/IDA.files/stroffdlg2.gif" width=783 border=0></P>
<P> <A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引">TOP</A></P>
<P>--------------------------------------------------------------------------------------------------------------</P>
<P><A name=第十三节:联合体偏移量>第十三节:联合体偏移量</A></P>
<P><FONT size=2>依靠产品种类,我们可以调用适当的函数来打印产品信息。<BR>但是这一次的结构体偏移量跟以前不一样了,它是product_u联合体中的一个成员,它是一个数,这时我们就选择Edit struct 菜单中Select union member命令来处理</FONT></P>
<P><IMG height=244 src="http://www.pediy.com/practise/IDA.files/unionoff2.gif" width=471 border=0></P>
<P><FONT size=2>结果就是这样:</FONT></P>
<P><IMG height=138 src="http://www.pediy.com/practise/IDA.files/unionoff3.gif" width=602 border=0></P>
<P><FONT size=2>Structure offset对话框显示如何表明一个联合体成员。在你选择的区域中打开了这个窗口,IDA就会用“?”来显示联合体类型。</FONT></P>
<P><IMG height=319 src="http://www.pediy.com/practise/IDA.files/unionoffdlg1.gif" width=654 border=0></P>
<P><BR><FONT size=2>如果展开树视图中适当的分支,我们可以选择被描述为联合体成员的偏移量。<BR>一旦选中,IDA会用在一种绿色的符号来表示偏移量指向的记录中的联合体。</FONT></P>
<P><IMG height=319 src="http://www.pediy.com/practise/IDA.files/unionoffdlg2.gif" width=654 border=0></P>
<P> <A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引">TOP</A></P>
<P>--------------------------------------------------------------------------------------------------------</P>
<P><A name=第十四节:地址偏移量>第十四节:地址偏移量</A></P>
<P><FONT size=2>IDA也可以重新定义操作数。在下面的例子中,桔黄色的部分显示一个可能存在的参考~</FONT></P>
<P><IMG height=113 src="http://www.pediy.com/practise/IDA.files/off1.gif" width=680 border=0></P>
<P><FONT size=2><BR>使用Operands 工具栏上的Offset 按钮就可以进行转换。</FONT></P>
<P><IMG height=196 src="http://www.pediy.com/practise/IDA.files/off2.gif" width=680 border=0></P>
<P> <A href="file:///F:/My%20web/practise/IDA简易教程.htm#索引">TOP</A></P>
<P><FONT size=2><BR>--------------------------------------------------------------------------------------------------------------------</FONT></P>
<P><A name=第十五节:最终逆向结果>第十五节:最终逆向结果</A></P>
<P>
<TABLE style="TEXT-ALIGN: center" cellSpacing=2 cellPadding=4 width="100%" border=0>
<TBODY>
<TR>
<TD class=StoryContentColor style="VERTICAL-ALIGN: top" width="100%">
<P align=left><FONT face="Arial, Helvetica, sans-serif" size=2>To end this tutorial, we propose you a visual comparison of the original C source code and our final interactively disassembled code.</FONT>
<P align=left><FONT size=2>来look look我们用IDA整理的结果把</FONT><BR><FONT face="Arial, Helvetica, sans-serif" size=2><BR></FONT></P>
<TABLE cellSpacing=2 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top><FONT face=新宋体><CODE><BR>struct customer_t {<BR> long id;<BR> char name[32];<BR> char sex;<BR>}</CODE><BR></FONT><BR></TD>
<TD vAlign=top><PRE><CODE><FONT color=#808080>; -------------------------------------------------------------</FONT>
<FONT color=#0000ff>customer_t struc</FONT> <FONT color=#808080>; (sizeof=0x28)</FONT>
<FONT color=#0000ff>id</FONT><FONT color=#000080> dd ?</FONT>
<FONT color=#0000ff>name</FONT><FONT color=#000080> </FONT><FONT color=#008000>db 32 dup(?)</FONT> <FONT color=#808080>; string(C)</FONT>
<FONT color=#0000ff>sex</FONT><FONT color=#000080> </FONT><FONT color=#008000>dd ?</FONT> <FONT color=#808080>; char</FONT>
<FONT color=#0000ff>customer_t ends</FONT>
</CODE></PRE></TD></TR>
<TR>
<TD vAlign=top><FONT face=新宋体><CODE><BR>struct softwares_t {<BR> long count;<BR> software_t softs[];<BR>};</CODE><BR></FONT><BR></TD>
<TD vAlign=top><PRE><CODE><FONT color=#808080>; -------------------------------------------------------------</FONT>
<FONT color=#0000ff>softwares_t struc</FONT> <FONT color=#808080>; (sizeof=0x4, variable size)</FONT>
<FONT color=#0000ff>count</FONT><FONT color=#000080> dd ?</FONT>
<FONT color=#0000ff>softs</FONT><FONT color=#000080> software_t 0 dup(?)</FONT>
<FONT color=#0000ff>softwares_t ends
</FONT> </CODE></PRE></TD></TR>
<TR>
<TD vAlign=top><CODE><FONT face=新宋体><BR>struct book_t {<BR> char title[128];<BR>};<BR></FONT></CODE><BR></TD>
<TD vAlign=top><PRE><CODE><FONT color=#808080>; -------------------------------------------------------------</FONT>
<FONT color=#0000ff>book_t struc</FONT> <FONT color=#808080>; (sizeof=0x80)</FONT>
<FONT color=#0000ff>title</FONT><FONT color=#000080> </FONT><FONT color=#008000>db 128 dup(?)</FONT> <FONT color=#808080>; string(C)</FONT>
<FONT color=#0000ff>book_t ends
</FONT></CODE></PRE></TD></TR>
<TR>
<TD vAlign=top><FONT face=新宋体><CODE><BR>struct software_t {<BR> software_info_t info;<BR> char name[32];<BR>};</CODE><BR><BR></FONT></TD>
<TD vAlign=top><PRE><CODE><FONT color=#808080>; -------------------------------------------------------------</FONT>
<FONT color=#0000ff>software_t struc</FONT> <FONT color=#808080>; (sizeof=0x24)</FONT>
<FONT color=#0000ff>info</FONT><FONT color=#000080> dd ?</FONT> <FONT color=#808080>; enum software_info_t</FONT>
<FONT color=#0000ff>name</FONT><FONT color=#000080> </FONT><FONT color=#008000>db 32 dup(?)</FONT> <FONT color=#808080>; string(C)</FONT>
<FONT color=#0000ff>software_t ends
</FONT>
</CODE></PRE></TD></TR>
<TR>
<TD vAlign=top><BR><FONT face=新宋体><CODE>union product_u {<BR> book_t book;<BR> software_t software;<BR>};</CODE><BR><BR></FONT></TD>
<TD vAlign=top><PRE><CODE><FONT color=#808080>; -------------------------------------------------------------</FONT>
<FONT color=#0000ff>product_u union</FONT> <FONT color=#808080>; (sizeof=0x80)</FONT>
<FONT color=#0000ff>book</FONT><FONT color=#000080> book_t ?</FONT>
<FONT color=#0000ff>software</FONT><FONT color=#000080> software_t ?</FONT>
<FONT color=#0000ff>product_u ends
</FONT>
</CODE></PRE></TD></TR>
<TR>
<TD vAlign=top><CODE><FONT face=新宋体><BR>struct product_t {<BR> long id;<BR> product_category_t category;<BR> product_u p;<BR>};<BR></FONT></CODE><BR></TD>
<TD vAlign=top><PRE><CODE><FONT color=#808080>; -------------------------------------------------------------</FONT>
<FONT color=#0000ff>product_t struc</FONT> <FONT color=#808080>; (sizeof=0x88)</FONT>
<FONT color=#0000ff>id</FONT><FONT color=#000080> dd ?</FONT>
<FONT color=#0000ff>category</FONT><FONT color=#000080> dd ?</FONT> <FONT color=#808080>; enum product_category_t</FONT>
<FONT color=#0000ff>p</FONT><FONT color=#000080> product_u ?</FONT>
<FONT color=#0000ff>product_t ends
</FONT></CODE></PRE></TD></TR>
<TR>
<TD vAlign=top><FONT face=新宋体><CODE><BR>enum product_category_t {<BR> BOOK,<BR> SOFTWARE,<BR> HARDWARE<BR>};<BR></CODE><BR></FONT></TD>
<TD vAlign=top><PRE><CODE><FONT color=#808080>; -------------------------------------------------------------</FONT>
<FONT color=#808080>; enum product_category_t</FONT>
<FONT color=#0000ff>BOOK</FONT> = <FONT color=#008040>0</FONT>
<FONT color=#0000ff>SOFTWARE</FONT> = <FONT color=#008040>1</FONT>
<FONT color=#0000ff>HARDWARE</FONT> = <FONT color=#008040>2
</FONT>
</CODE></PRE></TD></TR>
<TR>
<TD vAlign=top><FONT face=新宋体><CODE><BR>struct software_info_t {<BR> unsigned int plateform : 2;<BR>#define PC 0x1 // 0x01<BR>#define MAC 0x2 // 0x02<BR> unsigned int os : 3;<BR>#define WINDOWS 0x1 // 0x04<BR>#define DOS 0x2 // 0x08<BR>#define OS_X 0x4 // 0x10<BR> unsigned int category : 2;<BR>#define DISASSEMBLY 0x1 // 0x20<BR>#define RECOVERY 0x2 // 0x40<BR>#define CRYPTOGRAPHY 0x3 // 0x60<BR>};</CODE><BR><BR></FONT></TD>
<TD vAlign=top><PRE><CODE><FONT color=#808080>; -------------------------------------------------------------</FONT>
<FONT color=#808080>; enum software_info_t <FONT color=#0000ff>(bitfield)
</FONT></FONT><FONT color=#0000ff>PC</FONT> = <FONT color=#008040>1</FONT>
<FONT color=#0000ff>MAC</FONT> = <FONT color=#008040>2
</FONT><FONT color=#0000ff>WINDOWS</FONT> = <FONT color=#008040>4</FONT>
<FONT color=#0000ff>DOS</FONT> = <FONT color=#008040>8</FONT>
<FONT color=#0000ff>OS_X</FONT> = <FONT color=#008040>10h</FONT>
<FONT color=#808080>category</FONT> = <FONT color=#008040>60h</FONT>
<FONT color=#0000ff>DISASSEMBLY</FONT> = <FONT color=#008040>20h</FONT>
<FONT color=#0000ff>RECOVERY</FONT> = <FONT color=#008040>40h</FONT>
<FONT color=#0000ff>CRYPTOGRAPHY</FONT> = <FONT color=#008040>60h
</FONT>
</CODE></PRE></TD></TR>
<TR>
<TD vAlign=top><BR></TD>
<TD vAlign=top><PRE><CODE>; +------------------------------------------------------------+
;
页:
[1]
