![]() |
#2
zklhp2008-10-12 15:31
|
*/ 出自: 编程中国 https://www.bccn.net
*/ 作者: zklhp E-mail:zklhp@ QQ:493165744
*/ 时间: 2008-10-12 编程论坛首发
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ --------------------------------------------------------------------------------------
那天在一个win32汇编的群里下到一本win32汇编快速入门的电子书(英文的 已作为附件上传)
其中有个控制台输出的程序有这样一段

; ---------------------------------------------------------------------------procWriteString
proc
;
; Writes a null-terminated string pointed to by EDX to standard
; output using windows calls.
; ---------------------------------------------------------------------------
pushad
INVOKE procStrLength,edx ; return length of string in EAX
cld ; clear the direction flag
; must do this before WriteConsole
INVOKE WriteConsole,
consoleOutHandle, ; console output handle
edx, ; points to string
eax, ; string length
offset bytesWritten, ; returns number of bytes written
0
popad
ret
; ---------------------------------------------------------------------------
好像调用WriteConsole必须清方向位 于是用MasmPlus写个程序试试

;MASMPlus 代码模板 - 普通的 Windows 程序代码
.386
.Model Flat, StdCall
Option Casemap :None
Include windows.inc
Include user32.inc
Include kernel32.inc
Include gdi32.inc
include masm32.inc
includelib gdi32.lib
IncludeLib user32.lib
IncludeLib kernel32.lib
includelib masm32.lib
include macro.asm
.DATA
szBuf db 'bbs.bccn.net',0
.DATA?
hStdOut dd ?
.CODE
START:
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hStdOut,eax
invoke lstrlen,offset szBuf
push eax ;小把戏
mov ecx,esp
;int 3h
;std
invoke WriteConsole,hStdOut,offset szBuf,eax,ecx,0
pop eax
invoke StdIn,offset szBuf,2
invoke ExitProcess,0
END START
只有本站会员才能查看附件,请 登录
结果很明确了 不过方向位一般不会被置 所以大多数情况下不会出错
那为什么呢? 请出OD~~~~ 这里偶直接在前面加 int 3h 让它断下来~~(反正是自己写的)
只有本站会员才能查看附件,请 登录
7C81CE9E F3:A5 REP MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]
这肯定不对了
写到这里大家都明白了吧(要是不明白只能说明偶的表达能力不行……)
对汇编这种比较低级的语言来说 调用api也是很有讲究的
希望各位以后写程序时注意这些容易被忽视的地方
本人水平有限 有不当之处还望各位高手指出
附件里是和本文相关的一些东西 大家自己看吧
附件
只有本站会员才能查看附件,请 登录
[[it] 本帖最后由 zklhp 于 2008-10-12 16:58 编辑 [/it]]