unicode logger

This commit is contained in:
NtQuery 2014-03-14 21:03:53 +01:00
parent 55ace2599b
commit 2dc709b487
2 changed files with 18 additions and 35 deletions

View File

@ -9,6 +9,7 @@
enum eLogType {TS_LOG_NORMAL, TS_LOG_ERROR, TS_LOG_COMMAND, TS_LOG_DEBUG};
typedef void(*fLogCallback)(const char* szString, eLogType Type);
typedef void(*fLogCallbackW)(const wchar_t* szString, eLogType Type);
typedef bool (*tScripterLoadFileA)(const char*);
typedef bool (*tScripterLoadFileW)(const wchar_t*);
@ -18,6 +19,7 @@ typedef bool (*tScripterPause)();
typedef bool (*tScripterAutoDebugA)(const char*);
typedef bool (*tScripterAutoDebugW)(const wchar_t*);
typedef void (*tScripterSetLogCallback)(fLogCallback Callback);
typedef void (*tScripterSetLogCallbackW)(fLogCallbackW Callback);
typedef bool (*tScripterExecuteWithTitanMistA)(const char*, const char*);
typedef bool (*tScripterExecuteWithTitanMistW)(const wchar_t*, const wchar_t*);

View File

@ -24,7 +24,6 @@ static TCHAR FileNameIni[MAX_PATH] = {};
//functions
static INT_PTR CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static bool GetFileDialog(TCHAR[MAX_PATH]);
static void AddLogMessage(const char* szLogMessage, eLogType Type);
static void AddLogMessageW(const wchar_t* szLogMessage, eLogType Type);
static void SettingSet(const TCHAR* name, const TCHAR* value);
static void SettingGet(const TCHAR* name, TCHAR* value, int value_size);
@ -35,7 +34,7 @@ static DWORD WINAPI TitanScriptExecThread(LPVOID lpParam);
//TitanScript functions
static tScripterLoadFileW load_file = NULL;
static tScripterExecuteWithTitanMistW exec = NULL;
static tScripterSetLogCallback set_log_callback = NULL;
static tScripterSetLogCallbackW set_log_callback = NULL;
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
@ -102,8 +101,8 @@ INT_PTR CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
load_file = GetTSFunctionPointer( LoadFileW );
exec = GetTSFunctionPointer( ExecuteWithTitanMistW );
set_log_callback = GetTSFunctionPointer( SetLogCallback );
set_log_callback(&AddLogMessage);
set_log_callback = GetTSFunctionPointer( SetLogCallbackW );
set_log_callback(&AddLogMessageW);
}
break;
@ -240,6 +239,8 @@ static bool GetFileDialog(TCHAR Buffer[MAX_PATH])
}
static void AddLogMessageW(const wchar_t* szLogMessage, eLogType Type)
{
if (wcslen(szLogMessage) > 0)
{
LRESULT cSelect = SendMessage(hLogBox, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)szLogMessage);
if (cSelect == LB_ERR)
@ -254,6 +255,7 @@ static void AddLogMessageW(const wchar_t* szLogMessage, eLogType Type)
SendMessage(hLogBox, LB_SETCURSEL, cSelect, NULL);
}
}
}
static bool IsValidChar(char s)
{
@ -271,27 +273,6 @@ static bool IsValidChar(char s)
}
}
static void AddLogMessage(const char* szLogMessage, eLogType Type)
{
if (strlen(szLogMessage) > 0)
{
if (IsValidChar(szLogMessage[0]))
{
TCHAR * buf = (TCHAR *)calloc(strlen(szLogMessage) + 1, sizeof(TCHAR));
if (buf)
{
mbstowcs(buf, szLogMessage, strlen(szLogMessage) + 1);
AddLogMessageW(buf, Type);
free(buf);
}
}
else
{
AddLogMessageW(L"ERROR INVALID LOG MESSAGE", Type);
}
}
}
static void SettingSet(const TCHAR* name, const TCHAR* value)
{
WritePrivateProfileString(_T("Settings"), name, value, FileNameIni);