Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions source/cpp/error_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct ErrorCode {
std::string ToString() const {
std::stringstream ss;
ss << ErrorCategoryToString(category) << ":" << code << " - " << message;
return ss.string();
return ss.str();
}
};

Expand Down Expand Up @@ -273,15 +273,20 @@ class ErrorManager {
// Log the error
if (m_logEnabled) {
Logging::LogLevel logLevel;
switch (error.category) {
case ErrorCategory::WARNING:

// Map error severity to logging level
ErrorSeverity severity = error.category == ErrorCategory::MEMORY ?
ErrorSeverity::CRITICAL : ErrorSeverity::ERROR; // Default mapping

switch (severity) {
case ErrorSeverity::WARNING:
logLevel = Logging::LogLevel::WARNING;
break;
case ErrorCategory::ERROR:
case ErrorSeverity::ERROR:
logLevel = Logging::LogLevel::ERROR;
break;
case ErrorCategory::CRITICAL:
case ErrorCategory::FATAL:
case ErrorSeverity::CRITICAL:
case ErrorSeverity::FATAL:
logLevel = Logging::LogLevel::CRITICAL;
break;
default:
Expand Down Expand Up @@ -310,7 +315,15 @@ class ErrorManager {
}

// For fatal errors, generate crash report and terminate
if (error.category == ErrorCategory::FATAL) {
// Determine if this is a fatal error based on error category or other criteria
bool isFatalError = false;

// For security or memory errors, treat as fatal
if (error.category == ErrorCategory::SECURITY && error.code >= 400) {
isFatalError = true;
}

if (isFatalError) {
if (m_crashReportingEnabled) {
GenerateCrashReport(ex);
}
Expand Down Expand Up @@ -458,28 +471,9 @@ namespace IntegrityCheck {
return checksum == expectedChecksum;
}

// Simple tamper detection for the executable
bool CheckExecutableTampering() {
// In a real implementation, you would:
// 1. Calculate a checksum of critical code sections
// 2. Verify code signatures
// 3. Check for debuggers
// 4. Verify memory protection attributes

// Here's a simplified implementation that just checks for debuggers
#ifdef __APPLE__
struct kinfo_proc info;
size_t info_size = sizeof(info);
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };

if (sysctl(mib, 4, &info, &info_size, NULL, 0) == 0) {
return (info.kp_proc.p_flag & P_TRACED) == 0;
}
return true; // If we can't check, assume it's not tampered
#else
return true; // Implement platform-specific checks for other platforms
#endif
}
// Forward declaration of tamper detection function
// Implementation moved to a separate source file to avoid system header conflicts
bool CheckExecutableTampering();
}

// Initialize error handling
Expand All @@ -490,8 +484,14 @@ inline void InitializeErrorHandling() {
// Set up default error handlers
errorManager.AddHandler([](const ExecutorException& ex) {
// Example handler that logs to console
if (ex.GetErrorCode().category == ErrorCategory::CRITICAL ||
ex.GetErrorCode().category == ErrorCategory::FATAL) {
// Using severity for critical/fatal errors which is the appropriate enum for this
ErrorSeverity severity = ErrorSeverity::ERROR; // Default to ERROR

if (ex.GetErrorCode().category == ErrorCategory::MEMORY) {
severity = ErrorSeverity::CRITICAL; // Memory errors are critical
}

if (severity == ErrorSeverity::CRITICAL || severity == ErrorSeverity::FATAL) {
std::cerr << "CRITICAL ERROR: " << ex.GetFormattedMessage() << std::endl;
}
});
Expand Down
41 changes: 41 additions & 0 deletions source/cpp/error_handling_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// error_handling_impl.cpp - Implementation of functions requiring system headers
// This separates system header includes from header files to avoid conflicts

// Include system headers directly in the implementation file
#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#include <unistd.h>
#endif

// Now include our header with forward declarations
#include "error_handling.hpp"

namespace ErrorHandling {
namespace IntegrityCheck {

// Implementation of executable tampering detection
bool CheckExecutableTampering() {
// In a real implementation, you would:
// 1. Calculate a checksum of critical code sections
// 2. Verify code signatures
// 3. Check for debuggers
// 4. Verify memory protection attributes

// Here's a simplified implementation that just checks for debuggers
#ifdef __APPLE__
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
struct kinfo_proc info;
size_t info_size = sizeof(info);

if (sysctl(mib, 4, &info, &info_size, NULL, 0) == 0) {
return (info.kp_proc.p_flag & P_TRACED) == 0;
}
return true; // If we can't check, assume it's not tampered
#else
return true; // Implement platform-specific checks for other platforms
#endif
}

} // namespace IntegrityCheck
} // namespace ErrorHandling
4 changes: 1 addition & 3 deletions source/cpp/ios/FloatingButtonController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
#include <string>
#include <functional>

// Forward declaration for ObjC types
// Forward declarations for ObjC types already defined in objc_isolation.h
#ifdef __OBJC__
@class UIColor;
#else
typedef void UIColor;
#endif

namespace iOS {
Expand Down
19 changes: 4 additions & 15 deletions source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class ScriptGenerationModel : public LocalModelBase {
*/
std::string AnalyzeScript(const std::string& script);

/**
* @brief Generate a response to a general query
/*
* Generate a response to a general query
* @param query User's query
* @param context Optional context information
* @return Generated response
Expand Down Expand Up @@ -188,9 +188,8 @@ class ScriptGenerationModel : public LocalModelBase {
*/
static std::string CategoryToString(ScriptCategory category);

/**
/**
* @brief Check if the model is initialized
/*
* Check if the model is initialized
* @return True if initialized
*/
bool IsInitialized() const;
Expand All @@ -213,13 +212,3 @@ class ScriptGenerationModel : public LocalModelBase {
} // namespace LocalModels
} // namespace AIFeatures
} // namespace iOS
/**
* @brief Check if the model is initialized
* @return True if initialized
*/

/**
* @brief Set model path
* @param path Path to model files
* @return True if path was valid and set
*/
Original file line number Diff line number Diff line change
Expand Up @@ -486,34 +486,26 @@ class VulnerabilityDetectionModel : public LocalModelBase {
*/
void EnableAllVulnerabilityTypes();

/**
* @brief Get all detectable vulnerability types
/*
* Get all detectable vulnerability types
* @return Set of all vulnerability types the model can detect
/**
* @brief Check if the model is initialized
*/
std::set<VulnType> GetAllDetectableVulnerabilityTypes() const;

/*
* Check if the model is initialized
* @return True if initialized
*/
bool IsInitialized() const;

/**
* @brief Set model path
/*
* Set model path
* @param path Path to model files
* @return True if path was valid and set
*/
bool SetModelPath(const std::string& path);
std::set<VulnType> GetAllDetectableVulnerabilityTypes() const;
};

} // namespace LocalModels
} // namespace AIFeatures
} // namespace iOS
/**
* @brief Check if the model is initialized
* @return True if initialized
*/

/**
* @brief Set model path
* @param path Path to model files
* @return True if path was valid and set
*/
1 change: 1 addition & 0 deletions source/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "memory/mem.hpp"
#include "ios/ExecutionEngine.h"
#include "ios/ScriptManager.h"
#include "ios/UIController.h"
#include "ios/ai_features/AIIntegration.h"
#include "ios/ai_features/AIIntegrationManager.h"
#endif
Expand Down
8 changes: 6 additions & 2 deletions source/cpp/performance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@ class Profiler {
// Generate report
std::stringstream report;
report << "========================================\n";
report << "Performance Report - " << std::put_time(std::localtime(&std::chrono::system_clock::to_time_t(
std::chrono::system_clock::now())), "%Y-%m-%d %H:%M:%S") << "\n";

// Store time in a variable before taking its address
auto now = std::chrono::system_clock::now();
time_t time_now = std::chrono::system_clock::to_time_t(now);
report << "Performance Report - " << std::put_time(std::localtime(&time_now), "%Y-%m-%d %H:%M:%S") << "\n";

report << "========================================\n\n";

std::string currentCategory = "";
Expand Down
54 changes: 54 additions & 0 deletions source/cpp/security/anti_tamper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
// anti_tamper.cpp - Implementation for security anti-tampering system
// Include system headers first before any of our headers with extern "C" blocks
#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <mach/mach_init.h>
#include <mach/mach_error.h>
#include <mach/mach_traps.h>
#include <mach/task.h>
#include <mach/mach_port.h>
#include <dlfcn.h>
#include <mach-o/dyld.h>
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
#endif

// Now include our own header which uses forward declarations
#include "../security/anti_tamper.hpp"

namespace Security {
Expand All @@ -16,6 +35,20 @@ std::atomic<uint64_t> AntiTamper::s_checkInterval(5000); // Default: 5 seconds
std::vector<uint8_t> AntiTamper::s_codeHashes;
std::map<void*, uint32_t> AntiTamper::s_functionChecksums;

// Implementation of helper method that requires system headers
bool AntiTamper::CheckDebuggerUsingProcInfo() {
#ifdef __APPLE__
struct kinfo_proc info;
size_t info_size = sizeof(info);
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };

if (sysctl(mib, 4, &info, &info_size, NULL, 0) == 0) {
return (info.kp_proc.p_flag & P_TRACED) != 0;
}
#endif
return false;
}

// Private initialization methods implementation
void AntiTamper::InitializeCodeHashes() {
// Implementation would generate hashes of code sections for integrity checking
Expand All @@ -25,6 +58,27 @@ void AntiTamper::InitializeCodeHashes() {
void AntiTamper::InitializeFunctionChecksums() {
// Implementation would calculate checksums of critical functions to detect hooks
Logging::LogInfo("Security", "Initializing function checksums for hook detection");

// In a real implementation, you would add critical functions to monitor
// For example, security-related functions, authentication functions, etc.

#ifdef __APPLE__
// Example (using dlsym to find functions):
void* dlsymFunc = dlsym(RTLD_DEFAULT, "dlsym");
if (dlsymFunc) {
MonitorFunction(dlsymFunc);
}

void* mallocFunc = dlsym(RTLD_DEFAULT, "malloc");
if (mallocFunc) {
MonitorFunction(mallocFunc);
}

void* freeFunc = dlsym(RTLD_DEFAULT, "free");
if (freeFunc) {
MonitorFunction(freeFunc);
}
#endif
}

} // namespace Security
Loading