diff options
author | midipix <writeonce@midipix.org> | 2015-07-27 04:01:18 -0400 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2015-07-27 04:01:18 -0400 |
commit | dd89bb8ad4fe184a34b5dbdda237e640fc82121b (patch) | |
tree | 5e80d2da35f5892f92be29f57982b2708e6bd99b /src/tty | |
parent | dcdadc2702712fa750ed255ed1dfa354522797a0 (diff) | |
download | ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.bz2 ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.xz |
entered advanced internal development stage.
Diffstat (limited to 'src/tty')
-rw-r--r-- | src/tty/ntapi_tty_client_process_register.c | 37 | ||||
-rw-r--r-- | src/tty/ntapi_tty_client_session_query.c | 40 | ||||
-rw-r--r-- | src/tty/ntapi_tty_client_session_set.c | 38 | ||||
-rw-r--r-- | src/tty/ntapi_tty_connect.c | 47 | ||||
-rw-r--r-- | src/tty/ntapi_tty_create_session.c | 166 | ||||
-rw-r--r-- | src/tty/ntapi_tty_join_session.c | 53 | ||||
-rw-r--r-- | src/tty/ntapi_tty_query_information_server.c | 40 | ||||
-rw-r--r-- | src/tty/ntapi_tty_request_peer.c | 46 | ||||
-rw-r--r-- | src/tty/ntapi_tty_vms_query.c | 40 | ||||
-rw-r--r-- | src/tty/ntapi_tty_vms_request.c | 46 |
10 files changed, 553 insertions, 0 deletions
diff --git a/src/tty/ntapi_tty_client_process_register.c b/src/tty/ntapi_tty_client_process_register.c new file mode 100644 index 0000000..935cf1e --- /dev/null +++ b/src/tty/ntapi_tty_client_process_register.c @@ -0,0 +1,37 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +int32_t __stdcall __ntapi_tty_client_process_register( + __in void * hport, + __in uintptr_t process_id, + __in uintptr_t thread_id, + __in uintptr_t flags, + __in nt_large_integer * reserved) +{ + nt_status status; + nt_tty_register_msg msg; + + __ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_CLIENT_PROCESS_REGISTER; + + msg.data.reginfo.process_id = process_id; + msg.data.reginfo.thread_id = thread_id; + msg.data.reginfo.flags = flags; + + if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg))) + return status; + + return msg.data.ttyinfo.status; +} diff --git a/src/tty/ntapi_tty_client_session_query.c b/src/tty/ntapi_tty_client_session_query.c new file mode 100644 index 0000000..1d0dbe8 --- /dev/null +++ b/src/tty/ntapi_tty_client_session_query.c @@ -0,0 +1,40 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_tty.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +int32_t __stdcall __ntapi_tty_client_session_query( + __in void * hport, + __out nt_tty_session_info * sessioninfo) +{ + int32_t status; + nt_tty_session_msg msg; + + hport = hport ? hport : __ntapi_internals()->hport_tty_session; + + __ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_CLIENT_SESSION_QUERY; + + if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg))) + return status; + else if (msg.data.ttyinfo.status) + return msg.data.ttyinfo.status; + + sessioninfo->pid = msg.data.sessioninfo.pid; + sessioninfo->pgid = msg.data.sessioninfo.pgid; + sessioninfo->sid = msg.data.sessioninfo.sid; + sessioninfo->reserved = msg.data.sessioninfo.reserved; + + return NT_STATUS_SUCCESS; +} diff --git a/src/tty/ntapi_tty_client_session_set.c b/src/tty/ntapi_tty_client_session_set.c new file mode 100644 index 0000000..600fd5e --- /dev/null +++ b/src/tty/ntapi_tty_client_session_set.c @@ -0,0 +1,38 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_tty.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +int32_t __stdcall __ntapi_tty_client_session_set( + __in void * hport, + __in nt_tty_session_info * sessioninfo) +{ + int32_t status; + nt_tty_session_msg msg; + + hport = hport ? hport : __ntapi_internals()->hport_tty_session; + + __ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_CLIENT_SESSION_SET; + + msg.data.sessioninfo.pid = sessioninfo->pid; + msg.data.sessioninfo.pgid = sessioninfo->pgid; + msg.data.sessioninfo.sid = sessioninfo->sid; + msg.data.sessioninfo.reserved = sessioninfo->reserved; + + if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg))) + return status; + + return msg.data.ttyinfo.status; +} diff --git a/src/tty/ntapi_tty_connect.c b/src/tty/ntapi_tty_connect.c new file mode 100644 index 0000000..4ef198c --- /dev/null +++ b/src/tty/ntapi_tty_connect.c @@ -0,0 +1,47 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_object.h> +#include <ntapi/nt_port.h> +#include <ntapi/nt_string.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +int32_t __stdcall __ntapi_tty_connect( + __out void ** hport, + __in wchar16_t * tty_port_name, + __in int32_t impersonation_level) +{ + nt_object_attributes oa; + nt_unicode_string name; + nt_security_quality_of_service sqos; + + __ntapi->tt_init_unicode_string_from_utf16( + &name,tty_port_name); + + sqos.length = sizeof(sqos); + sqos.impersonation_level = impersonation_level; + sqos.context_tracking_mode = NT_SECURITY_TRACKING_DYNAMIC; + sqos.effective_only = 1; + + oa.len = sizeof(oa); + oa.root_dir = (void *)0; + oa.obj_name = &name; + oa.obj_attr = 0; + oa.sec_desc = (nt_security_descriptor *)0; + oa.sec_qos = &sqos; + + return __ntapi->zw_connect_port( + hport, + &name, + &sqos, + (nt_port_section_write *)0, + (nt_port_section_read *)0, + (uint32_t *)0, + (void *)0, + (uint32_t *)0); +} diff --git a/src/tty/ntapi_tty_create_session.c b/src/tty/ntapi_tty_create_session.c new file mode 100644 index 0000000..176b2fb --- /dev/null +++ b/src/tty/ntapi_tty_create_session.c @@ -0,0 +1,166 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +static int32_t __fastcall __tty_create_session_return( + nt_create_process_params * params, + int32_t status) +{ + if (status) + __ntapi->zw_terminate_process( + params->hprocess, + NT_STATUS_UNEXPECTED_IO_ERROR); + + __ntapi->zw_close(params->hprocess); + __ntapi->zw_close(params->hthread); + + return status; +} + +int32_t __stdcall __ntapi_tty_create_session( + __out void ** hport, + __out nt_port_name * port_name, + __in nt_tty_session_type type, + __in const nt_guid * guid __optional, + __in wchar16_t * image_name __optional) +{ + nt_status status; + ntapi_internals * __internals; + + nt_port_attr port_attr; + nt_runtime_data ssattr; + nt_runtime_data_block rtblock; + nt_create_process_params params; + + wchar16_t __attr_aligned__(8) __tty_image_name_fallback[] = { + '\\','?','?','\\', + 'C',':', + '\\','m','i','d','i','p','i','x', + '\\','b','i','n', + '\\','n','t','c','t','t','y', + '.','e','x','e', + 0}; + + /* init */ + __internals = __ntapi_internals(); + + __ntapi->tt_aligned_block_memset( + &port_attr,0,sizeof(port_attr)); + + switch (type) { + case NT_TTY_SESSION_PRIMARY: + port_attr.type = NT_PORT_TYPE_SUBSYSTEM; + port_attr.subtype = NT_PORT_SUBTYPE_DEFAULT; + + if (!hport) + hport = &__internals->hport_tty_session; + + if (!port_name) + port_name = __internals->subsystem; + + if (!image_name) + image_name = __tty_image_name_fallback; + + break; + + case NT_TTY_SESSION_PRIVATE: + port_attr.type = NT_PORT_TYPE_SUBSYSTEM; + port_attr.subtype = NT_PORT_SUBTYPE_PRIVATE; + break; + + default: + return NT_STATUS_INVALID_PARAMETER; + } + + /* port guid */ + if (guid) + __ntapi->tt_guid_copy( + &port_attr.guid, + guid); + else + __ntapi->tt_port_guid_from_type( + &port_attr.guid, + port_attr.type, + port_attr.subtype); + + /* port keys */ + if ((status = __ntapi->tt_port_generate_keys(&port_attr.keys))) + return status; + + /* port name */ + __ntapi->tt_port_name_from_attributes( + port_name, + &port_attr); + + /* subsystem attributes */ + __ntapi->tt_aligned_block_memset( + &ssattr,0,sizeof(ssattr)); + + ssattr.srv_type = port_attr.type; + ssattr.srv_subtype = port_attr.subtype; + ssattr.srv_keys[0] = port_attr.keys.key[0]; + ssattr.srv_keys[1] = port_attr.keys.key[1]; + ssattr.srv_keys[2] = port_attr.keys.key[2]; + ssattr.srv_keys[3] = port_attr.keys.key[3]; + ssattr.srv_keys[4] = port_attr.keys.key[4]; + ssattr.srv_keys[5] = port_attr.keys.key[5]; + + __ntapi->tt_guid_copy( + &ssattr.srv_guid, + &port_attr.guid); + + if ((status = __ntapi->tt_create_private_event( + &ssattr.srv_ready, + NT_SYNCHRONIZATION_EVENT, + NT_EVENT_NOT_SIGNALED))) + return status; + + /* create subsystem process */ + rtblock.addr = &ssattr; + rtblock.size = sizeof(ssattr); + rtblock.remote_addr = 0; + rtblock.remote_size = 0; + rtblock.flags = NT_RUNTIME_DATA_DUPLICATE_SESSION_HANDLES; + + __ntapi->tt_aligned_block_memset( + ¶ms,0,sizeof(params)); + + params.image_name = image_name; + params.rtblock = &rtblock; + + if ((status = __ntapi->tt_create_native_process(¶ms))) + return status; + + if ((status = __ntapi->zw_wait_for_single_object( + ssattr.srv_ready, + NT_SYNC_NON_ALERTABLE, + 0))) + return __tty_create_session_return(¶ms,status); + + /* connect to subsystem */ + if ((status = __ntapi->tty_connect( + hport, + &port_name->base_named_objects[0], + NT_SECURITY_IMPERSONATION))) + return __tty_create_session_return(¶ms,status); + + /* finalize primary session */ + if (type == NT_TTY_SESSION_PRIMARY) { + if (hport != &__internals->hport_tty_session) + __internals->hport_tty_session = *hport; + + if (port_name != __internals->subsystem) + __ntapi->tt_memcpy_utf16( + __internals->subsystem->base_named_objects, + port_name->base_named_objects, + sizeof(*port_name)); + }; + + return __tty_create_session_return(¶ms,NT_STATUS_SUCCESS); +} diff --git a/src/tty/ntapi_tty_join_session.c b/src/tty/ntapi_tty_join_session.c new file mode 100644 index 0000000..e88b9cb --- /dev/null +++ b/src/tty/ntapi_tty_join_session.c @@ -0,0 +1,53 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +int32_t __stdcall __ntapi_tty_join_session( + __out void ** hport, + __out nt_port_name * port_name, + __in nt_port_attr * port_attr, + __in nt_tty_session_type type) +{ + nt_status status; + ntapi_internals * __internals; + + /* init */ + __internals = __ntapi_internals(); + + if (type == NT_TTY_SESSION_PRIMARY) { + hport = hport ? hport : &__internals->hport_tty_session; + port_name = port_name ? port_name : __internals->subsystem; + } + + /* port name */ + __ntapi->tt_port_name_from_attributes( + port_name, + port_attr); + + /* connect to subsystem */ + if ((status = __ntapi->tty_connect( + hport, + (wchar16_t *)port_name, + NT_SECURITY_IMPERSONATION))) + return status; + + /* finalize primary session */ + if (type == NT_TTY_SESSION_PRIMARY) { + if (hport != &__internals->hport_tty_session) + __internals->hport_tty_session = *hport; + + if (port_name != __internals->subsystem) + __ntapi->tt_memcpy_utf16( + __internals->subsystem->base_named_objects, + port_name->base_named_objects, + sizeof(*port_name)); + }; + + return status; +} diff --git a/src/tty/ntapi_tty_query_information_server.c b/src/tty/ntapi_tty_query_information_server.c new file mode 100644 index 0000000..7930413 --- /dev/null +++ b/src/tty/ntapi_tty_query_information_server.c @@ -0,0 +1,40 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_tty.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +int32_t __stdcall __ntapi_tty_query_information_server( + __in void * hport, + __in nt_tty_server_info * srvinfo) +{ + int32_t status; + nt_tty_server_msg msg; + + hport = hport ? hport : __ntapi_internals()->hport_tty_session; + + __ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_QUERY_INFORMATION_SERVER; + + if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg))) + return status; + else if (msg.data.ttyinfo.status) + return msg.data.ttyinfo.status; + + __ntapi->tt_aligned_block_memcpy( + (uintptr_t *)srvinfo, + (uintptr_t *)&(msg.data.srvinfo), + sizeof(*srvinfo)); + + return NT_STATUS_SUCCESS; +} diff --git a/src/tty/ntapi_tty_request_peer.c b/src/tty/ntapi_tty_request_peer.c new file mode 100644 index 0000000..9f6550d --- /dev/null +++ b/src/tty/ntapi_tty_request_peer.c @@ -0,0 +1,46 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_tty.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +int32_t __stdcall __ntapi_tty_request_peer( + __in void * hport, + __in int32_t opcode, + __in uint32_t flags, + __in const nt_guid * service, + __in nt_port_attr * peer) +{ + int32_t status; + nt_tty_peer_msg msg; + + __ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_REQUEST_PEER; + + msg.data.peerinfo.opcode= opcode; + msg.data.peerinfo.flags = flags; + + if (service) __ntapi->tt_guid_copy( + &msg.data.peerinfo.service, + service); + + __ntapi->tt_aligned_block_memcpy( + (uintptr_t *)&msg.data.peerinfo.peer, + (uintptr_t *)peer, + sizeof(*peer)); + + if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg))) + return status; + + return msg.data.ttyinfo.status; +} diff --git a/src/tty/ntapi_tty_vms_query.c b/src/tty/ntapi_tty_vms_query.c new file mode 100644 index 0000000..08e3212 --- /dev/null +++ b/src/tty/ntapi_tty_vms_query.c @@ -0,0 +1,40 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_tty.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +int32_t __stdcall __ntapi_tty_vms_query( + __in void * hport, + __in nt_tty_vms_info * vmsinfo) +{ + int32_t status; + nt_tty_vms_msg msg; + + hport = hport ? hport : __ntapi_internals()->hport_tty_session; + + __ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_VMS_QUERY; + + if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg))) + return status; + else if (msg.data.ttyinfo.status) + return msg.data.ttyinfo.status; + + __ntapi->tt_aligned_block_memcpy( + (uintptr_t *)vmsinfo, + (uintptr_t *)&(msg.data.vmsinfo), + sizeof(*vmsinfo)); + + return NT_STATUS_SUCCESS; +} diff --git a/src/tty/ntapi_tty_vms_request.c b/src/tty/ntapi_tty_vms_request.c new file mode 100644 index 0000000..74dbf5b --- /dev/null +++ b/src/tty/ntapi_tty_vms_request.c @@ -0,0 +1,46 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_tty.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +int32_t __stdcall __ntapi_tty_vms_request( + __in void * hport, + __in nt_tty_vms_info * vmsinfo) +{ + int32_t status; + nt_tty_vms_msg msg; + + hport = hport ? hport : __ntapi_internals()->hport_tty_session; + + __ntapi->tt_aligned_block_memset( + &msg,0, + sizeof(nt_port_message) + sizeof(nt_tty_msg_info)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_VMS_REQUEST; + + __ntapi->tt_aligned_block_memcpy( + (uintptr_t *)&(msg.data.vmsinfo), + (uintptr_t *)vmsinfo, + sizeof(*vmsinfo)); + + if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg))) + return status; + else if (msg.data.ttyinfo.status) + return msg.data.ttyinfo.status; + + __ntapi->tt_aligned_block_memcpy( + (uintptr_t *)vmsinfo, + (uintptr_t *)&(msg.data.vmsinfo), + sizeof(*vmsinfo)); + + return NT_STATUS_SUCCESS; +} |