mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-10 13:23:41 +00:00
1. Removed usage of wcstomb_s(), which doesn't support UTF8
2. Added WideToUTF8_stupid() helper for API calls that give you byte count instead of character count of a non-null terminated UTF16 string 3. Fixed a few more places to support UTF8
This commit is contained in:
@@ -1213,6 +1213,27 @@ int wmain(int argc, char* wargv[])
|
||||
else
|
||||
{
|
||||
FreeConsole();
|
||||
HMODULE shCORE = LoadLibraryExA((LPCSTR)"Shcore.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
DpiAwarenessFunc dpiAwareness = NULL;
|
||||
if (shCORE != NULL)
|
||||
{
|
||||
if ((dpiAwareness = (DpiAwarenessFunc)GetProcAddress(shCORE, (LPCSTR)"SetProcessDpiAwareness")) == NULL)
|
||||
{
|
||||
FreeLibrary(shCORE);
|
||||
shCORE = NULL;
|
||||
}
|
||||
}
|
||||
if (dpiAwareness != NULL)
|
||||
{
|
||||
dpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
FreeLibrary(shCORE);
|
||||
shCORE = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetProcessDPIAware();
|
||||
}
|
||||
|
||||
DialogBox(NULL, MAKEINTRESOURCE(IDD_INSTALLDIALOG), NULL, DialogHandler);
|
||||
}
|
||||
}
|
||||
@@ -1303,9 +1324,8 @@ DWORD WINAPI StartTempAgent(_In_ LPVOID lpParameter)
|
||||
{
|
||||
ILib_DumpEnabledContext winException;
|
||||
char selfexe[_MAX_PATH];
|
||||
char *selfexe_ptr[] = { selfexe };
|
||||
char *selfexe_ptr[] = { selfexe, "--disableUpdate=1", "--serviceTemp=1" };
|
||||
WCHAR str[_MAX_PATH];
|
||||
size_t len;
|
||||
char *integratedJavaScript;
|
||||
int integragedJavaScriptLen;
|
||||
char setup1[_MAX_PATH];
|
||||
@@ -1316,7 +1336,7 @@ DWORD WINAPI StartTempAgent(_In_ LPVOID lpParameter)
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
||||
|
||||
// Get our own executable name
|
||||
if (GetModuleFileNameW(NULL, str, _MAX_PATH) > 5) { wcstombs_s(&len, selfexe, _MAX_PATH, str, _MAX_PATH); }
|
||||
if (GetModuleFileNameW(NULL, str, _MAX_PATH) > 5) { ILibWideToUTF8Ex(str, -1, selfexe, sizeof(selfexe)); }
|
||||
|
||||
// Setup proxy filenames
|
||||
if ((setup1len = (int)strnlen_s(selfexe, sizeof(selfexe))) >= 4) {
|
||||
@@ -1367,7 +1387,7 @@ DWORD WINAPI StartTempAgent(_In_ LPVOID lpParameter)
|
||||
agent->meshCoreCtx_embeddedScript = integratedJavaScript;
|
||||
agent->meshCoreCtx_embeddedScriptLen = integragedJavaScriptLen;
|
||||
agent->runningAsConsole = 1;
|
||||
MeshAgent_Start(agent, 1, selfexe_ptr);
|
||||
MeshAgent_Start(agent, 3, selfexe_ptr);
|
||||
//retCode = agent->exitCode;
|
||||
MeshAgent_Destroy(agent);
|
||||
agent = NULL;
|
||||
@@ -1429,9 +1449,10 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
|
||||
SetWindowTextA( GetDlgItem( hDlg, IDC_STATUSTEXT ), txt);
|
||||
|
||||
// Get current executable path
|
||||
GetModuleFileNameA(NULL, selfexe, MAX_PATH);
|
||||
WCHAR wselfexe[MAX_PATH];
|
||||
GetModuleFileNameW(NULL, wselfexe, sizeof(wselfexe) / 2);
|
||||
ILibWideToUTF8Ex(wselfexe, -1, selfexe, (int)sizeof(selfexe));
|
||||
fileName = MeshAgent_MakeAbsolutePath(selfexe, ".msh");
|
||||
|
||||
{
|
||||
DWORD dwSize = 0;
|
||||
BYTE *pVersionInfo = NULL;
|
||||
@@ -1439,10 +1460,10 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
|
||||
UINT pLenFileInfo = 0;
|
||||
int major, minor, hotfix, other;
|
||||
|
||||
if ((dwSize = GetFileVersionInfoSize(selfexe, NULL)))
|
||||
if ((dwSize = GetFileVersionInfoSizeW(wselfexe, NULL)))
|
||||
{
|
||||
if ((pVersionInfo = malloc(dwSize)) == NULL) { ILIBCRITICALEXIT(254); }
|
||||
if (GetFileVersionInfo(selfexe, 0, dwSize, pVersionInfo))
|
||||
if (GetFileVersionInfoW(wselfexe, 0, dwSize, pVersionInfo))
|
||||
{
|
||||
if (VerQueryValue(pVersionInfo, TEXT("\\"), (LPVOID*)&pFileInfo, &pLenFileInfo))
|
||||
{
|
||||
|
||||
@@ -1586,9 +1586,7 @@ duk_ret_t ILibDuktape_ScriptContainer_OS_networkInterfaces(duk_context *ctx)
|
||||
ILibDuktape_CreateReadonlyProperty(ctx, "interfaceIndexes");
|
||||
|
||||
char fqdn[4096];
|
||||
size_t fqdnLen;
|
||||
int i = 0;
|
||||
size_t converted;
|
||||
char tmpBuffer[32768];
|
||||
DWORD tmpBufferSize = sizeof(tmpBuffer);
|
||||
IP_ADAPTER_ADDRESSES *padapters = (IP_ADAPTER_ADDRESSES*)tmpBuffer;
|
||||
@@ -1612,7 +1610,7 @@ duk_ret_t ILibDuktape_ScriptContainer_OS_networkInterfaces(duk_context *ctx)
|
||||
duk_put_prop_string(ctx, -2, "gateway");
|
||||
}
|
||||
|
||||
wcstombs_s(&fqdnLen, fqdn, sizeof(fqdn), (const wchar_t*)padapters->DnsSuffix, wcsnlen_s(padapters->DnsSuffix, sizeof(fqdn)));
|
||||
ILibWideToUTF8Ex((wchar_t*)padapters->DnsSuffix, -1, fqdn, (int)sizeof(fqdn));
|
||||
duk_push_string(ctx, fqdn);
|
||||
duk_put_prop_string(ctx, -2, "fqdn");
|
||||
|
||||
@@ -1663,7 +1661,7 @@ duk_ret_t ILibDuktape_ScriptContainer_OS_networkInterfaces(duk_context *ctx)
|
||||
duk_put_prop_index(ctx, -2, i++);
|
||||
addr = addr->Next;
|
||||
}
|
||||
wcstombs_s(&converted, ILibScratchPad, sizeof(ILibScratchPad), padapters->FriendlyName, sizeof(ILibScratchPad));
|
||||
ILibWideToUTF8Ex(padapters->FriendlyName, -1, ILibScratchPad, (int)sizeof(ILibScratchPad));
|
||||
duk_put_prop_string(ctx, -2, ILibScratchPad);
|
||||
|
||||
duk_push_heapptr(ctx, indexTable); // [table]
|
||||
|
||||
@@ -974,7 +974,7 @@ void ILibDuktape_fs_watch_iocompletionEx(void *chain, void *user)
|
||||
|
||||
while (n != NULL)
|
||||
{
|
||||
wcstombs_s(&filenameLen, filename, sizeof(filename), n->FileName, n->FileNameLength);
|
||||
filenameLen = ILibWideToUTF8_stupidEx(n->FileName, n->FileNameLength, filename, (int)sizeof(filename));
|
||||
switch (n->Action)
|
||||
{
|
||||
case FILE_ACTION_RENAMED_OLD_NAME:
|
||||
|
||||
@@ -182,10 +182,21 @@ int ILibWhichPowerOfTwo(int number)
|
||||
#ifdef WIN32
|
||||
WCHAR ILibWideScratchPad[4096];
|
||||
char ILibUTF8ScratchPad[4096];
|
||||
char *ILibWideToUTF8(WCHAR* wstr, int len)
|
||||
char *ILibWideToUTF8Ex(WCHAR* wstr, int len, char *buffer, int bufferLen)
|
||||
{
|
||||
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)wstr, len, (LPSTR)ILibUTF8ScratchPad, (int)sizeof(ILibUTF8ScratchPad), NULL, NULL);
|
||||
return((char*)ILibUTF8ScratchPad);
|
||||
if (buffer == NULL) { buffer = ILibUTF8ScratchPad; bufferLen = (int)sizeof(ILibUTF8ScratchPad); }
|
||||
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)wstr, len, (LPSTR)buffer, bufferLen, NULL, NULL);
|
||||
return(buffer);
|
||||
}
|
||||
char *ILibWideToUTF8_stupidEx(WCHAR* wstr, int wstrBYTESIZE, char *buffer, int bufferLen)
|
||||
{
|
||||
char *ret = NULL;
|
||||
char *tmp = ILibMemory_SmartAllocate(wstrBYTESIZE + 2);
|
||||
memcpy_s(tmp, wstrBYTESIZE + 2, (char*)wstr, wstrBYTESIZE);
|
||||
|
||||
ret = ILibWideToUTF8Ex((WCHAR*)tmp, -1, buffer, bufferLen);
|
||||
ILibMemory_Free(tmp);
|
||||
return(ret);
|
||||
}
|
||||
WCHAR* ILibUTF8ToWideEx(char* str, int len, WCHAR* buffer, int bufferCharacterSize)
|
||||
{
|
||||
|
||||
@@ -171,12 +171,17 @@ static inline void ignore_result(uintptr_t result) { (void)result; }
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
char *ILibWideToUTF8(WCHAR* wstr, int len);
|
||||
char *ILibWideToUTF8Ex(WCHAR* wstr, int wstrCharacterLen, char *buffer, int bufferLen);
|
||||
#define ILibWideToUTF8(wstr, wstrCharacterLen) ILibWideToUTF8Ex(wstr, wstrCharacterLen, NULL, 0)
|
||||
char *ILibWideToUTF8_stupidEx(WCHAR* wstr, int wstrBYTESIZE, char *buffer, int bufferLen);
|
||||
#define ILibWideToUTF8_stupid(wstr, wstrBYTESIZE) ILibWideToUTF8_stupidEx(wstr, wstrBYTESIZE, NULL, 0)
|
||||
WCHAR* ILibUTF8ToWideEx(char* str, int len, WCHAR* buffer, int bufferCharacterSize);
|
||||
#define ILibUTF8ToWide(utf8string, len) ILibUTF8ToWideEx(utf8string, len, NULL, 0)
|
||||
#else
|
||||
#define ILibWideToUTF8(wstr, len) (wstr)
|
||||
#define ILibWideToUTF8Ex(wstr, len, buffer, sz) (wstr)
|
||||
#define ILibUTF8toWide(str, len) (str)
|
||||
#define ILibUTF8ToWideEx(str, len, buffer, ccsz) (str)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user