diff --git a/include/ntapi/nt_object.h b/include/ntapi/nt_object.h index e66e848..6cd93ce 100644 --- a/include/ntapi/nt_object.h +++ b/include/ntapi/nt_object.h @@ -555,6 +555,12 @@ typedef int32_t __stdcall ntapi_tt_create_keyed_object_directory_entry( __in nt_unicode_string * target_name, __in uint32_t key); +typedef int32_t __stdcall ntapi_tt_keyed_object_to_key( + __in void * hentry, + __out uint32_t * key, + __out void * buffer, + __in size_t buflen); + typedef void __stdcall ntapi_tt_sid_copy( __out nt_sid * dst, __in const nt_sid * src); diff --git a/include/ntapi/ntapi.h b/include/ntapi/ntapi.h index c92a7ac..2f073aa 100644 --- a/include/ntapi/ntapi.h +++ b/include/ntapi/ntapi.h @@ -375,6 +375,7 @@ typedef struct _ntapi_vtbl { ntapi_tt_create_keyed_object_directory * tt_create_keyed_object_directory; ntapi_tt_open_keyed_object_directory * tt_open_keyed_object_directory; ntapi_tt_create_keyed_object_directory_entry * tt_create_keyed_object_directory_entry; + ntapi_tt_keyed_object_to_key * tt_keyed_object_to_key; ntapi_tt_sid_copy * tt_sid_copy; ntapi_tt_sid_compare * tt_sid_compare; diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index 6f6b9ce..78075b6 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -171,6 +171,7 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) __ntapi->tt_create_keyed_object_directory = __ntapi_tt_create_keyed_object_directory; __ntapi->tt_open_keyed_object_directory = __ntapi_tt_open_keyed_object_directory; __ntapi->tt_create_keyed_object_directory_entry = __ntapi_tt_create_keyed_object_directory_entry; + __ntapi->tt_keyed_object_to_key = __ntapi_tt_keyed_object_to_key; __ntapi->tt_sid_copy = __ntapi_tt_sid_copy; __ntapi->tt_sid_compare = __ntapi_tt_sid_compare; diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h index 9157dc1..5cea58f 100644 --- a/src/internal/ntapi_fnapi.h +++ b/src/internal/ntapi_fnapi.h @@ -30,6 +30,7 @@ ntapi_tt_create_dev_object_directory_entry __ntapi_tt_create_dev_object_director ntapi_tt_create_keyed_object_directory __ntapi_tt_create_keyed_object_directory; ntapi_tt_open_keyed_object_directory __ntapi_tt_open_keyed_object_directory; ntapi_tt_create_keyed_object_directory_entry __ntapi_tt_create_keyed_object_directory_entry; +ntapi_tt_keyed_object_to_key __ntapi_tt_keyed_object_to_key; ntapi_tt_sid_copy __ntapi_tt_sid_copy; ntapi_tt_sid_compare __ntapi_tt_sid_compare; diff --git a/src/object/ntapi_tt_keyed_object_directory.c b/src/object/ntapi_tt_keyed_object_directory.c index 705eec9..988ed00 100644 --- a/src/object/ntapi_tt_keyed_object_directory.c +++ b/src/object/ntapi_tt_keyed_object_directory.c @@ -388,3 +388,36 @@ int32_t __stdcall __ntapi_tt_create_keyed_object_directory_entry( hentry,desired_access, hdir,htarget,target_name,key); } + +int32_t __stdcall __ntapi_tt_keyed_object_to_key( + __in void * hentry, + __out uint32_t * key, + __out void * buffer, + __in size_t buflen) +{ + int32_t status; + wchar16_t * pidname; + nt_unicode_string * dirname; + + if ((status = __ntapi->zw_query_object( + hentry, + NT_OBJECT_NAME_INFORMATION, + buffer,buflen, + &(uint32_t){0}))) + return status; + + dirname = (nt_unicode_string *)buffer; + pidname = dirname->buffer; + + if (dirname->strlen <= 8 * sizeof(wchar16_t)) + return NT_STATUS_INTERNAL_ERROR; + + pidname += dirname->strlen / sizeof(wchar16_t); + pidname -= 8; + + if (pidname[-1] != '\\') + return NT_STATUS_INVALID_PARAMETER; + + return __ntapi->tt_hex_utf16_to_uint32( + pidname,key); +}