From a7ffe354b225db0b2712af41ea82743fb07758ca Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 25 May 2019 12:20:51 +0000 Subject: internals: renamed nt_debug.h --> nt_log.h, renamed interfaces accordingly. --- src/internal/ntapi.c | 12 ++-- src/internal/ntapi_debug.c | 170 --------------------------------------------- src/internal/ntapi_fnapi.h | 6 +- src/internal/ntapi_log.c | 158 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 180 deletions(-) delete mode 100644 src/internal/ntapi_debug.c create mode 100644 src/internal/ntapi_log.c (limited to 'src') diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index 20b49fb..c96c62b 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include @@ -438,12 +438,10 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) /* nt_statfs.h */ __ntapi->tt_statfs = __ntapi_tt_statfs; - /* nt_debug.h */ - #ifdef __DEBUG - __ntapi->dbg_write = __dbg_write; - __ntapi->dbg_fn_call = __dbg_fn_call; - __ntapi->dbg_msg = __dbg_msg; - #endif + /* nt_log.h */ + __ntapi->log_write = __ntapi_log_write; + __ntapi->log_fn_call = __ntapi_log_fn_call; + __ntapi->log_msg = __ntapi_log_msg; /* OS version dependent functions */ diff --git a/src/internal/ntapi_debug.c b/src/internal/ntapi_debug.c deleted file mode 100644 index a81b80d..0000000 --- a/src/internal/ntapi_debug.c +++ /dev/null @@ -1,170 +0,0 @@ -/********************************************************/ -/* ntapi: Native API core library */ -/* Copyright (C) 2013--2017 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ -/********************************************************/ - -typedef int __dbg_dummy; - -#ifdef __DEBUG - -#include -#include -#include -#include "ntapi_impl.h" - -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 const char * fn_caller_name, - __in void * fn_callee_addr, - __in uintptr_t fn_ret, - __in ntapi_dbg_write* pfn_dbg_write __optional, - __in const 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[2048]; - - 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 const char * source __optional, - __in int line __optional, - __in const char * fn_caller_name, - __in const 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 index 0d50970..f1a6792 100644 --- a/src/internal/ntapi_fnapi.h +++ b/src/internal/ntapi_fnapi.h @@ -330,9 +330,9 @@ NTAPI_UFN(tt_guid_to_string_utf16); NTAPI_UFN(tt_string_to_guid_utf16); /* debug */ -NTAPI_UFN(dbg_write); -NTAPI_UFN(dbg_fn_call); -NTAPI_UFN(dbg_msg); +NTAPI_UFN(log_write); +NTAPI_UFN(log_fn_call); +NTAPI_UFN(log_msg); /* csrss */ NTAPI_VFN(tt_get_csr_port_handle_addr_by_logic,i386); diff --git a/src/internal/ntapi_log.c b/src/internal/ntapi_log.c new file mode 100644 index 0000000..04f6624 --- /dev/null +++ b/src/internal/ntapi_log.c @@ -0,0 +1,158 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include +#include +#include +#include "ntapi_impl.h" + +ssize_t __cdecl __ntapi_log_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 __ntapi_log_fn_call( + __in void * hfile __optional, + __in const char * fn_caller_name, + __in void * fn_callee_addr, + __in uintptr_t fn_ret, + __in ntapi_log_write* pfn_log_write __optional, + __in const char * source __optional, + __in int line __optional) +{ + struct pe_ldr_tbl_entry * image_meta; + void * image_base; + char * fn_name; + ssize_t bytes; + char log_buf[2048]; + + if (!pfn_log_write) + pfn_log_write = __ntapi_log_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 (source && fn_name) + bytes = __ntapi->sprintf( + log_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( + log_buf, + "%s: %s returned 0x%08x\n\n", + fn_caller_name, fn_name, fn_ret); + else if (source) + bytes = __ntapi->sprintf( + log_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( + log_buf, + "%s: calling 0x%08x returned 0x%08x\n\n", + fn_caller_name, fn_callee_addr, fn_ret); + + if (bytes) { + bytes = __ntapi->strlen(log_buf); + + if (bytes == pfn_log_write(hfile,log_buf,bytes)) + return NT_STATUS_SUCCESS; + else + return NT_STATUS_UNSUCCESSFUL; + } else + return NT_STATUS_UNSUCCESSFUL; +} + + +int32_t __cdecl __ntapi_log_msg( + __in void * hfile __optional, + __in const char * source __optional, + __in int line __optional, + __in const char * fn_caller_name, + __in const 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_log_write* pfn_log_write __optional) +{ + char * buffer; + ssize_t bytes; + char log_buf[2048]; + + if (!pfn_log_write) + pfn_log_write = __ntapi_log_write; + + bytes = 0; + buffer = log_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 + log_buf[0] = '\0'; + + if (bytes >= 0) + buffer += __ntapi->strlen(log_buf); + else + return NT_STATUS_UNSUCCESSFUL; + + bytes = __ntapi->sprintf(buffer,fmt,arg1,arg2,arg3,arg4,arg5,arg6); + + if (bytes) { + bytes = __ntapi->strlen(log_buf); + + if (bytes == pfn_log_write(hfile,log_buf,bytes)) + return NT_STATUS_SUCCESS; + else + return NT_STATUS_UNSUCCESSFUL; + } else + return NT_STATUS_UNSUCCESSFUL; +} -- cgit v1.2.3