Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing simple string to console using masm (assembly code)

i would like to write a string in console output using writeconsole API but it doesn't work i link and build it using console in masm

here is the code

.386
.MODEL Flat,STDCALL
option casemap:none 
include \masm32\include\windows.inc 
include \masm32\include\kernel32.inc 
includelib \masm32\lib\kernel32.lib 

STD_OUTPUT_HANDLE EQU -11

.DATA
Msg  db "Hello World",13,10,0
lmessage dd 13

.DATA?

consoleOutHandle dd ? 
bytesWritten dd ?

.code
start:
INVOKE GetStdHandle, STD_OUTPUT_HANDLE
mov [consoleOutHandle],eax

invoke WriteConsole, consoleOutHandle,offset Msg,offset lmessage,offset bytesWritten,0
INVOKE ExitProcess,0 
end start

when i run the exe output i got the following

C:\masm32>18.exe

C:\masm32>

empty ouput

so any advice

like image 261
mohamed essam Avatar asked Apr 30 '26 02:04

mohamed essam


1 Answers

The third parameter is the number of characters to be written, not the address of the number of characters to be written. Fortunately for you the address turned out to be over 64K which caused the call to fail with the error code ERROR_NOT_ENOUGH_MEMORY.

like image 146
Neil Avatar answered May 03 '26 17:05

Neil