mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +00:00
Addressed IOActive issues
This commit is contained in:
@@ -75,6 +75,7 @@ int gRemoteMouseRenderDefault = 0;
|
||||
#define EXE_IDENTIFIER (unsigned int)778401893
|
||||
#define MSH_IDENTIFIER (unsigned int)778924904
|
||||
#define SCRIPT_ENGINE_PIPE_BUFFER_SIZE 65535
|
||||
#define SERVER_DISCOVERY_BUFFER_SIZE 1024
|
||||
|
||||
#define MESH_AGENT_PORT 16990 //!< Default Mesh Agent Port
|
||||
#define MESH_MCASTv4_GROUP "239.255.255.235"
|
||||
@@ -586,6 +587,7 @@ void UDPSocket_OnData(ILibAsyncUDPSocket_SocketModule socketModule, char* buffer
|
||||
{
|
||||
//int isLoopback;
|
||||
MeshAgentHostContainer *agentHost = (MeshAgentHostContainer*)user;
|
||||
if (!bufferLength < SERVER_DISCOVERY_BUFFER_SIZE) { return; }
|
||||
|
||||
UNREFERENCED_PARAMETER(socketModule);
|
||||
UNREFERENCED_PARAMETER(user);
|
||||
@@ -1478,7 +1480,7 @@ void ILibDuktape_MeshAgent_dumpCoreModuleEx(void *chain, void *user)
|
||||
printf("CoreModule was manually dumped %d times, restarting!\n", ++dumpcount);
|
||||
|
||||
int CoreModuleLen = ILibSimpleDataStore_Get(agentHost->masterDb, "CoreModule", NULL, 0);
|
||||
if (CoreModuleLen > 0)
|
||||
if (CoreModuleLen > 4)
|
||||
{
|
||||
// There is a core module, launch it now.
|
||||
CoreModule = (char*)ILibMemory_Allocate(CoreModuleLen, 0, NULL, NULL);
|
||||
@@ -2257,7 +2259,7 @@ int GenerateSHA384FileHash(char *filePath, char *fileHash)
|
||||
unsigned int NTHeaderIndex = 0;
|
||||
fseek(tmpFile, 0, SEEK_SET);
|
||||
ignore_result(fread(ILibScratchPad, 1, 2, tmpFile));
|
||||
if (ntohs(((unsigned int*)ILibScratchPad)[0]) == 19802) // 5A4D
|
||||
if (ntohs(((uint16_t*)ILibScratchPad)[0]) == 19802) // 5A4D
|
||||
{
|
||||
fseek(tmpFile, 60, SEEK_SET);
|
||||
ignore_result(fread((void*)&NTHeaderIndex, 1, 4, tmpFile));
|
||||
@@ -2876,7 +2878,7 @@ void MeshServer_ProcessCommand(ILibWebClient_StateObject WebStateObject, MeshAge
|
||||
agent->coreTimeout = NULL;
|
||||
|
||||
int CoreModuleLen = ILibSimpleDataStore_Get(agent->masterDb, "CoreModule", NULL, 0);
|
||||
if (CoreModuleLen <= 0)
|
||||
if (CoreModuleLen <= 4)
|
||||
{
|
||||
printf(" meshcore not found...\n");
|
||||
}
|
||||
@@ -3898,7 +3900,7 @@ void MeshAgent_AgentMode_Core_ServerTimeout(duk_context *ctx, void ** args, int
|
||||
agentHost->coreTimeout = NULL;
|
||||
|
||||
printf("Timeout waiting for Server, launching cached meshcore...\n");
|
||||
if (CoreModuleLen <= 0)
|
||||
if (CoreModuleLen <= 4)
|
||||
{
|
||||
printf(" No meshcore found in db...\n");
|
||||
}
|
||||
@@ -4501,7 +4503,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
||||
{
|
||||
char tmp[16];
|
||||
int tmpLen = ILibSimpleDataStore_Get(agentHost->masterDb, "jsDebugPort", tmp, 16);
|
||||
if (tmpLen > 0)
|
||||
if (tmpLen > 0 && tmpLen < 16)
|
||||
{
|
||||
tmp[tmpLen] = 0;
|
||||
agentHost->jsDebugPort = atoi(tmp);
|
||||
@@ -4531,7 +4533,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
||||
duk_eval_string_noresult(agentHost->meshCoreCtx, "process.coreDumpLocation = process.platform=='win32'?(process.execPath.replace('.exe', '.dmp')):(process.execPath + '.dmp');");
|
||||
}
|
||||
|
||||
if (CoreModuleLen > 0)
|
||||
if (CoreModuleLen > 4)
|
||||
{
|
||||
if (ILibSimpleDataStore_Get(agentHost->masterDb, "noUpdateCoreModule", NULL, 0) != 0)
|
||||
{
|
||||
@@ -4609,11 +4611,11 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char **
|
||||
ILibInet_pton(AF_INET, MESH_MCASTv4_GROUP, &(multicastAddr4.sin_addr));
|
||||
|
||||
// Multicast socket on fixed port, will receive multicast from the server.
|
||||
agentHost->multicastDiscovery = ILibMulticastSocket_Create(agentHost->chain, 1024, MESH_AGENT_PORT, &multicastAddr4, &multicastAddr6, UDPSocket_OnData, agentHost, 1);
|
||||
agentHost->multicastDiscovery = ILibMulticastSocket_Create(agentHost->chain, SERVER_DISCOVERY_BUFFER_SIZE, MESH_AGENT_PORT, &multicastAddr4, &multicastAddr6, UDPSocket_OnData, agentHost, 1);
|
||||
if (agentHost->multicastDiscovery == NULL) { ILIBMARKPOSITION(219); return 1; }
|
||||
|
||||
// Multicast socket on a random port, used to multicast to the server and receive server unicast responses.
|
||||
agentHost->multicastDiscovery2 = ILibMulticastSocket_Create(agentHost->chain, 1024, 0, &multicastAddr4, &multicastAddr6, UDPSocket_OnData, agentHost, 1);
|
||||
agentHost->multicastDiscovery2 = ILibMulticastSocket_Create(agentHost->chain, SERVER_DISCOVERY_BUFFER_SIZE, 0, &multicastAddr4, &multicastAddr6, UDPSocket_OnData, agentHost, 1);
|
||||
if (agentHost->multicastDiscovery2 == NULL) { ILIBMARKPOSITION(219); return 1; }
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ int info_GetLocalInterfaces(char* data, int maxdata)
|
||||
// Get the list of all local interfaces
|
||||
if ((dwRetVal = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_GATEWAYS | GAA_FLAG_INCLUDE_PREFIX, NULL, pAdapterAddresses, &ulOutBufLen)) != ERROR_SUCCESS || ulOutBufLen == 0) { free(pAdapterInfo); free(pAdapterAddresses); return 0; }
|
||||
|
||||
int r = 0;
|
||||
j = 0;
|
||||
pAdapter = pAdapterInfo;
|
||||
while (pAdapter)
|
||||
@@ -117,47 +118,47 @@ int info_GetLocalInterfaces(char* data, int maxdata)
|
||||
while (pAdapterAddr != NULL && pAdapterAddr->IfIndex != pAdapter->Index) { pAdapterAddr = pAdapterAddr->Next; }
|
||||
if (pAdapterAddr == NULL) { free(pAdapterInfo); free(pAdapterAddresses); return 0; }
|
||||
|
||||
if (j > 0) { ptr += snprintf(data + ptr, maxdata - ptr, ","); }
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, "{");
|
||||
if (j > 0) { ptr += (r=sprintf_s(data + ptr, maxdata - ptr, ",")); }
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, "{"));
|
||||
|
||||
// Interface type
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, "\"type\":%d", pAdapter->Type);
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, "\"type\":%d", pAdapter->Type));
|
||||
|
||||
// Interface name
|
||||
if (wcslen(pAdapterAddr->FriendlyName) > 0) {
|
||||
wcstombs_s(&templen, temp, 1023, pAdapterAddr->FriendlyName, wcslen(pAdapterAddr->FriendlyName));
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, ",\"name\":\"%s\"", temp);
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, ",\"name\":\"%s\"", temp));
|
||||
}
|
||||
|
||||
// Interface description
|
||||
if (wcslen(pAdapterAddr->Description) > 0) {
|
||||
wcstombs_s(&templen, temp, 1023, pAdapterAddr->Description, wcslen(pAdapterAddr->Description));
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, ",\"desc\":\"%s\"", temp);
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, ",\"desc\":\"%s\"", temp));
|
||||
}
|
||||
|
||||
// Interface MAC address
|
||||
if (pAdapter->AddressLength == 6) {
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, ",\"mac\":\"%02x%02x%02x%02x%02x%02x\"", pAdapter->Address[0], pAdapter->Address[1], pAdapter->Address[2], pAdapter->Address[3], pAdapter->Address[4], pAdapter->Address[5]);
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, ",\"mac\":\"%02x%02x%02x%02x%02x%02x\"", pAdapter->Address[0], pAdapter->Address[1], pAdapter->Address[2], pAdapter->Address[3], pAdapter->Address[4], pAdapter->Address[5]));
|
||||
}
|
||||
|
||||
// Interface DNS suffix
|
||||
if (wcslen(pAdapterAddr->DnsSuffix) > 0) {
|
||||
wcstombs_s(&templen, temp, 1023, pAdapterAddr->DnsSuffix, wcslen(pAdapterAddr->DnsSuffix));
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, ",\"dnssuffix\":\"%s\"", temp);
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, ",\"dnssuffix\":\"%s\"", temp));
|
||||
}
|
||||
|
||||
// IPv4 address and subnet mask
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, ",\"v4addr\":\"%s\"", pAdapter->IpAddressList.IpAddress.String);
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, ",\"v4mask\":\"%s\"", pAdapter->IpAddressList.IpMask.String);
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, ",\"v4gateway\":\"%s\"", pAdapter->GatewayList.IpAddress.String);
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, ",\"v4addr\":\"%s\"", pAdapter->IpAddressList.IpAddress.String));
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, ",\"v4mask\":\"%s\"", pAdapter->IpAddressList.IpMask.String));
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, ",\"v4gateway\":\"%s\"", pAdapter->GatewayList.IpAddress.String));
|
||||
|
||||
// Get the gateway MAC address
|
||||
ILibInet_pton(AF_INET, pAdapter->IpAddressList.IpAddress.String, &ip1);
|
||||
ILibInet_pton(AF_INET, pAdapter->GatewayList.IpAddress.String, &ip2);
|
||||
SendARP(ip2, ip1, pa, &palen);
|
||||
if (palen == 6) { ptr += snprintf(data + ptr, maxdata - ptr, ",\"gatewaymac\":\"%02x%02x%02x%02x%02x%02x\"", pa[0], pa[1], pa[2], pa[3], pa[4], pa[5]); }
|
||||
if (palen == 6) { ptr += (r = sprintf_s(data + ptr, maxdata - ptr, ",\"gatewaymac\":\"%02x%02x%02x%02x%02x%02x\"", pa[0], pa[1], pa[2], pa[3], pa[4], pa[5])); }
|
||||
|
||||
ptr += snprintf(data + ptr, maxdata - ptr, "}");
|
||||
ptr += (r = sprintf_s(data + ptr, maxdata - ptr, "}"));
|
||||
|
||||
j++;
|
||||
pAdapter = pAdapter->Next;
|
||||
@@ -167,7 +168,7 @@ int info_GetLocalInterfaces(char* data, int maxdata)
|
||||
free(pAdapterInfo);
|
||||
free(pAdapterAddresses);
|
||||
|
||||
return ptr;
|
||||
return (r < 0 ? 0 : ptr);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -424,13 +425,22 @@ int MeshInfo_GetSystemInformation(char** data)
|
||||
|
||||
// Setup the response
|
||||
if ((*data = (char*)malloc(65536)) == NULL) { ILIBCRITICALEXIT(254); }
|
||||
ptr += snprintf(*data + ptr, 65536 - ptr, "{\"netif\":[");
|
||||
ptr += sprintf_s(*data + ptr, 65536 - ptr, "{\"netif\":[");
|
||||
ptr += info_GetLocalInterfaces(*data + ptr, 65536 - ptr);
|
||||
ptr += snprintf(*data + ptr, 65536 - ptr, "]}");
|
||||
(*data)[ptr] = 0;
|
||||
if ((*data = realloc(*data, ptr + 1)) == NULL) { ILIBCRITICALEXIT(254); }
|
||||
ptr += sprintf_s(*data + ptr, 65536 - ptr, "]}");
|
||||
if (ptr < 65535)
|
||||
{
|
||||
(*data)[ptr] = 0;
|
||||
if ((*data = realloc(*data, ptr + 1)) == NULL) { ILIBCRITICALEXIT(254); }
|
||||
|
||||
return ptr;
|
||||
return ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(*data);
|
||||
*data = NULL;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -542,6 +552,7 @@ int MeshInfo_PowerState(enum AgentPowerStateActions flg, int force)
|
||||
#elif defined(NACL)
|
||||
//do nothing
|
||||
#else
|
||||
sync();
|
||||
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_POWER_OFF, 0);
|
||||
#endif
|
||||
return 1;
|
||||
@@ -551,6 +562,7 @@ int MeshInfo_PowerState(enum AgentPowerStateActions flg, int force)
|
||||
#elif defined(NACL)
|
||||
//do nothing
|
||||
#else
|
||||
sync();
|
||||
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART, 0);
|
||||
#endif
|
||||
return 1;
|
||||
@@ -568,6 +580,7 @@ int MeshInfo_PowerState(enum AgentPowerStateActions flg, int force)
|
||||
#if defined(_ANDROID) || defined(__APPLE__)
|
||||
// TODO
|
||||
#else
|
||||
sync();
|
||||
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_SW_SUSPEND, 0);
|
||||
#endif
|
||||
return 1;
|
||||
|
||||
@@ -560,7 +560,6 @@
|
||||
<ClCompile Include="..\meshcore\KVM\Windows\kvm.c" />
|
||||
<ClCompile Include="..\meshcore\KVM\Windows\tile.cpp" />
|
||||
<ClCompile Include="..\meshcore\meshinfo.c" />
|
||||
<ClCompile Include="..\meshcore\signcheck.c" />
|
||||
<ClCompile Include="..\meshcore\wincrypto.cpp" />
|
||||
<ClCompile Include="..\meshcore\zlib\adler32.c" />
|
||||
<ClCompile Include="..\meshcore\zlib\deflate.c" />
|
||||
@@ -617,7 +616,6 @@
|
||||
<ClInclude Include="..\meshcore\KVM\Windows\tile.h" />
|
||||
<ClInclude Include="..\meshcore\meshdefines.h" />
|
||||
<ClInclude Include="..\meshcore\meshinfo.h" />
|
||||
<ClInclude Include="..\meshcore\signcheck.h" />
|
||||
<ClInclude Include="..\meshcore\wincrypto.h" />
|
||||
<ClInclude Include="..\meshcore\zlib\deflate.h" />
|
||||
<ClInclude Include="..\meshcore\zlib\gzguts.h" />
|
||||
|
||||
@@ -97,9 +97,6 @@
|
||||
<ClCompile Include="..\meshcore\agentcore.c">
|
||||
<Filter>Meshcore</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\meshcore\signcheck.c">
|
||||
<Filter>Meshcore</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\microscript\ILibDuktape_fs.c">
|
||||
<Filter>Microscript</Filter>
|
||||
</ClCompile>
|
||||
@@ -261,9 +258,6 @@
|
||||
<ClInclude Include="..\meshcore\meshdefines.h">
|
||||
<Filter>Meshcore</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\meshcore\signcheck.h">
|
||||
<Filter>Meshcore</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\microscript\ILibDuktape_fs.h">
|
||||
<Filter>Microscript</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -409,7 +409,6 @@ int wmain(int argc, char* wargv[])
|
||||
int i;
|
||||
size_t str2len = 0;// , proxylen = 0, taglen = 0;
|
||||
wchar_t str[_MAX_PATH];
|
||||
char str2[_MAX_PATH];
|
||||
ILib_DumpEnabledContext winException;
|
||||
int retCode = 0;
|
||||
|
||||
@@ -646,19 +645,7 @@ int wmain(int argc, char* wargv[])
|
||||
wmain_free(argv);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _MINCORE
|
||||
if (argc > 1 && strcasecmp(argv[1], "-signcheck") == 0)
|
||||
{
|
||||
// Check the signature of out own executable
|
||||
util_openssl_init();
|
||||
printf("%d", signcheck_verifysign(argv[0], 0));
|
||||
util_openssl_uninit();
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
#endif
|
||||
if (integratedJavaScript != NULL || (argc > 0 && strcasecmp(argv[0], "--slave") == 0) || (argc > 1 && ((strcasecmp(argv[1], "run") == 0) || (strcasecmp(argv[1], "connect") == 0) || (strcasecmp(argv[1], "--slave") == 0))))
|
||||
{
|
||||
// Run the mesh agent in console mode, since the agent is compiled for windows service, the KVM will not work right. This is only good for testing.
|
||||
@@ -706,20 +693,6 @@ int wmain(int argc, char* wargv[])
|
||||
wmain_free(argv);
|
||||
return serviceState;
|
||||
}
|
||||
else if (argc > 1 && strcasecmp(argv[1], "-signcheck") == 0 && GetModuleFileNameA(NULL, str2, _MAX_PATH) > 5)
|
||||
{
|
||||
// Check the signature of out own executable
|
||||
#ifndef MICROSTACK_NOTLS
|
||||
util_openssl_init();
|
||||
printf("%d", signcheck_verifysign(str2, 0));
|
||||
util_openssl_uninit();
|
||||
#else
|
||||
printf("Cannot verify without OpenSSL support");
|
||||
#endif
|
||||
wmain_free(argv);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
else if (argc > 1 && (strcasecmp(argv[1], "start") == 0 || strcasecmp(argv[1], "-start") == 0))
|
||||
{
|
||||
// Ask the service manager to launch the service
|
||||
|
||||
@@ -565,7 +565,7 @@ void ILibDuktape_Debugger_JSAttach_PopulateSource(duk_context *ctx, char *source
|
||||
{
|
||||
int CoreModuleLen = 0;
|
||||
ILibSimpleDataStore *db = (ILibSimpleDataStore*)Duktape_GetPointerProperty(ctx, -1, "\xFF_MasterDB");
|
||||
if (db == NULL || (CoreModuleLen = ILibSimpleDataStore_Get(db, "CoreModule", NULL, 0)) <= 0)
|
||||
if (db == NULL || (CoreModuleLen = ILibSimpleDataStore_Get(db, "CoreModule", NULL, 0)) <= 4)
|
||||
{
|
||||
ILibDuktape_Error(ctx, "Could Not retrive CoreModule from MeshAgent"); return;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ duk_ret_t ILibDuktape_EncryptionStream_CreateEncryption(duk_context *ctx)
|
||||
duk_size_t tmpLen;
|
||||
char *tmp = (char*)duk_get_lstring(ctx, -1, &tmpLen);
|
||||
duk_push_object(ctx); // [key][stream]
|
||||
duk_push_fixed_buffer(ctx, ILibBase64DecodeLength((int)tmpLen));// [key][stream][buffer]
|
||||
duk_push_fixed_buffer(ctx, ILibBase64DecodeLength(tmpLen));// [key][stream][buffer]
|
||||
key = (char*)Duktape_GetBuffer(ctx, -1, NULL);
|
||||
ILibBase64Decode((unsigned char*)tmp, (int)tmpLen, (unsigned char**)&key);
|
||||
duk_put_prop_string(ctx, -2, "\xFF_key"); // [key][stream]
|
||||
@@ -162,7 +162,7 @@ duk_ret_t ILibDuktape_EncryptionStream_CreateEncryption(duk_context *ctx)
|
||||
{
|
||||
duk_size_t tmpLen;
|
||||
char *tmp = (char*)duk_get_lstring(ctx, -1, &tmpLen);
|
||||
duk_push_fixed_buffer(ctx, ILibBase64DecodeLength((int)tmpLen)); // [stream][iv][buffer]
|
||||
duk_push_fixed_buffer(ctx, ILibBase64DecodeLength(tmpLen)); // [stream][iv][buffer]
|
||||
duk_swap_top(ctx, -2); // [stream][buffer][iv]
|
||||
iv = (char*)Duktape_GetBuffer(ctx, -2, NULL);
|
||||
ILibBase64Decode((unsigned char*)tmp, (int)tmpLen, (unsigned char**)&iv);
|
||||
|
||||
@@ -160,7 +160,7 @@ duk_ret_t ILibDuktape_GenericMarshal_Variable_Val_HSTRING2(duk_context *ctx)
|
||||
{
|
||||
void *ptr;
|
||||
int size;
|
||||
char hexString[255];
|
||||
char hexString[3*255];
|
||||
|
||||
duk_push_this(ctx); // [var]
|
||||
duk_get_prop_string(ctx, -1, "_ptr"); // [var][ptr]
|
||||
|
||||
@@ -2786,7 +2786,7 @@ duk_ret_t ILibDuktape_HttpStream_IncomingMessage_Digest_ValidatePassword(duk_con
|
||||
ILibGetEntryEx(DigestTable, "response", 8, (void**)&response, &responseLen);
|
||||
ILibGetEntryEx(DigestTable, "opaque", 6, (void**)&opaque, &opaqueLen);
|
||||
|
||||
if (username == NULL || uri == NULL || password == NULL || passwordLen == 0 || response == NULL)
|
||||
if (username == NULL || uri == NULL || password == NULL || passwordLen == 0 || response == NULL || opaqueLen != 16)
|
||||
{
|
||||
duk_push_false(ctx);
|
||||
return(1);
|
||||
|
||||
@@ -145,7 +145,7 @@ duk_ret_t ILibDuktape_Polyfills_Buffer_toString(duk_context *ctx)
|
||||
cType = (char*)duk_require_string(ctx, 0);
|
||||
if (strcmp(cType, "base64") == 0)
|
||||
{
|
||||
duk_push_fixed_buffer(ctx, ILibBase64EncodeLength((int)bufferLen));
|
||||
duk_push_fixed_buffer(ctx, ILibBase64EncodeLength(bufferLen));
|
||||
tmpBuffer = Duktape_GetBuffer(ctx, -1, NULL);
|
||||
ILibBase64Encode((unsigned char*)buffer, (int)bufferLen, (unsigned char**)&tmpBuffer);
|
||||
duk_push_string(ctx, tmpBuffer);
|
||||
@@ -208,7 +208,7 @@ duk_ret_t ILibDuktape_Polyfills_Buffer_from(duk_context *ctx)
|
||||
if (strcmp(encoding, "base64") == 0)
|
||||
{
|
||||
// Base64
|
||||
buffer = duk_push_fixed_buffer(ctx, ILibBase64DecodeLength((int)strlength));
|
||||
buffer = duk_push_fixed_buffer(ctx, ILibBase64DecodeLength(strlength));
|
||||
bufferLen = ILibBase64Decode((unsigned char*)str, (int)strlength, (unsigned char**)&buffer);
|
||||
duk_push_buffer_object(ctx, -1, 0, bufferLen, DUK_BUFOBJ_NODEJS_BUFFER);
|
||||
}
|
||||
|
||||
@@ -3156,8 +3156,8 @@ duk_ret_t ILibDuktape_ScriptContainer_ExecuteString(duk_context *ctx)
|
||||
char *payload;
|
||||
duk_size_t payloadLen;
|
||||
payload = (char*)duk_get_lstring(ctx, 0, &payloadLen);
|
||||
int encodedPayloadLen = ILibBase64EncodeLength((int)payloadLen);
|
||||
ILibDuktape_ScriptContainer_NonIsolated_Command *cmd = (ILibDuktape_ScriptContainer_NonIsolated_Command*)ILibMemory_Allocate(sizeof(ILibDuktape_ScriptContainer_NonIsolated_Command) + encodedPayloadLen + sizeof(json), 0, NULL, NULL);
|
||||
size_t encodedPayloadLen = ILibBase64EncodeLength(payloadLen);
|
||||
ILibDuktape_ScriptContainer_NonIsolated_Command *cmd = (ILibDuktape_ScriptContainer_NonIsolated_Command*)ILibMemory_Allocate((int)(sizeof(ILibDuktape_ScriptContainer_NonIsolated_Command) + encodedPayloadLen + sizeof(json)), 0, NULL, NULL);
|
||||
|
||||
cmd->container.slave = (ILibDuktape_ScriptContainer_Slave*)((void**)ILibMemory_GetExtraMemory(master->PeerChain, ILibMemory_CHAIN_CONTAINERSIZE))[1];
|
||||
int i = sprintf_s(cmd->json, sizeof(json) + encodedPayloadLen, json);
|
||||
|
||||
@@ -6779,13 +6779,13 @@ void ILibencodeblock( unsigned char in[3], unsigned char out[4], int len )
|
||||
out[3] = (unsigned char) (len > 2 ? cb64[ in[2] & 0x3f ] : '=');
|
||||
}
|
||||
|
||||
/*! \fn int ILibBase64EncodeLength(const int inputLen)
|
||||
/*! \fn size_t ILibBase64EncodeLength(size_t inputLen)
|
||||
\brief Returns the length the ILibBase64Encode function would use a stream adding padding and line breaks as per spec.
|
||||
\par
|
||||
\param input The length of the en-encoded data
|
||||
\return The length of the encoded stream
|
||||
*/
|
||||
int ILibBase64EncodeLength(const int inputLen)
|
||||
size_t ILibBase64EncodeLength(size_t inputLen)
|
||||
{
|
||||
return ((inputLen * 4) / 3) + 5;
|
||||
}
|
||||
@@ -6841,15 +6841,15 @@ void ILibdecodeblock( unsigned char in[4], unsigned char out[3] )
|
||||
out[ 2 ] = (unsigned char ) (((in[2] << 6) & 0xc0) | in[3]);
|
||||
}
|
||||
|
||||
/*! \fn int ILibBase64DecodeLength(const int inputLen)
|
||||
/*! \fn size_t ILibBase64DecodeLength(size_t inputLen)
|
||||
\brief Returns the length the ILibBase64Decode function would use to store the decoded string value
|
||||
\par
|
||||
\param input The length of the en-encoded data
|
||||
\return The length of the decoded stream
|
||||
*/
|
||||
int ILibBase64DecodeLength(const int inputLen)
|
||||
size_t ILibBase64DecodeLength(size_t inputLen)
|
||||
{
|
||||
return ((inputLen * 3) / 4) + 4;
|
||||
return(((inputLen * 3) / 4) + 4);
|
||||
}
|
||||
|
||||
int ILibBase64DecodeEx(unsigned char* input, const int inputlen, unsigned char* output)
|
||||
|
||||
@@ -1392,8 +1392,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
|
||||
|
||||
/* Base64 handling methods */
|
||||
int ILibBase64EncodeLength(const int inputLen);
|
||||
int ILibBase64DecodeLength(const int inputLen);
|
||||
size_t ILibBase64EncodeLength(size_t inputLen);
|
||||
size_t ILibBase64DecodeLength(size_t inputLen);
|
||||
int ILibBase64Encode(unsigned char* input, const int inputlen, unsigned char** output);
|
||||
int ILibBase64Decode(unsigned char* input, const int inputlen, unsigned char** output);
|
||||
int ILibBase64DecodeEx(unsigned char* input, const int inputlen, unsigned char* output);
|
||||
|
||||
@@ -814,10 +814,14 @@ __EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char*
|
||||
|
||||
return(centry->valueLength);
|
||||
}
|
||||
else
|
||||
else if(buffer == NULL)
|
||||
{
|
||||
return(centry->valueLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -869,7 +873,8 @@ __EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char*
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
return entry->valueLength;
|
||||
|
||||
return(buffer == NULL ? entry->valueLength : 0);
|
||||
}
|
||||
|
||||
// Get the reference to the SHA384 hash value from the datastore for a given a key.
|
||||
|
||||
Reference in New Issue
Block a user