从中国DOS联盟看到这个帖子:批处理输入密码但不显示字符的代码
感觉很有趣,分析一下:
- @echo off
- :echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5x>in.com
- echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>in.com
- set /p password=Enter password:<nul
- echo %password%
- for /f "tokens=*" %%i in ('in.com') do set password=%%i
- :pause
- del in.com
- echo.
- echo The Password is:"%password%"
- set password=
- pause
- goto exit
- comment:all data or code are printable!!!
- for /f "tokens=*" %%i in ('in.com') do set password=%%i
- variable i is the output string of program in.com
- in.com==hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5x==>
- xxxx:0100 68 50 31 58 35 30 30 50-5B 50 5A 42 42 42 66 68 hP1X500P[PZBBBfh
- xxxx:0110 23 62 23 23 66 58 66 2D-56 40 60 24 66 50 66 5D #b##fXf-V@`$fPf]
- xxxx:0120 66 33 2F 66 31 2F 35 2B-2B 75 35 78 0D 0A 00 00 f3/f1/5++u5x....
- in.com:
- xxxx:0100 685031 PUSH 3150h
- xxxx:0103 58 POP AX;ax=3150
- xxxx:0104 353030 XOR AX,3030h;ax=160
- xxxx:0107 50 PUSH AX
- xxxx:0108 5B POP BX;bx=160 <--
- xxxx:0109 50 PUSH AX
- xxxx:010A 5A POP DX;dx=160;can not use 'add dx,3'-->83C203 is not printable char
- xxxx:010B 42 INC DX;dx=161;printable char [0x20,0x7E]
- xxxx:010C 42 INC DX;dx=162;
- xxxx:010D 42 INC DX;dx=163 <--buffer base address
- xxxx:010E 666823622323 PUSHD 23236223h
- xxxx:0114 6658 POP EAX;eax=23236223h
- xxxx:0116 662D56406024 SUB EAX,24604056h;eax=FEC321CD;not printable char instruction,use this method(modify code
- segment) or stack.
- xxxx:011C 6650 PUSH EAX
- xxxx:011E 665D POP EBP;ebp=FEC321CD,'FE'-->max char to input,'C3'-->RET,'CD21'-->INT 21
- xxxx:0120 66332F XOR EBP,[BX]
- xxxx:0123 66312F XOR [BX],EBP;[BX]=ds:[160]=cs:[160]=FEC321CD=INT 21,RET,buffer size
- xxxx:0126 352B2B XOR AX,2B2Bh;eax=FEC30AE6, ah=0A
- xxxx:0129 7535 JNZ Short 0160;yes
- xxxx:012B 780D JS Short 013A;78 is not needed,'x'
- xxxx:012D 0A00 OR AL,[BX+SI]
- xxxx:012F 0000 ADD [BX+SI],AL
- xxxx:0131 0000 ADD [BX+SI],AL
- xxxx:0133 0000 ADD [BX+SI],AL
- xxxx:.... .... ...
- xxxx:0160 CD21 INT 21h;ah=0A: get keyboard input to buffer. ds:dx=buffer base address,[ds:dx]=max buffer size,
- [ds:dx+1]=actual buffer size
- xxxx:0162 C3 RET
- xxxx:0163 FE <--max char to input
- xxxx:0164 x <--buffer_size
- xxxx:0165 <-- buffer
不过,还是有一点不理解,为什么变量password可以取到in.com的buffer的字符串呢??