I have commented what I think the code is doing.
I have tried putting aaaaaaaaa
, AAAAAAAAA
, !!!!!!!!!
, and 000000000
, they all work. But it won't accept bbbbbbbbb
or 111111111
. It seems the password accepts that all ascii character corresponds to 0x21
, 0x31
, 0x41
, ...
Initially, it calls <getchar@plt>
, and it goes into a for loop, which accepts 10 characters.
After that, it starts a new loop, which I do not understand. Can you explain this loop? Is this doing modular division? Thanks in advance!
8048443: 88 44 1d e5 mov %al,-0x1b(%ebp,%ebx,1)
8048447: 83 45 f4 01 addl $0x1,-0xc(%ebp)
804844b: 83 7d f4 09 cmpl $0x9,-0xc(%ebp) # x ($ebp - 0xc) counter 9
804844f: 7e ea jle 804843b <puts@plt+0xe7>
8048451: 8b 45 f4 mov -0xc(%ebp),%eax
8048454: c6 44 05 e5 00 movb $0x0,-0x1b(%ebp,%eax,1)
8048459: c7 45 f4 01 00 00 00 movl $0x1,-0xc(%ebp) # counter = 1
8048460: eb 15 jmp 8048477 <puts@plt+0x123> # start of the loop
8048462: 8b 45 f4 mov -0xc(%ebp),%eax
8048465: 83 e8 01 sub $0x1,%eax
8048468: 0f b6 44 05 e5 movzbl -0x1b(%ebp,%eax,1),%eax
804846d: 0f be c0 movsbl %al,%eax
8048470: 01 45 f0 add %eax,-0x10(%ebp)
8048473: 83 45 f4 01 addl $0x1,-0xc(%ebp)
8048477: 83 7d f4 0a cmpl $0xa,-0xc(%ebp) # 10
804847b: 7e e5 jle 8048462 <puts@plt+0x10e> # end loop
804847d: 8b 45 f0 mov -0x10(%ebp),%eax
8048480: 89 c2 mov %eax,%edx
8048482: c1 fa 1f sar $0x1f,%edx
8048485: c1 ea 1c shr $0x1c,%edx
8048488: 01 d0 add %edx,%eax
804848a: 83 e0 0f and $0xf,%eax # only look at the lowest four bits
804848d: 29 d0 sub %edx,%eax
804848f: 89 45 f0 mov %eax,-0x10(%ebp)
8048492: 83 7d f0 03 cmpl $0x3,-0x10(%ebp) # compare to 3
8048496: 75 16 jne 80484ae <puts@plt+0x15a> # go to wrong answer
8048498: b8 b4 85 04 08 mov $0x80485b4,%eax
804849d: 8d 55 e5 lea -0x1b(%ebp),%edx
80484a0: 89 54 24 04 mov %edx,0x4(%esp)
80484a4: 89 04 24 mov %eax,(%esp)
80484a7: e8 98 fe ff ff call 8048344 <printf@plt> # correct answer
80484ac: eb 0c jmp 80484ba <puts@plt+0x166>
80484ae: c7 04 24 e2 85 04 08 movl $0x80485e2,(%esp)
80484b5: e8 9a fe ff ff call 8048354 <puts@plt> # wrong answer```