I'm writing a low-level logger function that appends text string to the end of a text (log) file. The requirement is that this function should not invoke any WinAPIs from DLLs that may not be yet available for the process -- such as when it's called from a DllMain handler. In other words, it can't use any libraries other than the ones that are guaranteed to be loaded into any user-mode process, i.e. kernel32.dll
or ntdll.dll
.
I was able to get by quite nicely with just CreateFile
, WriteFile
, CloseHandle
, HeapAlloc
, HeapFree
, etc. that are all from kernel32.dll
.
The issue is formatting the output string. For instance, I need to add some additional (automatically generated) details, such as current time, process ID, session ID, etc. I would normally use wsprintf
type function for that, or StringCchPrintf
to be exact, as such:
StringCchPrintf(buffer, buffer_size, L"%04u-%02u-%02u %02u:%02u:%02u pid=0x%x, sessID=%d, %s\r\n", /* parameters */ );
but those APIs violate the rule I noted above.
Does anyone know if there's a low level printf
type formatting API available?
all versions of ntdll.dll support how minimum next(from xp) string formating functions:
_snprintf
_snwprintf
_vsnprintf
_vsnwprintf
sprintf
swprintf
vsprintf
the signatures of course full matches same functions from crt. we can free use this api. new versions of ntdll add some new format string api. say win7 (and all latest version) ntdll.dll export next:
_snprintf
_snprintf_s
_snwprintf
_snwprintf_s
_swprintf
_vscwprintf
_vsnprintf
_vsnprintf_s
_vsnwprintf
_vsnwprintf_s
_vswprintf
swprintf
swprintf_s
vsprintf
vsprintf_s
vswprintf_s
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments