ASM(at&t 系统 V 32 位异或)

发布于 2024-11-14 10:18:58 字数 1146 浏览 4 评论 0原文

我试图制作一个简单的小密码程序(以进一步扩展我的知识),但我无法让它工作。问题是即使我输入正确的密码,它也不会跳转到“好”标签。

我验证密码的方法是将内置密码与用户提交的密码进行异或,如果返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞取 2024-11-21 10:18:58

你的问题是比较。

movl $password, %eax
xorl $buffer_data, %eax

美元符号意味着您正在处理变量的地址,而不是内容。由于密码和缓冲区位于不同的位置,因此比较总是错误的。你想要的是比较密码和缓冲区每个位置的字符。为此,您需要知道密码有多长。

password:
.ascii "abgirl\0"
.set password_len, . - password

请注意,我还在您的密码中添加了一个空字节,这样如果输入的密码较长,比较就会失败。现在,您需要更改比较以检查每个字节。

    movl $password, %ebx
    movl $buffer_data, %edx
    movl $password_len, %ecx
0:
    movb (%ebx), %al
    xorb (%edx), %al
    jnz bad
    inc %ebx
    inc %edx       # Go to next byte
    dec %ecx
    jnz 0b
    jmp good

Your problem is the comparison.

movl $password, %eax
xorl $buffer_data, %eax

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.

password:
.ascii "abgirl\0"
.set password_len, . - password

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.

    movl $password, %ebx
    movl $buffer_data, %edx
    movl $password_len, %ecx
0:
    movb (%ebx), %al
    xorb (%edx), %al
    jnz bad
    inc %ebx
    inc %edx       # Go to next byte
    dec %ecx
    jnz 0b
    jmp good
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文