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/internal | |
parent | dcdadc2702712fa750ed255ed1dfa354522797a0 (diff) | |
download | ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.bz2 ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.xz |
entered advanced internal development stage.
Diffstat (limited to 'src/internal')
-rw-r--r-- | src/internal/ntapi.c | 411 | ||||
-rw-r--r-- | src/internal/ntapi_blitter.h | 27 | ||||
-rw-r--r-- | src/internal/ntapi_context.h | 55 | ||||
-rw-r--r-- | src/internal/ntapi_debug.c | 170 | ||||
-rw-r--r-- | src/internal/ntapi_fnapi.h | 262 | ||||
-rw-r--r-- | src/internal/ntapi_hash_table.h | 266 | ||||
-rw-r--r-- | src/internal/ntapi_impl.h | 120 | ||||
-rw-r--r-- | src/internal/ntapi_lib_entry_point.c | 12 | ||||
-rw-r--r-- | src/internal/ntapi_pty.h | 37 |
9 files changed, 1360 insertions, 0 deletions
diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c new file mode 100644 index 0000000..2340c47 --- /dev/null +++ b/src/internal/ntapi.c @@ -0,0 +1,411 @@ +/********************************************************/ +/* 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 <pemagine/pemagine.h> + +#include <ntapi/nt_status.h> +#include <ntapi/nt_crc32.h> +#include <ntapi/nt_object.h> +#include <ntapi/nt_sysinfo.h> +#include <ntapi/nt_memory.h> +#include <ntapi/nt_section.h> +#include <ntapi/nt_thread.h> +#include <ntapi/nt_process.h> +#include <ntapi/nt_job.h> +#include <ntapi/nt_token.h> +#include <ntapi/nt_sync.h> +#include <ntapi/nt_time.h> +#include <ntapi/nt_profiling.h> +#include <ntapi/nt_port.h> +#include <ntapi/nt_device.h> +#include <ntapi/nt_file.h> +#include <ntapi/nt_registry.h> +#include <ntapi/nt_security.h> +#include <ntapi/nt_pnp.h> +#include <ntapi/nt_exception.h> +#include <ntapi/nt_locale.h> +#include <ntapi/nt_uuid.h> +#include <ntapi/nt_atom.h> +#include <ntapi/nt_os.h> +#include <ntapi/nt_ldr.h> +#include <ntapi/nt_string.h> +#include <ntapi/nt_guid.h> +#include <ntapi/nt_argv.h> +#include <ntapi/nt_blitter.h> +#include <ntapi/nt_unicode.h> +#include <ntapi/nt_socket.h> +#include <ntapi/nt_mount.h> +#include <ntapi/nt_istat.h> +#include <ntapi/nt_stat.h> +#include <ntapi/nt_statfs.h> +#include <ntapi/nt_daemon.h> +#include <ntapi/nt_tty.h> +#include <ntapi/nt_vmount.h> +#include <ntapi/nt_hash.h> +#include <ntapi/nt_debug.h> +#include <ntapi/nt_atomic.h> +#include <ntapi/ntapi.h> + +#include "ntapi_impl.h" +#include "ntapi_hash_table.h" + +/* simplified once mechanism for free-standing applications */ +typedef int32_t __fastcall __ntapi_init_fn(ntapi_vtbl ** pvtbl); + +static __ntapi_init_fn __ntapi_init_once; +static __ntapi_init_fn __ntapi_init_pending; +static __ntapi_init_fn __ntapi_init_completed; + +static intptr_t __ntapi_init_idx = 0; +static __ntapi_init_fn * __ntapi_init_vtbl[3] = { + __ntapi_init_once, + __ntapi_init_pending, + __ntapi_init_completed}; + +/* accessor */ +ntapi_vtbl ___ntapi = {0}; +ntapi_vtbl ___ntapi_shadow = {0}; + +/* .bss */ +static __ntapi_img_sec_bss __ntapi_img_bss; + +/* .rdata */ +static union __ntapi_img_rdata __ntapi_rdata = {{ + {__NTAPI_HASH_TABLE}, /* __ntapi_import_table */ + 0, /* __ntapi */ + {{0}}, /* __session_name */ + 0}}; /* __internals */ + +#define internals __ntapi_rdata.img_sec_data.__internals +#define import_table __ntapi_rdata.img_sec_data.__ntapi_import_table + + +static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) +{ + int32_t status; + void * hntdll; + size_t block_size; + ntapi_zw_allocate_virtual_memory * pfn_zw_allocate_virtual_memory; + char fname_allocate_virtual_memory[] = + "ZwAllocateVirtualMemory"; + /* once */ + at_locked_inc(&__ntapi_init_idx); + + /* pvtbl */ + if (!(pvtbl)) + return NT_STATUS_INVALID_PARAMETER; + else + *pvtbl = (ntapi_vtbl *)0; + + /* ntdll */ + if (!(hntdll = pe_get_ntdll_module_handle())) + return NT_STATUS_DLL_INIT_FAILED; + + pfn_zw_allocate_virtual_memory = (ntapi_zw_allocate_virtual_memory *) + pe_get_procedure_address( + hntdll, + fname_allocate_virtual_memory); + + if (!pfn_zw_allocate_virtual_memory) + return NT_STATUS_DLL_INIT_FAILED; + + /* ntapi_internals: alloc */ + block_size = sizeof(ntapi_internals); + status = pfn_zw_allocate_virtual_memory( + NT_CURRENT_PROCESS_HANDLE, + (void **)&internals, + 0, + &block_size, + NT_MEM_COMMIT, + NT_PAGE_READWRITE); + + if (status != NT_STATUS_SUCCESS) + return status; + + /* hashed import table */ + __ntapi_tt_populate_hashed_import_table( + pe_get_ntdll_module_handle(), + __ntapi, + import_table, + __NT_IMPORTED_SYMBOLS_ARRAY_SIZE); + + /* alternate implementation */ + __ntapi->rtl_init_unicode_string = __ntapi_tt_init_unicode_string_from_utf16; + + /* extension functions */ + /* nt_object.h */ + __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; + + /* nt_crc32.h */ + __ntapi->tt_buffer_crc32 = __ntapi_tt_buffer_crc32; + __ntapi->tt_mbstr_crc32 = __ntapi_tt_mbstr_crc32; + __ntapi->tt_crc32_table = __ntapi_tt_crc32_table; + + /* nt_file.h */ + __ntapi->tt_get_file_handle_type = __ntapi_tt_get_file_handle_type; + __ntapi->tt_open_logical_parent_directory = __ntapi_tt_open_logical_parent_directory; + __ntapi->tt_open_physical_parent_directory = __ntapi_tt_open_physical_parent_directory; + + /* nt_ldr.h */ + __ntapi->ldr_load_system_dll = __ntapi_ldr_load_system_dll; + __ntapi->ldr_create_state_snapshot = __ntapi_ldr_create_state_snapshot; + __ntapi->ldr_revert_state_to_snapshot = __ntapi_ldr_revert_state_to_snapshot; + + /* nt_string.h */ + __ntapi->tt_string_null_offset_multibyte = __ntapi_tt_string_null_offset_multibyte; + __ntapi->tt_string_null_offset_short = __ntapi_tt_string_null_offset_short; + __ntapi->tt_string_null_offset_dword = __ntapi_tt_string_null_offset_dword; + __ntapi->tt_string_null_offset_qword = __ntapi_tt_string_null_offset_qword; + __ntapi->tt_string_null_offset_ptrsize = __ntapi_tt_string_null_offset_ptrsize; + __ntapi->strlen = __ntapi_tt_string_null_offset_multibyte; + __ntapi->wcslen = __ntapi_wcslen; + __ntapi->tt_aligned_block_memset = __ntapi_tt_aligned_block_memset; + __ntapi->tt_aligned_block_memcpy = __ntapi_tt_aligned_block_memcpy; + __ntapi->tt_memcpy_utf16 = __ntapi_tt_memcpy_utf16; + __ntapi->tt_aligned_memcpy_utf16 = __ntapi_tt_aligned_memcpy_utf16; + __ntapi->tt_generic_memset = __ntapi_tt_generic_memset; + __ntapi->tt_generic_memcpy = __ntapi_tt_generic_memcpy; + __ntapi->tt_uint16_to_hex_utf16 = __ntapi_tt_uint16_to_hex_utf16; + __ntapi->tt_uint32_to_hex_utf16 = __ntapi_tt_uint32_to_hex_utf16; + __ntapi->tt_uint64_to_hex_utf16 = __ntapi_tt_uint64_to_hex_utf16; + __ntapi->tt_uintptr_to_hex_utf16 = __ntapi_tt_uintptr_to_hex_utf16; + __ntapi->tt_hex_utf16_to_uint16 = __ntapi_tt_hex_utf16_to_uint16; + __ntapi->tt_hex_utf16_to_uint32 = __ntapi_tt_hex_utf16_to_uint32; + __ntapi->tt_hex_utf16_to_uint64 = __ntapi_tt_hex_utf16_to_uint64; + __ntapi->tt_hex_utf16_to_uintptr = __ntapi_tt_hex_utf16_to_uintptr; + __ntapi->tt_init_unicode_string_from_utf16 = __ntapi_tt_init_unicode_string_from_utf16; + __ntapi->tt_uint16_to_hex_utf8 = __ntapi_tt_uint16_to_hex_utf8; + __ntapi->tt_uint32_to_hex_utf8 = __ntapi_tt_uint32_to_hex_utf8; + __ntapi->tt_uint64_to_hex_utf8 = __ntapi_tt_uint64_to_hex_utf8; + __ntapi->tt_uintptr_to_hex_utf8 = __ntapi_tt_uintptr_to_hex_utf8; + + /* nt_guid.h */ + __ntapi->tt_guid_copy = __ntapi_tt_guid_copy; + __ntapi->tt_guid_compare = __ntapi_tt_guid_compare; + __ntapi->tt_guid_to_utf16_string = __ntapi_tt_guid_to_utf16_string; + __ntapi->tt_utf16_string_to_guid = __ntapi_tt_utf16_string_to_guid; + + /* nt_sysinfo.h */ + __ntapi->tt_get_system_directory_native_path = __ntapi_tt_get_system_directory_native_path; + __ntapi->tt_get_system_directory_dos_path = __ntapi_tt_get_system_directory_dos_path; + __ntapi->tt_get_system_directory_handle = __ntapi_tt_get_system_directory_handle; + __ntapi->tt_get_system_info_snapshot = __ntapi_tt_get_system_info_snapshot; + + /* nt_thread.h */ + __ntapi->tt_create_local_thread = __ntapi_tt_create_local_thread; + __ntapi->tt_create_remote_thread = __ntapi_tt_create_remote_thread; + __ntapi->tt_create_thread = __ntapi_tt_create_thread; + + /* nt_process.h */ + __ntapi->tt_create_remote_process_params = __ntapi_tt_create_remote_process_params; + __ntapi->tt_get_runtime_data = __ntapi_tt_get_runtime_data; + __ntapi->tt_init_runtime_data = __ntapi_tt_init_runtime_data; + __ntapi->tt_update_runtime_data = __ntapi_tt_update_runtime_data; + __ntapi->tt_exec_map_image_as_data = __ntapi_tt_exec_map_image_as_data; + __ntapi->tt_exec_unmap_image = __ntapi_tt_exec_unmap_image; + + /* nt_section.h */ + __ntapi->tt_get_section_name = __ntapi_tt_get_section_name; + + /* nt_sync.h */ + __ntapi->tt_create_inheritable_event = __ntapi_tt_create_inheritable_event; + __ntapi->tt_create_private_event = __ntapi_tt_create_private_event; + __ntapi->tt_wait_for_dummy_event = __ntapi_tt_wait_for_dummy_event; + __ntapi->tt_sync_block_init = __ntapi_tt_sync_block_init; + __ntapi->tt_sync_block_lock = __ntapi_tt_sync_block_lock; + __ntapi->tt_sync_block_server_lock = __ntapi_tt_sync_block_server_lock; + __ntapi->tt_sync_block_unlock = __ntapi_tt_sync_block_unlock; + __ntapi->tt_sync_block_invalidate = __ntapi_tt_sync_block_invalidate; + + /* nt_port.h */ + __ntapi->csr_port_handle = __ntapi_csr_port_handle; + __ntapi->tt_port_guid_from_type = __ntapi_tt_port_guid_from_type; + __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; + + /* nt_argv.h */ + __ntapi->tt_get_cmd_line_utf16 = __ntapi_tt_get_cmd_line_utf16; + __ntapi->tt_get_peb_env_block_utf16 = __ntapi_tt_get_peb_env_block_utf16; + __ntapi->tt_parse_cmd_line_args_utf16 = __ntapi_tt_parse_cmd_line_args_utf16; + __ntapi->tt_get_argv_envp_utf8 = __ntapi_tt_get_argv_envp_utf8; + __ntapi->tt_get_argv_envp_utf16 = __ntapi_tt_get_argv_envp_utf16; + __ntapi->tt_get_env_var_meta_utf16 = __ntapi_tt_get_env_var_meta_utf16; + __ntapi->tt_get_short_option_meta_utf16 = __ntapi_tt_get_short_option_meta_utf16; + __ntapi->tt_get_long_option_meta_utf16 = __ntapi_tt_get_long_option_meta_utf16; + __ntapi->tt_array_copy_utf16 = __ntapi_tt_array_copy_utf16; + __ntapi->tt_array_copy_utf8 = __ntapi_tt_array_copy_utf8; + __ntapi->tt_array_convert_utf8_to_utf16 = __ntapi_tt_array_convert_utf8_to_utf16; + __ntapi->tt_array_convert_utf16_to_utf8 = __ntapi_tt_array_convert_utf16_to_utf8; + + /* nt_blitter.h */ + __ntapi->blt_alloc = __ntapi_blt_alloc; + __ntapi->blt_free = __ntapi_blt_free; + __ntapi->blt_acquire = __ntapi_blt_acquire; + __ntapi->blt_obtain = __ntapi_blt_obtain; + __ntapi->blt_possess = __ntapi_blt_possess; + __ntapi->blt_release = __ntapi_blt_release; + __ntapi->blt_get = __ntapi_blt_get; + __ntapi->blt_set = __ntapi_blt_set; + + /* nt_unicode.h */ + __ntapi->uc_validate_unicode_stream_utf8 = __ntapi_uc_validate_unicode_stream_utf8; + __ntapi->uc_validate_unicode_stream_utf16 = __ntapi_uc_validate_unicode_stream_utf16; + __ntapi->uc_get_code_point_byte_count_utf8 = __ntapi_uc_get_code_point_byte_count_utf8; + __ntapi->uc_get_code_point_byte_count_utf16 = __ntapi_uc_get_code_point_byte_count_utf16; + __ntapi->uc_convert_unicode_stream_utf8_to_utf16 = __ntapi_uc_convert_unicode_stream_utf8_to_utf16; + __ntapi->uc_convert_unicode_stream_utf8_to_utf32 = __ntapi_uc_convert_unicode_stream_utf8_to_utf32; + __ntapi->uc_convert_unicode_stream_utf16_to_utf8 = __ntapi_uc_convert_unicode_stream_utf16_to_utf8; + __ntapi->uc_convert_unicode_stream_utf16_to_utf32 = __ntapi_uc_convert_unicode_stream_utf16_to_utf32; + + /* nt_daemon.h */ + __ntapi->dsr_init = __ntapi_dsr_init; + __ntapi->dsr_start = __ntapi_dsr_start; + __ntapi->dsr_create_port = __ntapi_dsr_create_port; + __ntapi->dsr_connect_internal_client = __ntapi_dsr_connect_internal_client; + __ntapi->dsr_internal_client_connect = __ntapi_dsr_internal_client_connect; + + /* nt_vfd.h */ + __ntapi->vfd_dev_name_init = __ntapi_vfd_dev_name_init; + + /* nt_tty.h */ + __ntapi->tty_create_session = __ntapi_tty_create_session; + __ntapi->tty_join_session = __ntapi_tty_join_session; + __ntapi->tty_connect = __ntapi_tty_connect; + __ntapi->tty_client_session_query = __ntapi_tty_client_session_query; + __ntapi->tty_client_session_set = __ntapi_tty_client_session_set; + __ntapi->tty_client_process_register = __ntapi_tty_client_process_register; + __ntapi->tty_query_information_server = __ntapi_tty_query_information_server; + __ntapi->tty_request_peer = __ntapi_tty_request_peer; + __ntapi->tty_vms_query = __ntapi_tty_vms_query; + __ntapi->tty_vms_request = __ntapi_tty_vms_request; + __ntapi->pty_open = __ntapi_pty_open; + __ntapi->pty_reopen = __ntapi_pty_reopen; + __ntapi->pty_close = __ntapi_pty_close; + __ntapi->pty_read = __ntapi_pty_read; + __ntapi->pty_write = __ntapi_pty_write; + __ntapi->pty_ioctl = __ntapi_pty_ioctl; + __ntapi->pty_query = __ntapi_pty_query; + __ntapi->pty_set = __ntapi_pty_set; + __ntapi->pty_cancel = __ntapi_pty_cancel; + + /* nt_socket.h */ + __ntapi->sc_listen = __ntapi_sc_listen; + __ntapi->sc_accept = __ntapi_sc_accept; + __ntapi->sc_send = __ntapi_sc_send; + __ntapi->sc_recv = __ntapi_sc_recv; + __ntapi->sc_shutdown = __ntapi_sc_shutdown; + __ntapi->sc_server_duplicate_socket = __ntapi_sc_server_duplicate_socket; + __ntapi->sc_wait = __ntapi_sc_wait; + + /* nt_mount.h */ + __ntapi->tt_get_dos_drive_device_handle = __ntapi_tt_get_dos_drive_device_handle; + __ntapi->tt_get_dos_drive_root_handle = __ntapi_tt_get_dos_drive_root_handle; + __ntapi->tt_get_dos_drive_device_name = __ntapi_tt_get_dos_drive_device_name; + __ntapi->tt_get_dos_drive_mount_points = __ntapi_tt_get_dos_drive_mount_points; + __ntapi->tt_dev_mount_points_to_statfs = __ntapi_tt_dev_mount_points_to_statfs; + __ntapi->tt_get_dos_drive_letter_from_device = __ntapi_tt_get_dos_drive_letter_from_device; + + /* nt_istat.h */ + __ntapi->tt_istat = __ntapi_tt_istat; + __ntapi->tt_validate_fs_handle = __ntapi_tt_validate_fs_handle; + + /* nt_stat.h */ + __ntapi->tt_stat = __ntapi_tt_stat; + + /* nt_statfs.h */ + __ntapi->tt_statfs = __ntapi_tt_statfs; + + /* nt_vmount.h */ + __ntapi->vms_get_node_by_dev_name = __ntapi_vms_get_node_by_dev_name; + __ntapi->vms_get_node_by_end_component = __ntapi_vms_get_node_by_end_component; + __ntapi->vms_cache_alloc = __ntapi_vms_cache_alloc; + __ntapi->vms_cache_free = __ntapi_vms_cache_free; + __ntapi->vms_client_connect = __ntapi_vms_client_connect; + __ntapi->vms_client_disconnect = __ntapi_vms_client_disconnect; + __ntapi->vms_point_attach = __ntapi_vms_point_attach; + __ntapi->vms_point_get_handles = __ntapi_vms_point_get_handles; + __ntapi->vms_ref_count_inc = __ntapi_vms_ref_count_inc; + __ntapi->vms_ref_count_dec = __ntapi_vms_ref_count_dec; + __ntapi->vms_table_query = __ntapi_vms_table_query; + + /* nt_debug.h */ + #ifdef __DEBUG + __ntapi->dbg_write = __dbg_write; + __ntapi->dbg_fn_call = __dbg_fn_call; + __ntapi->dbg_msg = __dbg_msg; + #endif + + + /* OS version dependent functions */ + if (__ntapi->zw_create_user_process) { + __ntapi->tt_fork = __ntapi_tt_fork_v2; + __ntapi->tt_create_native_process = __ntapi_tt_create_native_process_v2; + __ntapi->ipc_create_pipe = __ntapi_ipc_create_pipe_v2; + __ntapi->sc_socket = __ntapi_sc_socket_v2; + __ntapi->sc_bind = __ntapi_sc_bind_v2; + __ntapi->sc_connect = __ntapi_sc_connect_v2; + __ntapi->sc_server_accept_connection = __ntapi_sc_server_accept_connection_v2; + __ntapi->sc_getsockname = __ntapi_sc_getsockname_v2; + } else { + __ntapi->tt_fork = __ntapi_tt_fork_v1; + __ntapi->tt_create_native_process = __ntapi_tt_create_native_process_v1; + __ntapi->ipc_create_pipe = __ntapi_ipc_create_pipe_v1; + __ntapi->sc_socket = __ntapi_sc_socket_v1; + __ntapi->sc_bind = __ntapi_sc_bind_v1; + __ntapi->sc_connect = __ntapi_sc_connect_v1; + __ntapi->sc_server_accept_connection = __ntapi_sc_server_accept_connection_v1; + __ntapi->sc_getsockname = __ntapi_sc_getsockname_v1; + } + + /* internals */ + internals->ntapi_img_sec_bss = &__ntapi_img_bss; + internals->subsystem = &__ntapi_rdata.img_sec_data.__session_name; + + internals->tt_get_csr_port_handle_addr_by_logic = __GET_CSR_PORT_HANDLE_BY_LOGIC; + internals->csr_port_handle_addr = __GET_CSR_PORT_HANDLE_BY_LOGIC(); + + /* shadow copy for client libraries */ + __ntapi->tt_aligned_block_memcpy( + (uintptr_t *)&___ntapi_shadow, + (uintptr_t *)&___ntapi, + sizeof(ntapi_vtbl)); + + /* done */ + *pvtbl = &___ntapi_shadow; + at_locked_inc(&__ntapi_init_idx); + + return NT_STATUS_SUCCESS; +} + + +static int32_t __fastcall __ntapi_init_pending(ntapi_vtbl ** pvtbl) +{ + return NT_STATUS_PENDING; +} + +static int32_t __fastcall __ntapi_init_completed(ntapi_vtbl ** pvtbl) +{ + *pvtbl = __ntapi; + return NT_STATUS_SUCCESS; +}; + + +__ntapi_api +int32_t __fastcall ntapi_init(ntapi_vtbl ** pvtbl) +{ + return __ntapi_init_vtbl[__ntapi_init_idx](pvtbl); +} + + +ntapi_internals * __cdecl __ntapi_internals(void) +{ + return internals; +} diff --git a/src/internal/ntapi_blitter.h b/src/internal/ntapi_blitter.h new file mode 100644 index 0000000..9a285d9 --- /dev/null +++ b/src/internal/ntapi_blitter.h @@ -0,0 +1,27 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#ifndef ___NTAPI_BLITTER_H_ +#define ___NTAPI_BLITTER_H_ + +#include <ntapi/nt_status.h> +#include <ntapi/nt_blitter.h> +#include <ntapi/nt_sync.h> + +#define __NT_BLITTER_DEFAULT_LOCK_TRIES 256 +#define __NT_BLITTER_DEFAULT_ROUND_TRIPS 64 + +typedef struct nt_blitter_context { + struct nt_blitter_context * addr; + size_t size; + uintptr_t ptrs; + nt_blitter_info info; + nt_blitter_params params; + uintptr_t * bitmap; + uintptr_t bits[]; +} nt_blitter; + +#endif diff --git a/src/internal/ntapi_context.h b/src/internal/ntapi_context.h new file mode 100644 index 0000000..4020158 --- /dev/null +++ b/src/internal/ntapi_context.h @@ -0,0 +1,55 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#ifndef ___NTAPI_CONTEXT_H_ +#define ___NTAPI_CONTEXT_H_ + +#if defined(__X86_MODEL) + /* csr port handle */ + #define __GET_CSR_PORT_HANDLE_BY_LOGIC __ntapi_tt_get_csr_port_handle_addr_by_logic_i386 + + /* register names */ + #define STACK_POINTER_REGISTER uc_esp + #define INSTRUCTION_POINTER_REGISTER uc_eip + #define FAST_CALL_ARG0 uc_ecx + #define FAST_CALL_ARG1 uc_edx + + /* thread context initialization */ + #define __INIT_CONTEXT(context) \ + context.uc_context_flags = NT_CONTEXT_JUST_EVERYTHING; \ + context.uc_seg_gs = 0x00; \ + context.uc_seg_fs = 0x3b; \ + context.uc_seg_es = 0x23; \ + context.uc_seg_ds = 0x23; \ + context.uc_seg_ss = 0x23; \ + context.uc_seg_cs = 0x1b; \ + context.uc_eflags = 0x200 + +#elif defined (__X86_64_MODEL) + /* csr port handle */ + #define __GET_CSR_PORT_HANDLE_BY_LOGIC __ntapi_tt_get_csr_port_handle_addr_by_logic_x86_64 + + /* register names */ + #define STACK_POINTER_REGISTER uc_rsp + #define INSTRUCTION_POINTER_REGISTER uc_rip + #define FAST_CALL_ARG0 uc_rcx + #define FAST_CALL_ARG1 uc_rdx + + /* thread context initialization */ + #define __INIT_CONTEXT(context) \ + context.uc_context_flags= NT_CONTEXT_JUST_EVERYTHING; \ + context.uc_seg_cs = 0x33; \ + context.uc_seg_ds = 0x2b; \ + context.uc_seg_es = 0x2b; \ + context.uc_seg_fs = 0x53; \ + context.uc_seg_gs = 0x2b; \ + context.uc_seg_ss = 0x2b; \ + context.uc_eflags = 0x200; \ + context.uc_mx_csr = 0x1f80 + +#endif + +#endif diff --git a/src/internal/ntapi_debug.c b/src/internal/ntapi_debug.c new file mode 100644 index 0000000..cb56c64 --- /dev/null +++ b/src/internal/ntapi_debug.c @@ -0,0 +1,170 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#ifdef __DEBUG + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_file.h> +#include <ntapi/ntapi.h> +#include "ntapi_impl.h" + +char dbg_buf[0x1000]; + +ssize_t __cdecl __dbg_write( + __in void * hfile, + __in const void * buf, + __in size_t bytes) +{ + nt_iosb iosb; + int32_t status; + + status = __ntapi->zw_write_file( + hfile, + (void *)0, + (nt_io_apc_routine *)0, + (void *)0, + &iosb, + (void *)buf, + (uint32_t)bytes, + (nt_large_integer *)0, + (uint32_t *)0); + + if (status == NT_STATUS_SUCCESS) + return iosb.info; + else + return -1; +} + + +int32_t __cdecl __dbg_fn_call( + __in void * hfile __optional, + __in char * fn_caller_name, + __in void * fn_callee_addr, + __in uintptr_t fn_ret, + __in ntapi_dbg_write* pfn_dbg_write __optional, + __in char * source __optional, + __in int line __optional) +{ + struct pe_ldr_tbl_entry * image_meta; + void * image_base; + char * fn_name; + size_t bytes; + char dbg_buf[256]; + + if (!pfn_dbg_write) + pfn_dbg_write = __dbg_write; + + image_meta = pe_get_symbol_module_info(fn_callee_addr); + fn_name = (char *)0; + + if (image_meta) + image_base = image_meta->dll_base; + else + image_base = (void *)0; + + + if (image_base) + fn_name = pe_get_symbol_name( + image_base, + fn_callee_addr); + + if (!fn_name) + fn_name = pe_get_import_symbol_info( + fn_callee_addr, + (void **)0, + (char **)0, + &image_meta); + + if (source && fn_name) + bytes = __ntapi->sprintf( + dbg_buf, + "%s: (%s:%d):\n" + "--> %s returned 0x%08x\n\n", + fn_caller_name, source, line, fn_name, fn_ret); + else if (fn_name) + bytes = __ntapi->sprintf( + dbg_buf, + "%s: %s returned 0x%08x\n\n", + fn_caller_name, fn_name, fn_ret); + else if (source) + bytes = __ntapi->sprintf( + dbg_buf, + "%s: (%s:%d):\n" + "--> calling 0x%08x returned 0x%08x\n\n", + fn_caller_name, source, line, fn_callee_addr, fn_ret); + else + bytes = __ntapi->sprintf( + dbg_buf, + "%s: calling 0x%08x returned 0x%08x\n\n", + fn_caller_name, fn_callee_addr, fn_ret); + + if (bytes) { + bytes = __ntapi->strlen(dbg_buf); + + if (bytes == pfn_dbg_write(hfile,dbg_buf,bytes)) + return NT_STATUS_SUCCESS; + else + return NT_STATUS_UNSUCCESSFUL; + } else + return NT_STATUS_UNSUCCESSFUL; +} + + +int32_t __cdecl __dbg_msg( + __in void * hfile __optional, + __in char * source __optional, + __in int line __optional, + __in char * fn_caller_name, + __in char * fmt, + __in uintptr_t arg1, + __in uintptr_t arg2, + __in uintptr_t arg3, + __in uintptr_t arg4, + __in uintptr_t arg5, + __in uintptr_t arg6, + __in ntapi_dbg_write* pfn_dbg_write __optional) +{ + char * buffer; + size_t bytes; + + if (!pfn_dbg_write) + pfn_dbg_write = __dbg_write; + + bytes = 0; + buffer = dbg_buf; + + if (source) + bytes = __ntapi->sprintf( + buffer, + "%s: (%s:%d):\n--> ", + fn_caller_name,source,line); + else if (fn_caller_name) + bytes = __ntapi->sprintf( + buffer, + "%s: ", + fn_caller_name); + else + dbg_buf[0] = '\0'; + + if (bytes >= 0) + buffer += __ntapi->strlen(dbg_buf); + else + return NT_STATUS_UNSUCCESSFUL; + + bytes = __ntapi->sprintf(buffer,fmt,arg1,arg2,arg3,arg4,arg5,arg6); + + if (bytes) { + bytes = __ntapi->strlen(dbg_buf); + + if (bytes == pfn_dbg_write(hfile,dbg_buf,bytes)) + return NT_STATUS_SUCCESS; + else + return NT_STATUS_UNSUCCESSFUL; + } else + return NT_STATUS_UNSUCCESSFUL; +} + +#endif diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h new file mode 100644 index 0000000..4474334 --- /dev/null +++ b/src/internal/ntapi_fnapi.h @@ -0,0 +1,262 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#ifndef ___NTAPI_FNAPI_H_ +#define ___NTAPI_FNAPI_H_ + +#include <psxtypes/psxtypes.h> +#include <ntapi/ntapi.h> +#include "ntapi_hash_table.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* internal prototypes */ +typedef int32_t __stdcall ntapi_tt_create_remote_runtime_data( + __in void * hprocess, + __in_out nt_runtime_data_block * runtime_data); + +typedef void ** __cdecl ntapi_tt_get_csr_port_handle_addr_by_logic(void); + +/* nt_object.h */ +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; + +/* nt_crc32.h */ +ntapi_tt_buffer_crc32 __ntapi_tt_buffer_crc32; +ntapi_tt_mbstr_crc32 __ntapi_tt_mbstr_crc32; +ntapi_tt_crc32_table __ntapi_tt_crc32_table; + +/* nt_file.h */ +ntapi_tt_get_file_handle_type __ntapi_tt_get_file_handle_type; +ntapi_tt_open_logical_parent_directory __ntapi_tt_open_logical_parent_directory; +ntapi_tt_open_physical_parent_directory __ntapi_tt_open_physical_parent_directory; + + +/* nt_ipc.h */ +ntapi_ipc_create_pipe __ntapi_ipc_create_pipe_v1; +ntapi_ipc_create_pipe __ntapi_ipc_create_pipe_v2; + +/* nt_ldr */ +ntapi_ldr_load_system_dll __ntapi_ldr_load_system_dll; +ntapi_ldr_create_state_snapshot __ntapi_ldr_create_state_snapshot; +ntapi_ldr_revert_state_to_snapshot __ntapi_ldr_revert_state_to_snapshot; + +/* nt_string.h */ +ntapi_tt_string_null_offset_multibyte __ntapi_tt_string_null_offset_multibyte; +ntapi_tt_string_null_offset_short __ntapi_tt_string_null_offset_short; +ntapi_tt_string_null_offset_dword __ntapi_tt_string_null_offset_dword; +ntapi_tt_string_null_offset_qword __ntapi_tt_string_null_offset_qword; +ntapi_tt_string_null_offset_ptrsize __ntapi_tt_string_null_offset_ptrsize; +ntapi_wcslen __ntapi_wcslen; +ntapi_tt_aligned_block_memset __ntapi_tt_aligned_block_memset; +ntapi_tt_aligned_block_memcpy __ntapi_tt_aligned_block_memcpy; +ntapi_tt_init_unicode_string_from_utf16 __ntapi_tt_init_unicode_string_from_utf16; +ntapi_tt_memcpy_utf16 __ntapi_tt_memcpy_utf16; +ntapi_tt_aligned_memcpy_utf16 __ntapi_tt_aligned_memcpy_utf16; +ntapi_tt_generic_memset __ntapi_tt_generic_memset; +ntapi_tt_generic_memcpy __ntapi_tt_generic_memcpy; +ntapi_tt_uint16_to_hex_utf16 __ntapi_tt_uint16_to_hex_utf16; +ntapi_tt_uint32_to_hex_utf16 __ntapi_tt_uint32_to_hex_utf16; +ntapi_tt_uint64_to_hex_utf16 __ntapi_tt_uint64_to_hex_utf16; +ntapi_tt_uintptr_to_hex_utf16 __ntapi_tt_uintptr_to_hex_utf16; +ntapi_tt_hex_utf16_to_uint16 __ntapi_tt_hex_utf16_to_uint16; +ntapi_tt_hex_utf16_to_uint32 __ntapi_tt_hex_utf16_to_uint32; +ntapi_tt_hex_utf16_to_uint64 __ntapi_tt_hex_utf16_to_uint64; +ntapi_tt_hex_utf16_to_uintptr __ntapi_tt_hex_utf16_to_uintptr; +ntapi_tt_uint16_to_hex_utf8 __ntapi_tt_uint16_to_hex_utf8; +ntapi_tt_uint32_to_hex_utf8 __ntapi_tt_uint32_to_hex_utf8; +ntapi_tt_uint64_to_hex_utf8 __ntapi_tt_uint64_to_hex_utf8; +ntapi_tt_uintptr_to_hex_utf8 __ntapi_tt_uintptr_to_hex_utf8; + +/* nt_guid.h */ +ntapi_tt_guid_to_utf16_string __ntapi_tt_guid_to_utf16_string; +ntapi_tt_utf16_string_to_guid __ntapi_tt_utf16_string_to_guid; + +/* nt_sysinfo.h */ +ntapi_tt_get_system_directory_native_path __ntapi_tt_get_system_directory_native_path; +ntapi_tt_get_system_directory_dos_path __ntapi_tt_get_system_directory_dos_path; +ntapi_tt_get_system_directory_handle __ntapi_tt_get_system_directory_handle; +ntapi_tt_get_system_info_snapshot __ntapi_tt_get_system_info_snapshot; + +/* nt_thread.h */ +ntapi_tt_create_thread __ntapi_tt_create_thread; +ntapi_tt_create_local_thread __ntapi_tt_create_local_thread; +ntapi_tt_create_remote_thread __ntapi_tt_create_remote_thread; + +/* nt_process.h */ +ntapi_tt_fork __ntapi_tt_fork_v1; +ntapi_tt_fork __ntapi_tt_fork_v2; +ntapi_tt_create_remote_process_params __ntapi_tt_create_remote_process_params; +ntapi_tt_create_remote_runtime_data __ntapi_tt_create_remote_runtime_data; +ntapi_tt_create_native_process __ntapi_tt_create_native_process_v1; +ntapi_tt_create_native_process __ntapi_tt_create_native_process_v2; +ntapi_tt_get_runtime_data __ntapi_tt_get_runtime_data; +ntapi_tt_init_runtime_data __ntapi_tt_init_runtime_data; +ntapi_tt_update_runtime_data __ntapi_tt_update_runtime_data; +ntapi_tt_exec_map_image_as_data __ntapi_tt_exec_map_image_as_data; +ntapi_tt_exec_unmap_image __ntapi_tt_exec_unmap_image; + +/* nt_section.h */ +ntapi_tt_get_section_name __ntapi_tt_get_section_name; + +/* nt_sync.h */ +ntapi_tt_create_inheritable_event __ntapi_tt_create_inheritable_event; +ntapi_tt_create_private_event __ntapi_tt_create_private_event; +ntapi_tt_wait_for_dummy_event __ntapi_tt_wait_for_dummy_event; +ntapi_tt_sync_block_init __ntapi_tt_sync_block_init; +ntapi_tt_sync_block_lock __ntapi_tt_sync_block_lock; +ntapi_tt_sync_block_server_lock __ntapi_tt_sync_block_server_lock; +ntapi_tt_sync_block_unlock __ntapi_tt_sync_block_unlock; +ntapi_tt_sync_block_invalidate __ntapi_tt_sync_block_invalidate; + +/* nt_port.h */ +ntapi_tt_port_guid_from_type __ntapi_tt_port_guid_from_type; +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; + +/* nt_argv.h */ +ntapi_tt_get_cmd_line_utf16 __ntapi_tt_get_cmd_line_utf16; +ntapi_tt_get_peb_env_block_utf16 __ntapi_tt_get_peb_env_block_utf16; +ntapi_tt_parse_cmd_line_args_utf16 __ntapi_tt_parse_cmd_line_args_utf16; +ntapi_tt_get_argv_envp_utf8 __ntapi_tt_get_argv_envp_utf8; +ntapi_tt_get_argv_envp_utf16 __ntapi_tt_get_argv_envp_utf16; +ntapi_tt_get_env_var_meta_utf16 __ntapi_tt_get_env_var_meta_utf16; +ntapi_tt_get_short_option_meta_utf16 __ntapi_tt_get_short_option_meta_utf16; +ntapi_tt_get_long_option_meta_utf16 __ntapi_tt_get_long_option_meta_utf16; +ntapi_tt_array_copy_utf8 __ntapi_tt_array_copy_utf8; +ntapi_tt_array_copy_utf16 __ntapi_tt_array_copy_utf16; +ntapi_tt_array_convert_utf8_to_utf16 __ntapi_tt_array_convert_utf8_to_utf16; +ntapi_tt_array_convert_utf16_to_utf8 __ntapi_tt_array_convert_utf16_to_utf8; + +/* nt_blitter.h */ +ntapi_blt_alloc __ntapi_blt_alloc; +ntapi_blt_free __ntapi_blt_free; +ntapi_blt_acquire __ntapi_blt_acquire; +ntapi_blt_obtain __ntapi_blt_obtain; +ntapi_blt_possess __ntapi_blt_possess; +ntapi_blt_release __ntapi_blt_release; +ntapi_blt_get __ntapi_blt_get; +ntapi_blt_set __ntapi_blt_set; + +/* nt_unicode.h */ +ntapi_uc_validate_unicode_stream_utf8 __ntapi_uc_validate_unicode_stream_utf8; +ntapi_uc_validate_unicode_stream_utf16 __ntapi_uc_validate_unicode_stream_utf16; +ntapi_uc_get_code_point_byte_count_utf8 __ntapi_uc_get_code_point_byte_count_utf8; +ntapi_uc_get_code_point_byte_count_utf16 __ntapi_uc_get_code_point_byte_count_utf16; +ntapi_uc_convert_unicode_stream_utf8_to_utf16 __ntapi_uc_convert_unicode_stream_utf8_to_utf16; +ntapi_uc_convert_unicode_stream_utf8_to_utf32 __ntapi_uc_convert_unicode_stream_utf8_to_utf32; +ntapi_uc_convert_unicode_stream_utf16_to_utf8 __ntapi_uc_convert_unicode_stream_utf16_to_utf8; +ntapi_uc_convert_unicode_stream_utf16_to_utf32 __ntapi_uc_convert_unicode_stream_utf16_to_utf32; + + +/* nt_daemon.h */ +ntapi_dsr_init __ntapi_dsr_init; +ntapi_dsr_start __ntapi_dsr_start; +ntapi_dsr_create_port __ntapi_dsr_create_port; +ntapi_dsr_connect_internal_client __ntapi_dsr_connect_internal_client; +ntapi_dsr_internal_client_connect __ntapi_dsr_internal_client_connect; + +/* nt_vfd.h */ +ntapi_vfd_dev_name_init __ntapi_vfd_dev_name_init; + +/* nt_tty.h */ +ntapi_tty_create_session __ntapi_tty_create_session; +ntapi_tty_join_session __ntapi_tty_join_session; +ntapi_tty_connect __ntapi_tty_connect; +ntapi_tty_client_session_query __ntapi_tty_client_session_query; +ntapi_tty_client_session_set __ntapi_tty_client_session_set; +ntapi_tty_client_process_register __ntapi_tty_client_process_register; +ntapi_tty_query_information_server __ntapi_tty_query_information_server; +ntapi_tty_request_peer __ntapi_tty_request_peer; +ntapi_tty_vms_query __ntapi_tty_vms_query; +ntapi_tty_vms_request __ntapi_tty_vms_request; +ntapi_pty_open __ntapi_pty_open; +ntapi_pty_reopen __ntapi_pty_reopen; +ntapi_pty_close __ntapi_pty_close; +ntapi_pty_read __ntapi_pty_read; +ntapi_pty_write __ntapi_pty_write; +ntapi_pty_ioctl __ntapi_pty_ioctl; +ntapi_pty_query __ntapi_pty_query; +ntapi_pty_set __ntapi_pty_set; +ntapi_pty_cancel __ntapi_pty_cancel; + +/* nt_socket.h */ +ntapi_sc_socket __ntapi_sc_socket_v1; +ntapi_sc_socket __ntapi_sc_socket_v2; +ntapi_sc_bind __ntapi_sc_bind_v1; +ntapi_sc_bind __ntapi_sc_bind_v2; +ntapi_sc_connect __ntapi_sc_connect_v1; +ntapi_sc_connect __ntapi_sc_connect_v2; +ntapi_sc_getsockname __ntapi_sc_getsockname_v1; +ntapi_sc_getsockname __ntapi_sc_getsockname_v2; +ntapi_sc_server_accept_connection __ntapi_sc_server_accept_connection_v1; +ntapi_sc_server_accept_connection __ntapi_sc_server_accept_connection_v2; +ntapi_sc_server_duplicate_socket __ntapi_sc_server_duplicate_socket; +ntapi_sc_listen __ntapi_sc_listen; +ntapi_sc_accept __ntapi_sc_accept; +ntapi_sc_send __ntapi_sc_send; +ntapi_sc_recv __ntapi_sc_recv; +ntapi_sc_shutdown __ntapi_sc_shutdown; +ntapi_sc_wait __ntapi_sc_wait; + +/* nt_mount.h */ +ntapi_tt_get_dos_drive_device_handle __ntapi_tt_get_dos_drive_device_handle; +ntapi_tt_get_dos_drive_root_handle __ntapi_tt_get_dos_drive_root_handle; +ntapi_tt_get_dos_drive_device_name __ntapi_tt_get_dos_drive_device_name; +ntapi_tt_get_dos_drive_mount_points __ntapi_tt_get_dos_drive_mount_points; +ntapi_tt_dev_mount_points_to_statfs __ntapi_tt_dev_mount_points_to_statfs; +ntapi_tt_get_dos_drive_letter_from_device __ntapi_tt_get_dos_drive_letter_from_device; + +/* nt_istat.h */ +ntapi_tt_istat __ntapi_tt_istat; +ntapi_tt_validate_fs_handle __ntapi_tt_validate_fs_handle; + +/* nt_stat.h */ +ntapi_tt_stat __ntapi_tt_stat; + +/* nt_statfs.h */ +ntapi_tt_statfs __ntapi_tt_statfs; + +/* nt_vmount.h */ +ntapi_vms_get_node_by_dev_name __ntapi_vms_get_node_by_dev_name; +ntapi_vms_get_node_by_end_component __ntapi_vms_get_node_by_end_component; +ntapi_vms_cache_alloc __ntapi_vms_cache_alloc; +ntapi_vms_cache_free __ntapi_vms_cache_free; +ntapi_vms_client_connect __ntapi_vms_client_connect; +ntapi_vms_client_disconnect __ntapi_vms_client_disconnect; +ntapi_vms_point_attach __ntapi_vms_point_attach; +ntapi_vms_point_get_handles __ntapi_vms_point_get_handles; +ntapi_vms_ref_count_inc __ntapi_vms_ref_count_inc; +ntapi_vms_ref_count_dec __ntapi_vms_ref_count_dec; +ntapi_vms_table_query __ntapi_vms_table_query; + +/* nt_hashes.h */ +ntapi_tt_populate_hashed_import_table __ntapi_tt_populate_hashed_import_table; + +/* nt_guid.h */ +ntapi_tt_guid_copy __ntapi_tt_guid_copy; +ntapi_tt_guid_compare __ntapi_tt_guid_compare; +ntapi_tt_guid_to_utf16_string __ntapi_tt_guid_to_utf16_string; +ntapi_tt_utf16_string_to_guid __ntapi_tt_utf16_string_to_guid; + +/* debug */ +ntapi_dbg_write __dbg_write; +ntapi_dbg_fn_call __dbg_fn_call; +ntapi_dbg_msg __dbg_msg; + +/* csrss */ +ntapi_tt_get_csr_port_handle_addr_by_logic __GET_CSR_PORT_HANDLE_BY_LOGIC; +ntapi_csr_port_handle __ntapi_csr_port_handle; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/internal/ntapi_hash_table.h b/src/internal/ntapi_hash_table.h new file mode 100644 index 0000000..727e4f2 --- /dev/null +++ b/src/internal/ntapi_hash_table.h @@ -0,0 +1,266 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#ifndef ___NTAPI_HASH_TABLE_H_ +#define ___NTAPI_HASH_TABLE_H_ + +#include <psxtypes/psxtypes.h> + +#define __NTAPI_HASH_TABLE \ + {0x000f6dee, (150)}, /* CsrPortHandle */ \ + {0x00b3a87b, (30)}, /* ZwMapUserPhysicalPages */ \ + {0x011c4489, (95)}, /* ZwPulseEvent */ \ + {0x02513506, (39)}, /* ZwAreMappedFilesTheSame */ \ + {0x034a4430, (63)}, /* RtlCreateProcessParameters */ \ + {0x03bb7a3c, (187)}, /* ZwRestoreKey */ \ + {0x04e21f45, (75)}, /* ZwCreateToken */ \ + {0x04f94dc4, (190)}, /* ZwUnloadKey */ \ + {0x06125322, (216)}, /* ZwAccessCheckByTypeResultListAndAuditAlarmByHandle */ \ + {0x06b550e3, (146)}, /* ZwWriteRequestData */ \ + {0x0708114b, (50)}, /* ZwTestAlert */ \ + {0x08087626, (34)}, /* ZwOpenSection */ \ + {0x08b1918f, (45)}, /* ZwSuspendThread */ \ + {0x097e0efd, (154)}, /* ZwOpenFile */ \ + {0x0a7a10d0, (88)}, /* ZwOpenTimer */ \ + {0x0a83f5d6, (191)}, /* ZwQueryOpenSubKeys */ \ + {0x0bd77556, (218)}, /* ZwSetThreadExecutionState */ \ + {0x0c5cf449, (168)}, /* ZwQueryEaFile */ \ + {0x0d638bd2, (74)}, /* ZwSetInformationJobObject */ \ + {0x0e629eed, (102)}, /* ZwQuerySemaphore */ \ + {0x11fcbb7c, (23)}, /* ZwReadVirtualMemory */ \ + {0x124a301e, (16)}, /* ZwSetSystemEnvironmentValue */ \ + {0x12ec66eb, (227)}, /* ZwQueryDefaultLocale */ \ + {0x1742c5c9, (162)}, /* ZwWriteFileGather */ \ + {0x177157e3, (42)}, /* ZwTerminateThread */ \ + {0x1af41c1a, (22)}, /* ZwProtectVirtualMemory */ \ + {0x1c0197e6, (233)}, /* ZwAllocateUuids */ \ + {0x1c7a90a1, (5)}, /* ZwQuerySecurityObject */ \ + {0x1cf668c5, (194)}, /* ZwQueryKey */ \ + {0x2259fc62, (2)}, /* ZwDuplicateObject */ \ + {0x24e09c64, (18)}, /* ZwSystemDebugControl */ \ + {0x255bf138, (142)}, /* ZwReplyWaitReplyPort */ \ + {0x25684721, (76)}, /* ZwOpenProcessToken */ \ + {0x25d91d90, (71)}, /* ZwTerminateJobObject */ \ + {0x26e1170e, (193)}, /* ZwSetInformationKey */ \ + {0x27dd46c3, (29)}, /* ZwFreeUserPhysicalPages */ \ + {0x2812eb3c, (232)}, /* ZwAllocateLocallyUniqueId */ \ + {0x28574a3f, (77)}, /* ZwOpenThreadToken */ \ + {0x29b5ea3d, (140)}, /* ZwRequestWaitReplyPort */ \ + {0x2a6ac6fb, (26)}, /* ZwUnlockVirtualMemory */ \ + {0x2aad9aed, (83)}, /* ZwSetInformationToken */ \ + {0x2b2356f7, (52)}, /* ZwAlertResumeThread */ \ + {0x2c0f001a, (230)}, /* ZwSetDefaultUILanguage */ \ + {0x2f22b634, (96)}, /* ZwResetEvent */ \ + {0x30309daa, (170)}, /* ZwCreateNamedPipeFile */ \ + {0x3064d37b, (68)}, /* RtlQueryProcessDebugInformation */ \ + {0x30911e3f, (196)}, /* ZwNotifyChangeKey */ \ + {0x32ad44f5, (73)}, /* ZwQueryInformationJobObject */ \ + {0x33a33c40, (163)}, /* ZwLockFile */ \ + {0x357f8a82, (36)}, /* ZwExtendSection */ \ + {0x3753c2c8, (198)}, /* ZwDeleteValueKey */ \ + {0x379a6717, (93)}, /* ZwOpenEvent */ \ + {0x391b8d79, (157)}, /* ZwCancelIoFile */ \ + {0x3928a4cc, (20)}, /* ZwFreeVirtualMemory */ \ + {0x39bea937, (89)}, /* ZwCancelTimer */ \ + {0x3abffc38, (239)}, /* ZwFlushWriteBuffer */ \ + {0x3b1f8d85, (124)}, /* ZwQueryTimerResolution */ \ + {0x3d4aceeb, (248)}, /* memset */ \ + {0x3e1d331d, (44)}, /* ZwSetInformationThread */ \ + {0x3f62370b, (204)}, /* ZwPrivilegeCheck */ \ + {0x416c4024, (118)}, /* ZwSetLowWaitHighEventPair */ \ + {0x43c1745d, (92)}, /* ZwCreateEvent */ \ + {0x43d65de2, (231)}, /* ZwQueryInstallUILanguage */ \ + {0x45d7086f, (108)}, /* ZwOpenIoCompletion */ \ + {0x465977c0, (129)}, /* ZwQueryIntervalProfile */ \ + {0x47b3fd39, (8)}, /* ZwOpenDirectoryObject */ \ + {0x47dd6896, (171)}, /* ZwCreateMailslotFile */ \ + {0x49d62b40, (246)}, /* LdrLoadDll */ \ + {0x4a638203, (91)}, /* ZwQueryTimer */ \ + {0x4c51093e, (189)}, /* ZwLoadKey2 */ \ + {0x4cb0ea34, (206)}, /* ZwPrivilegedServiceAuditAlarm */ \ + {0x4cc741f4, (222)}, /* ZwPowerInformation */ \ + {0x4d0aa736, (207)}, /* ZwAccessCheck */ \ + {0x4d361035, (181)}, /* ZwCreateKey */ \ + {0x4de0faef, (10)}, /* ZwCreateSymbolicLinkObject */ \ + {0x4e049b9b, (72)}, /* ZwAssignProcessToJobObject */ \ + {0x4ed4c833, (0)}, /* ZwQueryObject */ \ + {0x4efff89a, (166)}, /* ZwFsControlFile */ \ + {0x4fe5a956, (49)}, /* ZwQueueApcThread */ \ + {0x50f7777d, (84)}, /* ZwWaitForSingleObject */ \ + {0x513877ab, (61)}, /* ZwSetInformationProcess */ \ + {0x51d5c98d, (137)}, /* ZwAcceptConnectPort */ \ + {0x51ddffce, (242)}, /* ZwDisplayString */ \ + {0x51fbe1c4, (165)}, /* ZwDeviceIoControlFile */ \ + {0x52334a05, (213)}, /* ZwDeleteObjectAuditAlarm */ \ + {0x5288a7cf, (46)}, /* ZwResumeThread */ \ + {0x54a89e87, (131)}, /* ZwStopProfile */ \ + {0x56ada303, (185)}, /* ZwSaveKey */ \ + {0x57dd87c6, (114)}, /* ZwWaitLowEventPair */ \ + {0x5879157d, (241)}, /* ZwSetDefaultHardErrorPort */ \ + {0x58b766a7, (200)}, /* ZwQueryValueKey */ \ + {0x59d0cf7f, (9)}, /* ZwQueryDirectoryObject */ \ + {0x5a201018, (180)}, /* ZwSetInformationFile */ \ + {0x5b24a650, (155)}, /* ZwDeleteFile */ \ + {0x5cc5b0cc, (149)}, /* CsrClientCallServer */ \ + {0x5ccb443b, (245)}, /* ZwVdmControl */ \ + {0x5d5b0c74, (15)}, /* ZwQuerySystemEnvironmentValue */ \ + {0x5dcf9e33, (205)}, /* ZwPrivilegeObjectAuditAlarm */ \ + {0x5f3fb511, (164)}, /* ZwUnlockFile */ \ + {0x60ebf65f, (120)}, /* ZwQuerySystemTime */ \ + {0x63033516, (244)}, /* ZwSetLdtEntries */ \ + {0x63cc9e64, (66)}, /* RtlCreateQueryDebugBuffer */ \ + {0x64a2ceb5, (56)}, /* ZwCreateProcess */ \ + {0x654da6fd, (143)}, /* ZwReplyWaitReceivePort */ \ + {0x6570064e, (243)}, /* ZwCreatePagingFile */ \ + {0x65b5374b, (14)}, /* ZwSetSystemInformation */ \ + {0x6a2d88fc, (126)}, /* ZwYieldExecution */ \ + {0x6c1b25c0, (97)}, /* ZwClearEvent */ \ + {0x6db16208, (238)}, /* ZwQueryInformationAtom */ \ + {0x6e0c0f9d, (65)}, /* RtlNormalizeProcessParams */ \ + {0x6f11895e, (217)}, /* ZwIsSystemResumeAutomatic */ \ + {0x7160272d, (144)}, /* ZwReplyWaitReceivePortEx */ \ + {0x72f83a29, (67)}, /* RtlDestroyQueryDebugBuffer */ \ + {0x73349dea, (160)}, /* ZwWriteFile */ \ + {0x75e01428, (111)}, /* ZwQueryIoCompletion */ \ + {0x75e970e4, (115)}, /* ZwSetLowEventPair */ \ + {0x7683000f, (38)}, /* ZwUnmapViewOfSection */ \ + {0x76d9a68b, (159)}, /* ZwReadFile */ \ + {0x7783f5c4, (98)}, /* ZwQueryEvent */ \ + {0x78327b0d, (173)}, /* ZwSetVolumeInformationFile */ \ + {0x78a28538, (80)}, /* ZwAdjustPrivilegesToken */ \ + {0x7b9f9b64, (182)}, /* ZwOpenKey */ \ + {0x7ccd8968, (138)}, /* ZwCompleteConnectPort */ \ + {0x7dfb3677, (169)}, /* ZwSetEaFile */ \ + {0x7e21039a, (87)}, /* ZwCreateTimer */ \ + {0x7ec723c2, (122)}, /* ZwQueryPerformanceCounter */ \ + {0x7f99ab33, (145)}, /* ZwReadRequestData */ \ + {0x81b18dcd, (21)}, /* ZwQueryVirtualMemory */ \ + {0x842e9cbb, (43)}, /* ZwQueryInformationThread */ \ + {0x84d52359, (112)}, /* ZwCreateEventPair */ \ + {0x84e3898f, (183)}, /* ZwDeleteKey */ \ + {0x850106f7, (7)}, /* ZwCreateDirectoryObject */ \ + {0x8548dfbd, (106)}, /* ZwQueryMutant */ \ + {0x85f069ec, (197)}, /* ZwNotifyChangeMultipleKeys */ \ + {0x87763935, (249)}, /* sprintf */ \ + {0x87fd0a60, (24)}, /* ZwWriteVirtualMemory */ \ + {0x8a1989d8, (136)}, /* ZwListenPort */ \ + {0x8afaa2ca, (31)}, /* ZwGetWriteWatch */ \ + {0x8b3aacc6, (174)}, /* ZwQueryQuotaInformationFile */ \ + {0x8bf01eb2, (135)}, /* ZwSecureConnectPort */ \ + {0x8c4a9ca2, (100)}, /* ZwOpenSemaphore */ \ + {0x8cb632f5, (17)}, /* ZwShutdownSystem */ \ + {0x8d31519d, (58)}, /* ZwOpenProcess */ \ + {0x8d5b0647, (53)}, /* ZwRegisterThreadTerminatePort */ \ + {0x8df4b3ed, (158)}, /* ZwCancelIoFileEx */ \ + {0x8e80b080, (119)}, /* ZwSetHighWaitLowEventPair */ \ + {0x8eb2c33b, (121)}, /* ZwSetSystemTime */ \ + {0x8fe01ce6, (4)}, /* ZwClose */ \ + {0x8ffaebe4, (70)}, /* ZwOpenJobObject */ \ + {0x90bf911c, (177)}, /* ZwQueryFullAttributesFile */ \ + {0x920b0183, (116)}, /* ZwWaitHighEventPair */ \ + {0x9331fae3, (25)}, /* ZwLockVirtualMemory */ \ + {0x9384c236, (103)}, /* ZwCreateMutant */ \ + {0x93e64266, (130)}, /* ZwStartProfile */ \ + {0x949f76b6, (19)}, /* ZwAllocateVirtualMemory */ \ + {0x956ba548, (11)}, /* ZwOpenSymbolicLinkObject */ \ + {0x963cafbc, (229)}, /* ZwQueryDefaultUILanguage */ \ + {0x9731aded, (178)}, /* ZwQueryDirectoryFile */ \ + {0x978855cd, (37)}, /* ZwMapViewOfSection */ \ + {0x98058c5c, (86)}, /* ZwWaitForMultipleObjects */ \ + {0x997388d8, (237)}, /* ZwDeleteAtom */ \ + {0x9bf04a73, (172)}, /* ZwQueryVolumeInformationFile */ \ + {0x9c805856, (167)}, /* ZwNotifyChangeDirectoryFile */ \ + {0x9d9c64db, (186)}, /* ZwSaveMergedKeys */ \ + {0x9fb42181, (79)}, /* ZwFilterToken */ \ + {0x9fce5072, (57)}, /* ZwCreateUserProcess */ \ + {0xa09dea3c, (192)}, /* ZwReplaceKey */ \ + {0xa313f9b0, (220)}, /* ZwSetSystemPowerState */ \ + {0xa34a43e1, (48)}, /* ZwSetContextThread */ \ + {0xa51616fd, (156)}, /* ZwFlushBuffersFile */ \ + {0xa589ce00, (226)}, /* ZwContinue */ \ + {0xa5b2c609, (117)}, /* ZwSetHighEventPair */ \ + {0xa8720028, (153)}, /* ZwCreateFile */ \ + {0xa93301f4, (110)}, /* ZwRemoveIoCompletion */ \ + {0xa9e5e651, (199)}, /* ZwSetValueKey */ \ + {0xabc87b74, (32)}, /* ZwResetWriteWatch */ \ + {0xac5765bd, (211)}, /* ZwOpenObjectAuditAlarm */ \ + {0xac77c9d4, (47)}, /* ZwGetContextThread */ \ + {0xaccf3eee, (214)}, /* ZwAccessCheckByTypeAndAuditAlarm */ \ + {0xacdddfe2, (176)}, /* ZwQueryAttributesFile */ \ + {0xafe64c80, (179)}, /* ZwQueryInformationFile */ \ + {0xb28fcd19, (1)}, /* ZwSetInformationObject */ \ + {0xb2adc219, (209)}, /* ZwAccessCheckByType */ \ + {0xb32b8a16, (41)}, /* ZwOpenThread */ \ + {0xb39f2b58, (128)}, /* ZwSetIntervalProfile */ \ + {0xb3a5ef4c, (64)}, /* RtlDestroyProcessParameters */ \ + {0xb3d90f63, (60)}, /* ZwQueryInformationProcess */ \ + {0xb3f8b8ba, (184)}, /* ZwFlushKey */ \ + {0xb468e7d0, (225)}, /* ZwRaiseException */ \ + {0xb4f463e1, (175)}, /* ZwSetQuotaInformationFile */ \ + {0xb5ce95b0, (109)}, /* ZwSetIoCompletion */ \ + {0xb677bd15, (219)}, /* ZwGetDevicePowerState */ \ + {0xb891d19c, (141)}, /* ZwReplyPort */ \ + {0xba08cfed, (221)}, /* ZwInitiatePowerAction */ \ + {0xba5bdfc3, (234)}, /* ZwSetUuidSeed */ \ + {0xbc310050, (133)}, /* ZwCreateWaitablePort */ \ + {0xbde7d8d1, (151)}, /* ZwLoadDriver */ \ + {0xbe9990b9, (134)}, /* ZwConnectPort */ \ + {0xc0040fd0, (90)}, /* ZwSetTimer */ \ + {0xc00fc05c, (240)}, /* ZwRaiseHardError */ \ + {0xc4bd0fda, (99)}, /* ZwCreateSemaphore */ \ + {0xc524def2, (148)}, /* ZwImpersonateClientOfPort */ \ + {0xc6a277e0, (236)}, /* ZwFindAtom */ \ + {0xc6de9ce3, (139)}, /* ZwRequestPort */ \ + {0xc707f028, (27)}, /* ZwFlushVirtualMemory */ \ + {0xc70d789c, (69)}, /* ZwCreateJobObject */ \ + {0xc71b989a, (78)}, /* ZwDuplicateToken */ \ + {0xc7835b75, (195)}, /* ZwEnumerateKey */ \ + {0xc7d8afa4, (85)}, /* ZwSignalAndWaitForSingleObject */ \ + {0xc94ea8a6, (81)}, /* ZwAdjustGroupsToken */ \ + {0xc9f42a5d, (235)}, /* ZwAddAtom */ \ + {0xca250552, (210)}, /* ZwAccessCheckByTypeResultList */ \ + {0xcaf1f803, (152)}, /* ZwUnloadDriver */ \ + {0xcb3c8251, (223)}, /* ZwPlugPlayControl */ \ + {0xcc22b021, (113)}, /* ZwOpenEventPair */ \ + {0xcdb98ed4, (59)}, /* ZwTerminateProcess */ \ + {0xced9d11d, (123)}, /* ZwSetTimerResolution */ \ + {0xd4191071, (127)}, /* ZwCreateProfile */ \ + {0xd48a2bbc, (40)}, /* ZwCreateThread */ \ + {0xd517401d, (54)}, /* ZwImpersonateThread */ \ + {0xd5a16cee, (51)}, /* ZwAlertThread */ \ + {0xd628c8f6, (228)}, /* ZwSetDefaultLocale */ \ + {0xd7fef93d, (201)}, /* ZwEnumerateValueKey */ \ + {0xda57df71, (247)}, /* LdrUnloadDll */ \ + {0xdaa7575e, (215)}, /* ZwAccessCheckByTypeResultListAndAuditAlarm */ \ + {0xde07d08f, (224)}, /* ZwGetPlugPlayEvent */ \ + {0xde5468ed, (202)}, /* ZwQueryMultipleValueKey */ \ + {0xdf8698ed, (13)}, /* ZwQuerySystemInformation */ \ + {0xdf86b31f, (6)}, /* ZwSetSecurityObject */ \ + {0xe0c1d02e, (55)}, /* ZwImpersonateAnonymousToken */ \ + {0xe1562f17, (3)}, /* ZwMakeTemporaryObject */ \ + {0xe19be90e, (33)}, /* ZwCreateSection */ \ + {0xe23ef886, (161)}, /* ZwReadFileScatter */ \ + {0xe2ff4b82, (188)}, /* ZwLoadKey */ \ + {0xe3521fd4, (101)}, /* ZwReleaseSemaphore */ \ + {0xe3624a9b, (212)}, /* ZwCloseObjectAuditAlarm */ \ + {0xe3ae76c7, (132)}, /* ZwCreatePort */ \ + {0xe43a3a6f, (147)}, /* ZwQueryInformationPort */ \ + {0xe624ac47, (12)}, /* ZwQuerySymbolicLinkObject */ \ + {0xe6a6cc2d, (208)}, /* ZwAccessCheckAndAuditAlarm */ \ + {0xe8d1aec4, (105)}, /* ZwReleaseMutant */ \ + {0xeb69e74d, (62)}, /* ZwFlushInstructionCache */ \ + {0xed4a67c1, (28)}, /* ZwAllocateUserPhysicalPages */ \ + {0xed5deedd, (107)}, /* ZwCreateIoCompletion */ \ + {0xedac7230, (203)}, /* ZwInitializeRegistry */ \ + {0xee535edc, (35)}, /* ZwQuerySection */ \ + {0xee5cdc2d, (82)}, /* ZwQueryInformationToken */ \ + {0xf3d1faa7, (125)}, /* ZwDelayExecution */ \ + {0xf425639c, (104)}, /* ZwOpenMutant */ \ + {0xfde47817, (94)}, /* ZwSetEvent */ \ + +#define __NT_IMPORTED_SYMBOLS_ARRAY_SIZE 250 + +#endif diff --git a/src/internal/ntapi_impl.h b/src/internal/ntapi_impl.h new file mode 100644 index 0000000..b60fc66 --- /dev/null +++ b/src/internal/ntapi_impl.h @@ -0,0 +1,120 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#ifndef ___NTAPI_IMPL_H_ +#define ___NTAPI_IMPL_H_ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_object.h> +#include <ntapi/nt_sysinfo.h> +#include <ntapi/nt_thread.h> +#include <ntapi/nt_process.h> +#include <ntapi/ntapi.h> +#include "ntapi_hash_table.h" +#include "ntapi_context.h" +#include "ntapi_fnapi.h" + +#define __NT_BASED_NAMED_OBJECTS {'\\','B','a','s','e', \ + 'N','a','m','e','d', \ + 'O','b','j','e','c','t','s'} + +/* helper macros */ +#define __NT_ROUND_UP_TO_POWER_OF_2(x,y)(x + (y-1)) & ~(y-1) +#define __NT_IS_MISALIGNED_BUFFER(x) ((!(uintptr_t)x) || ((uintptr_t)x % sizeof(size_t))) +#define __NT_IS_MISALIGNED_LENGTH(x) (x % sizeof(size_t)) +#define __NT_FILE_SYNC_IO (NT_FILE_SYNCHRONOUS_IO_ALERT|NT_FILE_SYNCHRONOUS_IO_NONALERT) + +/* user-defined options: head */ +#ifndef __NT_TTY_MONITORS +#define __NT_TTY_MONITORS 0x10 +#endif + +#ifndef __NT_FORK_CHILD_WAIT_MILLISEC +#define __NT_FORK_CHILD_WAIT_MILLISEC 60000 +#endif + +#ifndef __NT_SYNC_BLOCK_LOCK_TRIES +#define __NT_SYNC_BLOCK_LOCK_TRIES 1024 +#endif +/* user-defined options: tail */ + +/* internal page size */ +#ifndef __NT_INTERNAL_PAGE_SIZE +#define __NT_INTERNAL_PAGE_SIZE 4096 +#endif + +/* .bss section */ +#ifndef __NT_BSS_RESERVED_PAGES +#define __NT_BSS_RESERVED_PAGES 8 +#endif + +/* runtime buffers */ +#define __NT_BSS_ARGV_BUFFER_SIZE __NT_INTERNAL_PAGE_SIZE * 2 + +#define __NT_BSS_ARGV_MAX_IDX __NT_BSS_ARGV_BUFFER_SIZE \ + / sizeof(uintptr_t) + +#define __NT_BSS_ARGS_BUFFER_SIZE __NT_INTERNAL_PAGE_SIZE \ + * __NT_BSS_RESERVED_PAGES \ + - __NT_BSS_ARGV_BUFFER_SIZE + +/* ntapi .bss section structure */ +typedef struct ___ntapi_img_sec_bss { + wchar16_t * argv_envp_array[__NT_BSS_ARGV_MAX_IDX]; + char args_envs_buffer[__NT_BSS_ARGS_BUFFER_SIZE]; +} __ntapi_img_sec_bss; + + +/* ntapi library internals */ +typedef struct __attr_ptr_size_aligned__ _ntapi_internals { + nt_runtime_data * rtdata; + nt_port_name * subsystem; + void * hport_tty_session; + void * hport_tty_daemon; + void * hport_tty_debug; + void * hport_tty_monitor[__NT_TTY_MONITORS]; + size_t nt_mem_page_size; + size_t nt_mem_allocation_granularity; + size_t ntapi_internals_alloc_size; + void ** csr_port_handle_addr; + void * hdev_mount_point_mgr; + void * hany[8]; + intptr_t hlock; + uintptr_t v1_pipe_counter; + ntapi_tt_get_csr_port_handle_addr_by_logic * tt_get_csr_port_handle_addr_by_logic; + __ntapi_img_sec_bss * ntapi_img_sec_bss; +} ntapi_internals; + + +/* __ntapi_img_sec_data */ +typedef struct __attr_ptr_size_aligned__ ___ntapi_img_sec_rdata { + ntapi_hashed_symbol __ntapi_import_table[__NT_IMPORTED_SYMBOLS_ARRAY_SIZE]; + ntapi_vtbl * __ntapi; + nt_port_name __session_name; + ntapi_internals * __internals; +} __ntapi_img_sec_rdata; + +union __ntapi_img_rdata { + __ntapi_img_sec_rdata img_sec_data; + char buffer[__NT_INTERNAL_PAGE_SIZE]; +}; + + +/* accessor table */ +extern ntapi_vtbl ___ntapi; +extern ntapi_vtbl ___ntapi_shadow; +#define __ntapi (&___ntapi) + + +/* access to library internals */ +ntapi_internals * __cdecl __ntapi_internals(void); + + +/* debug */ +#define __ntidx(x) (&(((ntapi_vtbl *)0)->x)) / sizeof(size_t) + + +#endif diff --git a/src/internal/ntapi_lib_entry_point.c b/src/internal/ntapi_lib_entry_point.c new file mode 100644 index 0000000..8b857c8 --- /dev/null +++ b/src/internal/ntapi_lib_entry_point.c @@ -0,0 +1,12 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include <psxtypes/psxtypes.h> + +int __stdcall __ntapi_entry(void * hinstance, uint32_t reason, void * reserved) +{ + return 1; +} diff --git a/src/internal/ntapi_pty.h b/src/internal/ntapi_pty.h new file mode 100644 index 0000000..ff85b3a --- /dev/null +++ b/src/internal/ntapi_pty.h @@ -0,0 +1,37 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#ifndef ___NTAPI_PTY_H_ +#define ___NTAPI_PTY_H_ + +#include <psxtypes/psxtypes.h> +#include <ntapi/nt_status.h> +#include <ntapi/nt_guid.h> +#include <ntapi/nt_sync.h> +#include <ntapi/nt_tty.h> + +#define __PTY_READ 0 +#define __PTY_WRITE 1 + +typedef struct nt_pty_context { + nt_sync_block sync[2]; + void * addr; + size_t size; + void * hport; + void * hpty; + void * section; + void * section_addr; + size_t section_size; + nt_guid guid; + nt_luid luid; + uint32_t access; + uint32_t flags; + uint32_t share; + uint32_t options; + nt_iosb iosb; +} nt_pty; + +#endif |