Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .stack 100h
- print macro txt
- mov ah, 9h
- lea dx, txt
- int 21h
- endm
- read macro buffer
- mov ah, 08h
- int 21h
- endm
- buffsize equ 08h
- hide equ '*'
- .data
- pasPrompt db 10,13,'Enter password:$'
- passWrong db 10,13,'Access Denied.$'
- inpComp db 10,13,'Input completed.$'
- selPrompt db 10,13,'Select an option:$'
- optionOne db 10,13, '[1] One.$'
- oOneMessage db 10,13,'You have selected the first option.$'
- oTwoMessage db 10,13,'You have selected the second option.$'
- oInvalid db 10,13,'Invalid selection.'
- oExiting db 10,13,'Exiting...$'
- optionTwo db 10,13, '[2] Two.$'
- optionThree db 10,13,'[3] Exit.$'
- pass db 'password'
- buffLen db 0
- passbuff db 8 DUP(0)
- .code
- mov ax, @data
- mov ds, ax
- ; We need to initialize our ES as well as our DS, the ES is used in REP instructions.
- mov es, ax
- Main:
- print pasPrompt
- readPass:
- ; First, we need to reset out strings length.
- ; Next, we load the source index of our buffer.
- ; This index will later be used to insert chars into byte by byte.
- xor cl, cl
- lea si, passbuff
- readPass_Loop:
- ; Read char by char until CX is max buffer size
- ; Results go into 'passbuff'
- ; Display hidden char each input
- ; 0D = enter key
- ; Now lets get a char as the start of our password input.
- mov ah, 08h
- int 21h
- ; If char==enter then
- ; compare the passwords
- cmp al, 0Dh
- je readPass_Done
- ; else
- ; If we are not pressing enter
- ; Move the char into our buffer
- ; Increment the char read.
- ; Store char into buffer.
- mov [si], al
- ;Check if we are at the last char
- ; If so, check password.
- cmp cl, buffSize
- je readPass_Done
- ; Increment length.
- ; Move pointer to next char in buffer.
- inc cl
- inc si
- ; Print password "star"
- mov ah, 02h
- mov dl, hide
- int 21h
- jmp readPass_Loop
- readPass_Done:
- ; Load the length of our read string into a variable.
- mov [buffLen], cl
- ; Make sure we are comparing from password length
- ; and NOT buffer length, if we used our buffer length
- ; simply entering the first letter of our password would let us in.
- xor cx, cx
- mov cl, buffSize
- ; Set direction of comparison.
- cld
- ; Load our 2 passwords to be checked by CMPSB <Compare Strings by Bytes>
- lea si, [pass]
- lea di, [passbuff]
- ; Check if password is correct.
- ; Using REP CMPSB <Repeat Compare String Bytes>
- rep cmpsb
- ; If equal go to menus
- ; If not, display "Access Denied"
- je Menus
- jne Denied
- Denied:
- print passWrong
- jmp exit
- Menus:
- ; Clear password buffer.
- ; Clear counter register(s), retrieve pointer to password input buffer.
- xor cx, cx
- lea si, passbuff
- ; Clear buffer char by char until it is completely cleared.
- clearloop:
- mov [si], 0h
- inc si
- inc cl
- cmp cl, buffsize
- jne clearloop
- ; Print "GUI"
- print selPrompt
- print optionOne
- print optionTwo
- print optionThree
- ; Prompt for an input, check against ASCII for 1,2,3
- getOption:
- mov ah, 8h
- int 21h
- cmp al, 31h
- je opOne
- cmp al, 32h
- je opTwo
- cmp al, 33h
- je opThree
- ; If the previous 3 chars were not pressed proceed
- ; to tell the user that the option was invalid.
- ; Then go back to the menu.
- jne opInvalid
- opOne:
- print oOneMessage
- jmp Menus
- opTwo:
- print oTwoMessage
- jmp Menus
- opThree:
- print oExiting
- jmp Main
- opInvalid:
- print oInvalid
- jmp Menus
- exit:
- mov ah, 4ch
- int 21h
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement