最后译者说道精华在于附录中,我略作修改重建一个文件,但不管怎么调,都无法运行。
一开始还以为是什么地方没有写对,可运行附的hello.exe也是报错。
看来用0x20对齐在XP下是不行的。这篇附录中就是太老了...
我来说说我改写的过程吧。
1.先写一段简单的代码
;MASMPlus 代码模板 - 普通的 Windows 程序代码
.386
.Model Flat, StdCall
Option Casemap :None
Include user32.inc
Include kernel32.inc
IncludeLib user32.lib
IncludeLib kernel32.lib
.data
MsgBoxText db "Hello.",0
MsgCaption db "Test",0
.CODE
START:
invoke MessageBox, NULL,addr MsgBoxText, addr MsgCaption, MB_OK
invoke ExitProcess,NULL
END START
顺便提一下,我用的是MASMPlus,可以在
http://www.aogosoft.com/下载。
2.编译完之后用OD看一看
00401000 >/$ 6A 00 push 0 ; /Style = MB_OK|MB_APPLMODAL
00401002 |. 68 07304000 push 00403007 ; |Title = "Test"
00401007 |. 68 00304000 push 00403000 ; |Text = "Hello."
0040100C |. 6A 00 push 0 ; |hOwner = NULL
0040100E |. E8 07000000 call <jmp.&user32.MessageBoxA> ; \MessageBoxA
00401013 |. 6A 00 push 0 ; /ExitCode = 0
00401015 \. E8 06000000 call <jmp.&kernel32.ExitProcess> ; \ExitProcess
0040101A $- FF25 08204000 jmp dword ptr [<&user32.MessageBoxA>> ; user32.MessageBoxA
00401020 .- FF25 00204000 jmp dword ptr [<&kernel32.ExitProces> ; kernel32.ExitProcess
不错,以后代码照这个抄就可以了。
发现用到了两个DLL的函数,稍微复杂了一点。
再看看原文中的代码
6A 00 ; push 0x00000000
68 d0 01 10 00 ; push offset _written
6A 0D ; push 0x0000000d
68 c0 01 10 00 ; push offset hello_string
6A F5 ; push 0xfffffff5
2E FF 15 28 02 10 00 ; call dword ptr cs:__imp__GetStdHandle@4
50 &n