回 帖 发 新 帖 刷新版面

主题:[原创]求助:想请教各位高手、大虾一个关于密码校验程序的问题

求助:想请教各位高手、大虾一个关于密码校验程序的问题

大家好,先展示源代码

.286
.model small
.stack 200h
.DATA
;buffer for Keyboard Input, formatted for easy reference:
MaxKbLength db 05h
KbLength db 00h
KbBuffer dd 00h

;strings: note the password is not encrypted, though it should be...
szGuessIt db 'Care to guess the super-secret password?',0Dh,0Ah,'$'
szString1 db 'Congratulations! You solved it!',0Dh,0Ah, '$'
szString2 db 'Ah, damn, too bad eh?',0Dh,0Ah,'$'
secret_word db "this"

.CODE
;===========================================
start:
mov ax,@data ; set segment registers
mov ds, ax ; same as "assume" directive
mov es, ax
call Query ; prompt user for password
mov ah, 0Ah ; DOS 'Get Keyboard Input' function
mov dx, offset MaxKbLength ; start of buffer
int 21h
call Compare ; compare passwords and patch
exit:
mov ah,4ch ; 'Terminate to DOS' function
int 21h
;===========================================
Query proc
mov dx, offset szGuessIt ; Prompt string
mov ah, 09h ; 'Display String' function
int 21h
ret
Query endp
;===========================================
Reply proc
PatchSpot:
mov dx, offset szString2 ; 'You failed' string
mov ah, 09h ; 'Display String' function
int 21h
ret
Reply endp
;===========================================
Compare proc
mov cx, 4 ; # of bytes in password
mov si, offset KbBuffer ; start of password-input in Buffer
mov di, offset secret_word ; location of real password
rep cmpsb ; compare them
or cx, cx ; are they equal?
jnz bad_guess ; nope, do not patch
mov word ptr cs:PatchSpot[1], offset szString1 ;patch to GoodString
bad_guess:
call Reply ; output string to display result
ret
Compare endp
end start


*****************
我用masm5.0编译、连接成 .exe程序,一切正常,但我不明白的问题是:
KbLength这个常量在程序正文中从来没有出现过,定义它有什么用?

于是我将这个变量删除后,也就是开头的数据段变成:
.286
.model small
.stack 200h
.DATA
MaxKbLength db 05h
KbBuffer dd 00h




也可以正常编译和连接,但是在运行程序时,即使输入正确的密码“this”,程序也是回答“Ah, damn, too bad eh?”,后来我把MaxKbLength的数据类型改为字,开头的数据段变成了:
.286
.model small
.stack 200h
.DATA
MaxKbLength dw 05h
KbBuffer dd 00h



结果一切又正常了,为什么会这样?还有KbBuffer这个变量是何时被赋值为键盘输入的字符的?
呼唤大虾的帮助


我的qq是:17227313

期待ing

 
[em10]

回复列表 (共1个回复)

沙发

在我这里正常呀,没有发现你说的问题

我来回复

您尚未登录,请登录后再回复。点此登录或注册