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/fs/ntapi_tt_get_file_handle_type.c | |
parent | dcdadc2702712fa750ed255ed1dfa354522797a0 (diff) | |
download | ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.bz2 ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.xz |
entered advanced internal development stage.
Diffstat (limited to 'src/fs/ntapi_tt_get_file_handle_type.c')
-rw-r--r-- | src/fs/ntapi_tt_get_file_handle_type.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/fs/ntapi_tt_get_file_handle_type.c b/src/fs/ntapi_tt_get_file_handle_type.c new file mode 100644 index 0000000..e1175a5 --- /dev/null +++ b/src/fs/ntapi_tt_get_file_handle_type.c @@ -0,0 +1,83 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <ntapi/ntapi.h> +#include <ntapi/nt_file.h> +#include "ntapi_impl.h" + +typedef int __stdcall winapi_get_console_mode(void * handle, uint32_t * mode); + +int32_t __stdcall __ntapi_tt_get_file_handle_type( + __in void * handle, + __out int32_t * type) +{ + int32_t status; + uint32_t info; + nt_iosb iosb; + nt_fsssi fsssi; + nt_file_directory_information fdi; + nt_file_pipe_information fpi; + nt_object_basic_information obi; + + void * hkernel32; + char str_get_con_mode[32] = "GetConsoleMode"; + winapi_get_console_mode * pfn_get_con_mode; + + /* validation */ + if (!handle) return NT_STATUS_INVALID_HANDLE; + + /* file-system directory? */ + if (!(status = __ntapi->zw_query_information_file( + handle, + &iosb,&fdi,sizeof(fdi), + NT_FILE_DIRECTORY_INFORMATION))) { + *type = NT_FILE_TYPE_DIRECTORY; + return 0; + } + + /* file-system file? */ + if (!(status = __ntapi->zw_query_volume_information_file( + handle, + &iosb,&fsssi,sizeof(fsssi), + NT_FILE_FS_SECTOR_SIZE_INFORMATION))) { + *type = NT_FILE_TYPE_FILE; + return 0; + } + + /* pipe? */ + if (!(status = __ntapi->zw_query_information_file( + handle, + &iosb,&fpi,sizeof(fpi), + NT_FILE_PIPE_INFORMATION))) { + *type = NT_FILE_TYPE_PIPE; + return 0; + } + + + /* csrss? */ + if (!(hkernel32 = pe_get_kernel32_module_handle())) + return NT_STATUS_DLL_INIT_FAILED; + else if (!(pfn_get_con_mode = (winapi_get_console_mode *)pe_get_procedure_address( + hkernel32,str_get_con_mode))) + return NT_STATUS_DLL_INIT_FAILED; + + + /* (console functions return non-zero on success) */ + if ((pfn_get_con_mode(handle,&info))) { + *type = NT_FILE_TYPE_CSRSS; + return 0; + } + + /* invalid handle? */ + if ((status = __ntapi->zw_query_object( + handle,NT_OBJECT_BASIC_INFORMATION, + &obi,sizeof(obi),&info))) + return status; + + /* unknown object */ + *type = NT_FILE_TYPE_UNKNOWN; + return NT_STATUS_SUCCESS; +} |