From d9d1789535a1ef6b0bc6dde9fba721ac923fe86c Mon Sep 17 00:00:00 2001 From: midipix Date: Jul 31 2017 12:43:35 +0000 Subject: subsystem interfaces: integrated extended port name helper functions. --- diff --git a/include/ntapi/nt_port.h b/include/ntapi/nt_port.h index 4cd330e..5978802 100644 --- a/include/ntapi/nt_port.h +++ b/include/ntapi/nt_port.h @@ -337,4 +337,19 @@ typedef void __stdcall ntapi_tt_port_name_from_attributes( __out nt_port_name * name, __in nt_port_attr * attr); + +typedef int32_t __stdcall ntapi_tt_port_attr_from_name( + __out nt_port_attr * attr, + __in const nt_port_name * name); + + +typedef int32_t __stdcall ntapi_tt_port_attr_from_string( + __out nt_port_attr * attr, + __in const nt_unicode_string*str); + + +typedef int32_t __stdcall ntapi_tt_port_attr_from_symlink( + __out nt_port_attr * attr, + __in void * symlink); + #endif diff --git a/include/ntapi/ntapi.h b/include/ntapi/ntapi.h index bf066bd..b5cf1bf 100644 --- a/include/ntapi/ntapi.h +++ b/include/ntapi/ntapi.h @@ -476,6 +476,9 @@ typedef struct _ntapi_vtbl { ntapi_tt_port_generate_keys * tt_port_generate_keys; ntapi_tt_port_format_keys * tt_port_format_keys; ntapi_tt_port_name_from_attributes * tt_port_name_from_attributes; + ntapi_tt_port_attr_from_name * tt_port_attr_from_name; + ntapi_tt_port_attr_from_string * tt_port_attr_from_string; + ntapi_tt_port_attr_from_symlink * tt_port_attr_from_symlink; /* nt_argv.h */ ntapi_tt_get_cmd_line_utf16 * tt_get_cmd_line_utf16; diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index 65b5c72..f6eb0b2 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -251,6 +251,9 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) __ntapi->tt_port_generate_keys = __ntapi_tt_port_generate_keys; __ntapi->tt_port_format_keys = __ntapi_tt_port_format_keys; __ntapi->tt_port_name_from_attributes = __ntapi_tt_port_name_from_attributes; + __ntapi->tt_port_attr_from_name = __ntapi_tt_port_attr_from_name; + __ntapi->tt_port_attr_from_string = __ntapi_tt_port_attr_from_string; + __ntapi->tt_port_attr_from_symlink = __ntapi_tt_port_attr_from_symlink; /* nt_argv.h */ __ntapi->tt_get_cmd_line_utf16 = __ntapi_tt_get_cmd_line_utf16; diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h index 09d87b6..5f682b8 100644 --- a/src/internal/ntapi_fnapi.h +++ b/src/internal/ntapi_fnapi.h @@ -138,6 +138,9 @@ ntapi_tt_port_type_from_guid __ntapi_tt_port_type_from_guid; ntapi_tt_port_generate_keys __ntapi_tt_port_generate_keys; ntapi_tt_port_format_keys __ntapi_tt_port_format_keys; ntapi_tt_port_name_from_attributes __ntapi_tt_port_name_from_attributes; +ntapi_tt_port_attr_from_name __ntapi_tt_port_attr_from_name; +ntapi_tt_port_attr_from_string __ntapi_tt_port_attr_from_string; +ntapi_tt_port_attr_from_symlink __ntapi_tt_port_attr_from_symlink; /* nt_argv.h */ ntapi_tt_get_cmd_line_utf16 __ntapi_tt_get_cmd_line_utf16; diff --git a/src/port/ntapi_port_name_helper.c b/src/port/ntapi_port_name_helper.c index e55ffba..ae36c86 100644 --- a/src/port/ntapi_port_name_helper.c +++ b/src/port/ntapi_port_name_helper.c @@ -167,3 +167,147 @@ void __stdcall __ntapi_tt_port_name_from_attributes( return; } + + +static int32_t __tt_port_attr_from_name( + __out nt_port_attr * attr, + __in const nt_port_name * name) +{ + int i; + int type; + int32_t status; + const wchar16_t bno[] = __NT_BASED_NAMED_OBJECTS; + + /* base named objects */ + if (__ntapi->tt_strncmp_utf16( + name->base_named_objects, + bno,sizeof(bno))) + return NT_STATUS_INVALID_PARAMETER; + + /* service prefix */ + for (i=0, type=-1; itt_strncmp_utf16( + name->svc_prefix, + __port_service_prefixes[i][0], + sizeof(__port_service_prefix)))) + type = i; + + if (type < 0) + return NT_STATUS_INVALID_PARAMETER; + + /* port guid */ + if ((status = __ntapi->tt_string_to_guid_utf16( + (nt_guid_str_utf16 *)&name->port_guid, + &attr->guid))) + return status; + + /* port keys */ + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_1st, + &attr->keys.key[0]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_2nd, + &attr->keys.key[1]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_3rd, + &attr->keys.key[2]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_4th, + &attr->keys.key[3]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_5th, + &attr->keys.key[4]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_6th, + &attr->keys.key[5]))) + return status; + + /* backslash and underscores */ + if (name->backslash != '\\') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_1st != '_') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_2nd != '_') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_3rd != '_') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_4th != '_') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_5th != '_') + return NT_STATUS_INVALID_PARAMETER; + + /* unknown defaults */ + attr->ver_major = 0; + attr->ver_minor = 0; + attr->options = 0; + attr->flags = 0; + + /* all done */ + return NT_STATUS_SUCCESS; +} + + +int32_t __stdcall __ntapi_tt_port_attr_from_name( + __out nt_port_attr * attr, + __in const nt_port_name * name) +{ + /* null termination */ + if (name->null_termination) + return NT_STATUS_INVALID_PARAMETER; + + return __tt_port_attr_from_name( + attr,name); +} + + +int32_t __stdcall __ntapi_tt_port_attr_from_string( + __out nt_port_attr * attr, + __in const nt_unicode_string * str) +{ + if (str->strlen != ((size_t)&(((nt_port_name *)0)->null_termination))) + return NT_STATUS_INVALID_PARAMETER; + + return __tt_port_attr_from_name( + attr,(const nt_port_name *)str->buffer); +} + + +int32_t __stdcall __ntapi_tt_port_attr_from_symlink( + __out nt_port_attr * attr, + __in void * symlink) +{ + int32_t status; + size_t size; + nt_unicode_string * target; + uintptr_t buffer[512/sizeof(uintptr_t)]; + + target = (nt_unicode_string *)buffer; + target->strlen = 0; + target->maxlen = sizeof(buffer) - sizeof(nt_unicode_string); + target->buffer = (wchar16_t *)&target[1]; + + if ((status = __ntapi->zw_query_symbolic_link_object( + symlink,target,&size))) + return status; + + if (target->strlen != ((size_t)&(((nt_port_name *)0)->null_termination))) + return NT_STATUS_INVALID_PARAMETER; + + return __tt_port_attr_from_name( + attr,(const nt_port_name *)target->buffer); +}