Prevent OOM

This commit is contained in:
2026-06-18 05:55:31 +10:00
parent ebba70b9d9
commit b3436a61ee
44 changed files with 1797 additions and 66 deletions
+1 -1
View File
@@ -461,7 +461,7 @@ namespace ANSCENTER {
") returned null — the DLL may be corrupt.");
s_ort_api = api;
Ort::Global<void>::api_ = api;
Ort::InitApi(api);
std::cout << "[EPLoader] ORT loaded successfully." << std::endl;
std::cout << "[EPLoader] ORT DLL version : " << base->GetVersionString() << std::endl;
+21
View File
@@ -1427,6 +1427,27 @@ namespace ANSCENTER
return str.c_str();
}
// Static, handle-free hardware id. Mirrors ANSLSHelper::GetCurrentHardwareId but has no
// instance/_logger, so diagnostics go to DebugView via ANS_DBG. Returns "" on failure.
std::string ANSLicenseHelper::GetHardwareId() {
try {
const wchar_t* hwid = KeyHelper::GetCurrentHardwareId();
std::wstring result_t = std::wstring(hwid);
std::string result = WString2String(result_t);
ANS_DBG("ANSLicenseHelper", "GetHardwareId -> '%s'", result.c_str());
return result;
}
catch (ANSCENTER::Licensing::Exception* ex) {
ANS_DBG("ANSLicenseHelper", "GetHardwareId failed: %s", ex->GetExceptionMessage());
ex->Destroy();
return "";
}
catch (...) {
ANS_DBG("ANSLicenseHelper", "GetHardwareId failed: unknown exception");
return "";
}
}
bool ANSLicenseHelper::isPathSafe(const std::string& pathStr) {
// Basic safety checks - customize as needed
if (pathStr.empty()) return false;
+11
View File
@@ -523,6 +523,10 @@ namespace ANSCENTER
[[nodiscard]] static bool isPathSafe(const std::string& pathStr);
public:
[[nodiscard]] static bool LicenseVerification(std::string licenseKey, int productId, std::string registrationName);
// Returns this machine's hardware id (same value as ANSLSHelper::GetCurrentHardwareId)
// but as a static call requiring no handle/instance — convenient for LabVIEW and other
// callers that just need the HWID. Returns "" on failure.
[[nodiscard]] static std::string GetHardwareId();
[[nodiscard]] static EngineType CheckHardwareInformation();
[[nodiscard]] static SystemHealthInfo GetSystemHealthInformation();
@@ -564,6 +568,13 @@ extern "C" __declspec(dllexport) void SetLicenseServiceURL(ANSCENTER::ANSLSHelpe
extern "C" __declspec(dllexport) int GetLicenseData(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, LStrHandle licenseData);
extern "C" __declspec(dllexport) int LoadLicenseTemplate(ANSCENTER::ANSLSHelper * *Handle, const char* templateFilePath);
extern "C" __declspec(dllexport) int GetCurrentHardwareId(ANSCENTER::ANSLSHelper * *Handle, LStrHandle currentHwID);
// Handle-free static hardware id, two flavours:
// - GetHardwareId: LabVIEW native string handle (LStrHandle) output. Returns 1 on success, 0 on failure.
// - GetHardwareIdBuffer: caller-provided C buffer; works from plain C/C++ too (no LabVIEW manager).
// Writes a null-terminated string into 'buffer' (capacity 'bufferSize') and returns the number of
// characters written (excluding the null terminator), or 0 on failure / insufficient buffer.
extern "C" __declspec(dllexport) int GetHardwareId(LStrHandle currentHwID);
extern "C" __declspec(dllexport) int GetHardwareIdBuffer(char* buffer, int bufferSize);
extern "C" __declspec(dllexport) int GenerateKey(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int trialLicense, LStrHandle generatedKey);
extern "C" __declspec(dllexport) int GenerateKeyWithExpiredDate(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int expiredYear, int expiredMonth, int expiredDate, LStrHandle generatedKey);
extern "C" __declspec(dllexport) int CheckLicenseKey(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, int productId);// , LStrHandle strEnableFeature); // Check if the license key is valid
+37
View File
@@ -109,6 +109,43 @@ extern "C" __declspec(dllexport) int GetCurrentHardwareId(ANSCENTER::ANSLSHelper
return 0;
}
}
extern "C" __declspec(dllexport) int GetHardwareId(LStrHandle currentHwID) {
try {
std::string st = ANSCENTER::ANSLicenseHelper::GetHardwareId();
int size = (int)st.length();
if (size > 0) {
MgErr error;
error = DSSetHandleSize(currentHwID, sizeof(int32) + size * sizeof(uChar));
if (error == noErr)
{
(*currentHwID)->cnt = size;
memcpy((*currentHwID)->str, st.c_str(), size);
return 1;
}
else return 0;
}
else return 0;
}
catch (...) {
return 0;
}
}
extern "C" __declspec(dllexport) int GetHardwareIdBuffer(char* buffer, int bufferSize) {
try {
if (!buffer || bufferSize <= 0) return 0;
std::string st = ANSCENTER::ANSLicenseHelper::GetHardwareId();
int size = (int)st.length();
if (size <= 0) return 0;
// Need room for the string plus the null terminator.
if (size + 1 > bufferSize) return 0;
memcpy(buffer, st.c_str(), size);
buffer[size] = '\0';
return size;
}
catch (...) {
return 0;
}
}
extern "C" __declspec(dllexport) int GenerateKey(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int trialLicense, LStrHandle generatedKey) {
try {
if (!Handle || !(*Handle) || !registrationName) return 0;