首页
社区
课程
招聘
[旧帖] [分享]C函数直接调用反汇编学习(入门) 0.00雪花
发表于: 2011-7-7 16:39 2051

[旧帖] [分享]C函数直接调用反汇编学习(入门) 0.00雪花

2011-7-7 16:39
2051
源程序:
#include <stdio.h>

int fun(int a)
{
	a += 1;
	return a;
}

int main()
{
	int a;

	a = 1;

	a = fun(a);

	printf("a=%d\n", a);

	a = fun(a);

	printf("a=%d\n", a);

	return 0;
}


debug对应汇编
fun 函数debug版对应汇编代码
PUBLIC	?fun@@YAHH@Z					; fun
;	COMDAT ?fun@@YAHH@Z
_TEXT	SEGMENT
_a$ = 8
?fun@@YAHH@Z PROC NEAR					; fun, COMDAT

; 4    : {

	push	ebp
	mov	ebp, esp
	sub	esp, 64					; 00000040H
	push	ebx
	push	esi
	push	edi
	
	;局部变量全部初始化为0xcccccccc
	lea	edi, DWORD PTR [ebp-64]
	mov	ecx, 16					; 00000010H
	mov	eax, -858993460				; ccccccccH
	rep stosd

; 5    : 	a += 1;

	mov	eax, DWORD PTR _a$[ebp] ;  _a$[ebp]=[ebp+8]为接收参数   [ebp+4] 为函数返回地址    
	add	eax, 1
	mov	DWORD PTR _a$[ebp], eax

; 6    : 	return a;

	mov	eax, DWORD PTR _a$[ebp]

; 7    : }

	pop	edi
	pop	esi
	pop	ebx
	mov	esp, ebp
	pop	ebp
	ret	0
?fun@@YAHH@Z ENDP					; fun
_TEXT	ENDS

main 函数debug版对应汇编代码
;	COMDAT _main
_TEXT	SEGMENT
_a$ = -4
_main	PROC NEAR					; COMDAT

; 10   : {

	push	ebp
	mov	ebp, esp
	sub	esp, 68					; 00000044H
	push	ebx
	push	esi
	push	edi
	lea	edi, DWORD PTR [ebp-68]
	mov	ecx, 17					; 00000011H
	mov	eax, -858993460				; ccccccccH
	rep stosd

; 11   : 	int a;
; 12   : 
; 13   : 	a = 1;

	mov	DWORD PTR _a$[ebp], 1

; 14   : 
; 15   : 	a = fun(a);

	mov	eax, DWORD PTR _a$[ebp]
	push	eax
	call	?fun@@YAHH@Z				; fun
	add	esp, 4
	mov	DWORD PTR _a$[ebp], eax

; 16   : 
; 17   : 	printf("a=%d\n", a);

	mov	ecx, DWORD PTR _a$[ebp]
	push	ecx
	push	OFFSET FLAT:??_C@_05LEGA@a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 18   : 
; 19   : 	a = fun(a);

	mov	edx, DWORD PTR _a$[ebp]
	push	edx
	call	?fun@@YAHH@Z				; fun
	add	esp, 4
	mov	DWORD PTR _a$[ebp], eax

; 20   : 
; 21   : 	printf("a=%d\n", a);

	mov	eax, DWORD PTR _a$[ebp]
	push	eax
	push	OFFSET FLAT:??_C@_05LEGA@a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 22   : 
; 23   : 	return 0;

	xor	eax, eax

; 24   : }

	pop	edi
	pop	esi
	pop	ebx
	add	esp, 68					; 00000044H
	cmp	ebp, esp
	call	__chkesp      ;检查栈平衡
	mov	esp, ebp
	pop	ebp
	ret	0
_main	ENDP
_TEXT	ENDS
END



release版对应汇编代码:
fun 函数release版对应汇编代码
PUBLIC	?fun@@YAHH@Z					; fun
;	COMDAT ?fun@@YAHH@Z
_TEXT	SEGMENT
_a$ = 8
?fun@@YAHH@Z PROC NEAR					; fun, COMDAT

; 5    : 	a += 1;

	mov	eax, DWORD PTR _a$[esp-4]
	inc	eax

; 6    : 	return a;
; 7    : }

	ret	0
?fun@@YAHH@Z ENDP					; fun
_TEXT	ENDS



main 函数release版对应汇编代码
;	COMDAT _main
_TEXT	SEGMENT
_main	PROC NEAR					; COMDAT

; 10   : {

	push	esi

; 11   : 	int a;
; 12   : 
; 13   : 	a = 1;
; 14   : 
; 15   : 	a = fun(a);

	push	1                   ;直接把a局部变量优化掉了
	call	?fun@@YAHH@Z				; fun
	add	esp, 4
	mov	esi, eax

; 16   : 
; 17   : 	printf("a=%d\n", a);

	push	esi
	push	OFFSET FLAT:??_C@_05LEGA@a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf

; 18   : 
; 19   : 	a = fun(a);

	push	esi
	call	?fun@@YAHH@Z				; fun
	add	esp, 12					; 0000000cH

; 20   : 
; 21   : 	printf("a=%d\n", a);

	push	eax
	push	OFFSET FLAT:??_C@_05LEGA@a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 22   : 
; 23   : 	return 0;

	xor	eax, eax
	pop	esi

; 24   : }

	ret	0
_main	ENDP
_TEXT	ENDS
END


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (10)
雪    币: 65
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
把main函数该为指针调用:
main函数源码:
#include <stdio.h>

int fun(int a)
{
	a += 1;
	return a;
}

int main()
{
	int a;
	a = 1;
	
	int (*f)(int);
	f = fun;

	a = f(a);	

	printf("a=%d\n", a);

	a = f(a);

	printf("a=%d\n", a);

	return 0;
}

release版把函数指针优化掉了,和直接调用的汇编代码相同。
对应 debug版汇编代码:
;	COMDAT _main
_TEXT	SEGMENT
_a$ = -4
_f$ = -8
_main	PROC NEAR					; COMDAT

; 10   : {

	push	ebp
	mov	ebp, esp
	sub	esp, 72					; 00000048H
	push	ebx
	push	esi
	push	edi
	lea	edi, DWORD PTR [ebp-72]
	mov	ecx, 18					; 00000012H
	mov	eax, -858993460				; ccccccccH
	rep stosd

; 11   : 	int a;
; 12   : 	a = 1;

	mov	DWORD PTR _a$[ebp], 1

; 13   : 	
; 14   : 	int (*f)(int);
; 15   : 	f = fun;

	mov	DWORD PTR _f$[ebp], OFFSET FLAT:?fun@@YAHH@Z ; fun

; 16   : 
; 17   : 	a = f(a);	

	mov	esi, esp
	mov	eax, DWORD PTR _a$[ebp]
	push	eax
	call	DWORD PTR _f$[ebp]
	add	esp, 4
	cmp	esi, esp
	call	__chkesp
	mov	DWORD PTR _a$[ebp], eax

; 18   : 
; 19   : 	printf("a=%d\n", a);

	mov	ecx, DWORD PTR _a$[ebp]
	push	ecx
	push	OFFSET FLAT:??_C@_05LEGA@a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 20   : 
; 21   : 	a = f(a);

	mov	esi, esp
	mov	edx, DWORD PTR _a$[ebp]
	push	edx
	call	DWORD PTR _f$[ebp]
	add	esp, 4
	cmp	esi, esp
	call	__chkesp
	mov	DWORD PTR _a$[ebp], eax

; 22   : 
; 23   : 	printf("a=%d\n", a);

	mov	eax, DWORD PTR _a$[ebp]
	push	eax
	push	OFFSET FLAT:??_C@_05LEGA@a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 24   : 
; 25   : 	return 0;

	xor	eax, eax

; 26   : }

	pop	edi
	pop	esi
	pop	ebx
	add	esp, 72					; 00000048H
	cmp	ebp, esp
	call	__chkesp
	mov	esp, ebp
	pop	ebp
	ret	0
_main	ENDP
_TEXT	ENDS
END

2011-7-7 16:52
0
雪    币: 65
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
函数改为内联函数,main函数代码:
#include <stdio.h>

inline int fun(int a)
{
	a += 1;
	return a;
}

int main()
{
	int a;
	a = 1;
	
	//int (*f)(int);
	//f = fun;

	a = fun(a);	

	printf("a=%d\n", a);

	a = fun(a);

	printf("a=%d\n", a);

	return 0;
}


debug版并没有把内联函数展开,和普通函数一样调用,汇编代码没有变化,
release版直接把值算出来了:
release版对应汇编代码:
release版汇编代码,直接把函数值计算出了
;	COMDAT _main
_TEXT	SEGMENT
_main	PROC NEAR					; COMDAT

; 11   : 	int a;
; 12   : 	a = 1;
; 13   : 	
; 14   : 	//int (*f)(int);
; 15   : 	//f = fun;
; 16   : 
; 17   : 	a = fun(a);	
; 18   : 
; 19   : 	printf("a=%d\n", a);

	push	2
	push	OFFSET FLAT:??_C@_05LEGA@a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 20   : 
; 21   : 	a = fun(a);
; 22   : 
; 23   : 	printf("a=%d\n", a);

	push	3
	push	OFFSET FLAT:??_C@_05LEGA@a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 24   : 
; 25   : 	return 0;

	xor	eax, eax

; 26   : }

	ret	0
_main	ENDP
_TEXT	ENDS
END

2011-7-7 17:03
0
雪    币: 166
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
先学C语言然后学汇编就明白上面的例子了
2011-7-7 17:15
0
雪    币: 26
活跃值: (56)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
我想问一下:C语言和汇编语言有什么联系么???
2011-7-7 18:41
0
雪    币: 0
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
太长了,看的眼晕
2011-7-7 18:48
0
雪    币: 322
活跃值: (59)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
c  和汇编   都要学习的~
2011-7-8 07:47
0
雪    币: 793
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
楼主辛苦了
2011-7-8 07:50
0
雪    币: 65
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
虚函数的调用:
源程序代码如下:
#include <stdio.h>

class Base
{
public:
	virtual int fun(int a)
	{
		a += 1;
		printf("Base : a=%d\n", a);

		return a;
	}

	int fun_no_virtual(int a)
	{
		a += 1;
		printf("Base : a=%d\n", a);

		return a;
	}

};

class Derived:public Base
{
public:
	virtual int fun(int a)
	{
		a += 10;
		printf("Derived : a=%d\n", a);

		return a;
	}

	int fun_no_virtual(int a)
	{
		a += 10;
		printf("Derived : a=%d\n", a);

		return a;
	}
};

int main()
{
	int a;
	a = 1;
	
	Base *p = new Base;
	p->fun(a);
	p->fun_no_virtual(a);

	a = 1;
	p = new Derived;
	p->fun(a);
	p->fun_no_virtual(a);

	return 0;
}


release版 main函数汇编代码:
把两个类的构造函数都内联进了主函数
_TEXT	SEGMENT
_main	PROC NEAR					; COMDAT

; 46   : 	int a;
; 47   : 	a = 1;
; 48   : 	
; 49   : 	Base *p = new Base;

	push	4
	call	??2@YAPAXI@Z				; operator new
	add	esp, 4
	test	eax, eax
	je	SHORT $L645
	mov	DWORD PTR [eax], OFFSET FLAT:??_7Base@@6B@ ; Base::`vftable'  ;初始化虚函数表
	mov	ecx, eax
	jmp	SHORT $L646
$L645:
	xor	ecx, ecx
$L646:

; 50   : 	p->fun(a);

	mov	eax, DWORD PTR [ecx]
	push	1
	call	DWORD PTR [eax]               ;ecx=this指针   eax为虚函数表

; 51   : 	p->fun_no_virtual(a);

	push	2
	push	OFFSET FLAT:??_C@_0N@NKPA@Base?5?3?5a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf

; 52   : 
; 53   : 	a = 1;
; 54   : 	p = new Derived;

	push	4
	call	??2@YAPAXI@Z				; operator new
	add	esp, 12					; 0000000cH
	test	eax, eax
	je	SHORT $L649
	mov	DWORD PTR [eax], OFFSET FLAT:??_7Derived@@6B@ ; Derived::`vftable'
	jmp	SHORT $L650
$L649:
	xor	eax, eax
$L650:

; 55   : 	p->fun(a);

	mov	edx, DWORD PTR [eax]
	push	1
	mov	ecx, eax
	call	DWORD PTR [edx]

; 56   : 	p->fun_no_virtual(a);

	push	2
	push	OFFSET FLAT:??_C@_0N@NKPA@Base?5?3?5a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 57   : 
; 58   : 	return 0;

	xor	eax, eax

; 59   : }

	ret	0
_main	ENDP
_TEXT	ENDS



debug版的main函数汇编代码:
;	COMDAT _main
_TEXT	SEGMENT
_a$ = -16
_p$ = -20
$T644 = -24
$T645 = -28
$T648 = -32
$T649 = -36
__$EHRec$ = -12
_main	PROC NEAR					; COMDAT

; 45   : {

	push	ebp
	mov	ebp, esp
	
	;以下为SEH链
	push	-1
	push	__ehhandler$_main
	mov	eax, DWORD PTR fs:__except_list
	push	eax
	mov	DWORD PTR fs:__except_list, esp
	
	
	sub	esp, 96					; 00000060H
	push	ebx
	push	esi
	push	edi
	lea	edi, DWORD PTR [ebp-108]
	mov	ecx, 24					; 00000018H
	mov	eax, -858993460				; ccccccccH
	rep stosd

; 46   : 	int a;
; 47   : 	a = 1;

	mov	DWORD PTR _a$[ebp], 1

; 48   : 	
; 49   : 	Base *p = new Base;

	push	4
	call	??2@YAPAXI@Z				; operator new
	add	esp, 4
	mov	DWORD PTR $T645[ebp], eax
	mov	DWORD PTR __$EHRec$[ebp+8], 0   ;异常处理标志
	cmp	DWORD PTR $T645[ebp], 0
	je	SHORT $L646
	mov	ecx, DWORD PTR $T645[ebp]
	call	??0Base@@QAE@XZ				; Base::Base
	mov	DWORD PTR -40+[ebp], eax
	jmp	SHORT $L647
$L646:
	mov	DWORD PTR -40+[ebp], 0
$L647:
	mov	eax, DWORD PTR -40+[ebp]
	mov	DWORD PTR $T644[ebp], eax
	mov	DWORD PTR __$EHRec$[ebp+8], -1   ;异常处理标志
	mov	ecx, DWORD PTR $T644[ebp]
	mov	DWORD PTR _p$[ebp], ecx

; 50   : 	p->fun(a);

	mov	esi, esp
	mov	edx, DWORD PTR _a$[ebp]
	push	edx
	mov	eax, DWORD PTR _p$[ebp]
	mov	edx, DWORD PTR [eax]           ;[eax]为虚函数表指针
	mov	ecx, DWORD PTR _p$[ebp]        ;_p$[ebp]为this指针
	call	DWORD PTR [edx]
	cmp	esi, esp
	call	__chkesp                    ;检查栈平衡

; 51   : 	p->fun_no_virtual(a);

	mov	eax, DWORD PTR _a$[ebp]
	push	eax
	mov	ecx, DWORD PTR _p$[ebp]
	call	?fun_no_virtual@Base@@QAEHH@Z		; Base::fun_no_virtual

; 52   : 
; 53   : 	a = 1;

	mov	DWORD PTR _a$[ebp], 1

; 54   : 	p = new Derived;

	push	4
	call	??2@YAPAXI@Z				; operator new
	add	esp, 4
	mov	DWORD PTR $T649[ebp], eax
	mov	DWORD PTR __$EHRec$[ebp+8], 1
	cmp	DWORD PTR $T649[ebp], 0
	je	SHORT $L650
	mov	ecx, DWORD PTR $T649[ebp]
	call	??0Derived@@QAE@XZ			; Derived::Derived
	mov	DWORD PTR -44+[ebp], eax
	jmp	SHORT $L651
$L650:
	mov	DWORD PTR -44+[ebp], 0
$L651:
	mov	ecx, DWORD PTR -44+[ebp]
	mov	DWORD PTR $T648[ebp], ecx
	mov	DWORD PTR __$EHRec$[ebp+8], -1
	mov	edx, DWORD PTR $T648[ebp]
	mov	DWORD PTR _p$[ebp], edx

; 55   : 	p->fun(a);

	mov	esi, esp
	mov	eax, DWORD PTR _a$[ebp]
	push	eax
	mov	ecx, DWORD PTR _p$[ebp]
	mov	edx, DWORD PTR [ecx]
	mov	ecx, DWORD PTR _p$[ebp]
	call	DWORD PTR [edx]
	cmp	esi, esp
	call	__chkesp

; 56   : 	p->fun_no_virtual(a);

	mov	eax, DWORD PTR _a$[ebp]
	push	eax
	mov	ecx, DWORD PTR _p$[ebp]
	call	?fun_no_virtual@Base@@QAEHH@Z		; Base::fun_no_virtual

; 57   : 
; 58   : 	return 0;

	xor	eax, eax

; 59   : }

	mov	ecx, DWORD PTR __$EHRec$[ebp]
	mov	DWORD PTR fs:__except_list, ecx
	pop	edi
	pop	esi
	pop	ebx
	add	esp, 108				; 0000006cH
	cmp	ebp, esp
	call	__chkesp
	mov	esp, ebp
	pop	ebp
	ret	0
_TEXT	ENDS


Base的构造函数

_TEXT	SEGMENT
_this$ = -4
??0Base@@QAE@XZ PROC NEAR				; Base::Base, COMDAT
	push	ebp
	mov	ebp, esp
	sub	esp, 68					; 00000044H
	push	ebx
	push	esi
	push	edi
	push	ecx
	lea	edi, DWORD PTR [ebp-68]
	mov	ecx, 17					; 00000011H
	mov	eax, -858993460				; ccccccccH
	rep stosd
	pop	ecx
	mov	DWORD PTR _this$[ebp], ecx
	mov	eax, DWORD PTR _this$[ebp]
	mov	DWORD PTR [eax], OFFSET FLAT:??_7Base@@6B@ ; Base::`vftable'
	mov	eax, DWORD PTR _this$[ebp]
	pop	edi
	pop	esi
	pop	ebx
	mov	esp, ebp
	pop	ebp
	ret	0
??0Base@@QAE@XZ ENDP					; Base::Base
_TEXT	ENDS


Derived的构造函数的汇编代码:
_TEXT	SEGMENT
_this$ = -4
??0Derived@@QAE@XZ PROC NEAR				; Derived::Derived, COMDAT
	push	ebp
	mov	ebp, esp
	sub	esp, 68					; 00000044H
	push	ebx
	push	esi
	push	edi
	push	ecx
	lea	edi, DWORD PTR [ebp-68]
	mov	ecx, 17					; 00000011H
	mov	eax, -858993460				; ccccccccH
	rep stosd
	pop	ecx
	mov	DWORD PTR _this$[ebp], ecx
	mov	ecx, DWORD PTR _this$[ebp]
	call	??0Base@@QAE@XZ				; Base::Base
	mov	eax, DWORD PTR _this$[ebp]
	mov	DWORD PTR [eax], OFFSET FLAT:??_7Derived@@6B@ ; Derived::`vftable'
	mov	eax, DWORD PTR _this$[ebp]
	pop	edi
	pop	esi
	pop	ebx
	add	esp, 68					; 00000044H
	cmp	ebp, esp
	call	__chkesp
	mov	esp, ebp
	pop	ebp
	ret	0
??0Derived@@QAE@XZ ENDP					; Derived::Derived
_TEXT	ENDS
2011-7-8 08:54
0
雪    币: 65
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
全局对象的构造函数:

C源代码:
#include <stdio.h>

class Base
{
public:
	virtual int fun(int a)
	{
		a += 1;
		printf("Base : a=%d\n", a);

		return a;
	}

	int fun_no_virtual(int a)
	{
		a += 1;
		printf("Base : a=%d\n", a);

		return a;
	}

};

int main()
{
	int a;
	a = 1;
	
	static Base base;
	base.fun(a);
	base.fun_no_virtual(a);

	return 0;
}


main 函数的汇编代码:

;	COMDAT _main
_TEXT	SEGMENT
_main	PROC NEAR					; COMDAT

; 26   : 	int a;
; 27   : 	a = 1;
; 28   : 	
; 29   : 	static Base base;

;BYTE PTR _?$S1@?1??main@@9@4EA存放的是标志该静态类是不是第一次调用,如果是第一次调用
;则改值为0,调用构造函数,然后将改值置为1,不是第一次调用,则改值为1,不调用构造函数
	mov	cl, BYTE PTR _?$S1@?1??main@@9@4EA  
	mov	al, 1
	test	cl, al
	jne	SHORT $L602
	mov	dl, cl
	push	OFFSET FLAT:_$E2
	or	dl, al
	mov	DWORD PTR _?base@?1??main@@9@4VBase@@A, OFFSET FLAT:??_7Base@@6B@ ; Base::`vftable'
	mov	BYTE PTR _?$S1@?1??main@@9@4EA, dl
	call	_atexit
	add	esp, 4
$L602:

; 30   : 	base.fun(a);

	push	2
	push	OFFSET FLAT:??_C@_0N@NKPA@Base?5?3?5a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 31   : 	base.fun_no_virtual(a);

	push	2
	push	OFFSET FLAT:??_C@_0N@NKPA@Base?5?3?5a?$DN?$CFd?6?$AA@ ; `string'
	call	_printf
	add	esp, 8

; 32   : 
; 33   : 	return 0;

	xor	eax, eax

; 34   : }

	ret	0
_main	ENDP
_TEXT	ENDS
;	COMDAT ?fun@Base@@UAEHH@Z
_TEXT	SEGMENT
2011-7-8 09:51
0
雪    币: 65
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
结构体反汇编代码:
当结构体作为函数参数传递时,作为一个整体采用 sub esp,XXX来为参数压栈,
作为多个变量参数时时,采用push XXX  pushXXX 来压栈,
但如果不作为函数参数,则无法区分结构体。
C源代码:
#include <stdio.h>
#include <string.h>

struct zzz
{
	char s[16];
	int a;
	int f;
};

int fun(struct zzz x)
{
	x.a += 1;
	printf("%s %x  %x\n", x.s, x.a, x.f);

	return 0;
}

int main()
{
	struct zzz x;
	strcpy(x.s, "hello");
	x.a = 0x12345;
	x.f = 0x123456;

	fun(x);

	return 0;
}


main函数对应的汇编代码:(release版)
_TEXT	SEGMENT
_x$ = -24
_main	PROC NEAR					; COMDAT

; 20   : {

	sub	esp, 24					; 00000018H
	push	esi
	push	edi

; 21   : 	struct zzz x;
; 22   : 	strcpy(x.s, "hello");

	mov	edi, OFFSET FLAT:??_C@_05DLON@hello?$AA@ ; `string'
	or	ecx, -1
	xor	eax, eax
	lea	edx, DWORD PTR _x$[esp+32]
	repne scasb
	not	ecx
	sub	edi, ecx            ;ecx为字符串长度+1

; 23   : 	x.a = 0x12345;
; 24   : 	x.f = 0x123456;
; 25   : 
; 26   : 	fun(x);

	sub	esp, 24					; 00000018H
	mov	eax, ecx
	mov	esi, edi
	mov	edi, edx
	shr	ecx, 2
	rep movsd                               ;先复制eax/4

	mov	ecx, eax
	and	ecx, 3
	rep movsb                              ;再复制eax%4

	mov	ecx, 6
	lea	esi, DWORD PTR _x$[esp+56]
	mov	edi, esp
	mov	DWORD PTR _x$[esp+72], 74565		; 00012345H
	mov	DWORD PTR _x$[esp+76], 1193046		; 00123456H
	rep movsd
	call	?fun@@YAHUzzz@@@Z			; fun
	add	esp, 24					; 00000018H

; 27   : 
; 28   : 	return 0;

	xor	eax, eax

; 29   : }

	pop	edi
	pop	esi
	add	esp, 24					; 00000018H
	ret	0
_main	ENDP
_TEXT	ENDS
END

2011-7-8 16:41
0
游客
登录 | 注册 方可回帖
返回
//