Continued hack to win32/console.c, so that the IDA Pro Disassembler
works again. Needs much more work however.
This commit is contained in:
parent
c80f32458a
commit
a2ca7b9852
118
win32/console.c
118
win32/console.c
|
@ -50,9 +50,6 @@
|
||||||
/* The CONSOLE kernel32 Object */
|
/* The CONSOLE kernel32 Object */
|
||||||
typedef struct _CONSOLE {
|
typedef struct _CONSOLE {
|
||||||
K32OBJ header;
|
K32OBJ header;
|
||||||
|
|
||||||
INPUT_RECORD *irs; /* buffered input records */
|
|
||||||
int nrofirs;/* nr of buffered input records */
|
|
||||||
} CONSOLE;
|
} CONSOLE;
|
||||||
|
|
||||||
static void CONSOLE_Destroy( K32OBJ *obj );
|
static void CONSOLE_Destroy( K32OBJ *obj );
|
||||||
|
@ -99,18 +96,6 @@ static BOOL32 CONSOLE_GetInfo( HANDLE32 handle, struct get_console_info_reply *r
|
||||||
return !CLIENT_WaitSimpleReply( reply, sizeof(*reply), NULL );
|
return !CLIENT_WaitSimpleReply( reply, sizeof(*reply), NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* CONSOLE_add_input_record [internal]
|
|
||||||
*
|
|
||||||
* Adds an INPUT_RECORD to the CONSOLEs input queue.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
CONSOLE_add_input_record(CONSOLE *console,INPUT_RECORD *inp) {
|
|
||||||
console->irs = HeapReAlloc(GetProcessHeap(),0,console->irs,sizeof(INPUT_RECORD)*(console->nrofirs+1));
|
|
||||||
console->irs[console->nrofirs++]=*inp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* XTERM_string_to_IR [internal]
|
* XTERM_string_to_IR [internal]
|
||||||
*
|
*
|
||||||
|
@ -121,7 +106,7 @@ static void
|
||||||
CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) {
|
CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) {
|
||||||
int j,k;
|
int j,k;
|
||||||
INPUT_RECORD ir;
|
INPUT_RECORD ir;
|
||||||
CONSOLE *console = CONSOLE_GetPtr( hConsoleInput );
|
DWORD junk;
|
||||||
|
|
||||||
for (j=0;j<len;j++) {
|
for (j=0;j<len;j++) {
|
||||||
unsigned char inchar = buf[j];
|
unsigned char inchar = buf[j];
|
||||||
|
@ -148,22 +133,29 @@ CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) {
|
||||||
ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff,
|
ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff,
|
||||||
0 /* VirtualKeyCodes to ScanCode */
|
0 /* VirtualKeyCodes to ScanCode */
|
||||||
);
|
);
|
||||||
|
ir.Event.KeyEvent.uChar.AsciiChar = inchar;
|
||||||
|
|
||||||
|
if (inchar==127) { /* backspace */
|
||||||
|
ir.Event.KeyEvent.uChar.AsciiChar = '\b'; /* FIXME: hmm */
|
||||||
|
ir.Event.KeyEvent.wVirtualScanCode = 0x0e;
|
||||||
|
ir.Event.KeyEvent.wVirtualKeyCode = VK_BACK;
|
||||||
|
} else {
|
||||||
if (inchar=='\n') {
|
if (inchar=='\n') {
|
||||||
ir.Event.KeyEvent.uChar.AsciiChar = '\r';
|
ir.Event.KeyEvent.uChar.AsciiChar = '\r';
|
||||||
ir.Event.KeyEvent.wVirtualKeyCode = 0x0d;
|
ir.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
|
||||||
ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
|
ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
|
||||||
} else {
|
} else {
|
||||||
ir.Event.KeyEvent.uChar.AsciiChar = inchar;
|
|
||||||
if (inchar<' ') {
|
if (inchar<' ') {
|
||||||
/* FIXME: find good values for ^X */
|
/* FIXME: find good values for ^X */
|
||||||
ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
|
ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
|
||||||
ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
|
ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CONSOLE_add_input_record(console,&ir);
|
assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk ));
|
||||||
ir.Event.KeyEvent.bKeyDown = 0;
|
ir.Event.KeyEvent.bKeyDown = 0;
|
||||||
CONSOLE_add_input_record(console,&ir);
|
assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk ));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* inchar is ESC */
|
/* inchar is ESC */
|
||||||
|
@ -178,9 +170,9 @@ CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) {
|
||||||
);
|
);
|
||||||
ir.Event.KeyEvent.dwControlKeyState = 0;
|
ir.Event.KeyEvent.dwControlKeyState = 0;
|
||||||
ir.Event.KeyEvent.uChar.AsciiChar = 27;
|
ir.Event.KeyEvent.uChar.AsciiChar = 27;
|
||||||
CONSOLE_add_input_record(console,&ir);
|
assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk ));
|
||||||
ir.Event.KeyEvent.bKeyDown = 0;
|
ir.Event.KeyEvent.bKeyDown = 0;
|
||||||
CONSOLE_add_input_record(console,&ir);
|
assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk ));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (k=j;k<len;k++) {
|
for (k=j;k<len;k++) {
|
||||||
|
@ -247,7 +239,7 @@ CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) {
|
||||||
else
|
else
|
||||||
ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
|
ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
|
||||||
ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
|
ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
|
||||||
CONSOLE_add_input_record(console,&ir);
|
assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk));
|
||||||
j=k+3;
|
j=k+3;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -256,15 +248,14 @@ CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) {
|
||||||
if (scancode) {
|
if (scancode) {
|
||||||
ir.Event.KeyEvent.wVirtualScanCode = scancode;
|
ir.Event.KeyEvent.wVirtualScanCode = scancode;
|
||||||
ir.Event.KeyEvent.wVirtualKeyCode = MapVirtualKey16(scancode,1);
|
ir.Event.KeyEvent.wVirtualKeyCode = MapVirtualKey16(scancode,1);
|
||||||
CONSOLE_add_input_record(console,&ir);
|
assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk ));
|
||||||
ir.Event.KeyEvent.bKeyDown = 0;
|
ir.Event.KeyEvent.bKeyDown = 0;
|
||||||
CONSOLE_add_input_record(console,&ir);
|
assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk ));
|
||||||
j=k;
|
j=k;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
K32OBJ_DecCount(&console->header);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -274,7 +265,7 @@ CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) {
|
||||||
* in an internal queue.
|
* in an internal queue.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
CONSOLE_get_input( HANDLE32 handle )
|
CONSOLE_get_input( HANDLE32 handle, BOOL32 blockwait )
|
||||||
{
|
{
|
||||||
char *buf = HeapAlloc(GetProcessHeap(),0,1);
|
char *buf = HeapAlloc(GetProcessHeap(),0,1);
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
@ -294,30 +285,6 @@ CONSOLE_get_input( HANDLE32 handle )
|
||||||
HeapFree(GetProcessHeap(),0,buf);
|
HeapFree(GetProcessHeap(),0,buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* CONSOLE_drain_input (internal)
|
|
||||||
*
|
|
||||||
* Drains 'n' console input events from the queue.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
CONSOLE_drain_input(CONSOLE *console,int n) {
|
|
||||||
assert(n<=console->nrofirs);
|
|
||||||
if (n) {
|
|
||||||
console->nrofirs-=n;
|
|
||||||
memcpy( &console->irs[0],
|
|
||||||
&console->irs[n],
|
|
||||||
console->nrofirs*sizeof(INPUT_RECORD)
|
|
||||||
);
|
|
||||||
console->irs = HeapReAlloc(
|
|
||||||
GetProcessHeap(),
|
|
||||||
0,
|
|
||||||
console->irs,
|
|
||||||
console->nrofirs*sizeof(INPUT_RECORD)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list
|
* SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list
|
||||||
*
|
*
|
||||||
|
@ -544,8 +511,6 @@ HANDLE32 CONSOLE_OpenHandle( BOOL32 output, DWORD access, LPSECURITY_ATTRIBUTES
|
||||||
}
|
}
|
||||||
console->header.type = K32OBJ_CONSOLE;
|
console->header.type = K32OBJ_CONSOLE;
|
||||||
console->header.refcount = 1;
|
console->header.refcount = 1;
|
||||||
console->nrofirs = 0;
|
|
||||||
console->irs = HeapAlloc(GetProcessHeap(),0,1);;
|
|
||||||
handle = HANDLE_Alloc( PROCESS_Current(), &console->header, req.access,
|
handle = HANDLE_Alloc( PROCESS_Current(), &console->header, req.access,
|
||||||
req.inherit, reply.handle );
|
req.inherit, reply.handle );
|
||||||
SYSTEM_UNLOCK();
|
SYSTEM_UNLOCK();
|
||||||
|
@ -672,8 +637,6 @@ BOOL32 WINAPI AllocConsole(VOID)
|
||||||
|
|
||||||
console->header.type = K32OBJ_CONSOLE;
|
console->header.type = K32OBJ_CONSOLE;
|
||||||
console->header.refcount = 1;
|
console->header.refcount = 1;
|
||||||
console->nrofirs = 0;
|
|
||||||
console->irs = HeapAlloc(GetProcessHeap(),0,1);;
|
|
||||||
|
|
||||||
CLIENT_SendRequest( REQ_ALLOC_CONSOLE, -1, 0 );
|
CLIENT_SendRequest( REQ_ALLOC_CONSOLE, -1, 0 );
|
||||||
if (CLIENT_WaitReply( NULL, NULL, 0 ) != ERROR_SUCCESS)
|
if (CLIENT_WaitReply( NULL, NULL, 0 ) != ERROR_SUCCESS)
|
||||||
|
@ -968,35 +931,43 @@ BOOL32 WINAPI ReadConsole32A( HANDLE32 hConsoleInput,
|
||||||
LPDWORD lpNumberOfCharsRead,
|
LPDWORD lpNumberOfCharsRead,
|
||||||
LPVOID lpReserved )
|
LPVOID lpReserved )
|
||||||
{
|
{
|
||||||
CONSOLE *console = CONSOLE_GetPtr( hConsoleInput );
|
int charsread = 0;
|
||||||
int i,charsread = 0;
|
|
||||||
LPSTR xbuf = (LPSTR)lpBuffer;
|
LPSTR xbuf = (LPSTR)lpBuffer;
|
||||||
|
struct read_console_input_request req;
|
||||||
|
INPUT_RECORD ir;
|
||||||
|
|
||||||
if (!console) {
|
if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hConsoleInput,
|
||||||
SetLastError(ERROR_INVALID_HANDLE);
|
K32OBJ_CONSOLE, GENERIC_READ )) == -1)
|
||||||
FIXME(console,"(%d,...), no console handle!\n",hConsoleInput);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
TRACE(console,"(%d,%p,%ld,%p,%p)\n",
|
TRACE(console,"(%d,%p,%ld,%p,%p)\n",
|
||||||
hConsoleInput,lpBuffer,nNumberOfCharsToRead,
|
hConsoleInput,lpBuffer,nNumberOfCharsToRead,
|
||||||
lpNumberOfCharsRead,lpReserved
|
lpNumberOfCharsRead,lpReserved
|
||||||
);
|
);
|
||||||
CONSOLE_get_input(hConsoleInput);
|
|
||||||
|
CONSOLE_get_input(hConsoleInput,FALSE);
|
||||||
|
|
||||||
|
req.count = 1;
|
||||||
|
req.flush = 1;
|
||||||
|
|
||||||
/* FIXME: should we read at least 1 char? The SDK does not say */
|
/* FIXME: should we read at least 1 char? The SDK does not say */
|
||||||
for (i=0;(i<console->nrofirs)&&(charsread<nNumberOfCharsToRead);i++) {
|
while (charsread<nNumberOfCharsToRead)
|
||||||
if (console->irs[i].EventType != KEY_EVENT)
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) );
|
||||||
|
if (CLIENT_WaitReply( &len, NULL, 1, &ir, sizeof(ir) ))
|
||||||
|
return FALSE;
|
||||||
|
assert( !(len % sizeof(ir)) );
|
||||||
|
if (!len) break;
|
||||||
|
if (!ir.Event.KeyEvent.bKeyDown)
|
||||||
continue;
|
continue;
|
||||||
if (!console->irs[i].Event.KeyEvent.bKeyDown)
|
if (ir.EventType != KEY_EVENT)
|
||||||
continue;
|
continue;
|
||||||
*xbuf++ = console->irs[i].Event.KeyEvent.uChar.AsciiChar;
|
*xbuf++ = ir.Event.KeyEvent.uChar.AsciiChar;
|
||||||
charsread++;
|
charsread++;
|
||||||
}
|
}
|
||||||
/* SDK says: Drains all other input events from queue. */
|
|
||||||
CONSOLE_drain_input(console,i);
|
|
||||||
if (lpNumberOfCharsRead)
|
if (lpNumberOfCharsRead)
|
||||||
*lpNumberOfCharsRead = charsread;
|
*lpNumberOfCharsRead = charsread;
|
||||||
K32OBJ_DecCount(&console->header);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,7 +1031,8 @@ BOOL32 WINAPI ReadConsoleInput32A(HANDLE32 hConsoleInput,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
assert( !(len % sizeof(INPUT_RECORD)) );
|
assert( !(len % sizeof(INPUT_RECORD)) );
|
||||||
if (len) break;
|
if (len) break;
|
||||||
WaitForSingleObject( hConsoleInput, INFINITE32 );
|
CONSOLE_get_input(hConsoleInput,TRUE);
|
||||||
|
/*WaitForSingleObject( hConsoleInput, INFINITE32 );*/
|
||||||
}
|
}
|
||||||
if (lpNumberOfEventsRead) *lpNumberOfEventsRead = len / sizeof(INPUT_RECORD);
|
if (lpNumberOfEventsRead) *lpNumberOfEventsRead = len / sizeof(INPUT_RECORD);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -1112,6 +1084,8 @@ BOOL32 WINAPI PeekConsoleInput32A( HANDLE32 handle, LPINPUT_RECORD buffer,
|
||||||
if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle,
|
if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle,
|
||||||
K32OBJ_CONSOLE, GENERIC_READ )) == -1)
|
K32OBJ_CONSOLE, GENERIC_READ )) == -1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
CONSOLE_get_input(handle,FALSE);
|
||||||
req.count = count;
|
req.count = count;
|
||||||
req.flush = 0;
|
req.flush = 0;
|
||||||
|
|
||||||
|
@ -1306,8 +1280,8 @@ BOOL32 WINAPI GetNumberOfConsoleInputEvents(HANDLE32 hcon,LPDWORD nrofevents)
|
||||||
FIXME(console,"(%d,%p), no console handle!\n",hcon,nrofevents);
|
FIXME(console,"(%d,%p), no console handle!\n",hcon,nrofevents);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
CONSOLE_get_input(hcon);
|
CONSOLE_get_input(hcon,FALSE);
|
||||||
*nrofevents = console->nrofirs;
|
*nrofevents = 1; /* UMM */
|
||||||
K32OBJ_DecCount(&console->header);
|
K32OBJ_DecCount(&console->header);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue