Hello guys,
I wrote this program to encrypt a string. It uses the WriteConsoleA function to print output, and the ReadConsoleA function for the input. I have called all the functions using stack. Here is the code:
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
extrn GetStdHandle@4 : PROC
extrn WriteConsoleA@20 :PROC
extrn ReadConsoleA@20 : PROC
.data
prompt BYTE "Please Enter Your name:", 13, 10 ,0
prompt1 BYTE "Encrypted Name is:", 13, 10 ,0
.data?
buf BYTE 100 DUP(?)
inp BYTE 100 DUP(?)
ln DWORD ?
.code
main PROC
;pushing arguments into stack for function GetStdHandle
mov eax, STD_OUTPUT_HANDLE
push eax
CALL GetStdHandle@4
;WriteConsoleA
mov ebx, 0
push ebx
mov ebx, OFFSET buf
push ebx
mov ebx, LENGTHOF prompt
push ebx
mov ebx, OFFSET prompt
push ebx
push eax
CALL WriteConsoleA@20
;push arguments for getstdhandle
mov eax, STD_INPUT_HANDLE
push eax
CALL GetStdHandle
;push arguments for ReadConsoleA
mov ebx, OFFSET buf
push ebx
mov ebx, 0
push ebx
mov ebx, 100
push ebx
lea ebx, inp
push ebx
push eax
CALL ReadConsoleA@20
;call StripLF
lea ebx, inp
push ebx
CALL StripLF
;Start Encryption
mov ecx, SIZEOF inp
mov esi, 0
L1:
xor inp[esi], 11101101b
inc esi
loop L1
;Print Cipher Text:
;GetStdHandle
mov eax, STD_OUTPUT_HANDLE
push eax
CALL GetStdHandle
;WriteConsoleA
mov ebx, 0
push ebx
mov ebx, OFFSET ln
push ebx
mov ebx, LENGTHOF inp
push ebx
lea ebx, inp
push eax
CALL WriteConsoleA
mov eax,0
push eax
CALL ExitProcess
main ENDP
END main
For some reason, when i run the program, it first asks me for a string, then inputs the string and then exits. The second WriteConsoleA is not executed I guess. I was wondering if i needed to pop the registers. Help me out guys!
Thanks!
Devjeet