ASM(at&t 系统 V 32 位异或)
我试图制作一个简单的小密码程序(以进一步扩展我的知识),但我无法让它工作。问题是即使我输入正确的密码,它也不会跳转到“好”标签。
我验证密码的方法是将内置密码与用户提交的密码进行异或,如果返回 0,则意味着它们是相同的。 (因为任何异或本身都是 0)
所以我的错误很可能是在 cmpl 和 je 命令中或在我的异或本身中。任何帮助都会很好我根本找不到我的错误。
.section .data
hmm:
.ascii "Enter the password\n\0"
password:
.ascii "abgirl"
success:
.ascii "Password is right\n\0"
bad:
.ascii "password is wrong\n\0"
.section .bss
.equ buffer_size, 500
.lcomm buffer_data, buffer_size
.section .text
.global _start
_start:
pushl $hmm
call printf #print $hmm
movl $0, %ebx
movl $buffer_data, %ecx
movl $buffer_size, %edx
movl $3, %eax
int $0x80 #get user input
movl $password, %eax
xorl $buffer_data, %eax #xor the passwords (value stored in eax)
cmpl $0, %eax #compare
je good #jump if equal
pushl $bad
call printf #print bad pass if not equal
jmp end #jump to exit
good:
pushl $success
call printf #print $success
end:
movl $0, %ebx
movl $1, %eax
int $0x80 #cleanup and exit
i was trying to make a simple little password program (to further expand my knowledge) and i just can't get it to work. the problem is even though i enter the correct password it will not jump to the label "good".
my way of validating the password is to xor the built in password with the user submitted one and if it returns 0 that means they are the same. (because anything xor'd by itself is 0)
so my mistake is most likely within the cmpl and je commands or within my xoring itself. any help would be nice i simply can't find my mistake.
.section .data
hmm:
.ascii "Enter the password\n\0"
password:
.ascii "abgirl"
success:
.ascii "Password is right\n\0"
bad:
.ascii "password is wrong\n\0"
.section .bss
.equ buffer_size, 500
.lcomm buffer_data, buffer_size
.section .text
.global _start
_start:
pushl $hmm
call printf #print $hmm
movl $0, %ebx
movl $buffer_data, %ecx
movl $buffer_size, %edx
movl $3, %eax
int $0x80 #get user input
movl $password, %eax
xorl $buffer_data, %eax #xor the passwords (value stored in eax)
cmpl $0, %eax #compare
je good #jump if equal
pushl $bad
call printf #print bad pass if not equal
jmp end #jump to exit
good:
pushl $success
call printf #print $success
end:
movl $0, %ebx
movl $1, %eax
int $0x80 #cleanup and exit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题是比较。
美元符号意味着您正在处理变量的地址,而不是内容。由于密码和缓冲区位于不同的位置,因此比较总是错误的。你想要的是比较密码和缓冲区每个位置的字符。为此,您需要知道密码有多长。
请注意,我还在您的密码中添加了一个空字节,这样如果输入的密码较长,比较就会失败。现在,您需要更改比较以检查每个字节。
Your problem is the comparison.
The dollar signs mean you are working with the addresses of the variables, not the contents. Since the password and buffer are at different locations, the comparison will always be false. What you want is to compare the character in each position of the password and buffer. To do this, you will need to know how long the password is.
Notice that I also added a null byte to your password, so that the comparison will fail if the input password is longer. Now, you need to change your comparison to check each byte.