|
|
25347d |
/********************************************************/
|
|
|
25347d |
/* ntapi: Native API core library */
|
|
|
dde53a |
/* Copyright (C) 2013--2017 Z. Gilboa */
|
|
|
25347d |
/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
|
|
|
25347d |
/********************************************************/
|
|
|
25347d |
|
|
|
25347d |
#include <psxtypes/psxtypes.h>
|
|
|
25347d |
#include <ntapi/nt_file.h>
|
|
|
25347d |
#include <ntapi/ntapi.h>
|
|
|
25347d |
#include "ntapi_impl.h"
|
|
|
25347d |
|
|
|
25347d |
static inline int __ntapi_uintptr_to_utf8(uintptr_t value,unsigned char * buf)
|
|
|
25347d |
{
|
|
|
25347d |
int i,len;
|
|
|
25347d |
uintptr_t val;
|
|
|
25347d |
|
|
|
25347d |
if (!value) {
|
|
|
25347d |
*buf = '0';
|
|
|
25347d |
len = 1;
|
|
|
25347d |
} else {
|
|
|
25347d |
for (len=0,val=value; val; val=val/10,len++);
|
|
|
25347d |
for (i=len,buf+=len-1; i; i--,buf--,value=value/10)
|
|
|
25347d |
*buf = '0' + (value % 10);
|
|
|
25347d |
}
|
|
|
25347d |
|
|
|
25347d |
return len;
|
|
|
25347d |
}
|
|
|
25347d |
|
|
|
25347d |
static inline ssize_t __ntapi_log_write(void * msg,uint32_t size)
|
|
|
25347d |
{
|
|
|
25347d |
int32_t status;
|
|
|
25347d |
void * hlog;
|
|
|
25347d |
nt_iosb iosb;
|
|
|
25347d |
uintptr_t buffer[8] = {0};
|
|
|
62cbab |
unsigned char * ch = (unsigned char *)buffer;
|
|
|
25347d |
|
|
|
25347d |
if (!(hlog = __ntapi_internals()->rtdata->hlog))
|
|
|
25347d |
return NT_STATUS_INVALID_HANDLE;
|
|
|
25347d |
|
|
|
25347d |
*ch++ = '@';
|
|
|
25347d |
ch += __ntapi_uintptr_to_utf8(
|
|
|
25347d |
pe_get_current_process_id(),
|
|
|
25347d |
ch);
|
|
|
25347d |
*ch++ = ':';
|
|
|
25347d |
ch += __ntapi_uintptr_to_utf8(
|
|
|
25347d |
pe_get_current_thread_id(),
|
|
|
25347d |
ch);
|
|
|
25347d |
*ch++ = '@';
|
|
|
25347d |
*ch++ = ' ';
|
|
|
25347d |
|
|
|
25347d |
__ntapi->zw_write_file(
|
|
|
25347d |
hlog,
|
|
|
25347d |
0,0,0,&iosb,
|
|
|
25347d |
buffer,
|
|
|
62cbab |
(uint32_t)(ch-(unsigned char *)buffer),
|
|
|
25347d |
0,0);
|
|
|
25347d |
|
|
|
25347d |
status = __ntapi->zw_write_file(
|
|
|
25347d |
hlog,
|
|
|
25347d |
0,0,0,&iosb,
|
|
|
25347d |
msg,
|
|
|
25347d |
(uint32_t)size,
|
|
|
25347d |
0,0);
|
|
|
25347d |
|
|
|
25347d |
return status ? -1 : iosb.info;
|
|
|
25347d |
}
|