Linux x8664汇编,Linux Udis86 反汇编引擎使用

前两篇说了capstone/beaengine,这节一起用一用经典的udis86;

github:https://github.com/vmt/udis86

0x01:udis86相比于前面两个,用起来还是比较简单的,使用文档如下所示:

Getting Started

===============

Building and Installing udis86

------------------------------

udis86 is developed for unix-like environments, and like most software,

the basic steps towards building and installing it are as follows.

.. code::

$ ./configure

$ make

$ make install

Depending on your choice of install location, you may need to have root

privileges to do an install. The install scripts copy the necessary header

and library files to appropriate locations in your system.

Interfacing with libudis86: A Quick Example

-------------------------------------------

The following is an example of a program that interfaces with libudis86

and uses the API to generate assembly language output for 64-bit code,

input from STDIN.

.. code-block:: c

#include

#include

int main()

{

ud_t ud_obj;

ud_init(&ud_obj);

ud_set_input_file(&ud_obj, stdin);

ud_set_mode(&ud_obj, 64);

ud_set_syntax(&ud_obj, UD_SYN_INTEL);

while (ud_disassemble(&ud_obj)) {

printf("\t%s\n", ud_insn_asm(&ud_obj));

}

return 0;

}

To compile the program (using gcc):

.. code::

$ gcc -ludis86 example.c -o example

This example should give you an idea of how this library can be used. The

following sections describe, in detail, the complete API of libudis86.

0x02:那就按照这个步骤来,关键你会发现,master文件夹中并没有configure文件,再看看README,先要配置好build环境;

Autotools Build

---------------

You need autotools if building from sources cloned form version control

system, or if you need to regenerate the build system. The wrapper

script 'autogen.sh' is provided that'll generate the build system.

//执行 ./autogen.sh报错 --> 原因是没有安装autoreconf

curits@curits-virtual-machine:~ /Desktop/udis86-master$ sudo ./autogen.sh

./autogen.sh: line 4: autoreconf: command not found

autogen: autoreconf -i failed.

//安装

curits@curits-virtual-machine:~/Desktop/udis86-master$ sudo apt-get install autoconf automake libtool

//然后再执行./autogen.sh --> 生成build环境

curits@curits-virtual-machine:~/Desktop/udis86-master$ ./autogen.sh

autoreconf: Entering directory `.'

autoreconf: configure.ac: not using Gettext

autoreconf: running: aclocal --force -I build/m4

autoreconf: configure.ac: tracing

autoreconf: running: libtoolize --copy --force

libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build'.

libtoolize: copying file 'build/ltmain.sh'

libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'build/m4'.

libtoolize: copying file 'build/m4/libtool.m4'

libtoolize: copying file 'build/m4/ltoptions.m4'

libtoolize: copying file 'build/m4/ltsugar.m4'

libtoolize: copying file 'build/m4/ltversion.m4'

libtoolize: copying file 'build/m4/lt~obsolete.m4'

autoreconf: running: /usr/bin/autoconf --force

autoreconf: running: /usr/bin/autoheader --force

autoreconf: running: automake --add-missing --copy --force-missing

configure.ac:43: installing 'build/compile'

configure.ac:24: installing 'build/config.guess'

configure.ac:24: installing 'build/config.sub'

configure.ac:34: installing 'build/install-sh'

configure.ac:34: installing 'build/missing'

libudis86/Makefile.am: installing 'build/depcomp'

autoreconf: Leaving directory `.'

//接下来就是三板斧 ./configure --> make --> sudo make install (安装时使用root权限)

然后将example的代码拷贝下来,按照给定的方法进行方式进行编译,报错,究竟为啥没编译成功不太清楚;

curits@curits-virtual-machine:~/Desktop/udis86-master$ g++ -ludis86 example.c -o example

/tmp/ccXcpvEg.o: In function `main':

example.c:(.text+0x25): undefined reference to `ud_init'

example.c:(.text+0x3e): undefined reference to `ud_set_input_file'

example.c:(.text+0x52): undefined reference to `ud_set_mode'

example.c:(.text+0x60): undefined reference to `ud_translate_intel'

example.c:(.text+0x6b): undefined reference to `ud_set_syntax'

example.c:(.text+0x7a): undefined reference to `ud_disassemble'

example.c:(.text+0x92): undefined reference to `ud_insn_asm'

collect2: error: ld returned 1 exit status

解决办法:从make install 的打印信息可以看出,把编译出来的动态库拷贝到了/user/local/lib下;

curits@curits-virtual-machine:/usr/local/lib$ ls

libudis86.la libudis86.so libudis86.so.0 libudis86.so.0.0.0 python2.7 python3.6

索性直接把example.c文件夹拷贝到当前目录,直接用编译出来的libudis86.so动态库;

//成功编译出二进制文件、

curits@curits-virtual-machine:/usr/local/lib$ export LD_LIBRARY_PATH=./

curits@curits-virtual-machine:/usr/local/lib$ sudo g++ -o example example.c libudis86.so

curits@curits-virtual-machine:/usr/local/lib$ ls

example example.c libudis86.la libudis86.so libudis86.so.0 libudis86.so.0.0.0 python2.7 python3.6

//执行example,从stdin中输入opencode

curits@curits-virtual-machine:/usr/local/lib$ ./example

65 67 89 87 76 65 54 56 78 89 09 00 90

sub eax, 0x35360a78

and [rsi], dh

invalid

and [rax], bh

cmp [rax], esp

cmp [rdi], dh

and [rdi], dh

and [ss:rsi], dh

xor eax, 0x20343520

xor eax, 0x38372036

and [rax], bh

cmp [rax], esp

xor [rcx], bh

and [rax], dh

xor [rax], ah

cmp [rax], esi

虽然生成了反汇编代码,但是结果却是有问题的,具体什么问题,还得研究研究源码;

从官网查看相应API:http://udis86.sourceforge.net/manual/libudis86.html#setup-input

//对input函数 ud_set_input_file的相关说明

void ud_set_input_file(ud_t*, FILE* filep)

Sets the input source to a file pointed to by a given standard library FILE pointer. Note that libudis86 does not perform any checks, and assumes that the file pointer is properly initialized and open for reading.

//example代码初始化

ud_set_input_file(&ud_obj, stdin);

修改example.c代码,给ud_set_input_file()传一个文件指针:

#include

#include

#define FILENAME "/home/curits/Desktop/ins.txt"

int main()

{

ud_t ud_obj;

FILE * filep;

filep = fopen( FILENAME, "rb+");

if(!filep)

{

printf("Can not open file\n");

return 0;

}

ud_init(&ud_obj);

// ud_set_input_file(&ud_obj, stdin);

ud_set_input_file(&ud_obj, filep);

ud_set_mode(&ud_obj, 64);

ud_set_syntax(&ud_obj, UD_SYN_INTEL);

while (ud_disassemble(&ud_obj)) {

printf("\t%s\n", ud_insn_asm(&ud_obj));

}

fclose(filep);

return 0;

}

编译执行:

//成功将ins.txt文件反汇编

curits@curits-virtual-machine:/usr/local/lib$ ./example

nop [rax+rax]

push rbp

mov rbp, rsp

pop rbp

ret

nop [rax+rax]

//与intel-xed反汇编比较

curits@curits-virtual-machine:~/Desktop/xed-master/obj/wkit/bin$ ./xed -ir /home/curits/Desktop/ins.txt -64

XDIS 0: WIDENOP BASE 0F1F440000 nop dword ptr [rax+rax*1], eax

XDIS 5: PUSH BASE 55 push rbp

XDIS 6: DATAXFER BASE 4889E5 mov rbp, rsp

XDIS 9: POP BASE 5D pop rbp

XDIS a: RET BASE C3 ret

XDIS b: WIDENOP BASE 0F1F440000 nop dword ptr [rax+rax*1], eax

# end of text section.

# Errors: 0

#XED3 DECODE STATS

#Total DECODE cycles: 1071003

#Total instructions DECODE: 6

#Total tail DECODE cycles: 1071003

#Total tail instructions DECODE: 6

#Total cycles/instruction DECODE: 178500.50

#Total tail cycles/instruction DECODE: 178500.50

更多功能可以基于这个开发;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441278.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【HDU - 2200】Eddy's AC难题(简单组合数学)

题干: Eddy是个ACMer,他不仅喜欢做ACM题,而且对于Ranklist中每个人的ac数量也有一定的研究,他在无聊时经常在纸上把Ranklist上每个人的ac题目的数量摘录下来,然后从中选择一部分人(或者全部)按照ac的数量分成两组进行比较,他想使第一组中的最…

C语言用字符串sex储存,2005年计算机等级考试二级C语言全真标准预测试卷(2)

一、选择题(1~40题每题1分,41~50题每题2分,共60分)1.微型计算机的运算器、控制器及内存储器组合在一起,称之为()(本题分值:1分)A.ALUB.CPUC.MPUD.主机【正确答案】D2.下列存储器中,存取速度最快…

【POJ - 3320 】Jessica's Reading Problem (尺取,哈希)

题干: Jessicas a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas included in a very thick text book. The aut…

c语言全局变量SQR,c语言a/=SQR(k+m);是什么意思?

满意答案NightmareJJ2013.03.16采纳率:47% 等级:12已帮助:11233人先看第一个main() // 主函数{printf("%ld\n", fun(3));} //输出fun(3)这个函数的返回值,3就是下一个//函数中的n 值。long fun (int n) //定义fun函数…

【POJ - 1850】Code (组合数学,字符串另类排序)

题干: Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is that one where a number is associated to a character sequence. It is considered that …

c语言蓝牙接收6,终于搞定了通过两路蓝牙接收数据

一直想做无线传感器,通过蓝牙来接收数据,无奈因为arduino接收串口数据的一些问题,一直搁到现在。因为学校里给学生开了选修课,所以手边有一些nano和mega可以使用,所以就做了用两个nano加上两个蓝牙模块来发射数据&…

【POJ - 1942 】Paths on a Grid (组合数学,求组合数的无数种方法)

题干: Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time hes explaining that (ab) 2a 22abb 2). So you decide to waste your time with d…

编译原理last集c语言,编译原理作业集-第七章.doc

编译原理作业集-第七章第七章 语义分析和中间代码产生本章要点1. 中间语言,各种常见中间语言形式;2. 说明语句赋值语句布尔表达式控制语句的翻译;3. 过程调用的处理;4. 类型检查;本章目标掌握和理解中间语言&#xff0…

【CodeForces - 244A 】Dividing Orange (构造,水题)

题干: One day Ms Swan bought an orange in a shop. The orange consisted of nk segments, numbered with integers from 1 to nk. There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided…

兔子吃萝卜的c语言编程,狼追兔子的c语言实现

满意答案16guoyuming2013.03.05采纳率:49% 等级:13已帮助:8005人用单链表实现#include #includetypedef struct node{int cave;struct node * next;}node,*LinkList;void main(){int i0,j,count1; // 初始值为1;LinkList L,p,h…

【CodeForces - 244B】Undoubtedly Lucky Numbers (dfs打表 + 二分)

题干: Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x  4, and y  7, then numbers 47, 74…

c语言二叉树构造与输出,C语言数据结构树状输出二叉树,谁能给详细的解释一下...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼void TranslevelPrint(Bitree bt){struct node{Bitree vec[MAXLEN]; //存放树结点int layer[MAXLEN]; //结点所在的层int locate[MAXLEN]; //打印结点的位置int front,rear;}q;int i,j,k;int nLocate;j 1;k 0;q.front 0;q.rear …

【CodeForces - 245C 】Game with Coins (思维,贪心)

题干: Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has aicoins. Polycarpus and Vasily move in turns. Polycarpus moves first. Du…

【CodeForces - 246D】Colorful Graph (暴力,图,存边,STL)

题干: Youve got an undirected graph, consisting of n vertices and m edges. We will consider the graphs vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer ci. Lets consi…

android 动态换肤框架,GitHub - ss520k/Android-Skin-Loader: 一个通过动态加载本地皮肤包进行换肤的皮肤框架...

Android-Skin-Loader更新日志导入到Android Studio,使用gradle构建皮肤包(见7. 皮肤包是什么?如何生成?)(2015-12-02)解决Fragment换肤在某些版本的support-v4包下失效的问题(感谢javake同学)(2015-12-02)对textColor加入selector类型的资源的…

【CodeForces - 349A】Cinema Line (贪心(其实不是贪心),乱搞)

题干: The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the boo…

android 获取默认程序图标,android – PackageManager.getApplicationIcon()返回默认图标?...

我刚想通了.有一个PackageManager.getDefaultActivityIcon()方法返回一个Drawable.如果Drawable的Bitmap与应用程序图标Drawable的Bitmap匹配,则它是默认图标.PackageManager pm context.getPackageManager();Drawable icon pm.getApplicationIcon(apk.package_name);Drawabl…

【CodeForces - 255A】Greg's Workout (水题)

题干: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in orde…

android吸附菜单,Android仿微博、人人Feed详情页吸附导航栏

仿微博、人人的feed详情页面:Listview上下滑动,导航栏view可吸附在顶部的效果。一、实现效果上图:效果图.gif欢迎拍砖,拍拍更进步。没有对比,怎么会有伤害,下面是 微博、人人的Feed详情页:微博、…

android 居右属性,使用layoutDirection属性设置布局靠左或靠右

通过设置layoutDirection属性值为mx.core.LayoutDirection.RTL(右到左)或mx.core.LayoutDirection.LTR(左到右),使布局为靠左或靠右(如下图)。该属性可设置3种值,LayoutDirection.RTL、LayoutDirection.LTR和null(ILayoutDirectionElement时)/undefined(…