|Seven | |XP | |98 | |8.1 | |10 | |
hInput | 3 | 3 | 8 | |54h | |80h |
hOutput | 7 | 7 | |0Ch | |58h | |84h |
hError | 0Bh | |0Bh | |10h | |5Ch | |88h |
include \masm32\include64\masm64rt.inc
.data
NameConsole db 'Values of stdinput, stdoutput, stderror',0
format db 'StdOutput=%016Xh',10,'StdInput=%016Xh',10,'StdError=%016Xh',0
.code
WinMain proc
local hIn:qword
local hOut:qword
local hError:qword
local BUFF[100]:byte
; to receive input handle
invoke GetStdHandle,STD_INPUT_HANDLE
mov hIn,rax
; to receive output handle
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hOut,rax
; to receive error handle
invoke GetStdHandle,STD_ERROR_HANDLE
mov hError,rax
;-------------------------------------------------------
invoke wsprintf,&BUFF,&format,hOut,hIn,rax
invoke MessageBox,0,&BUFF,&NameConsole,MB_OK
; release descriptors
invoke CloseHandle,hOut
invoke CloseHandle,hIn
invoke CloseHandle,hError
; switch off the console
invoke FreeConsole
invoke ExitProcess,0
WinMain endp
end
include \masm32\include64\masm64rt.inc
MAXSCREENX = 43
MAXSCREENY = 8
SMALL_RECT STRUCT
Left WORD ?
Top WORD ?
Right WORD ?
Bottom WORD ?
SMALL_RECT ENDS
CONSOLE_CURSOR_INFO STRUCT
dwSize DWORD ?
bVisible DWORD ?
CONSOLE_CURSOR_INFO ENDS
COORD STRUCT
x WORD ?
y WORD ?
COORD ENDS
KEY_EVENT_RECORD STRUCT
bKeyDown DWORD ?
wRepeatCount WORD ?
wVirtualKeyCode WORD ?
wVirtualScanCode WORD ?
UNION
UnicodeChar WORD ?
AsciiChar BYTE ?
ENDS
dwControlKeyState DWORD ?
KEY_EVENT_RECORD ENDS
MOUSE_EVENT_RECORD STRUCT
dwMousePosition COORD <>
dwButtonState DWORD ?
dwControlKeyState DWORD ?
dwEventFlags DWORD ?
MOUSE_EVENT_RECORD ENDS
MENU_EVENT_RECORD STRUCT
dwCommandId DWORD ?
MENU_EVENT_RECORD ENDS
FOCUS_EVENT_RECORD STRUCT
bSetFocus DWORD ?
FOCUS_EVENT_RECORD ENDS
WINDOW_BUFFER_SIZE_RECORD STRUCT
dwSize COORD <>
WINDOW_BUFFER_SIZE_RECORD ENDS
INPUT_RECORD STRUCT
EventType WORD ?
two_byte_alignment WORD ?
UNION
KeyEvent KEY_EVENT_RECORD <>
MouseEvent MOUSE_EVENT_RECORD <>
WindowBufferSizeEvent WINDOW_BUFFER_SIZE_RECORD <>
MenuEvent MENU_EVENT_RECORD <>
FocusEvent FOCUS_EVENT_RECORD <>
ENDS
INPUT_RECORD ENDS
.data
Str1 db 'This console was created by system at start of the console application.',10,\
'For continue press the Esc key'
Str2 db 'First console',0
Str3 db 'Second console',0
Str4 db 'c28.exe',0
Str5 db 'cls',0
Str6 db 'Third console',0
Str7 db 'This console was created by the AllocConsole function.',10,\
'For an exit from the program press the Esc key'
.code
WinMain proc
local ConsoleWindow:SMALL_RECT; sizeof=0x8, align=0x2
local cci:CONSOLE_CURSOR_INFO; sizeof=0x8, align=0x4
local ExitCode:DWORD;
local pi:PROCESS_INFORMATION; sizeof=0x18, align=0x8
local cif:STARTUPINFO; sizeof=0x68, align=0x8
local MOUSE_KEY:INPUT_RECORD; sizeof=0x14, align=0x4
local Result:QWORD
local hOut:DWORD
local hIn:DWORD
xor ebx,ebx
invoke SetConsoleTitle,addr Str2
invoke system,addr Str5
invoke GetStdHandle,STD_INPUT_HANDLE
mov hIn,eax
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hOut,eax
invoke WriteConsole,eax,addr Str1,sizeof Str1,addr Result,0
@@: invoke ReadConsoleInput,hIn,addr MOUSE_KEY,TRUE,addr Result
cmp MOUSE_KEY.EventType,KEY_EVENT
jnz @b
cmp MOUSE_KEY.KeyEvent.bKeyDown,ebx;FALSE
jnz @b
cmp MOUSE_KEY.KeyEvent.wVirtualKeyCode,VK_ESCAPE
jnz @b
invoke FreeConsole
;----------------------------------------------------------------
mov cif.cb,sizeof STARTUPINFO
mov cif.lpReserved,rbx;0
mov cif.lpDesktop,rbx;0
lea rax,Str3
mov cif.lpTitle,rax ;Display name for the title bar of the new console's window
mov cif.dwFlags,STARTF_USEPOSITION or STARTF_USESIZE or \
STARTF_USECOUNTCHARS or STARTF_USEFILLATTRIBUTE or \
STARTF_USESHOWWINDOW
mov cif.dwFillAttribute,BACKGROUND_BLUE+FOREGROUND_BLUE+\
FOREGROUND_GREEN+FOREGROUND_RED;Text and background color attributes of the new console's screen buffer
mov cif.dwX,200 ; left edge Location of the new console window, in screen pixel coordinates
mov cif.dwY,200 ; upper edge
mov cif.dwXSize,400 ; width 400/8=50
mov cif.dwYSize,96 ; height 96/12=8
mov cif.dwXCountChars,50 ; width Size of the new console's screen buffer, in character cells
mov cif.dwYCountChars,8 ; height
mov cif.wShowWindow,SW_SHOW
mov cif.cbReserved2,0
mov cif.lpReserved2,rbx
invoke CreateProcess,addr Str4,0,0,0,0,CREATE_NEW_CONSOLE,0,0,addr cif,addr pi
@@: invoke GetExitCodeProcess,pi.hProcess,addr ExitCode
cmp ExitCode,STILL_ACTIVE
jz @b
invoke TerminateProcess,pi.hProcess,0
invoke CloseHandle,pi.hThread
invoke CloseHandle,pi.hProcess
invoke FreeConsole
;--------------------------------------------------
invoke AllocConsole
invoke GetLargestConsoleWindowSize,hOut
lea r8d,ConsoleWindow
mov [r8],ebx;ConsoleWindow.Left = 0 ConsoleWindow.Top = 0
sub ax,MAXSCREENX
sbb edx,edx
and ax,dx
add ax,MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax
shr eax,16
sub eax,MAXSCREENY
sbb edx,edx
and eax,edx
add eax,MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax
invoke SetConsoleWindowInfo,hOut,TRUE
invoke SetConsoleScreenBufferSize,hOut,MAXSCREENY*10000h+MAXSCREENX
invoke SetConsoleTitle,addr Str6
invoke WriteConsole,hOut,addr Str7,sizeof Str7,addr Result,0
invoke GetConsoleCursorInfo,hOut,addr cci
mov cci.bVisible,ebx;FALSE
invoke SetConsoleCursorInfo,hOut,addr cci
@@: invoke ReadConsoleInput,hIn,addr MOUSE_KEY,TRUE,addr Result
cmp MOUSE_KEY.EventType,KEY_EVENT
jnz @b
cmp MOUSE_KEY.KeyEvent.bKeyDown,ebx;FALSE
jnz @b
cmp MOUSE_KEY.KeyEvent.wVirtualKeyCode,VK_ESCAPE
jnz @b
invoke CloseHandle,hIn
invoke CloseHandle,hOut
invoke FreeConsole
invoke ExitProcess,0
WinMain endp
end
c28.asminclude \masm32\include64\masm64rt.inc
;----------------------------------------------
SMALL_RECT STRUCT
Left WORD ?
Top WORD ?
Right WORD ?
Bottom WORD ?
SMALL_RECT ENDS
CONSOLE_CURSOR_INFO STRUCT
dwSize DWORD ?
bVisible DWORD ?
CONSOLE_CURSOR_INFO ENDS
COORD STRUCT
x WORD ?
y WORD ?
COORD ENDS
KEY_EVENT_RECORD STRUCT
bKeyDown DWORD ?
wRepeatCount WORD ?
wVirtualKeyCode WORD ?
wVirtualScanCode WORD ?
UNION
UnicodeChar WORD ?
AsciiChar BYTE ?
ENDS
dwControlKeyState DWORD ?
KEY_EVENT_RECORD ENDS
MOUSE_EVENT_RECORD STRUCT
dwMousePosition COORD <>
dwButtonState DWORD ?
dwControlKeyState DWORD ?
dwEventFlags DWORD ?
MOUSE_EVENT_RECORD ENDS
MENU_EVENT_RECORD STRUCT
dwCommandId DWORD ?
MENU_EVENT_RECORD ENDS
FOCUS_EVENT_RECORD STRUCT
bSetFocus DWORD ?
FOCUS_EVENT_RECORD ENDS
WINDOW_BUFFER_SIZE_RECORD STRUCT
dwSize COORD <>
WINDOW_BUFFER_SIZE_RECORD ENDS
INPUT_RECORD STRUCT
EventType WORD ?
two_byte_alignment WORD ?
UNION
KeyEvent KEY_EVENT_RECORD <>
MouseEvent MOUSE_EVENT_RECORD <>
WindowBufferSizeEvent WINDOW_BUFFER_SIZE_RECORD <>
MenuEvent MENU_EVENT_RECORD <>
FocusEvent FOCUS_EVENT_RECORD <>
ENDS
INPUT_RECORD ENDS
.data
Str1 db 'This console was created by the CreateProcess',10,\
'function with the CREATE_NEW_CONSOLE parameter.',10,\
'For continuation press the Esc key'
.code
WinMain proc
local MOUSE_KEY:INPUT_RECORD; sizeof=0x14, align=0x4
local Result:QWORD
local hOut:DWORD
local hIn:DWORD
xor ebx,ebx
invoke GetStdHandle,STD_INPUT_HANDLE
mov hIn,eax
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hOut,eax
invoke WriteConsole,eax,addr Str1,sizeof Str1,addr Result,0
@@: invoke ReadConsoleInput,hIn,addr MOUSE_KEY,TRUE,addr Result
cmp MOUSE_KEY.EventType,KEY_EVENT
jnz @b
cmp MOUSE_KEY.KeyEvent.bKeyDown,ebx;FALSE
jnz @b
cmp MOUSE_KEY.KeyEvent.wVirtualKeyCode,VK_ESCAPE
jnz @b
invoke CloseHandle,hIn
invoke CloseHandle,hOut
invoke FreeConsole
invoke ExitProcess,0
WinMain endp
end
makeit.bat@echo off
::set appname=c27
set appname=c28
cls
\masm32\bin64\ml64.exe /c %appname%.asm
\masm32\bin64\link.exe /SUBSYSTEM:CONSOLE /MACHINE:X64 /ENTRY:WinMain /nologo /LARGEADDRESSAWARE %appname%.obj
del %appname%.obj
dir %appname%.*
pause
There are files "msvcrt.inc" and "msvcrt.lib" need to be placed in directories include64 and lib64 in the attachment...
Quote from: TimoVJL on February 08, 2019, 06:34:45 PM
Windows 8.1
StdInput=54h
StdOutput=58h
StdError=5Ch
Windows 10
StdInput=80h
StdOutput=84h
StdError=88h
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma comment(lib, "msvcrt.lib")
typedef struct _RTL_USER_PROCESS_PARAMETERS
{
ULONG MaximumLength;
ULONG Length;
ULONG Flags;
ULONG DebugFlags;
PVOID ConsoleHandle;
ULONG ConsoleFlags;
PVOID StandardInput;
PVOID StandardOutput;
PVOID StandardError;
// ...
} RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
void __cdecl mainCRTStartup(void)
{
#ifndef _WIN64
void *pPeb = (void*)__readfsdword(0x30); //
PRTL_USER_PROCESS_PARAMETERS pUPP = *(PRTL_USER_PROCESS_PARAMETERS*)((BYTE*)pPeb+0x10);
#else
void *pPeb = (void*)__readgsqword(0x60); //
PRTL_USER_PROCESS_PARAMETERS pUPP = *(PRTL_USER_PROCESS_PARAMETERS*)((BYTE*)pPeb+0x20);
#endif
printf("Input\tOutput\tError\n");
printf("%Xh\t%Xh\t%Xh\n", pUPP->StandardInput, pUPP->StandardOutput, pUPP->StandardError);
ExitProcess(0);
}
include \masm32_backup\include64\masm64rt.inc
include .\windows64.inc
.data
Str1 BYTE 'This console was created by the CreateProcess',10,\
'function with the CREATE_NEW_CONSOLE parameter.',10,\
'For continuation press the Esc key. . . ', 13, 10
mouseMsg BYTE "You clicked the left mouse button.", 13, 10
msMsg BYTE "MOUSE_EVENT", 0
keyMsg BYTE "You clicked 'esc' - the escape key.", 0
keySMsg BYTE "You clicked 'space' - the space bar.", 0
keConMsg BYTE "You clicked 'esc' - the escape key.", 13, 10
keSpMsg BYTE "You clicked 'space' - the space bar.", 13, 10
keMsg BYTE "KEY_EVENT", 0
refMode DWORD ?
.code
WinMain proc
LOCAL EVENT_KEY:INPUT_RECORD ; sizeof=0x14, align=0x4
LOCAL Result:DWORD
LOCAL hOut:DWORD
LOCAL hIn:DWORD
xor ebx, ebx
mov ecx, STD_INPUT_HANDLE
call GetStdHandle
mov hIn, eax
mov ecx, STD_OUTPUT_HANDLE
call GetStdHandle
mov hOut, eax
mov edx, ENABLE_WINDOW_INPUT or ENABLE_MOUSE_INPUT
mov refMode, edx
mov edx, refMode
mov ecx, hIn
call SetConsoleMode
test eax, eax
jz _FinalExit
mov [rsp+20h], rbx
lea r9d, Result
mov r8d, sizeof Str1
mov edx, offset Str1
mov ecx, hOut
call WriteConsole
SWITCH:
lea r9d, Result
mov r8d, 1
lea edx, EVENT_KEY
mov ecx, hIn
call ReadConsoleInput
cmp EVENT_KEY.EventType, KEY_EVENT
jz _KEY_EVENT
cmp EVENT_KEY.EventType, MOUSE_EVENT
jz _MOUSE_EVENT
jnz SWITCH
_KEY_EVENT:
cmp EVENT_KEY.KeyEvent.bKeyDown, 0
jnz SWITCH
cmp EVENT_KEY.KeyEvent.wVirtualKeyCode, SPACE_BAR
jz _Exit1
cmp EVENT_KEY.KeyEvent.wVirtualKeyCode, VK_ESCAPE
jnz SWITCH
jz _Exit2
_MOUSE_EVENT:
cmp EVENT_KEY.MouseEvent.dwButtonState, FROM_LEFT_1ST_BUTTON_PRESSED
jnz SWITCH
mov r9d, MB_OK
mov r8d, offset msMsg
mov edx, offset mouseMsg
mov ecx, 0
call MessageBoxA
_Exit1:
xor rbx, rbx
mov [rsp+20h], rbx
lea r9d, Result
mov r8d, sizeof keSpMsg
mov edx, offset keSpMsg
mov ecx, hOut
call WriteConsole
mov r9d, MB_OK
mov r8d, offset keMsg
mov edx, offset keySMsg
mov ecx, 0
call MessageBoxA
jmp SWITCH
_Exit2:
xor rbx, rbx
mov [rsp+20h], rbx
lea r9d, Result
mov r8d, sizeof keConMsg
mov edx, offset keConMsg
mov ecx, hOut
call WriteConsole
mov r9d, MB_OK
mov r8d, offset keMsg
mov edx, offset keyMsg
mov ecx, 0
call MessageBoxA
_FinalExit:
mov ecx, hIn
call CloseHandle
mov ecx, hOut
call CloseHandle
call FreeConsole
xor ecx, ecx
call ExitProcess
WinMain endp
end
Quote from: TimoVJL on February 09, 2019, 06:36:51 PMHey Timo,
Use SetConsoleMode ENABLE_MOUSE_INPUT
This console was created by the CreateProcess
function with the CREATE_NEW_CONSOLE parameter.
For continuation press the Esc key. . . You clicked the left mouse button.
mov edx, ENABLE_EXTENDED_FLAGS
mov ecx, hIn
call SetConsoleMode
test eax, eax
jz _FinalExit
mov edx, ENABLE_WINDOW_INPUT or ENABLE_MOUSE_INPUT
mov refMode, edx
mov edx, refMode
mov ecx, hIn
call SetConsoleMode
Quote from: Mikl__ on February 10, 2019, 02:42:20 AM
Hi, TBRANSO1!
http://masm32.com/board/index.php?topic=4190.msg54978#msg54978
QuoteDo you use WASM, because no hard feelings, but I don't want to use yet another assembler or compilerHi, TBRANSO1!
Quote from: Mikl__ on February 10, 2019, 10:27:16 AMQuoteDo you use WASM, because no hard feelings, but I don't want to use yet another assembler or compilerHi, TBRANSO1!
I not used WASM, I use MASM dialect. The name of the site in my signature WASM.IN -- it isn't Open Watcom Assembler or WASM (an x86 assembler produced by Watcom and included as part of the Watcom C/C++ compiler). It is Windows + ASseMbler
There are inc-files that I use in attachment