News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

INPUT_RECORD STRUCT

Started by TBRANSO1, February 07, 2019, 08:01:43 AM

Previous topic - Next topic

TBRANSO1

Hutch,

I have masm64 installed and want to use the INPUT_RECORD STRUCT, I have the masm64rt.inc as the include, and have done my string search and shows not found, it's obviously in the 32 library.  Is there an update that I missed?

Thanks


TBRANSO1

I looked through that but still no closer to an answer.

I have the latest files for masm32 and masm64, it's in windows.h in masm32, but not in masm64's files.. I am trying to use the masm64 library and using the INPUT_RECORD STRUCT and other related macros.

I am at a loss, I see include files for which I find no references, I found win64a.inc, but there isn't a lib associated with it so I can't use.  I found a reference to a mysterious temphlp.inc for which I can find nowhere... I can't tell if this is a wasm thing or a masm32 thing?

I ended up on _mikl's russian forum and found some clues, but I am still no closer to resolve this:

I have include \masm32\include64\masm64rt.inc

Microsoft (R) Macro Assembler (x64) Version 14.16.27026.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Assembling: c28.asm
c28.asm(15) : error A2006:undefined symbol : INPUT_RECORD
c28.asm(15) : error A2195:parameter or local cannot have void type
c28.asm(48) : error A2070:invalid instruction operands
c28.asm(22) : error A2006:undefined symbol : INPUT_RECORD
c28.asm(42) : error A2006:undefined symbol : EventType
c28.asm(44) : error A2006:undefined symbol : dwEventFlags
c28.asm(46) : error A2006:undefined symbol : dwButtonState
c28.asm(54) : error A2006:undefined symbol : EventType
c28.asm(56) : error A2006:undefined symbol : KeyEvent
c28.asm(58) : error A2006:undefined symbol : KeyEvent


hutch--

MSDN

typedef struct _INPUT_RECORD {
  WORD  EventType;
  union {
    KEY_EVENT_RECORD          KeyEvent;
    MOUSE_EVENT_RECORD        MouseEvent;
    WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
    MENU_EVENT_RECORD         MenuEvent;
    FOCUS_EVENT_RECORD        FocusEvent;
  } Event;
} INPUT_RECORD;

https://msdn.microsoft.com/en-us/windows/desktop/ms683499

In Windows.inc 32 bit.

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


TBRANSO1

@Hutch,

I have tried to add the windows.inc from the masm32 part, along with the masm64rt.inc, and it makes it worse... it throws off a line of errors 7,855 lines long.

I am doing:

ml64 /c filename.asm

I live on MSDN lately, so I am familiar with the struct. I've successfully used in with masm32, but have this problem with 64.

How is the include line supposed to look?

it's his c27 and c28 code.
The code that i have came from Jochen with the include win64a.inc, I am playing with console API stuff... I got the c28.exe and c28.asm, but modifying it and playing with it.  I am having trouble reassembling it with from this win64a.inc stuff, I am finally trying to make a console app. 

So, Jochen, could you supply this win64a.inc and the win64.lib?  :biggrin:

hutch--

The 32 bit and 64 bit files are incompatible, they are for OS versions that are technically different, mix them together and nothing will work. Be warned that ML64 is really intolerant with any include file errors. For the INPUT_RECORD structured, add it into your own app and see if that does the job for you.

Mikl__

Hi, TBRANSO1!
Can I look at the contents of the your c28.asm file?

TBRANSO1

@Mikl_

I attached what I did...

I got it to assemble by putting in the structs, hard coded per se.

But, something that I don't understand about the console signal thing is that it doesn't recognize my mouse signals.  I've read the MSDN docs.  I have also created similar code in C++, but it doesn't recognize the mouse, in C++ it recognizes keyboard inputs, and resizing inputs.

I haven't got the logic correct it seems in assembly.

Thanks

Mikl__

#8
Hi, TBRANSO1!
the first thing you have to do is look by means of a value debugger which are returned by the GetStdHandle function. To the surprise I have found these values are constants.

|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


If you have another version of Windows or get other values write me about it

      

TimoVJL

Windows 8.1
StdInput=54h
StdOutput=58h
StdError=5Ch

Windows 10
StdInput=80h
StdOutput=84h
StdError=88h
May the source be with you

Mikl__

#10
Kiitos, Timo!
c27.asm
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...

TBRANSO1

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

I got:

Windows Pro 10
StdIn = 0x00000008h
StdOut = 0x0000000Ch
StdErr = 0x00000010h

I debugged in both 32 and 64 bit formats, same results.
Why if I have the latest Win 10 Professional, all updated does it show Win98 results acc. to your chart?
I will take a look at your code, it looks like I will have to tweek the MASM64 library a little bit.

TimoVJL

Those dynamic values are not constant.
Input   Output  Error
4Ch     50h     54h
Input   Output  Error
58h     5Ch     60h
Input   Output  Error
50h     54h     58h

#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);
}
May the source be with you

Mikl__

Timo, kiitos vielä kerran!

TBRANSO1

#14
I still have one problem, however, could someone give me any ideas on why the console doesn't recognize any mouse signals?
It doesn't matter whether I programmed this in assembly or C++.  I don't get why???
The keyboard works great, just no mouse signals.

Here is what I have to attempt to find a mouse event.
the windows64.inc is my include with all the structs and defines

c28.asm

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


I never realized that consoles don't normally recognize mouse clicks, except to copy and paste text. Surely, it has to recognize a click?

What the heck is this for?
https://docs.microsoft.com/en-us/windows/console/setconsolemode

ENABLE_MOUSE_INPUT 0x0010    

If the mouse pointer is within the borders of the console window and the window has the keyboard focus, mouse events generated by mouse movement and button presses are placed in the input buffer.

I later added a line to enable mouse and line input and window size, and call SetConsoleMode on the StdIn handle, it still doesn't work.  WTH?