diff --git a/.github/workflows/build-openssl-linux.yml b/.github/workflows/build-openssl-linux.yml index 190dacbd7..23758ff7b 100644 --- a/.github/workflows/build-openssl-linux.yml +++ b/.github/workflows/build-openssl-linux.yml @@ -271,7 +271,7 @@ jobs: - name: Create build report run: | - cat > BUILD_REPORT.md << 'EOF' + cat > BUILD_REPORT.md << EOF # OpenSSL 3.5.4 Linux Build Report ## Build Date @@ -327,12 +327,12 @@ jobs: ## Build Configuration All builds use identical OpenSSL configure options: - ``` + \`\`\` no-weak-ssl-ciphers no-srp no-psk no-comp no-zlib no-zlib-dynamic no-threads no-dso no-shared no-asm no-rc5 no-idea no-md4 no-rmd160 no-ssl no-ssl3 no-seed no-camellia no-bf no-cast no-md2 no-mdc2 - ``` + \`\`\` ## Compiler - GCC from Debian Bullseye (glibc builds) @@ -348,7 +348,7 @@ jobs: - MIPS: Cross-compilation on amd64 host ## GitHub Actions Workflow - Built using: `.github/workflows/build-openssl-linux.yml` + Built using: \`.github/workflows/build-openssl-linux.yml\` EOF @@ -358,3 +358,4 @@ jobs: name: build-report path: BUILD_REPORT.md retention-days: 90 + diff --git a/.github/workflows/build-openssl-macos.yml b/.github/workflows/build-openssl-macos.yml index 7c0faa0e7..35aa22f90 100644 --- a/.github/workflows/build-openssl-macos.yml +++ b/.github/workflows/build-openssl-macos.yml @@ -113,14 +113,15 @@ jobs: - name: Upload combined artifact uses: actions/upload-artifact@v4 with: - name: openssl-3.5.4-macos-all + name: openssl-${{ github.event.inputs.openssl_version || '3.5.4' }}-macos-all path: openssl-macos-libs/ retention-days: 90 - name: Create build report run: | - cat > BUILD_REPORT.md << 'EOF' - # OpenSSL 3.5.4 macOS Build Report + OPENSSL_VERSION="${{ github.event.inputs.openssl_version || '3.5.4' }}" + cat > BUILD_REPORT.md << EOF + # OpenSSL $OPENSSL_VERSION macOS Build Report ## Build Date $(date -u +"%Y-%m-%d %H:%M:%S UTC") @@ -139,12 +140,12 @@ jobs: ## Build Configuration All builds use identical OpenSSL configure options: - ``` + \`\`\` no-weak-ssl-ciphers no-srp no-psk no-comp no-zlib no-zlib-dynamic no-threads no-dso no-shared no-asm no-rc5 no-idea no-md4 no-rmd160 no-ssl no-ssl3 no-seed no-camellia no-bf no-cast no-md2 no-mdc2 - ``` + \`\`\` ## Compiler - Xcode Command Line Tools (Clang) @@ -152,7 +153,7 @@ jobs: - ARM64: darwin64-arm64-cc target with -mmacosx-version-min=11.0 ## GitHub Actions Workflow - Built using: `.github/workflows/build-openssl-macos.yml` + Built using: \`.github/workflows/build-openssl-macos.yml\` EOF @@ -162,3 +163,4 @@ jobs: name: build-report path: BUILD_REPORT.md retention-days: 90 + diff --git a/.github/workflows/build-openssl-windows.yml b/.github/workflows/build-openssl-windows.yml index 471ca76d3..8edecbaf4 100644 --- a/.github/workflows/build-openssl-windows.yml +++ b/.github/workflows/build-openssl-windows.yml @@ -134,7 +134,7 @@ jobs: - name: Create build report run: | - cat > BUILD_REPORT.md << 'EOF' + cat > BUILD_REPORT.md << EOF # OpenSSL 3.5.4 Windows Build Report ## Build Date @@ -163,19 +163,19 @@ jobs: ## Build Configuration All builds use identical OpenSSL configure options: - ``` + \`\`\` no-weak-ssl-ciphers no-srp no-psk no-comp no-zlib no-zlib-dynamic no-threads no-err no-dso no-shared no-asm no-rc5 no-idea no-md4 no-rmd160 no-ssl no-ssl3 no-seed no-camellia no-bf no-cast no-md2 no-mdc2 - ``` + \`\`\` ## Compiler - Visual Studio 2022 (MSVC) - Static runtime linking (/MT and /MTd) ## GitHub Actions Workflow - Built using: `.github/workflows/build-openssl-windows.yml` + Built using: \`.github/workflows/build-openssl-windows.yml\` EOF @@ -185,3 +185,4 @@ jobs: name: build-report path: BUILD_REPORT.md retention-days: 90 + diff --git a/docs/modules/apply_labels.py b/docs/modules/apply_labels.py index 42ee46c88..a6f2ad36e 100644 --- a/docs/modules/apply_labels.py +++ b/docs/modules/apply_labels.py @@ -1,8 +1,10 @@ #!/usr/bin/env python3 +import argparse import os import subprocess import re +import sys # Label mappings LABELS = { @@ -54,6 +56,10 @@ def apply_label(filepath, platform): if platform not in LABELS: return False + if sys.platform != 'darwin': + print(f"Error applying label to {filepath}: Finder labels via xattr are only supported on macOS") + return False + label_hex, label_name = LABELS[platform] hex_value = f"000000000000000000{label_hex}00000000000000000000000000000000000000000000" @@ -69,7 +75,15 @@ def apply_label(filepath, platform): return False def main(): - doc_dir = '/Users/peet/GitHub/MeshAgent_installer/bin/modules_documentation' + parser = argparse.ArgumentParser() + parser.add_argument( + 'doc_dir', + nargs='?', + default=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'modules_documentation'), + help='Directory containing module documentation markdown files' + ) + args = parser.parse_args() + doc_dir = args.doc_dir print("Processing module documentation files...") print("=" * 60) diff --git a/meshcore/KVM/Linux/linux_compression.c b/meshcore/KVM/Linux/linux_compression.c index 8176ee57c..fd3d09dcf 100644 --- a/meshcore/KVM/Linux/linux_compression.c +++ b/meshcore/KVM/Linux/linux_compression.c @@ -95,6 +95,7 @@ int write_JPEG_buffer(JSAMPLE * image_buffer, int image_width, int image_height, jpeg_create_compress(&cinfo); cinfo.dest = (struct jpeg_destination_mgr *) malloc(sizeof(struct jpeg_destination_mgr)); + if (cinfo.dest == NULL) { ILIBCRITICALEXIT(254); } cinfo.dest->init_destination = &init_destination; cinfo.dest->empty_output_buffer = &empty_output_buffer; cinfo.dest->term_destination = &term_destination; @@ -132,3 +133,4 @@ int write_JPEG_buffer(JSAMPLE * image_buffer, int image_width, int image_height, return 0; } + diff --git a/meshcore/meshinfo.c b/meshcore/meshinfo.c index 4d2f9d31a..5ff265b6f 100644 --- a/meshcore/meshinfo.c +++ b/meshcore/meshinfo.c @@ -85,7 +85,13 @@ int info_GetLocalInterfaces(char* data, int maxdata) pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO)); if (pAdapterInfo == NULL) return 0; ulOutBufLen = sizeof(IP_ADAPTER_INFO); - if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS) { free(pAdapterInfo); if (ulOutBufLen == 0) return 0; pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen); } + if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS) + { + free(pAdapterInfo); + if (ulOutBufLen == 0) return 0; + pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen); + if (pAdapterInfo == NULL) return 0; + } // Get the list of all local interfaces if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) != ERROR_SUCCESS || ulOutBufLen == 0) { free(pAdapterInfo); return 0; } @@ -107,6 +113,7 @@ int info_GetLocalInterfaces(char* data, int maxdata) return 0; } pAdapterAddresses = (IP_ADAPTER_ADDRESSES *)malloc(ulOutBufLen); + if (pAdapterAddresses == NULL) { free(pAdapterInfo); return 0; } } // Get the list of all local interfaces @@ -366,9 +373,9 @@ int info_GetLocalInterfaces(char* data, int maxdata) { ++size; // realloc buffer size until no overflow occurs - if ((ifc.ifc_req = realloc(ifc.ifc_req, IFRSIZE)) == NULL) return 0; + if ((ifc.ifc_req = realloc(ifc.ifc_req, IFRSIZE)) == NULL) { close(sockfd); return 0; } ifc.ifc_len = IFRSIZE; - if (ioctl(sockfd, SIOCGIFCONF, &ifc) != 0) return 0; + if (ioctl(sockfd, SIOCGIFCONF, &ifc) != 0) { free(ifc.ifc_req); close(sockfd); return 0; } } while (IFRSIZE <= ifc.ifc_len); ifr = ifc.ifc_req; @@ -650,3 +657,4 @@ int MeshInfo_PowerState(enum AgentPowerStateActions flg, int force) #endif #endif + diff --git a/meshcore/openframe_file_logger.h b/meshcore/openframe_file_logger.h index f13aeee99..f8973a789 100644 --- a/meshcore/openframe_file_logger.h +++ b/meshcore/openframe_file_logger.h @@ -3,9 +3,9 @@ OpenFrame File Logger - Duplicates printf to both console and file Usage: Call enable_file_logging() at the start of main() Features: -- Single log file: meshagent.log +- Single log file: meshcentral-agent.log - Auto-rotation at 10MB -- Keeps only 1 archive (meshagent.log.old.gz) +- Keeps only 1 archive (meshcentral-agent.log.old.gz) */ #ifndef OPENFRAME_FILE_LOGGER_H @@ -39,6 +39,7 @@ Usage: Call enable_file_logging() at the start of main() #include #include #include +#include #endif /* Macro to ignore return values */ @@ -173,30 +174,6 @@ static inline long get_file_size(const char* filepath) { } static inline int compress_file_to_gzip(const char* source_path, const char* dest_path) { -#ifdef WIN32 - FILE* src = fopen(source_path, "rb"); - FILE* dst = fopen(dest_path, "wb"); - char buffer[8192]; - size_t bytes; - - if (!src || !dst) { - if (src) fclose(src); - if (dst) fclose(dst); - return 0; - } - - while ((bytes = fread(buffer, 1, sizeof(buffer), src)) > 0) { - if (fwrite(buffer, 1, bytes, dst) != bytes) { - fclose(src); - fclose(dst); - return 0; - } - } - - fclose(src); - fclose(dst); - return 1; -#else FILE* src = fopen(source_path, "rb"); gzFile dst = gzopen(dest_path, "wb9"); char buffer[8192]; @@ -219,7 +196,6 @@ static inline int compress_file_to_gzip(const char* source_path, const char* des fclose(src); gzclose(dst); return 1; -#endif } static inline int rotate_log_file(void) { diff --git a/microstack/ILibAsyncUDPSocket.c b/microstack/ILibAsyncUDPSocket.c index cd5769eaa..1670e31c4 100644 --- a/microstack/ILibAsyncUDPSocket.c +++ b/microstack/ILibAsyncUDPSocket.c @@ -286,7 +286,7 @@ void ILibAsyncUDPSocket_SetMulticastTTL(ILibAsyncUDPSocket_SocketModule module, { struct sockaddr_in6 localAddress; #if defined(__SYMBIAN32__) - return 0; + return; #else #if defined(WIN32) || defined(_WIN32_WCE) SOCKET s = *((SOCKET*)ILibAsyncSocket_GetSocket(module)); @@ -310,3 +310,4 @@ void ILibAsyncUDPSocket_SetMulticastLoopback(ILibAsyncUDPSocket_SocketModule mod ILibAsyncSocket_GetLocalInterface(module, (struct sockaddr*)&localAddress); if (setsockopt(s, localAddress.sin6_family == PF_INET6 ? IPPROTO_IPV6 : IPPROTO_IP, localAddress.sin6_family == PF_INET6 ? IPV6_MULTICAST_LOOP : IP_MULTICAST_LOOP, (char*)&loopback, sizeof(loopback)) != 0) ILIBCRITICALERREXIT(253); } + diff --git a/microstack/ILibMulticastSocket.c b/microstack/ILibMulticastSocket.c index 21b5ad65b..3a251156d 100644 --- a/microstack/ILibMulticastSocket.c +++ b/microstack/ILibMulticastSocket.c @@ -169,7 +169,6 @@ int ILibMulticastSocket_ResetMulticast(struct ILibMulticastSocket_StateModule *m #if !defined(NACL) if (setsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&(module->TTL), sizeof(int)) != 0) ILIBCRITICALERREXIT(253); if (setsockopt(socket, IPPROTO_IP, IP_MULTICAST_LOOP, (const char*)&(module->Loopback), sizeof(int)) != 0) ILIBCRITICALERREXIT(253); - if (setsockopt(socket, IPPROTO_IP, IP_MULTICAST_LOOP, (const char*)&(module->Loopback), sizeof(int)) != 0) ILIBCRITICALERREXIT(253); #endif module->AddressListV4[i].sin_port = 0; @@ -214,7 +213,7 @@ void ILibMulticastSocket_BroadcastUdpPacketV4(struct ILibMulticastSocket_StateMo #ifndef NACL if (module->UDPServers[i] != NULL) { - socket = ILibAsyncUDPSocket_GetSocket(module->UDPServer); + socket = ILibAsyncUDPSocket_GetSocket(module->UDPServers[i]); setsockopt(socket, IPPROTO_IP, IP_MULTICAST_IF, (const char*)&(module->AddressListV4[i].sin_addr), sizeof(struct in_addr)); setsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&(module->TTL), sizeof(int)); for (j = 0; j < count; j++) sendto(socket, data, datalen, 0, (struct sockaddr*)addr, sizeof(struct sockaddr_in)); @@ -397,3 +396,4 @@ void ILibMulticastSocket_WakeOnLan(void *module, char* mac) ILibMulticastSocket_Broadcast((struct ILibMulticastSocket_StateModule*)module, ILibScratchPad, 102, 1); } } + diff --git a/modules/PE_Parser.js b/modules/PE_Parser.js index 757faa665..0b9d08a7d 100644 --- a/modules/PE_Parser.js +++ b/modules/PE_Parser.js @@ -27,115 +27,121 @@ function parse(exePath) var optHeader; var z; - // Read the DOS header - bytesRead = fs.readSync(fd, dosHeader, 0, 64, 0); - if (dosHeader.readUInt16LE(0).toString(16).toUpperCase() != '5A4D') + try { - throw ('unrecognized binary format'); - } + // Read the DOS header + bytesRead = fs.readSync(fd, dosHeader, 0, 64, 0); + if (dosHeader.readUInt16LE(0).toString(16).toUpperCase() != '5A4D') + { + throw ('unrecognized binary format'); + } - // Read the NT header - bytesRead = fs.readSync(fd, ntHeader, 0, ntHeader.length, dosHeader.readUInt32LE(60)); - if (ntHeader.slice(0, 4).toString('hex') != '50450000') - { - throw ('not a PE file'); - } - switch (ntHeader.readUInt16LE(4).toString(16)) - { - case '14c': // 32 bit - retVal.format = 'x86'; - break; - case '8664': // 64 bit - retVal.format = 'x64'; - break; - default: // Unknown - retVal.format = undefined; - break; - } + // Read the NT header + bytesRead = fs.readSync(fd, ntHeader, 0, ntHeader.length, dosHeader.readUInt32LE(60)); + if (ntHeader.slice(0, 4).toString('hex') != '50450000') + { + throw ('not a PE file'); + } + switch (ntHeader.readUInt16LE(4).toString(16)) + { + case '14c': // 32 bit + retVal.format = 'x86'; + break; + case '8664': // 64 bit + retVal.format = 'x64'; + break; + default: // Unknown + retVal.format = undefined; + break; + } - retVal.optionalHeaderSize = ntHeader.readUInt16LE(20); - retVal.optionalHeaderSizeAddress = dosHeader.readUInt32LE(60) + 24; - retVal.sectionHeadersAddress = retVal.optionalHeaderSizeAddress + retVal.optionalHeaderSize; - - // Read the optional header - optHeader = Buffer.alloc(ntHeader.readUInt16LE(20)); - bytesRead = fs.readSync(fd, optHeader, 0, optHeader.length, dosHeader.readUInt32LE(60) + 24); - var numRVA = undefined; - var rvaStart = 0; - retVal.CheckSumPos = dosHeader.readUInt32LE(60) + 24 + 64; - retVal.SizeOfCode = optHeader.readUInt32LE(4); - retVal.SizeOfInitializedData = optHeader.readUInt32LE(8); - retVal.SizeOfUnInitializedData = optHeader.readUInt32LE(12); - retVal.sections = {}; - - // read section headers - var sect = Buffer.alloc(40); - for (z = 0; z < 16; ++z) - { - fs.readSync(fd, sect, 0, sect.length, retVal.sectionHeadersAddress + (z * 40)); - if (sect[0] != 46) { break; } - var s = {}; - s.sectionName = sect.slice(0, 8).toString().trim('\0'); - s.virtualSize = sect.readUInt32LE(8); - s.virtualAddr = sect.readUInt32LE(12); - s.rawSize = sect.readUInt32LE(16); - s.rawAddr = sect.readUInt32LE(20); - s.relocAddr = sect.readUInt32LE(24); - s.lineNumbers = sect.readUInt32LE(28); - s.relocNumber = sect.readUInt16LE(32); - s.lineNumbersNumber = sect.readUInt16LE(34); - s.characteristics = sect.readUInt32LE(36); - retVal.sections[s.sectionName] = s; - } + retVal.optionalHeaderSize = ntHeader.readUInt16LE(20); + retVal.optionalHeaderSizeAddress = dosHeader.readUInt32LE(60) + 24; + retVal.sectionHeadersAddress = retVal.optionalHeaderSizeAddress + retVal.optionalHeaderSize; + + // Read the optional header + optHeader = Buffer.alloc(ntHeader.readUInt16LE(20)); + bytesRead = fs.readSync(fd, optHeader, 0, optHeader.length, dosHeader.readUInt32LE(60) + 24); + var numRVA = undefined; + var rvaStart = 0; + retVal.CheckSumPos = dosHeader.readUInt32LE(60) + 24 + 64; + retVal.SizeOfCode = optHeader.readUInt32LE(4); + retVal.SizeOfInitializedData = optHeader.readUInt32LE(8); + retVal.SizeOfUnInitializedData = optHeader.readUInt32LE(12); + retVal.sections = {}; + + // read section headers + var sect = Buffer.alloc(40); + for (z = 0; z < 16; ++z) + { + fs.readSync(fd, sect, 0, sect.length, retVal.sectionHeadersAddress + (z * 40)); + if (sect[0] != 46) { break; } + var s = {}; + s.sectionName = sect.slice(0, 8).toString().trim('\0'); + s.virtualSize = sect.readUInt32LE(8); + s.virtualAddr = sect.readUInt32LE(12); + s.rawSize = sect.readUInt32LE(16); + s.rawAddr = sect.readUInt32LE(20); + s.relocAddr = sect.readUInt32LE(24); + s.lineNumbers = sect.readUInt32LE(28); + s.relocNumber = sect.readUInt16LE(32); + s.lineNumbersNumber = sect.readUInt16LE(34); + s.characteristics = sect.readUInt32LE(36); + retVal.sections[s.sectionName] = s; + } - if (retVal.sections['.rsrc'] != null) - { - retVal.resources = readResourceTable(fd, retVal.sections['.rsrc'].rawAddr, 0); // Read all resources recursively - } + if (retVal.sections['.rsrc'] != null) + { + retVal.resources = readResourceTable(fd, retVal.sections['.rsrc'].rawAddr, 0); // Read all resources recursively + } - switch (optHeader.readUInt16LE(0).toString(16).toUpperCase()) - { - case '10B': // 32 bit binary - numRVA = optHeader.readUInt32LE(92); - rvaStart = 96; - retVal.CertificateTableAddress = optHeader.readUInt32LE(128); - retVal.CertificateTableSize = optHeader.readUInt32LE(132); - retVal.CertificateTableSizePos = dosHeader.readUInt32LE(60) + 24 + 132; - retVal.rvaStartAddress = dosHeader.readUInt32LE(60) + 24 + 96; - break; - case '20B': // 64 bit binary - numRVA = optHeader.readUInt32LE(108); - rvaStart = 112; - retVal.CertificateTableAddress = optHeader.readUInt32LE(144); - retVal.CertificateTableSize = optHeader.readUInt32LE(148); - retVal.CertificateTableSizePos = dosHeader.readUInt32LE(60) + 24 + 148; - retVal.rvaStartAddress = dosHeader.readUInt32LE(60) + 24 + 112; - break; - default: - throw ('Unknown Value found for Optional Magic: ' + ntHeader.readUInt16LE(24).toString(16).toUpperCase()); - break; - } - retVal.rvaCount = numRVA; + switch (optHeader.readUInt16LE(0).toString(16).toUpperCase()) + { + case '10B': // 32 bit binary + numRVA = optHeader.readUInt32LE(92); + rvaStart = 96; + retVal.CertificateTableAddress = optHeader.readUInt32LE(128); + retVal.CertificateTableSize = optHeader.readUInt32LE(132); + retVal.CertificateTableSizePos = dosHeader.readUInt32LE(60) + 24 + 132; + retVal.rvaStartAddress = dosHeader.readUInt32LE(60) + 24 + 96; + break; + case '20B': // 64 bit binary + numRVA = optHeader.readUInt32LE(108); + rvaStart = 112; + retVal.CertificateTableAddress = optHeader.readUInt32LE(144); + retVal.CertificateTableSize = optHeader.readUInt32LE(148); + retVal.CertificateTableSizePos = dosHeader.readUInt32LE(60) + 24 + 148; + retVal.rvaStartAddress = dosHeader.readUInt32LE(60) + 24 + 112; + break; + default: + throw ('Unknown Value found for Optional Magic: ' + ntHeader.readUInt16LE(24).toString(16).toUpperCase()); + break; + } + retVal.rvaCount = numRVA; - retVal.rva = []; - for (z = 0; z < retVal.rvaCount && z < 32; ++z) - { - retVal.rva.push({ virtualAddress: optHeader.readUInt32LE(rvaStart + (z * 8)), size: optHeader.readUInt32LE(rvaStart + 4 + (z * 8)) }); - } + retVal.rva = []; + for (z = 0; z < retVal.rvaCount && z < 32; ++z) + { + retVal.rva.push({ virtualAddress: optHeader.readUInt32LE(rvaStart + (z * 8)), size: optHeader.readUInt32LE(rvaStart + 4 + (z * 8)) }); + } - if (retVal.CertificateTableAddress) + if (retVal.CertificateTableAddress) + { + // Read the authenticode certificate, only one cert (only the first entry) + var hdr = Buffer.alloc(8); + fs.readSync(fd, hdr, 0, hdr.length, retVal.CertificateTableAddress); + retVal.certificate = Buffer.alloc(hdr.readUInt32LE(0)); + fs.readSync(fd, retVal.certificate, 0, retVal.certificate.length, retVal.CertificateTableAddress + hdr.length); + retVal.certificate = retVal.certificate.toString('base64'); + retVal.certificateDwLength = hdr.readUInt32LE(0); + } + retVal.versionInfo = getVersionInfo(fd, retVal); + } + finally { - // Read the authenticode certificate, only one cert (only the first entry) - var hdr = Buffer.alloc(8); - fs.readSync(fd, hdr, 0, hdr.length, retVal.CertificateTableAddress); - retVal.certificate = Buffer.alloc(hdr.readUInt32LE(0)); - fs.readSync(fd, retVal.certificate, 0, retVal.certificate.length, retVal.CertificateTableAddress + hdr.length); - retVal.certificate = retVal.certificate.toString('base64'); - retVal.certificateDwLength = hdr.readUInt32LE(0); + fs.closeSync(fd); } - retVal.versionInfo = getVersionInfo(fd, retVal); - fs.closeSync(fd); return (retVal); } @@ -144,11 +150,11 @@ function readLenPrefixUnicodeString(fd, ptr) { var name = ''; var tmp = Buffer.alloc(1); - require('fs').readSync(fd, tmp, 0, 1, 0); + require('fs').readSync(fd, tmp, 0, 1, ptr); var nameLen = tmp[0]; var buf = Buffer.alloc(nameLen * 2); - require('fs').readSync(fd, buf, 0, buf.length, 1); + require('fs').readSync(fd, buf, 0, buf.length, ptr + 1); return (require('_GenericMarshal').CreateVariable(buf).Wide2UTF8); } // Read a resource item diff --git a/modules/amt-script.js b/modules/amt-script.js index d00ed101a..02064645e 100644 --- a/modules/amt-script.js +++ b/modules/amt-script.js @@ -47,9 +47,9 @@ function IntToStrX(v) { return String.fromCharCode(v & 0xFF, (v >> 8) & 0xFF, (v function btoa(x) { return Buffer.from(x).toString('base64');} function atob(x) { var z = null; try { z = Buffer.from(x, 'base64').toString(); } catch (e) { console.log(e); } return z; } function passwordcheck(p) { if (p.length < 8) return false; var upper = 0, lower = 0, number = 0, nonalpha = 0; for (var i in p) { var c = p.charCodeAt(i); if ((c > 64) && (c < 91)) { upper = 1; } else if ((c > 96) && (c < 123)) { lower = 1; } else if ((c > 47) && (c < 58)) { number = 1; } else { nonalpha = 1; } } return ((upper + lower + number + nonalpha) == 4); } -function hex2rstr(x) { Buffer.from(x, 'hex').toString(); } -function rstr2hex(x) { Buffer.from(x).toString('hex'); } -function random() { return Math.floor(Math.random()*max); } +function hex2rstr(x) { return Buffer.from(x, 'hex').toString(); } +function rstr2hex(x) { return Buffer.from(x).toString('hex'); } +function random(max) { return Math.floor(Math.random()*max); } function rstr_md5(str) { return hex2rstr(hex_md5(str)); } function getItem(x, y, z) { for (var i in x) { if (x[i][y] == z) return x[i]; } return null; } @@ -399,3 +399,4 @@ module.exports.decompile = function(binary, onecmd) { } return r; } + diff --git a/modules/amt-wsman.js b/modules/amt-wsman.js index 717fd4c96..e8b878347 100644 --- a/modules/amt-wsman.js +++ b/modules/amt-wsman.js @@ -63,7 +63,7 @@ function WsmanStackCreateService(/*CreateWsmanComm, host, port, user, pass, tls, // Perform a WSMAN Subscribe operation obj.ExecSubscribe = function ExecSubscribe(resuri, delivery, url, callback, tag, pri, selectors, opaque, user, pass) { - var digest = "", digest2 = "", opaque = ""; + var digest = "", digest2 = ""; if (user != null && pass != null) { digest = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken' + user + '' + pass + ''; digest2 = ''; } if (opaque != null) { opaque = '' + opaque + ''; } if (delivery == 'PushWithAck') { delivery = 'dmtf.org/wbem/wsman/1/wsman/PushWithAck'; } else if (delivery == 'Push') { delivery = 'xmlsoap.org/ws/2004/08/eventing/DeliveryModes/Push'; } diff --git a/modules/child-container.js b/modules/child-container.js index b949cff6f..1c9226f19 100644 --- a/modules/child-container.js +++ b/modules/child-container.js @@ -145,8 +145,8 @@ function childContainer() if (u[0] == '"') { u = u.substring(1, u.length - 1); } var tokens = u.split('\\'); if (tokens.length != 2) { throw ('invalid user format'); } - user = tokens[1]; - domain = tokens[0]; + var user = tokens[1]; + var domain = tokens[0]; var task = { name: 'MeshUserTask', user: user, domain: domain, execPath: process.execPath, arguments: ['-b64exec ' + script] }; require('win-tasks').addTask(task); @@ -282,4 +282,4 @@ function childContainer() } -module.exports = new childContainer(); \ No newline at end of file +module.exports = new childContainer(); diff --git a/modules/exe.js b/modules/exe.js index 8a9dc676a..bad7c5913 100644 --- a/modules/exe.js +++ b/modules/exe.js @@ -79,6 +79,7 @@ for (i = 1; i < process.argv.length; ++i) { // Read all dependencies in the path if (depPath != null) { + var filenames = []; try { filenames = fs.readdirSync(depPath + '\\*'); @@ -87,7 +88,7 @@ if (depPath != null) var currentPath = process.execPath.substring(0, process.execPath.lastIndexOf('/')); filenames = fs.readdirSync(currentPath + '/' + depPath + '/*'); } - } catch (e) { } + } catch (e) { filenames = []; } filenames.forEach(function (filename) { var fname = process.platform == 'win32' ? (depPath + '\\' + filename) : (depPath + '/' + filename); @@ -182,3 +183,4 @@ function escapeCodeString(str) { } return r; } + diff --git a/modules/file-search.js b/modules/file-search.js index 15f47e79a..86d1fb8ec 100644 --- a/modules/file-search.js +++ b/modules/file-search.js @@ -42,7 +42,7 @@ function filesearch() c.on('end', function () { var last = this.str.trim(); - if (last != '') { this.parent.promise.emit('result', lines.shift()); } + if (last != '') { this.parent.promise.emit('result', last); } console.info1('Powershell Search Client disconnected'); this.end(); this.parent._connection = null; @@ -68,7 +68,10 @@ function filesearch() ret.child.stdin.write('$pipe = new-object System.IO.Pipes.NamedPipeClientStream(".", "' + ret._clientpath + '", 3);\r\n'); ret.child.stdin.write('$pipe.Connect(); \r\n'); ret.child.stdin.write('$sw = new-object System.IO.StreamWriter($pipe);\r\n'); - ret.child.stdin.write('Get-ChildItem -Path ' + root.split('\\').join('\\\\') + ' -Include ' + (Array.isArray(criteria)?criteria.join(','):criteria) + ' -File -Recurse -ErrorAction SilentlyContinue |'); + var psEscape = function (s) { return ("'" + String(s).replace(/'/g, "''") + "'"); }; + var criteriaList = Array.isArray(criteria) ? criteria : [criteria]; + var criteriaArg = '@(' + criteriaList.map(psEscape).join(',') + ')'; + ret.child.stdin.write('Get-ChildItem -Path ' + psEscape(root) + ' -Include ' + criteriaArg + ' -File -Recurse -ErrorAction SilentlyContinue |'); ret.child.stdin.write(' ForEach-Object -Process { $sw.WriteLine($_.FullName); $sw.Flush(); }\r\n'); ret.child.stdin.write('exit\r\n'); @@ -145,4 +148,4 @@ function filesearch() } } -module.exports = new filesearch(); \ No newline at end of file +module.exports = new filesearch(); diff --git a/modules/heci.js b/modules/heci.js index 02f4011f1..22eb09d0b 100644 --- a/modules/heci.js +++ b/modules/heci.js @@ -253,7 +253,7 @@ function heci_create() // Try again to get the device interface detail info if (setup.SetupDiGetDeviceInterfaceDetailA(deviceInfo, interfaceData, deviceDetail, bufferSize, 0, 0).Val == 0) { - deviceDetail = NULL; + deviceDetail = null; continue; } break; @@ -603,4 +603,4 @@ Object.defineProperty(module.exports, "supported", { return (false); } } -}); \ No newline at end of file +}); diff --git a/modules/linux-cpuflags.js b/modules/linux-cpuflags.js index 45b40396b..3fd473884 100644 --- a/modules/linux-cpuflags.js +++ b/modules/linux-cpuflags.js @@ -66,10 +66,10 @@ cpu_feature.X86_FEATURE_LONGRUN = ( 2*32+ 1); /* Longrun power control */ cpu_feature.X86_FEATURE_LRTI = (2 * 32 + 3); /* LongRun table interface */ /* Other features, Linux-defined mapping, word 3 */ -cpu_Feature.X86_FEATURE_CXMMX = ( 3*32+ 0); /* Cyrix MMX extensions */ -cpu_Feature.X86_FEATURE_K6_MTRR = ( 3*32+ 1); /* AMD K6 nonstandard MTRRs */ -cpu_Feature.X86_FEATURE_CYRIX_ARR = ( 3*32+ 2); /* Cyrix ARRs (= MTRRs) */ -cpu_Feature.X86_FEATURE_CENTAUR_MCR = (3 * 32 + 3); /* Centaur MCRs (= MTRRs) */ +cpu_feature.X86_FEATURE_CXMMX = ( 3*32+ 0); /* Cyrix MMX extensions */ +cpu_feature.X86_FEATURE_K6_MTRR = ( 3*32+ 1); /* AMD K6 nonstandard MTRRs */ +cpu_feature.X86_FEATURE_CYRIX_ARR = ( 3*32+ 2); /* Cyrix ARRs (= MTRRs) */ +cpu_feature.X86_FEATURE_CENTAUR_MCR = (3 * 32 + 3); /* Centaur MCRs (= MTRRs) */ cpu_feature.X86_FEATURE_K8 = ( 3*32+ 4); /* "" Opteron, Athlon64 */ cpu_feature.X86_FEATURE_K7 = ( 3*32+ 5); /* "" Athlon */ cpu_feature.X86_FEATURE_P3 = ( 3*32+ 6); /* "" P3 */ diff --git a/modules/smbios.js b/modules/smbios.js index 2391b8e96..ab84b4024 100644 --- a/modules/smbios.js +++ b/modules/smbios.js @@ -178,7 +178,7 @@ function SMBiosTables() } try { - r.systemSlots = this.systemInfo(data); + r.systemSlots = this.systemSlots(data); } catch(e) { @@ -279,7 +279,7 @@ function SMBiosTables() retVal.storageRedirection = amt[6] ? true : false; retVal.serialOverLan = amt[7] ? true : false; retVal.kvm = amt[14] ? true : false; - if (data[131].peek() && data[131].peek().slice(52, 56).toString() == 'vPro') + if (data[131] && data[131].peek() && data[131].peek().slice(52, 56).toString() == 'vPro') { var settings = data[131].peek(); if (settings[0] & 0x04) { retVal.TXT = (settings[0] & 0x08) ? true : false; } @@ -300,7 +300,7 @@ function SMBiosTables() } if (!retVal.AMT) { - if (data[131].peek() && data[131].peek().slice(52, 56).toString() == 'vPro') + if (data[131] && data[131].peek() && data[131].peek().slice(52, 56).toString() == 'vPro') { var settings = data[131].peek(); if ((settings[20] & 0x08) == 0x08) { retVal.AMT = true; } @@ -356,4 +356,4 @@ function SMBiosTables() } } -module.exports = new SMBiosTables(); \ No newline at end of file +module.exports = new SMBiosTables(); diff --git a/modules/upnp.js b/modules/upnp.js index 1b79b3ceb..5d7e4df06 100644 --- a/modules/upnp.js +++ b/modules/upnp.js @@ -273,7 +273,7 @@ function upnpaction(service, xmlDoc) { parameters += ('' + args[this.arguments[i].name] + ''); } - else if(this.arguments.direction == 'in') + else if (this.arguments[i].direction == 'in') { ret._rej('missing parameter: [' + this.arguments[i].name + '] when invoking Action: ' + this.name); return (ret); @@ -688,3 +688,4 @@ module.exports.displayService = display_service; module.exports.displayActionDetail = display_actionDetail; + diff --git a/modules/utils/win-kblayout.js b/modules/utils/win-kblayout.js index 20a776f79..ca43e8663 100644 --- a/modules/utils/win-kblayout.js +++ b/modules/utils/win-kblayout.js @@ -37,10 +37,6 @@ str += ' }\r\n'; str += ' return(ret);\r\n'; str += '}'; -console.log('Value saved to clipboard...'); -require('clipboard')(str); -process.exit(); - var check = {}; diff --git a/modules/win-crypto.js b/modules/win-crypto.js index 8423f5963..0c56b2734 100644 --- a/modules/win-crypto.js +++ b/modules/win-crypto.js @@ -279,7 +279,7 @@ function WinCrypto() this._Kernel32.GetSystemTime(expiration); // If today is Feb-29, change the expiration to Feb-28, because that's simpler than dealing with leap-year exception complexity - if (expiration.toBuffer().readUInt16LE(2) == 2 && expiration.toBuffer().readUInt16LE(6) == 29) { exipiration.toBuffer().writeUInt16LE(28, 6); } + if (expiration.toBuffer().readUInt16LE(2) == 2 && expiration.toBuffer().readUInt16LE(6) == 29) { expiration.toBuffer().writeUInt16LE(28, 6); } var year = expiration.toBuffer().readUInt16LE(0); year += options._years; expiration.toBuffer().writeUInt16LE(year, 0); @@ -772,4 +772,4 @@ module.exports = new WinCrypto(); //console.log(result.data, result.signingCertificate.publicKeyHash, result.signingCertificate.fingerprint); //var decoded = cng.verifyMessage(msg, { encodingType: PKCS_7_ASN_ENCODING }); -//console.log(decoded.toString()); \ No newline at end of file +//console.log(decoded.toString()); diff --git a/modules/win-firewall.js b/modules/win-firewall.js index 86e3413c2..8fdeda4eb 100644 --- a/modules/win-firewall.js +++ b/modules/win-firewall.js @@ -367,7 +367,6 @@ function getFirewallRulesAsync2(p) } p.emit('rule', obj); if (p.options.noResult != true) { p.arr.push(obj); } - p.arr.push(obj); } rule.funcs.Release(rule.Deref()); setImmediate(getFirewallRulesAsync2, p); @@ -696,4 +695,4 @@ module.exports = addFirewallRule: addFirewallRule, removeFirewallRule: removeFirewallRule, netsecurityExists: false - }; \ No newline at end of file + }; diff --git a/modules/win-registry.js b/modules/win-registry.js index 998b8bbad..9fb40756c 100644 --- a/modules/win-registry.js +++ b/modules/win-registry.js @@ -203,12 +203,14 @@ function windows_registry() v = this._AdvApi.RegQueryInfoKeyW(h.Deref(), achClass, achClassSize, 0, numSubKeys, longestSubkeySize, longestClassString, numValues, longestValueName, longestValueData, securityDescriptor, lastWriteTime); - if (v.Val != 0) { throw ('RegQueryInfoKeyW() returned error: ' + v.Val); } + if (v.Val != 0) { this._AdvApi.RegCloseKey(h.Deref()); throw ('RegQueryInfoKeyW() returned error: ' + v.Val); } // Convert the time format var systime = this._marshal.CreateVariable(16); - if (this._Kernel32.FileTimeToSystemTime(lastWriteTime, systime).Val == 0) { throw ('Error parsing time'); } - return (require('fs').convertFileTime(lastWriteTime)); + if (this._Kernel32.FileTimeToSystemTime(lastWriteTime, systime).Val == 0) { this._AdvApi.RegCloseKey(h.Deref()); throw ('Error parsing time'); } + var result = require('fs').convertFileTime(lastWriteTime); + this._AdvApi.RegCloseKey(h.Deref()); + return (result); }; this.WriteKey = function WriteKey(hkey, path, key, value) diff --git a/modules/zip-reader.js b/modules/zip-reader.js index cfd4217d7..4fed4edb9 100644 --- a/modules/zip-reader.js +++ b/modules/zip-reader.js @@ -46,6 +46,7 @@ function extractNext(p) { if (p.pending.length == 0) { p.source.close(); p._res(); return; } var next = p.pending.pop(); + if (next.indexOf('..') !== -1) { p.source.close(); p._rej('Illegal path in zip entry: ' + next); return; } var dest = p.baseFolder + (process.platform == 'win32' ? '\\' : '/') + next; if (process.platform == 'win32') { @@ -457,4 +458,4 @@ function isZip(path) return (false); } -module.exports = { read: read, isZip: isZip }; \ No newline at end of file +module.exports = { read: read, isZip: isZip }; diff --git a/samples/webrtc/C# Sample/SimpleRendezvousServer.cs b/samples/webrtc/C# Sample/SimpleRendezvousServer.cs index 64af6a5bf..8174e9976 100644 --- a/samples/webrtc/C# Sample/SimpleRendezvousServer.cs +++ b/samples/webrtc/C# Sample/SimpleRendezvousServer.cs @@ -148,7 +148,7 @@ private async void OnRead(Task t, object j) { case GET_HEADER: byte[] resp = await ProcessGet(RW.client.Client.LocalEndPoint as IPEndPoint, headers[0]).ConfigureAwait(false); - if (resp.Length > 0) { RW.s.Write(resp, 0, resp.Length); } + if (resp != null && resp.Length > 0) { RW.s.Write(resp, 0, resp.Length); } RW.s.Close(); break; case POST_HEADER: @@ -168,7 +168,7 @@ private async void OnRead(Task t, object j) if (contentLength + eoh + 4 <= RW.totalRead) { byte[] postResp = await ProcessPost(headers[0], UTF8Encoding.UTF8.GetString(RW.buffer, eoh + 4, contentLength)).ConfigureAwait(false); - if (postResp.Length > 0) { RW.s.Write(postResp, 0, postResp.Length); } + if (postResp != null && postResp.Length > 0) { RW.s.Write(postResp, 0, postResp.Length); } RW.s.Close(); } else @@ -180,7 +180,7 @@ private async void OnRead(Task t, object j) else { byte[] postResp = await ProcessPost(headers[0], null).ConfigureAwait(false); - if (postResp.Length > 0) { RW.s.Write(postResp, 0, postResp.Length); } + if (postResp != null && postResp.Length > 0) { RW.s.Write(postResp, 0, postResp.Length); } RW.s.Close(); } break;