mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +00:00
1. Fixed compiler warning
2. Updated chain, so that thread id is saved at creation time 3. Updated Make_AbsolutePath() per IOActive
This commit is contained in:
@@ -1838,56 +1838,30 @@ End Mesh Agent Duktape Abstraction
|
||||
// !!!WARNING!!!: The result of this method is stored in ILibScratchPad2
|
||||
char* MeshAgent_MakeAbsolutePath(char *basePath, char *localPath)
|
||||
{
|
||||
duk_context *ctx = NULL;
|
||||
MeshAgentHostContainer *agent = ILibMemory_CanaryOK(basePath) ? ((MeshAgentHostContainer**)ILibMemory_Extra(basePath))[0] : NULL;
|
||||
if (agent != NULL && agent->configPathUsesCWD != 0)
|
||||
{
|
||||
ctx = agent->meshCoreCtx != NULL ? agent->meshCoreCtx : ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx(0, 0, agent->chain, NULL, NULL, agent->exePath, NULL, NULL, agent->chain);
|
||||
if (duk_peval_string(ctx, "(function (){ return(process.cwd() + process.execPath.split(process.platform=='win32'?'\\\\':'/').pop()); })();") == 0)
|
||||
{
|
||||
basePath = (char*)duk_get_string(ctx, -1);
|
||||
}
|
||||
}
|
||||
duk_context *ctx = (agent != NULL && agent->meshCoreCtx != NULL) ? agent->meshCoreCtx : ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx(0, 0, agent->chain, NULL, NULL, agent->exePath, NULL, NULL, agent->chain);
|
||||
|
||||
size_t localPathLen = strnlen_s(localPath, sizeof(ILibScratchPad2));
|
||||
size_t basePathLen = strnlen_s(basePath, sizeof(ILibScratchPad2));
|
||||
int i, sz;
|
||||
if (localPath[0] == '.')
|
||||
if (duk_peval_string(ctx, "require('util-pathHelper');") == 0) // [helper]
|
||||
{
|
||||
// Use Same executable Name, but different extension
|
||||
sz = (int)basePathLen;
|
||||
if (sz>=4 && ntohl(((unsigned int*)(basePath + sz - 4))[0]) == EXE_IDENTIFIER)
|
||||
duk_push_string(ctx, basePath); // [helper][basePath]
|
||||
duk_push_string(ctx, localPath); // [helper][basePath][localPath]
|
||||
duk_push_boolean(ctx, agent->configPathUsesCWD != 0); // [helper][basePath][localPath][bool]
|
||||
if (duk_pcall(ctx, 3) == 0) // [result]
|
||||
{
|
||||
// BasePath ends with .exe
|
||||
memcpy_s(ILibScratchPad2, sizeof(ILibScratchPad2), basePath, sz - 4);
|
||||
memcpy_s(ILibScratchPad2 + sz - 4, sizeof(ILibScratchPad2) - sz - 4, localPath, localPathLen);
|
||||
sz = sz - 4 + (int)localPathLen;
|
||||
}
|
||||
else
|
||||
duk_size_t len;
|
||||
char *buffer = Duktape_GetBuffer(ctx, -1, &len);
|
||||
if (len < sizeof(ILibScratchPad2))
|
||||
{
|
||||
// BasePath does not end with .exe
|
||||
memcpy_s(ILibScratchPad2, sizeof(ILibScratchPad2), basePath, sz);
|
||||
memcpy_s(ILibScratchPad2 + sz, sizeof(ILibScratchPad2) - sz, localPath, localPathLen);
|
||||
sz += (int)localPathLen;
|
||||
}
|
||||
ILibScratchPad2[sz] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((i = ILibString_LastIndexOf(basePath, (int)basePathLen, "\\", 1)) < 0) { i = ILibString_LastIndexOf(basePath, (int)basePathLen, "/", 1); }
|
||||
|
||||
i += 1;
|
||||
sz = i + (int)localPathLen;
|
||||
memcpy_s(ILibScratchPad2, sizeof(ILibScratchPad2), basePath, i);
|
||||
memcpy_s(ILibScratchPad2 + i, sizeof(ILibScratchPad2) - i, localPath, localPathLen);
|
||||
ILibScratchPad2[sz] = 0;
|
||||
}
|
||||
if (ctx != NULL)
|
||||
{
|
||||
duk_pop(ctx);
|
||||
ILibScratchPad2[len] = 0;
|
||||
memcpy_s(ILibScratchPad2, sizeof(ILibScratchPad2), buffer, len);
|
||||
duk_pop(ctx); // ...
|
||||
if (agent->meshCoreCtx == NULL) { Duktape_SafeDestroyHeap(ctx); }
|
||||
return(ILibScratchPad2);
|
||||
}
|
||||
return ILibScratchPad2;
|
||||
}
|
||||
}
|
||||
|
||||
ILIBCRITICALEXITMSG(254, "PATH MANIPULATION ERROR");
|
||||
}
|
||||
|
||||
#ifndef MICROSTACK_NOTLS
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1925,6 +1925,12 @@ void *ILibCreateChainEx(int extraMemorySize)
|
||||
|
||||
RetVal->Timer = ILibCreateLifeTime(RetVal);
|
||||
|
||||
#if defined(WIN32)
|
||||
RetVal->ChainThreadID = GetCurrentThreadId();
|
||||
#else
|
||||
RetVal->ChainThreadID = pthread_self();
|
||||
#endif
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ uint16_t ILib_atoi2_uint16(const char *instr, size_t instrLen);
|
||||
#define ILib_atoi_uint64(pval, instr, instrLen) ILib_atoi_uint64_ex(pval, instr, instrLen, UINT64_MAX)
|
||||
#define ILib_atoi_int64(pval, instr, instrLen) ILib_atoi_uint64_ex(pval, instr, instrLen, INT64_MAX)
|
||||
#define ILib_atoi_uint32(pval, instr, instrLen) ILib_atoi_uint32_ex(pval, instr, instrLen, UINT32_MAX)
|
||||
#define ILib_atoi_int32(pval, instr, instrLen) ILib_atoi_uint32_ex(pval, instr, instrLen, INT32_MAX)
|
||||
#define ILib_atoi_int32(pval, instr, instrLen) ILib_atoi_uint32_ex((uint32_t*)pval, instr, instrLen, INT32_MAX)
|
||||
#define ILib_atoi_uint16(pval, instr, instrLen) ILib_atoi_uint16_ex(pval, instr, instrLen, UINT16_MAX)
|
||||
#define ILib_atoi_int16(pval, instr, instrLen) ILib_atoi_uint16_ex(pval, instr, instrLen, INT16_MAX)
|
||||
|
||||
|
||||
44
modules/util-pathHelper.js
Normal file
44
modules/util-pathHelper.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
Copyright 2020 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
function makePath(path1, path2, useCWD)
|
||||
{
|
||||
if (useCWD != null && useCWD)
|
||||
{
|
||||
var tokens = process.cwd().split(process.platform == 'win32' ? '\\' : '/');
|
||||
tokens.pop();
|
||||
tokens.push(path1.split(process.platform == 'win32' ? '\\' : '/').pop());
|
||||
path1 = tokens.join(process.platform == 'win32' ? '\\' : '/');
|
||||
}
|
||||
|
||||
if (path2.startsWith('.'))
|
||||
{
|
||||
if (path1.toLowerCase().endsWith('.exe')) { path1 = path1.substring(0, path1.length - 4); }
|
||||
path1 += path2;
|
||||
}
|
||||
else
|
||||
{
|
||||
var tokens = path1.split(process.platform == 'win32' ? '\\' : '/');
|
||||
tokens.pop();
|
||||
tokens.push(path2);
|
||||
path1 = tokens.join(process.platform == 'win32' ? '\\' : '/');
|
||||
}
|
||||
return (path1);
|
||||
}
|
||||
|
||||
module.exports = makePath;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user