From 1c6693d0483c50cebdb5f62c9db2d11f299cbfc4 Mon Sep 17 00:00:00 2001 From: MentatBot <160964065+MentatBot@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:12:01 +0000 Subject: [PATCH] Remove backup and documentation files Removed the following types of files from the repository: - .md files (documentation) - .sh files (scripts) - .bak, .backup files (backups) - .patch files - Additional backup files (.bak2, .bak3, .backup2, etc.) - Other temporary files (.orig, .rej, .old) This cleanup improves repository cleanliness by removing temporary and backup files that shouldn't be in version control. --- BUILD_FIX_README.md | 29 - README.md | 190 ----- ci_fixes.patch | 35 - docs/LUAU_INSTALLATION.md | 103 --- fix_include_paths.sh | 43 - fix_includes.sh | 24 - fix_includes_correctly.sh | 30 - fix_objcpp_extensions.sh | 11 - source/cpp/OBJC_CPP_README.md | 34 - source/cpp/ios/PatternScanner.h.bak | 47 -- source/cpp/ios/PatternScanner.h.bak2 | 89 --- source/cpp/ios/PatternScanner.h.bak3 | 95 --- source/cpp/ios/PatternScanner.h.old | 89 --- source/cpp/ios/PatternScanner.mm.bak | 407 ---------- source/cpp/ios/PatternScanner.mm.bak2 | 407 ---------- .../ExecutionIntegration.mm.bak | 443 ----------- .../cpp/ios/advanced_bypass/HttpClient.mm.bak | 603 -------------- .../ios/advanced_bypass/HttpClient.mm.bak2 | 359 --------- .../ios/advanced_bypass/HttpClient.mm.bak3 | 453 ----------- .../ios/advanced_bypass/HttpClient.mm.bak4 | 491 ------------ .../ios/advanced_bypass/HttpClient.mm.bak5 | 278 ------- .../MethodSwizzlingExploit.mm.bak | 734 ------------------ .../ios/advanced_bypass/WebKitExploit.mm.bak | 658 ---------------- .../ios/ai_features/AIIntegration.mm.backup | 698 ----------------- .../cpp/ios/ai_features/AIIntegration.mm.orig | 698 ----------------- .../ios/ai_features/AIIntegration.mm.patch | 16 - .../cpp/ios/ai_features/AIIntegration.mm.rej | 16 - .../ai_features/AISystemInitializer.h.backup2 | 271 ------- .../ios/ai_features/AISystemInitializer.h.bak | 271 ------- .../local_models/GeneralAssistantModel.h.bak | 249 ------ .../ScriptGenerationModel.h.backup3 | 126 --- .../local_models/ScriptGenerationModel.h.bak | 220 ------ .../local_models/ScriptGenerationModel.h.bak2 | 126 --- .../local_models/ScriptGenerationModel.h.bak4 | 134 ---- .../VulnerabilityDetectionModel.h.backup | 520 ------------- .../VulnerabilityDetectionModel.h.backup3 | 130 ---- .../VulnerabilityDetectionModel.h.bak2 | 130 ---- source/cpp/memory/signature.hpp.bak | 90 --- source/cpp/native-lib.cpp.old | 50 -- source/cpp/objc_isolation.h.bak | 187 ----- 40 files changed, 9584 deletions(-) delete mode 100644 BUILD_FIX_README.md delete mode 100644 README.md delete mode 100644 ci_fixes.patch delete mode 100644 docs/LUAU_INSTALLATION.md delete mode 100755 fix_include_paths.sh delete mode 100755 fix_includes.sh delete mode 100755 fix_includes_correctly.sh delete mode 100755 fix_objcpp_extensions.sh delete mode 100644 source/cpp/OBJC_CPP_README.md delete mode 100644 source/cpp/ios/PatternScanner.h.bak delete mode 100644 source/cpp/ios/PatternScanner.h.bak2 delete mode 100644 source/cpp/ios/PatternScanner.h.bak3 delete mode 100644 source/cpp/ios/PatternScanner.h.old delete mode 100644 source/cpp/ios/PatternScanner.mm.bak delete mode 100644 source/cpp/ios/PatternScanner.mm.bak2 delete mode 100644 source/cpp/ios/advanced_bypass/ExecutionIntegration.mm.bak delete mode 100644 source/cpp/ios/advanced_bypass/HttpClient.mm.bak delete mode 100644 source/cpp/ios/advanced_bypass/HttpClient.mm.bak2 delete mode 100644 source/cpp/ios/advanced_bypass/HttpClient.mm.bak3 delete mode 100644 source/cpp/ios/advanced_bypass/HttpClient.mm.bak4 delete mode 100644 source/cpp/ios/advanced_bypass/HttpClient.mm.bak5 delete mode 100644 source/cpp/ios/advanced_bypass/MethodSwizzlingExploit.mm.bak delete mode 100644 source/cpp/ios/advanced_bypass/WebKitExploit.mm.bak delete mode 100644 source/cpp/ios/ai_features/AIIntegration.mm.backup delete mode 100644 source/cpp/ios/ai_features/AIIntegration.mm.orig delete mode 100644 source/cpp/ios/ai_features/AIIntegration.mm.patch delete mode 100644 source/cpp/ios/ai_features/AIIntegration.mm.rej delete mode 100644 source/cpp/ios/ai_features/AISystemInitializer.h.backup2 delete mode 100644 source/cpp/ios/ai_features/AISystemInitializer.h.bak delete mode 100644 source/cpp/ios/ai_features/local_models/GeneralAssistantModel.h.bak delete mode 100644 source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.backup3 delete mode 100644 source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak delete mode 100644 source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak2 delete mode 100644 source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak4 delete mode 100644 source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.backup delete mode 100644 source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.backup3 delete mode 100644 source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.bak2 delete mode 100644 source/cpp/memory/signature.hpp.bak delete mode 100644 source/cpp/native-lib.cpp.old delete mode 100644 source/cpp/objc_isolation.h.bak diff --git a/BUILD_FIX_README.md b/BUILD_FIX_README.md deleted file mode 100644 index c68bb543..00000000 --- a/BUILD_FIX_README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Build Failure Fixes - -This PR addresses the build failures that occurred after removing the `fix_paths.sh` script. Here's a summary of the changes: - -## 1. Fixed Include Paths - -The main issue was that many files were using incorrect relative paths to include `objc_isolation.h` after the path-fixing script was removed. We fixed this by: - -- Calculating the correct relative path for each file based on its directory depth -- Updating all include statements across the iOS subdirectories: - - Files in `source/cpp/ios/` now use `#include "../objc_isolation.h"` - - Files in `source/cpp/ios/*/` now use `#include "../../objc_isolation.h"` - - Files in `source/cpp/ios/*/*/` now use `#include "../../../objc_isolation.h"` - -## 2. Improved CMake Configuration - -To prevent similar issues in the future and improve build stability: - -- Added `${CMAKE_SOURCE_DIR}/source/cpp` to the include directories, making it easier to include files from this directory -- Added stronger compiler warnings and error flags (`-Wall -Wextra -Werror`) to catch potential issues earlier -- Added iOS-specific compiler definitions for better compatibility - -## 3. Added Central Include Guard - -Created a new `include_guard.h` header that can be used in future development as a central way to include platform-specific headers without worrying about relative paths. - -## Lessons Learned - -When removing utility scripts like `fix_paths.sh`, it's important to first understand what they were fixing and implement a proper solution before removal. In this case, the script was critical for ensuring the correct include paths across different directory levels. diff --git a/README.md b/README.md deleted file mode 100644 index 845fd4be..00000000 --- a/README.md +++ /dev/null @@ -1,190 +0,0 @@ -# Roblox Executor for iOS - -A comprehensive script execution engine for Roblox on iOS devices, featuring advanced bypass techniques, memory manipulation capabilities, and AI-powered script assistance. - -## 🚀 Features - -- **Powerful Script Execution**: Execute custom Lua scripts in Roblox with high performance -- **Cross-Environment Support**: Works on both jailbroken and non-jailbroken devices -- **Advanced Byfron Bypass**: Sophisticated techniques to bypass Roblox's anti-cheat system -- **Memory Manipulation**: Read and write memory with protection management -- **Method Hooking**: Hook into game functions for extended capabilities -- **Script Management**: Organize, save, and load scripts with categories and favorites -- **AI-Powered Features**: Script generation, debugging assistance, and vulnerability detection -- **Intuitive UI**: Floating button interface with script management and editing -- **Security Hardening**: Anti-debugging and anti-tampering protection -- **Performance Monitoring**: Track execution times and optimize performance - -## 📋 Requirements - -- iOS 15.0+ -- Xcode 13+ (for building) -- CMake 3.16+ (for building) -- Optional: Dobby library for enhanced hooking capabilities - -## 🔧 Installation - -### Building from Source - -1. Clone the repository: - ``` - git clone https://github.com/yourusername/roblox-executor.git - cd roblox-executor - ``` - -2. Configure the build: - ``` - mkdir build - cd build - cmake .. -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=arm64 - ``` - -3. Build the project: - ``` - cmake --build . --config Release - ``` - -4. The compiled library (`libmylibrary.dylib`) will be available in the `build/lib` directory. - -### Installation on Device - -#### Jailbroken Device -1. Copy `libmylibrary.dylib` to your device -2. Inject the library into Roblox using a tool like libhooker, Substitute, or similar injection methods - -#### Non-Jailbroken Device -For non-jailbroken devices, additional steps are required: -1. Sign the library with a developer certificate -2. Use a sideloading method compatible with your iOS version -3. Follow the specific integration instructions for your deployment method - -## 💻 Usage - -### Basic Script Execution - -```cpp -// Initialize the execution engine -auto engine = std::make_shared(); -engine->Initialize(); - -// Execute a script -std::string script = "print('Hello from Roblox Executor!')"; -auto result = engine->Execute(script); - -if (result.m_success) { - std::cout << "Script executed successfully" << std::endl; -} else { - std::cout << "Execution failed: " << result.m_error << std::endl; -} -``` - -### Script Management - -```cpp -// Initialize script manager -auto scriptManager = std::make_shared(); -scriptManager->Initialize(); - -// Add a script -iOS::ScriptManager::Script newScript( - "MyScript", // Name - "print('Hello, Roblox!')", // Content - "Simple hello world script", // Description - "YourUsername", // Author - iOS::ScriptManager::Category::Utilities // Category -); -scriptManager->AddScript(newScript); - -// Execute the script -scriptManager->ExecuteScript("MyScript"); -``` - -### UI Integration - -```objective-c -// Initialize UI controller -UIController *controller = [[UIController alloc] init]; -[controller show]; - -// Handle button press events -controller.scriptButtonPressHandler = ^{ - // Show script selection UI - [controller showScriptSelector]; -}; -``` - -### AI Features - -```cpp -// Initialize AI integration -auto ai = std::make_shared(); -ai->Initialize(); - -// Generate a script -ai->ProcessQuery("Create a script that makes the player jump higher", - [](const std::string& response) { - std::cout << "Generated script: " << response << std::endl; - }); -``` - -## 🔒 Security Considerations - -This project includes advanced security features: - -- Anti-debugging detection -- Code integrity verification -- Protection against function hooking -- Tampering detection and response mechanisms - -These security measures help protect the library against reverse engineering and detection. - -## 🧩 Architecture - -The project is organized into several key components: - -- **VM**: Lua virtual machine implementation -- **ExecutionEngine**: Core script execution system -- **ScriptManager**: Script storage and management -- **Hooks**: Function hooking mechanisms -- **Memory**: Memory manipulation utilities -- **UI**: User interface components -- **AI Features**: Artificial intelligence capabilities -- **Security**: Anti-tamper and anti-detection mechanisms - -## ⚙️ Configuration Options - -The following build options are available: - -- `USE_DOBBY`: Enable Dobby for function hooking (ON by default) -- `USE_LUAU`: Use Luau (Roblox's Lua) instead of standard Lua (ON by default) -- `ENABLE_AI_FEATURES`: Enable AI-powered features (ON by default) -- `ENABLE_ADVANCED_BYPASS`: Enable advanced bypass techniques (ON by default) -- `BUILD_TESTING`: Build test executables (OFF by default) -- `BUILD_DOCS`: Build documentation (OFF by default) - -Set these options when configuring with CMake: -``` -cmake .. -DCMAKE_SYSTEM_NAME=iOS -DUSE_DOBBY=ON -DENABLE_AI_FEATURES=ON -``` - -## 📝 License - -This project is licensed under [Your License] - see the LICENSE file for details. - -## ⚠️ Disclaimer - -This software is provided for educational purposes only. Using this software may violate Roblox's Terms of Service. The authors are not responsible for any consequences resulting from the use of this software. - -## 🤝 Contributing - -Contributions are welcome! Please feel free to submit a Pull Request. - -1. Fork the repository -2. Create your feature branch (`git checkout -b feature/amazing-feature`) -3. Commit your changes (`git commit -m 'Add some amazing feature'`) -4. Push to the branch (`git push origin feature/amazing-feature`) -5. Open a Pull Request - -## 📞 Contact - -Project Link: [https://github.com/yourusername/roblox-executor](https://github.com/yourusername/roblox-executor) diff --git a/ci_fixes.patch b/ci_fixes.patch deleted file mode 100644 index 2daa00a7..00000000 --- a/ci_fixes.patch +++ /dev/null @@ -1,35 +0,0 @@ -diff --git a/source/cpp/memory/signature.hpp b/source/cpp/memory/signature.hpp -index 7e6dea8..7d2d8e7 100644 ---- a/source/cpp/memory/signature.hpp -+++ b/source/cpp/memory/signature.hpp -@@ -1,5 +1,6 @@ - #pragma once - -+#include - #include - #include - -@@ -8,6 +9,13 @@ - - namespace Memory { - -+ // Forward declaration or dummy implementation for CI builds -+#ifdef CI_BUILD -+ inline uintptr_t getLibBase(const char* name) { -+ (void)name; -+ return 0; -+ } -+#endif - // Signature scanning utility functions - namespace Signature { - -@@ -61,6 +69,9 @@ namespace Memory { - - // Get Roblox function address by pattern - static uintptr_t GetAddressByPattern(const char* pattern) { -+ #ifdef CI_BUILD -+ return 0; // Skip in CI -+ #endif - // Get Roblox module info - uintptr_t base = getLibBase("libroblox.so"); - if (!base) return 0; diff --git a/docs/LUAU_INSTALLATION.md b/docs/LUAU_INSTALLATION.md deleted file mode 100644 index f82500b8..00000000 --- a/docs/LUAU_INSTALLATION.md +++ /dev/null @@ -1,103 +0,0 @@ -# Luau Installation Guide - -This project uses Luau (Roblox's Lua implementation) libraries for script execution. - -## Required Files - -You need to have the following Luau files installed: - -1. **Header Files**: - - `lua.h` - - `luaconf.h` - - `lualib.h` - - `lauxlib.h` - -2. **Library Files**: - - `libLuau.VM.a` or `Luau.VM.a` (required) - - `libLuau.Compiler.a` or `Luau.Compiler.a` (optional) - -## Default Location - -By default, the build system looks for Luau files in these locations: - -``` -external/luau/ -├── VM/ -│ └── include/ -│ ├── lua.h -│ ├── luaconf.h -│ ├── lualib.h -│ └── lauxlib.h -└── build/ - ├── libLuau.VM.a (or Luau.VM.a) - └── libLuau.Compiler.a (or Luau.Compiler.a) -``` - -## Installing Luau - -If you don't already have Luau installed, you can build it from source: - -```bash -# Clone the repository -git clone https://github.com/Roblox/luau.git -cd luau - -# Create build directory -mkdir build && cd build - -# Configure and build -cmake .. -DCMAKE_BUILD_TYPE=Release -DLUAU_BUILD_TESTS=OFF -cmake --build . --target Luau.VM Luau.Compiler -``` - -Then place the files in the expected locations: - -```bash -# Create directories -mkdir -p external/luau/VM/include -mkdir -p external/luau/build - -# Copy headers -cp luau/VM/include/*.h external/luau/VM/include/ - -# Copy libraries -cp luau/build/libLuau.VM.a external/luau/build/ -cp luau/build/libLuau.Compiler.a external/luau/build/ -``` - -## Custom Locations - -If your Luau files are in a different location, you can specify the paths when running CMake: - -```bash -cmake \ - -DLUAU_ROOT=/path/to/luau \ - -DLUAU_INCLUDE_DIR=/path/to/luau/VM/include \ - -DLUAU_VM_LIBRARY=/path/to/luau/build/libLuau.VM.a \ - .. -``` - -## Troubleshooting - -### Missing Headers Error - -If you get an error like: -``` -Luau headers not found at /path/to/include -``` - -Make sure: -1. The header files exist in the specified directory -2. Set the correct path with `-DLUAU_INCLUDE_DIR=/correct/path/to/headers` - -### Missing Library Error - -If you get an error like: -``` -Luau VM library not found at /path/to/library -``` - -Make sure: -1. The library file exists in the specified directory -2. Check if the library has a different name (e.g., `Luau.VM.a` instead of `libLuau.VM.a`) -3. Set the correct path with `-DLUAU_VM_LIBRARY=/correct/path/to/library` diff --git a/fix_include_paths.sh b/fix_include_paths.sh deleted file mode 100755 index 85ce1cbc..00000000 --- a/fix_include_paths.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -# This script fixes all include paths for iOS files - -# Process each .mm file to correct the include paths -find source/cpp/ios -name "*.mm" | while read file; do - # Fix the include paths - echo "Fixing include paths in $file" - - # Replace ../ios_compat.h with the correct path - # Calculate the correct path based on directory depth - dir=$(dirname "$file") - depth=$(echo "$dir" | tr '/' '\n' | wc -l) - - # source/cpp/ios/ is depth 3, so we need 1 "../" (to get to source/cpp/) - # source/cpp/ios/subfolder/ is depth 4, so we need 2 "../" - prefix="" - for ((i=0; i<$depth-2; i++)); do - prefix="../$prefix" - done - - # Replace the include path - sed -i "s|#include \"../ios_compat.h\"|#include \"${prefix}ios_compat.h\"|g" "$file" - sed -i "s|#include \"ios_compat.h\"|#include \"${prefix}ios_compat.h\"|g" "$file" -done - -# Fix the include paths for .h files too -find source/cpp/ios -name "*.h" | while read file; do - echo "Fixing include paths in $file" - - # Calculate the correct path based on directory depth - dir=$(dirname "$file") - depth=$(echo "$dir" | tr '/' '\n' | wc -l) - - # Calculate the prefix - prefix="" - for ((i=0; i<$depth-2; i++)); do - prefix="../$prefix" - done - - # Replace the include path - sed -i "s|#include \"../ios_compat.h\"|#include \"${prefix}ios_compat.h\"|g" "$file" - sed -i "s|#include \"ios_compat.h\"|#include \"${prefix}ios_compat.h\"|g" "$file" -done diff --git a/fix_includes.sh b/fix_includes.sh deleted file mode 100755 index 7c2147a3..00000000 --- a/fix_includes.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# Script to fix all paths that include objc_isolation.h based on their depth in the directory structure - -# Process files in source/cpp/ios directly - they should include "../objc_isolation.h" -find source/cpp/ios -maxdepth 1 -type f \( -name "*.h" -o -name "*.mm" -o -name "*.cpp" -o -name "*.m" \) -print0 | xargs -0 grep -l "objc_isolation.h" | while read file; do - echo "Fixing $file => #include \"../objc_isolation.h\"" - # If the file uses "objc_isolation.h", change to "../objc_isolation.h" - sed -i 's|#include "objc_isolation.h"|#include "../objc_isolation.h"|g' "$file" - # If it already had "../objc_isolation.h", no change needed -done - -# Process files in first-level subdirectories of source/cpp/ios - they should include "../../objc_isolation.h" -find source/cpp/ios/* -maxdepth 1 -type f \( -name "*.h" -o -name "*.mm" -o -name "*.cpp" -o -name "*.m" \) -print0 | xargs -0 grep -l "../objc_isolation.h" | while read file; do - echo "Fixing $file => #include \"../../objc_isolation.h\"" - # Fix the path to use "../../objc_isolation.h" - sed -i 's|#include "../objc_isolation.h"|#include "../../objc_isolation.h"|g' "$file" -done - -# Process files in second-level subdirectories of source/cpp/ios - they should include "../../../objc_isolation.h" -find source/cpp/ios/*/*/* -type f \( -name "*.h" -o -name "*.mm" -o -name "*.cpp" -o -name "*.m" \) -print0 | xargs -0 grep -l "../../objc_isolation.h" | while read file; do - echo "Fixing $file => #include \"../../../objc_isolation.h\"" - # Fix the path to use "../../../objc_isolation.h" - sed -i 's|#include "../../objc_isolation.h"|#include "../../../objc_isolation.h"|g' "$file" -done diff --git a/fix_includes_correctly.sh b/fix_includes_correctly.sh deleted file mode 100755 index b2199dac..00000000 --- a/fix_includes_correctly.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# Script to correctly fix all paths that include objc_isolation.h based on their depth in the directory structure - -# Find all files that include objc_isolation.h -find source/cpp/ios -type f \( -name "*.h" -o -name "*.mm" -o -name "*.cpp" -o -name "*.m" \) -print0 | xargs -0 grep -l "objc_isolation.h" | while read file; do - # Get the directory depth relative to source/cpp - dir=$(dirname "$file") - depth=$(echo "$dir" | tr '/' '\n' | wc -l) - - # Calculate the correct path prefix - # source/cpp is depth 2, so files directly in source/cpp need no "../" - # source/cpp/ios is depth 3, so we need 1 "../" from there - # source/cpp/ios/something is depth 4, so we need 2 "../" from there - # etc. - - rel_path="" - for ((i=0; i<$depth-2; i++)); do - rel_path="../$rel_path" - done - - rel_path="${rel_path}objc_isolation.h" - - echo "Fixing $file => #include \"$rel_path\"" - - # First, normalize all objc_isolation.h includes to a common pattern - sed -i 's|#include\s*"[./]*objc_isolation.h"|#include "TEMP_PLACEHOLDER"|g' "$file" - - # Then replace with the correct path - sed -i "s|#include \"TEMP_PLACEHOLDER\"|#include \"$rel_path\"|g" "$file" -done diff --git a/fix_objcpp_extensions.sh b/fix_objcpp_extensions.sh deleted file mode 100755 index 59118b75..00000000 --- a/fix_objcpp_extensions.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -# This script finds .cpp files that contain Objective-C code and renames them to .mm - -# Find .cpp files in ios directory that might contain Objective-C code -find source/cpp/ios -name "*.cpp" | while read file; do - # Check if file contains Objective-C syntax ([] method calls or NS* types) - if grep -q "\\[.*\\]" "$file" || grep -q "NS[A-Z]" "$file"; then - echo "Renaming $file to ${file%.cpp}.mm" - git mv "$file" "${file%.cpp}.mm" - fi -done diff --git a/source/cpp/OBJC_CPP_README.md b/source/cpp/OBJC_CPP_README.md deleted file mode 100644 index 86dc6236..00000000 --- a/source/cpp/OBJC_CPP_README.md +++ /dev/null @@ -1,34 +0,0 @@ -# Objective-C++ Interoperability - -This document describes how C++ and Objective-C interoperability is handled in this project. - -## Key Files - -1. **utility.h** - Pure C++ macros and utilities that can be used anywhere without Objective-C dependencies -2. **objc_isolation.h** - Interface layer between C++ and Objective-C that properly guards Objective-C syntax -3. **include_guard.h** - Central include file that brings in the right headers based on the compilation context - -## How It Works - -### For C++ Files -- Include `utility.h` for basic macros (UNUSED_PARAM, etc.) -- Include `include_guard.h` if you need platform-specific features -- Use the SKIP_IOS_INTEGRATION define to prevent Objective-C includes in C++ context - -### For Objective-C++ (.mm) Files -- Can directly include Objective-C headers and use Objective-C syntax -- Include `objc_isolation.h` to interact with C++ code -- Compile with `-x objective-c++` flag - -## CMake Configuration - -- C++ files that need to interact with Objective-C should include `utility.h` or `include_guard.h` rather than including Objective-C headers directly -- Objective-C classes are forward-declared for C++ files as opaque types -- Special compile flags are set for specific files based on their content - -## Tips for Maintaining Compatibility - -1. Don't include UIKit or Foundation directly in C++ files -2. Use the UNUSED_PARAM macro for unused parameters -3. Always properly guard platform-specific code with `#ifdef __APPLE__` -4. Add the SKIP_IOS_INTEGRATION define when compiling C++ files that shouldn't try to include Objective-C diff --git a/source/cpp/ios/PatternScanner.h.bak b/source/cpp/ios/PatternScanner.h.bak deleted file mode 100644 index 677592af..00000000 --- a/source/cpp/ios/PatternScanner.h.bak +++ /dev/null @@ -1,47 +0,0 @@ -// Pattern scanner for memory searching -#pragma once - -#include "MemoryAccess.h" -#include -#include -#include - -namespace iOS { - class PatternScanner { - public: - // Represents a scan result - struct ScanResult { - uintptr_t address; - size_t size; - - ScanResult() : address(0), size(0) {} - ScanResult(uintptr_t addr, size_t sz = 0) : address(addr), size(sz) {} - - // For compatibility with code that treats this as a uintptr_t - operator uintptr_t() const { return address; } - }; - - // Scan for a pattern in memory - static ScanResult ScanForPattern(const char* pattern, const char* mask, void* startAddress = nullptr, void* endAddress = nullptr); - - // Scan for a signature (pattern in hex format) - static ScanResult ScanForSignature(const std::string& signature, void* startAddress = nullptr, void* endAddress = nullptr); - - // Scan for a string - static ScanResult ScanForString(const std::string& str, void* startAddress = nullptr, void* endAddress = nullptr); - - // Find all occurrences of a pattern - static std::vector FindAllPatterns(const char* pattern, const char* mask, void* startAddress = nullptr, void* endAddress = nullptr); - - // Memory utility methods - static uintptr_t GetBaseAddress(); - static uintptr_t GetModuleBaseAddress(const std::string& moduleName); - static size_t GetModuleSize(const std::string& moduleName); - - // Simplified implementation for this example - static ScanResult FindPattern(const char* module, const char* pattern, const char* mask) { - // For now, return a stub result - return ScanResult(0); // Properly using constructor instead of raw cast - } - }; -} diff --git a/source/cpp/ios/PatternScanner.h.bak2 b/source/cpp/ios/PatternScanner.h.bak2 deleted file mode 100644 index aa827710..00000000 --- a/source/cpp/ios/PatternScanner.h.bak2 +++ /dev/null @@ -1,89 +0,0 @@ -#include "../memory/ci_compat.h" - -#pragma once - -#include -#include -#include -#include -#include - -// We don't need to forward declare UIImage - it's already defined in UIKit -// and forward-declaring it in C++ context causes conflicts - -namespace iOS { - // Pattern scanning utilities for iOS - class PatternScanner { - public: - // Result structure for pattern scanning - struct ScanResult { - uintptr_t address; - size_t size; - - ScanResult() : address(0), size(0) {} - ScanResult(uintptr_t addr, size_t s) : address(addr), size(s) {} - - operator bool() const { return address != 0; } - }; - - // Find a byte pattern in memory - static ScanResult FindPattern(const char* module, const char* pattern, const char* mask) { - #ifdef CI_BUILD - return ScanResult(0, 0); // Return empty result in CI - #else - // Stub implementation for now - would need real pattern scanning on iOS - return ScanResult(0, 0); - #endif - } - - // Find pattern using string representation (like "48 8B 05 ?? ?? ?? ??") - static ScanResult FindPattern(const char* module, const char* patternString) { - #ifdef CI_BUILD - return ScanResult(0, 0); // Return empty result in CI - #else - // Parse pattern string and convert to byte pattern + mask - std::vector pattern; - std::vector mask; - - // Parse the pattern string - for (const char* p = patternString; *p; ++p) { - if (*p == ' ') continue; - - if (*p == '?') { - pattern.push_back(0); - mask.push_back(false); - - if (*(p + 1) == '?') ++p; // Skip second ? if present - } else { - // Convert hex string to byte - char hex[3] = {*p, *(p + 1), 0}; - pattern.push_back(static_cast(strtol(hex, nullptr, 16))); - mask.push_back(true); - ++p; // Skip second character - } - } - - // Create pattern and mask strings - std::string patternStr(pattern.begin(), pattern.end()); - std::string maskStr; - for (bool b : mask) { - maskStr.push_back(b ? 'x' : '?'); - } - - return FindPattern(module, patternStr.c_str(), maskStr.c_str()); - #endif - } - - // Get base address of the main executable - static uintptr_t GetBaseAddress(); - - // Get base address of a specific module - static uintptr_t GetModuleBaseAddress(const std::string& moduleName); - - // Get module info (base address and size) - static std::pair GetModuleInfo(const std::string& moduleName); - - // Find a symbol in a module - static void* FindSymbol(const std::string& moduleName, const std::string& symbolName); - }; -} diff --git a/source/cpp/ios/PatternScanner.h.bak3 b/source/cpp/ios/PatternScanner.h.bak3 deleted file mode 100644 index 1f7884c5..00000000 --- a/source/cpp/ios/PatternScanner.h.bak3 +++ /dev/null @@ -1,95 +0,0 @@ -#include "../memory/ci_compat.h" - -#pragma once - -#include -#include -#include -#include -#include - -// We don't need to forward declare UIImage - it's already defined in UIKit -// and forward-declaring it in C++ context causes conflicts - -namespace iOS { - // Pattern scanning utilities for iOS - class PatternScanner { - public: - // Result structure for pattern scanning - struct ScanResult { - uintptr_t address; - size_t size; - - ScanResult() : address(0), size(0) {} - ScanResult(uintptr_t addr, size_t s) : address(addr), size(s) {} - - operator bool() const { return address != 0; } - }; - - // Find a byte pattern in memory - static ScanResult FindPattern(const char* module, const char* pattern, const char* mask) { - #ifdef CI_BUILD - return ScanResult(0, 0); // Return empty result in CI - #else - // Stub implementation for now - would need real pattern scanning on iOS - return ScanResult(0, 0); - #endif - } - - // Find pattern using string representation (like "48 8B 05 ?? ?? ?? ??") - static ScanResult FindPattern(const char* module, const char* patternString) { - #ifdef CI_BUILD - return ScanResult(0, 0); // Return empty result in CI - #else - // Parse pattern string and convert to byte pattern + mask - std::vector pattern; - std::vector mask; - - // Parse the pattern string - for (const char* p = patternString; *p; ++p) { - if (*p == ' ') continue; - - if (*p == '?') { - pattern.push_back(0); - mask.push_back(false); - - if (*(p + 1) == '?') ++p; // Skip second ? if present - } else { - // Convert hex string to byte - char hex[3] = {*p, *(p + 1), 0}; - pattern.push_back(static_cast(strtol(hex, nullptr, 16))); - mask.push_back(true); - ++p; // Skip second character - } - } - - // Create pattern and mask strings - std::string patternStr(pattern.begin(), pattern.end()); - std::string maskStr; - for (bool b : mask) { - maskStr.push_back(b ? 'x' : '?'); - } - - return FindPattern(module, patternStr.c_str(), maskStr.c_str()); - #endif - } - - // Get base address of the main executable - static uintptr_t GetBaseAddress(); - - // Get base address of a specific module - static uintptr_t GetModuleBaseAddress(const std::string& moduleName); - - // Get module info (base address and size) - static std::pair GetModuleInfo(const std::string& moduleName); - - // Find a symbol in a module - static void* FindSymbol(const std::string& moduleName, const std::string& symbolName); - - // Additional methods that are implemented in PatternScanner.mm but were missing from the header - static ScanResult ScanForSignature(const std::string& signature, void* startAddress, void* endAddress); - static ScanResult ScanForString(const std::string& str, void* startAddress, void* endAddress); - static std::vector FindAllPatterns(const char* pattern, const char* mask, void* startAddress, void* endAddress); - static size_t GetModuleSize(const std::string& moduleName); - }; -} diff --git a/source/cpp/ios/PatternScanner.h.old b/source/cpp/ios/PatternScanner.h.old deleted file mode 100644 index c7cbc755..00000000 --- a/source/cpp/ios/PatternScanner.h.old +++ /dev/null @@ -1,89 +0,0 @@ -#include "../memory/ci_compat.h" - -#pragma once - -#include -#include -#include -#include -#include - -// Forward declarations -class UIImage; - -namespace iOS { - // Pattern scanning utilities for iOS - class PatternScanner { - public: - // Result structure for pattern scanning - struct ScanResult { - uintptr_t address; - size_t size; - - ScanResult() : address(0), size(0) {} - ScanResult(uintptr_t addr, size_t s) : address(addr), size(s) {} - - operator bool() const { return address != 0; } - }; - - // Find a byte pattern in memory - static ScanResult FindPattern(const char* module, const char* pattern, const char* mask) { - #ifdef CI_BUILD - return ScanResult(0, 0); // Return empty result in CI - #else - // Stub implementation for now - would need real pattern scanning on iOS - return ScanResult(0, 0); - #endif - } - - // Find pattern using string representation (like "48 8B 05 ?? ?? ?? ??") - static ScanResult FindPattern(const char* module, const char* patternString) { - #ifdef CI_BUILD - return ScanResult(0, 0); // Return empty result in CI - #else - // Parse pattern string and convert to byte pattern + mask - std::vector pattern; - std::vector mask; - - // Parse the pattern string - for (const char* p = patternString; *p; ++p) { - if (*p == ' ') continue; - - if (*p == '?') { - pattern.push_back(0); - mask.push_back(false); - - if (*(p + 1) == '?') ++p; // Skip second ? if present - } else { - // Convert hex string to byte - char hex[3] = {*p, *(p + 1), 0}; - pattern.push_back(static_cast(strtol(hex, nullptr, 16))); - mask.push_back(true); - ++p; // Skip second character - } - } - - // Create pattern and mask strings - std::string patternStr(pattern.begin(), pattern.end()); - std::string maskStr; - for (bool b : mask) { - maskStr.push_back(b ? 'x' : '?'); - } - - return FindPattern(module, patternStr.c_str(), maskStr.c_str()); - #endif - } - - // Get base address of the main executable - static uintptr_t GetBaseAddress(); - - // Get base address of a specific module - static uintptr_t GetModuleBaseAddress(const std::string& moduleName); - - // Get module info (base address and size) - static std::pair GetModuleInfo(const std::string& moduleName); - - // Find a symbol in a module - static void* FindSymbol(const std::string& moduleName, const std::string& symbolName); - }; -} diff --git a/source/cpp/ios/PatternScanner.mm.bak b/source/cpp/ios/PatternScanner.mm.bak deleted file mode 100644 index f3b6b770..00000000 --- a/source/cpp/ios/PatternScanner.mm.bak +++ /dev/null @@ -1,407 +0,0 @@ -// PatternScanner.mm - Production-grade implementation -#include "PatternScanner.h" -#include "MemoryAccess.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace iOS { - // Static cache variables for performance - static std::unordered_map moduleBaseCache; - static std::unordered_map moduleSizeCache; - static std::mutex cacheMutex; - - // Convert a hex signature string to a byte pattern and mask - static std::pair, std::string> ParseSignature(const std::string& signature) { - std::vector pattern; - std::string mask; - - std::istringstream stream(signature); - std::string byteStr; - - while (stream >> byteStr) { - if (byteStr == "?" || byteStr == "??") { - // Wildcard byte - pattern.push_back(0); - mask.push_back('?'); - } else { - // Convert hex string to byte - try { - uint8_t byte = static_cast(std::stoul(byteStr, nullptr, 16)); - pattern.push_back(byte); - mask.push_back('x'); - } catch (const std::exception& e) { - std::cerr << "PatternScanner: Invalid byte in signature: " << byteStr << std::endl; - // Handle invalid hex by treating as wildcard - pattern.push_back(0); - mask.push_back('?'); - } - } - } - - return {pattern, mask}; - } - - // Implements Boyer-Moore-Horspool pattern matching algorithm for efficient scanning - PatternScanner::ScanResult PatternScanner::ScanForPattern(const char* pattern, const char* mask, void* startAddress, void* endAddress) { - if (!pattern || !mask) { - std::cerr << "PatternScanner: Null pattern or mask provided" << std::endl; - return ScanResult(0); - } - - size_t patternLength = strlen(mask); - if (patternLength == 0) { - std::cerr << "PatternScanner: Empty pattern" << std::endl; - return ScanResult(0); - } - - // Get process memory bounds if not specified - if (!startAddress || !endAddress) { - task_t task = mach_task_self(); - vm_address_t address = 0; - vm_size_t size = 0; - uint32_t depth = 1; - - startAddress = reinterpret_cast(GetBaseAddress()); - if (!startAddress) { - std::cerr << "PatternScanner: Failed to get base address" << std::endl; - return ScanResult(0); - } - - // Use a fixed large size if we can't get actual module size - endAddress = reinterpret_cast(reinterpret_cast(startAddress) + 0x10000000); // 256 MB search space - } - - // Ensure addresses are valid - uintptr_t start = reinterpret_cast(startAddress); - uintptr_t end = reinterpret_cast(endAddress); - - if (start >= end) { - std::cerr << "PatternScanner: Invalid address range" << std::endl; - return ScanResult(0); - } - - // Create bad character table for Boyer-Moore-Horspool algorithm - size_t badCharTable[256]; - for (size_t i = 0; i < 256; i++) { - badCharTable[i] = patternLength; - } - - for (size_t i = 0; i < patternLength - 1; i++) { - if (mask[i] == 'x') { - badCharTable[static_cast(pattern[i])] = patternLength - i - 1; - } - } - - // Scan memory for pattern - size_t scanSize = end - start; - const size_t bufferSize = 4096; // Read memory in chunks to improve performance - uint8_t buffer[bufferSize]; - - for (size_t offset = 0; offset < scanSize; ) { - // Calculate how much to read - size_t bytesToRead = std::min(bufferSize, scanSize - offset); - if (bytesToRead < patternLength) { - break; // Not enough memory left to match pattern - } - - // Read memory chunk - if (!MemoryAccess::ReadMemory(reinterpret_cast(start + offset), buffer, bytesToRead)) { - // Skip unreadable memory regions - offset += bytesToRead; - continue; - } - - // Scan this memory chunk - size_t chunkPos = 0; - while (chunkPos <= bytesToRead - patternLength) { - size_t j = patternLength - 1; - - // Check pattern backward - while (j != static_cast(-1) && (mask[j] == '?' || buffer[chunkPos + j] == pattern[j])) { - j--; - } - - if (j == static_cast(-1)) { - // Pattern found - return ScanResult(start + offset + chunkPos, patternLength); - } - - // Skip using bad character rule - size_t skip = badCharTable[buffer[chunkPos + patternLength - 1]]; - if (skip == 0) skip = 1; // Ensure progress - - chunkPos += skip; - } - - // Move to next chunk, overlapping a bit to handle patterns that cross chunk boundaries - offset += (bytesToRead - patternLength + 1); - } - - // Pattern not found - return ScanResult(0); - } - - // Scan for a signature in hex format (e.g., "48 8B 05 ?? ?? ?? ??") - PatternScanner::ScanResult PatternScanner::ScanForSignature(const std::string& signature, void* startAddress, void* endAddress) { - auto [pattern, mask] = ParseSignature(signature); - - if (pattern.empty()) { - std::cerr << "PatternScanner: Failed to parse signature: " << signature << std::endl; - return ScanResult(0); - } - - return ScanForPattern(reinterpret_cast(pattern.data()), mask.c_str(), startAddress, endAddress); - } - - // Scan for a string in memory - PatternScanner::ScanResult PatternScanner::ScanForString(const std::string& str, void* startAddress, void* endAddress) { - if (str.empty()) { - std::cerr << "PatternScanner: Empty string to scan for" << std::endl; - return ScanResult(0); - } - - // Create pattern and mask from string - std::vector pattern(str.begin(), str.end()); - std::string mask(str.length(), 'x'); - - return ScanForPattern(pattern.data(), mask.c_str(), startAddress, endAddress); - } - - // Find all occurrences of a pattern - std::vector PatternScanner::FindAllPatterns(const char* pattern, const char* mask, void* startAddress, void* endAddress) { - std::vector results; - size_t patternLength = strlen(mask); - - if (!pattern || !mask || patternLength == 0) { - std::cerr << "PatternScanner: Invalid pattern for FindAllPatterns" << std::endl; - return results; - } - - // Get initial result - ScanResult result = ScanForPattern(pattern, mask, startAddress, endAddress); - if (result.address == 0) { - return results; // No matches - } - - results.push_back(result); - - // Find additional matches - uintptr_t lastAddress = result.address + patternLength; - while (true) { - // Get next match - result = ScanForPattern(pattern, mask, - reinterpret_cast(lastAddress), - endAddress); - - if (result.address == 0) { - break; // No more matches - } - - results.push_back(result); - lastAddress = result.address + patternLength; - } - - return results; - } - - // Get base address of the current process - uintptr_t PatternScanner::GetBaseAddress() { - #ifdef CI_BUILD - return 0; - #endif - return GetModuleBaseAddress(""); // Empty string = main executable - } - - // Get base address of a module - uintptr_t PatternScanner::GetModuleBaseAddress(const std::string& moduleName) { - // Lock cache - std::lock_guard lock(cacheMutex); - - // Check cache first - std::string lookupName = moduleName.empty() ? "_main" : moduleName; - auto it = moduleBaseCache.find(lookupName); - if (it != moduleBaseCache.end()) { - return it->second; - } - - uintptr_t baseAddress = 0; - - if (moduleName.empty()) { - // Get main executable base address - for (uint32_t i = 0; i < _dyld_image_count(); i++) { - const char* imageName = _dyld_get_image_name(i); - const mach_header* header = _dyld_get_image_header(i); - - if (imageName && strstr(imageName, "/Roblox") != nullptr) { - baseAddress = reinterpret_cast(header); - break; - } - } - - // If we couldn't find Roblox, fall back to the main executable - if (baseAddress == 0) { - baseAddress = reinterpret_cast(_dyld_get_image_header(0)); - } - } else { - // Find a specific module - for (uint32_t i = 0; i < _dyld_image_count(); i++) { - const char* imageName = _dyld_get_image_name(i); - if (imageName && (strstr(imageName, moduleName.c_str()) != nullptr)) { - baseAddress = reinterpret_cast(_dyld_get_image_header(i)); - break; - } - } - - // Try using dlopen as a backup - if (baseAddress == 0) { - void* handle = dlopen(moduleName.c_str(), RTLD_NOLOAD); - if (!handle) { - // Try with various extensions - std::vector attempts = { - moduleName + ".dylib", - moduleName + ".framework/" + moduleName, - "/usr/lib/" + moduleName, - "/System/Library/Frameworks/" + moduleName + ".framework/" + moduleName - }; - - for (const auto& attempt : attempts) { - handle = dlopen(attempt.c_str(), RTLD_NOLOAD); - if (handle) { - break; - } - } - } - - if (handle) { - Dl_info info; - if (dladdr(handle, &info) != 0) { - baseAddress = reinterpret_cast(info.dli_fbase); - } - dlclose(handle); - } - } - } - - // Cache the result - if (baseAddress != 0) { - moduleBaseCache[lookupName] = baseAddress; - } else { - std::cerr << "PatternScanner: Failed to find module: " << - (moduleName.empty() ? "main executable" : moduleName) << std::endl; - } - - return baseAddress; - } - - // Get module size - size_t PatternScanner::GetModuleSize(const std::string& moduleName) { - // Lock cache - std::lock_guard lock(cacheMutex); - - // Check cache first - std::string lookupName = moduleName.empty() ? "_main" : moduleName; - auto it = moduleSizeCache.find(lookupName); - if (it != moduleSizeCache.end()) { - return it->second; - } - - // Get the module base address first - uintptr_t baseAddress = GetModuleBaseAddress(moduleName); - if (baseAddress == 0) { - return 0; - } - - // Use memory mapping to determine module size - task_t task = mach_task_self(); - vm_address_t address = static_cast(baseAddress); - vm_size_t size = 0; - - // Find the memory region containing this address - vm_region_basic_info_data_64_t info; - mach_msg_type_number_t infoCount = VM_REGION_BASIC_INFO_COUNT_64; - mach_port_t objectName = MACH_PORT_NULL; - - // First get the region containing the base address - kern_return_t kr = vm_region_64(task, - &address, - &size, - VM_REGION_BASIC_INFO_64, - (vm_region_info_t)&info, - &infoCount, - &objectName); - - if (kr != KERN_SUCCESS) { - // Fallback to a conservative estimate - size_t fallbackSize = 0x1000000; // 16 MB - moduleSizeCache[lookupName] = fallbackSize; - return fallbackSize; - } - - // Now we need to find all consecutive regions - uintptr_t moduleEnd = baseAddress; - vm_address_t currentAddress = address + size; - - // Scan for consecutive memory regions - bool foundEnd = false; - const size_t maxRegions = 100; // Safety limit - size_t regionCount = 0; - - while (!foundEnd && regionCount < maxRegions) { - vm_address_t regionAddress = currentAddress; - vm_size_t regionSize = 0; - - kr = vm_region_64(task, - ®ionAddress, - ®ionSize, - VM_REGION_BASIC_INFO_64, - (vm_region_info_t)&info, - &infoCount, - &objectName); - - if (kr != KERN_SUCCESS || regionAddress > currentAddress) { - // Gap in memory or end of regions - foundEnd = true; - } else { - // Check if this is still the same module - // For iOS, we can't always rely on shared segment names - // Instead we check if the memory is the expected protection - bool isExecutable = (info.protection & VM_PROT_EXECUTE) != 0; - bool isPartOfModule = isExecutable || - (info.protection & VM_PROT_READ) != 0; - - if (isPartOfModule && (regionAddress == currentAddress)) { - // Still part of the module - moduleEnd = regionAddress + regionSize; - currentAddress = moduleEnd; - } else { - // Different module/end of module - foundEnd = true; - } - } - - regionCount++; - } - - // Calculate final size - size_t moduleSize = moduleEnd - baseAddress; - - // Validate size is reasonable - if (moduleSize > 0x10000000) { // > 256 MB is suspicious - moduleSize = 0x1000000; // Fallback to 16 MB - } - - // Cache and return the size - moduleSizeCache[lookupName] = moduleSize; - return moduleSize; - } -} diff --git a/source/cpp/ios/PatternScanner.mm.bak2 b/source/cpp/ios/PatternScanner.mm.bak2 deleted file mode 100644 index 446090dc..00000000 --- a/source/cpp/ios/PatternScanner.mm.bak2 +++ /dev/null @@ -1,407 +0,0 @@ -// PatternScanner.mm - Production-grade implementation -#include "PatternScanner.h" -#include "MemoryAccess.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace iOS { - // Static cache variables for performance - static std::unordered_map moduleBaseCache; - static std::unordered_map moduleSizeCache; - static std::mutex cacheMutex; - - // Convert a hex signature string to a byte pattern and mask - static std::pair, std::string> ParseSignature(const std::string& signature) { - std::vector pattern; - std::string mask; - - std::istringstream stream(signature); - std::string byteStr; - - while (stream >> byteStr) { - if (byteStr == "?" || byteStr == "??") { - // Wildcard byte - pattern.push_back(0); - mask.push_back('?'); - } else { - // Convert hex string to byte - try { - uint8_t byte = static_cast(std::stoul(byteStr, nullptr, 16)); - pattern.push_back(byte); - mask.push_back('x'); - } catch (const std::exception& e) { - std::cerr << "PatternScanner: Invalid byte in signature: " << byteStr << std::endl; - // Handle invalid hex by treating as wildcard - pattern.push_back(0); - mask.push_back('?'); - } - } - } - - return {pattern, mask}; - } - - // Implements Boyer-Moore-Horspool pattern matching algorithm for efficient scanning - PatternScanner::ScanResult PatternScanner::ScanForPattern(const char* pattern, const char* mask, void* startAddress, void* endAddress) { - if (!pattern || !mask) { - std::cerr << "PatternScanner: Null pattern or mask provided" << std::endl; - return ScanResult(0, 0); - } - - size_t patternLength = strlen(mask); - if (patternLength == 0) { - std::cerr << "PatternScanner: Empty pattern" << std::endl; - return ScanResult(0, 0); - } - - // Get process memory bounds if not specified - if (!startAddress || !endAddress) { - task_t task = mach_task_self(); - vm_address_t address = 0; - vm_size_t size = 0; - uint32_t depth = 1; - - startAddress = reinterpret_cast(GetBaseAddress()); - if (!startAddress) { - std::cerr << "PatternScanner: Failed to get base address" << std::endl; - return ScanResult(0, 0); - } - - // Use a fixed large size if we can't get actual module size - endAddress = reinterpret_cast(reinterpret_cast(startAddress) + 0x10000000); // 256 MB search space - } - - // Ensure addresses are valid - uintptr_t start = reinterpret_cast(startAddress); - uintptr_t end = reinterpret_cast(endAddress); - - if (start >= end) { - std::cerr << "PatternScanner: Invalid address range" << std::endl; - return ScanResult(0, 0); - } - - // Create bad character table for Boyer-Moore-Horspool algorithm - size_t badCharTable[256]; - for (size_t i = 0; i < 256; i++) { - badCharTable[i] = patternLength; - } - - for (size_t i = 0; i < patternLength - 1; i++) { - if (mask[i] == 'x') { - badCharTable[static_cast(pattern[i])] = patternLength - i - 1; - } - } - - // Scan memory for pattern - size_t scanSize = end - start; - const size_t bufferSize = 4096; // Read memory in chunks to improve performance - uint8_t buffer[bufferSize]; - - for (size_t offset = 0; offset < scanSize; ) { - // Calculate how much to read - size_t bytesToRead = std::min(bufferSize, scanSize - offset); - if (bytesToRead < patternLength) { - break; // Not enough memory left to match pattern - } - - // Read memory chunk - if (!MemoryAccess::ReadMemory(reinterpret_cast(start + offset), buffer, bytesToRead)) { - // Skip unreadable memory regions - offset += bytesToRead; - continue; - } - - // Scan this memory chunk - size_t chunkPos = 0; - while (chunkPos <= bytesToRead - patternLength) { - size_t j = patternLength - 1; - - // Check pattern backward - while (j != static_cast(-1) && (mask[j] == '?' || buffer[chunkPos + j] == pattern[j])) { - j--; - } - - if (j == static_cast(-1)) { - // Pattern found - return ScanResult(start + offset + chunkPos, patternLength); - } - - // Skip using bad character rule - size_t skip = badCharTable[buffer[chunkPos + patternLength - 1]]; - if (skip == 0) skip = 1; // Ensure progress - - chunkPos += skip; - } - - // Move to next chunk, overlapping a bit to handle patterns that cross chunk boundaries - offset += (bytesToRead - patternLength + 1); - } - - // Pattern not found - return ScanResult(0, 0); - } - - // Scan for a signature in hex format (e.g., "48 8B 05 ?? ?? ?? ??") - PatternScanner::ScanResult PatternScanner::ScanForSignature(const std::string& signature, void* startAddress, void* endAddress) { - auto [pattern, mask] = ParseSignature(signature); - - if (pattern.empty()) { - std::cerr << "PatternScanner: Failed to parse signature: " << signature << std::endl; - return ScanResult(0, 0); - } - - return ScanForPattern(reinterpret_cast(pattern.data()), mask.c_str(), startAddress, endAddress); - } - - // Scan for a string in memory - PatternScanner::ScanResult PatternScanner::ScanForString(const std::string& str, void* startAddress, void* endAddress) { - if (str.empty()) { - std::cerr << "PatternScanner: Empty string to scan for" << std::endl; - return ScanResult(0, 0); - } - - // Create pattern and mask from string - std::vector pattern(str.begin(), str.end()); - std::string mask(str.length(), 'x'); - - return ScanForPattern(pattern.data(), mask.c_str(), startAddress, endAddress); - } - - // Find all occurrences of a pattern - std::vector PatternScanner::FindAllPatterns(const char* pattern, const char* mask, void* startAddress, void* endAddress) { - std::vector results; - size_t patternLength = strlen(mask); - - if (!pattern || !mask || patternLength == 0) { - std::cerr << "PatternScanner: Invalid pattern for FindAllPatterns" << std::endl; - return results; - } - - // Get initial result - ScanResult result = ScanForPattern(pattern, mask, startAddress, endAddress); - if (result.address == 0) { - return results; // No matches - } - - results.push_back(result); - - // Find additional matches - uintptr_t lastAddress = result.address + patternLength; - while (true) { - // Get next match - result = ScanForPattern(pattern, mask, - reinterpret_cast(lastAddress), - endAddress); - - if (result.address == 0) { - break; // No more matches - } - - results.push_back(result); - lastAddress = result.address + patternLength; - } - - return results; - } - - // Get base address of the current process - uintptr_t PatternScanner::GetBaseAddress() { - #ifdef CI_BUILD - return 0; - #endif - return GetModuleBaseAddress(""); // Empty string = main executable - } - - // Get base address of a module - uintptr_t PatternScanner::GetModuleBaseAddress(const std::string& moduleName) { - // Lock cache - std::lock_guard lock(cacheMutex); - - // Check cache first - std::string lookupName = moduleName.empty() ? "_main" : moduleName; - auto it = moduleBaseCache.find(lookupName); - if (it != moduleBaseCache.end()) { - return it->second; - } - - uintptr_t baseAddress = 0; - - if (moduleName.empty()) { - // Get main executable base address - for (uint32_t i = 0; i < _dyld_image_count(); i++) { - const char* imageName = _dyld_get_image_name(i); - const mach_header* header = _dyld_get_image_header(i); - - if (imageName && strstr(imageName, "/Roblox") != nullptr) { - baseAddress = reinterpret_cast(header); - break; - } - } - - // If we couldn't find Roblox, fall back to the main executable - if (baseAddress == 0) { - baseAddress = reinterpret_cast(_dyld_get_image_header(0)); - } - } else { - // Find a specific module - for (uint32_t i = 0; i < _dyld_image_count(); i++) { - const char* imageName = _dyld_get_image_name(i); - if (imageName && (strstr(imageName, moduleName.c_str()) != nullptr)) { - baseAddress = reinterpret_cast(_dyld_get_image_header(i)); - break; - } - } - - // Try using dlopen as a backup - if (baseAddress == 0) { - void* handle = dlopen(moduleName.c_str(), RTLD_NOLOAD); - if (!handle) { - // Try with various extensions - std::vector attempts = { - moduleName + ".dylib", - moduleName + ".framework/" + moduleName, - "/usr/lib/" + moduleName, - "/System/Library/Frameworks/" + moduleName + ".framework/" + moduleName - }; - - for (const auto& attempt : attempts) { - handle = dlopen(attempt.c_str(), RTLD_NOLOAD); - if (handle) { - break; - } - } - } - - if (handle) { - Dl_info info; - if (dladdr(handle, &info) != 0) { - baseAddress = reinterpret_cast(info.dli_fbase); - } - dlclose(handle); - } - } - } - - // Cache the result - if (baseAddress != 0) { - moduleBaseCache[lookupName] = baseAddress; - } else { - std::cerr << "PatternScanner: Failed to find module: " << - (moduleName.empty() ? "main executable" : moduleName) << std::endl; - } - - return baseAddress; - } - - // Get module size - size_t PatternScanner::GetModuleSize(const std::string& moduleName) { - // Lock cache - std::lock_guard lock(cacheMutex); - - // Check cache first - std::string lookupName = moduleName.empty() ? "_main" : moduleName; - auto it = moduleSizeCache.find(lookupName); - if (it != moduleSizeCache.end()) { - return it->second; - } - - // Get the module base address first - uintptr_t baseAddress = GetModuleBaseAddress(moduleName); - if (baseAddress == 0) { - return 0; - } - - // Use memory mapping to determine module size - task_t task = mach_task_self(); - vm_address_t address = static_cast(baseAddress); - vm_size_t size = 0; - - // Find the memory region containing this address - vm_region_basic_info_data_64_t info; - mach_msg_type_number_t infoCount = VM_REGION_BASIC_INFO_COUNT_64; - mach_port_t objectName = MACH_PORT_NULL; - - // First get the region containing the base address - kern_return_t kr = vm_region_64(task, - &address, - &size, - VM_REGION_BASIC_INFO_64, - (vm_region_info_t)&info, - &infoCount, - &objectName); - - if (kr != KERN_SUCCESS) { - // Fallback to a conservative estimate - size_t fallbackSize = 0x1000000; // 16 MB - moduleSizeCache[lookupName] = fallbackSize; - return fallbackSize; - } - - // Now we need to find all consecutive regions - uintptr_t moduleEnd = baseAddress; - vm_address_t currentAddress = address + size; - - // Scan for consecutive memory regions - bool foundEnd = false; - const size_t maxRegions = 100; // Safety limit - size_t regionCount = 0; - - while (!foundEnd && regionCount < maxRegions) { - vm_address_t regionAddress = currentAddress; - vm_size_t regionSize = 0; - - kr = vm_region_64(task, - ®ionAddress, - ®ionSize, - VM_REGION_BASIC_INFO_64, - (vm_region_info_t)&info, - &infoCount, - &objectName); - - if (kr != KERN_SUCCESS || regionAddress > currentAddress) { - // Gap in memory or end of regions - foundEnd = true; - } else { - // Check if this is still the same module - // For iOS, we can't always rely on shared segment names - // Instead we check if the memory is the expected protection - bool isExecutable = (info.protection & VM_PROT_EXECUTE) != 0; - bool isPartOfModule = isExecutable || - (info.protection & VM_PROT_READ) != 0; - - if (isPartOfModule && (regionAddress == currentAddress)) { - // Still part of the module - moduleEnd = regionAddress + regionSize; - currentAddress = moduleEnd; - } else { - // Different module/end of module - foundEnd = true; - } - } - - regionCount++; - } - - // Calculate final size - size_t moduleSize = moduleEnd - baseAddress; - - // Validate size is reasonable - if (moduleSize > 0x10000000) { // > 256 MB is suspicious - moduleSize = 0x1000000; // Fallback to 16 MB - } - - // Cache and return the size - moduleSizeCache[lookupName] = moduleSize; - return moduleSize; - } -} diff --git a/source/cpp/ios/advanced_bypass/ExecutionIntegration.mm.bak b/source/cpp/ios/advanced_bypass/ExecutionIntegration.mm.bak deleted file mode 100644 index 50028520..00000000 --- a/source/cpp/ios/advanced_bypass/ExecutionIntegration.mm.bak +++ /dev/null @@ -1,443 +0,0 @@ -#include "WebKitExploit.h" -#include "MethodSwizzlingExploit.h" -#include "DynamicMessageDispatcher.h" -#include "LoadstringSupport.h" -#include "../../ios_compat.h" -#include "ExecutionIntegration.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Include headers -#include "../GameDetector.h" -#include "../../hooks/hooks.hpp" -#include "../../memory/mem.hpp" -#include "../../memory/signature.hpp" -#include "../PatternScanner.h" - -namespace iOS { - namespace AdvancedBypass { - - // Helper function to get current timestamp - static uint64_t GetCurrentTimeMs() { - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - } - - // Implementation of ExecutionIntegration - ExecutionIntegration::ExecutionIntegration(Method method) - : m_primaryMethod(method), - m_webKit(nullptr), - m_methodSwizzling(nullptr), - m_dynamicMessage(nullptr), - m_loadstring(nullptr), - m_loadstringInjected(false) { - - std::cout << "ExecutionIntegration: Creating with method " - << MethodToString(method) << std::endl; - - // Setup fallback chain if method is FallbackChain - if (method == Method::FallbackChain) { - m_fallbackChain = { - Method::WebKit, - Method::MethodSwizzling, - Method::DynamicMessage - }; - } - } - - ExecutionIntegration::~ExecutionIntegration() { - // Cleanup resources - m_webKit = nullptr; - m_methodSwizzling = nullptr; - m_dynamicMessage = nullptr; - m_loadstring = nullptr; - - std::cout << "ExecutionIntegration: Destroyed" << std::endl; - } - - bool ExecutionIntegration::Initialize() { - std::cout << "ExecutionIntegration: Initializing..." << std::endl; - - // If AutoSelect, determine best method first - if (m_primaryMethod == Method::AutoSelect) { - m_primaryMethod = DetermineBestMethod(); - std::cout << "ExecutionIntegration: Auto-selected method: " - << MethodToString(m_primaryMethod) << std::endl; - } - - // Initialize primary method - bool success = InitializeMethod(m_primaryMethod); - - // Initialize fallback methods if using fallback chain - if (m_primaryMethod == Method::FallbackChain) { - for (const auto& method : m_fallbackChain) { - InitializeMethod(method); - } - } - - // Initialize loadstring support - m_loadstring = std::make_shared(); - if (m_loadstring) { - m_loadstring->Initialize(); - } - - std::cout << "ExecutionIntegration: Initialization " - << (success ? "successful" : "failed") << std::endl; - - return success; - } - - bool ExecutionIntegration::InitializeMethod(Method method) { - switch (method) { - case Method::WebKit: - m_webKit = std::make_shared(); - return m_webKit->Initialize(); - - case Method::MethodSwizzling: - m_methodSwizzling = std::make_shared(); - return m_methodSwizzling->Initialize(); - - case Method::DynamicMessage: - m_dynamicMessage = std::make_shared(); - return m_dynamicMessage->Initialize(); - - case Method::AutoSelect: - case Method::FallbackChain: - // These are handled separately - return true; - - default: - return false; - } - } - - ExecutionIntegration::Method ExecutionIntegration::DetermineBestMethod() { - // Try to initialize each method and test its availability - std::shared_ptr webKit = std::make_shared(); - if (webKit->Initialize() && webKit->IsAvailable()) { - return Method::WebKit; - } - - std::shared_ptr methodSwizzling = std::make_shared(); - if (methodSwizzling->Initialize() && methodSwizzling->IsAvailable()) { - return Method::MethodSwizzling; - } - - std::shared_ptr dynamicMessage = std::make_shared(); - if (dynamicMessage->Initialize() && dynamicMessage->IsAvailable()) { - return Method::DynamicMessage; - } - - // If no method is available, use fallback chain - return Method::FallbackChain; - } - - ExecutionIntegration::ExecutionResult ExecutionIntegration::Execute(const std::string& script) { - // Check for cached result - auto it = m_scriptCache.find(script); - if (it != m_scriptCache.end()) { - ExecutionResult result(true, "", it->second, 0, "Cache"); - return result; - } - - // Execute based on primary method - if (m_primaryMethod == Method::FallbackChain) { - // Try each method in the fallback chain - for (const auto& method : m_fallbackChain) { - ExecutionResult result = ExecuteWithMethod(script, method); - if (result.m_success) { - // Cache successful result - m_scriptCache[script] = result.m_output; - return result; - } - } - - // All methods failed - return ExecutionResult(false, "All execution methods failed", "", 0, "FallbackChain"); - } else { - // Execute with the primary method - ExecutionResult result = ExecuteWithMethod(script, m_primaryMethod); - - // Cache successful result - if (result.m_success) { - m_scriptCache[script] = result.m_output; - } - - return result; - } - } - - ExecutionIntegration::ExecutionResult ExecutionIntegration::ExecuteWithMethod( - const std::string& script, Method method) { - - uint64_t startTime = GetCurrentTimeMs(); - std::string output; - bool success = false; - std::string error; - - try { - switch (method) { - case Method::WebKit: - if (m_webKit && m_webKit->IsAvailable()) { - output = m_webKit->ExecuteScript(script); - success = true; - } else { - error = "WebKit execution method not available"; - } - break; - - case Method::MethodSwizzling: - if (m_methodSwizzling && m_methodSwizzling->IsAvailable()) { - output = m_methodSwizzling->ExecuteScript(script); - success = true; - } else { - error = "Method swizzling execution method not available"; - } - break; - - case Method::DynamicMessage: - if (m_dynamicMessage && m_dynamicMessage->IsAvailable()) { - output = m_dynamicMessage->ExecuteScript(script); - success = true; - } else { - error = "Dynamic message execution method not available"; - } - break; - - default: - error = "Invalid execution method"; - break; - } - } catch (const std::exception& e) { - error = "Exception during execution: " + std::string(e.what()); - success = false; - } - - // Calculate execution time - uint64_t executionTime = GetCurrentTimeMs() - startTime; - - // Process output if callback is set - if (success && m_outputCallback) { - ProcessOutput(output); - } - - return ExecutionResult(success, error, output, executionTime, MethodToString(method)); - } - - ExecutionIntegration::ExecutionResult ExecutionIntegration::ExecuteWithLoadstring( - const std::string& script, const std::string& chunkName) { - - // Check if loadstring is supported - if (!m_loadstring || !m_loadstring->IsAvailable()) { - return ExecutionResult(false, "Loadstring support not available", "", 0, "Loadstring"); - } - - // Inject loadstring support if not already injected - if (!m_loadstringInjected) { - Execute(m_loadstring->GetInjectionScript()); - m_loadstringInjected = true; - } - - // Prepare the loadstring script - std::string wrappedScript = m_loadstring->WrapScript(script, chunkName); - - // Execute the wrapped script - return Execute(wrappedScript); - } - - bool ExecutionIntegration::SetMethod(Method method) { - // Cannot change to AutoSelect or FallbackChain after initialization - if (m_webKit || m_methodSwizzling || m_dynamicMessage) { - if (method == Method::AutoSelect || method == Method::FallbackChain) { - return false; - } - } - - // Set the new method - m_primaryMethod = method; - - // Initialize the new method if needed - if (!InitializeMethod(method)) { - return false; - } - - return true; - } - - ExecutionIntegration::Method ExecutionIntegration::GetMethod() const { - return m_primaryMethod; - } - - void ExecutionIntegration::SetOutputCallback(const OutputCallback& callback) { - m_outputCallback = callback; - } - - void ExecutionIntegration::SetFallbackChain(const std::vector& methods) { - m_fallbackChain = methods; - } - - std::vector ExecutionIntegration::GetFallbackChain() const { - return m_fallbackChain; - } - - void ExecutionIntegration::ClearCache() { - m_scriptCache.clear(); - } - - bool ExecutionIntegration::IsMethodAvailable(Method method) const { - switch (method) { - case Method::WebKit: - return m_webKit && m_webKit->IsAvailable(); - - case Method::MethodSwizzling: - return m_methodSwizzling && m_methodSwizzling->IsAvailable(); - - case Method::DynamicMessage: - return m_dynamicMessage && m_dynamicMessage->IsAvailable(); - - case Method::AutoSelect: - case Method::FallbackChain: - // These are always available - return true; - - default: - return false; - } - } - - std::vector ExecutionIntegration::GetAvailableMethods() const { - std::vector availableMethods; - - if (IsMethodAvailable(Method::WebKit)) { - availableMethods.push_back(Method::WebKit); - } - - if (IsMethodAvailable(Method::MethodSwizzling)) { - availableMethods.push_back(Method::MethodSwizzling); - } - - if (IsMethodAvailable(Method::DynamicMessage)) { - availableMethods.push_back(Method::DynamicMessage); - } - - // AutoSelect and FallbackChain are always available - availableMethods.push_back(Method::AutoSelect); - availableMethods.push_back(Method::FallbackChain); - - return availableMethods; - } - - std::string ExecutionIntegration::MethodToString(Method method) { - switch (method) { - case Method::WebKit: - return "WebKit"; - case Method::MethodSwizzling: - return "MethodSwizzling"; - case Method::DynamicMessage: - return "DynamicMessage"; - case Method::AutoSelect: - return "AutoSelect"; - case Method::FallbackChain: - return "FallbackChain"; - default: - return "Unknown"; - } - } - - std::string ExecutionIntegration::GetMethodDescription(Method method) { - switch (method) { - case Method::WebKit: - return "Executes scripts using WebKit JavaScript engine"; - - case Method::MethodSwizzling: - return "Executes scripts using Objective-C method swizzling"; - - case Method::DynamicMessage: - return "Executes scripts using dynamic message dispatch"; - - case Method::AutoSelect: - return "Automatically selects the best available execution method"; - - case Method::FallbackChain: - return "Tries multiple execution methods in succession"; - - default: - return "Unknown execution method"; - } - } - - void ExecutionIntegration::ProcessOutput(const std::string& output) { - if (m_outputCallback) { - m_outputCallback(output); - } - } - - std::string ExecutionIntegration::InjectLoadstringSupport(const std::string& script) { - if (!m_loadstring) { - return script; - } - - return m_loadstring->InjectSupport(script); - } - - // Helper function to integrate HTTP functions - bool IntegrateHttpFunctions(std::shared_ptr engine) { - if (!engine) { - return false; - } - - // Set up HTTP functions wrapper script - const std::string httpFunctionsScript = R"( - -- HTTP functions wrapper - local http = {} - - -- HTTP GET request - function http.get(url, headers) - headers = headers or {} - -- Implementation goes here - return { - Success = true, - StatusCode = 200, - StatusMessage = "OK", - Headers = {}, - Body = "HTTP GET simulation" - } - end - - -- HTTP POST request - function http.post(url, body, headers, contentType) - headers = headers or {} - contentType = contentType or "application/json" - -- Implementation goes here - return { - Success = true, - StatusCode = 200, - StatusMessage = "OK", - Headers = {}, - Body = "HTTP POST simulation" - } - end - - -- Make HTTP functions available globally - _G.http = http - - return "HTTP functions integrated" - )"; - - // Execute the script to set up HTTP functions - auto result = engine->Execute(httpFunctionsScript); - - std::cout << "HTTP Functions Integration: " - << (result.m_success ? "Successful" : "Failed") << std::endl; - - return result.m_success; - } - } -} diff --git a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak b/source/cpp/ios/advanced_bypass/HttpClient.mm.bak deleted file mode 100644 index f73953fe..00000000 --- a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak +++ /dev/null @@ -1,603 +0,0 @@ - -#include "../../ios_compat.h" -#include "HttpClient.h" -#include -#include -#include -#include -#include - -namespace iOS { -namespace AdvancedBypass { - - // Constructor - HttpClient::HttpClient(int defaultTimeout, bool useCache) - : m_initialized(false), - m_defaultTimeout(defaultTimeout), - m_useCache(useCache), - m_sessionConfig(nullptr), - m_session(nullptr) { - } - - // Destructor - HttpClient::~HttpClient() { - // Release NSURLSession and configuration (manual memory management) - if (m_session) { - NSURLSession* session = (NSURLSession*)m_session; - [session release]; - m_session = nullptr; - } - - if (m_sessionConfig) { - NSURLSessionConfiguration* config = (NSURLSessionConfiguration*)m_sessionConfig; - [config release]; - m_sessionConfig = nullptr; - } - } - - // Initialize the HTTP client - bool HttpClient::Initialize() { - if (m_initialized) { - return true; - } - - @autoreleasepool { - // Create session configuration - NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; - config.timeoutIntervalForRequest = m_defaultTimeout; - config.timeoutIntervalForResource = m_defaultTimeout; - - // Set up headers to mimic a normal browser - config.HTTPAdditionalHeaders = @{ - @"User-Agent": @"Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1", - @"Accept": @"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - @"Accept-Language": @"en-US,en;q=0.9" - }; - - // Store configuration (manual retain) - m_sessionConfig = (void*)config; - [config retain]; - - // Create session (manual retain) - NSURLSession* session = [NSURLSession sessionWithConfiguration:config]; - m_session = (void*)session; - [session retain]; - - m_initialized = true; - return true; - } - } - - // Synchronous HTTP GET request - HttpClient::RequestResult HttpClient::Get(const std::string& url, int timeout) { - // Initialize if needed - if (!m_initialized && !Initialize()) { - return RequestResult(false, 0, "Failed to initialize HTTP client", "", 0); - } - - // Validate URL - if (!ValidateUrl(url)) { - return RequestResult(false, 0, "Invalid URL: " + url, "", 0); - } - - // Check cache - if (m_useCache) { - RequestResult cachedResult = GetFromCacheIfAvailable(url); - if (cachedResult.m_success) { - return cachedResult; - } - } - - // Create semaphore for synchronous request - std::mutex mutex; - std::condition_variable cv; - bool requestComplete = false; - RequestResult result; - - // Send async request and wait for completion - SendRequest(url, "GET", {}, "", timeout > 0 ? timeout : m_defaultTimeout, - [&mutex, &cv, &requestComplete, &result](const RequestResult& asyncResult) { - std::lock_guard lock(mutex); - result = asyncResult; - requestComplete = true; - cv.notify_one(); - }); - - // Wait for completion with timeout - { - std::unique_lock lock(mutex); - if (!cv.wait_for(lock, std::chrono::seconds(timeout > 0 ? timeout : m_defaultTimeout), - [&requestComplete]() { return requestComplete; })) { - return RequestResult(false, 0, "Request timed out: " + url, "", 0); - } - } - - // Cache result if successful - if (result.m_success && m_useCache) { - AddToCacheIfNeeded(url, result); - } - - return result; - } - - // Asynchronous HTTP GET request - void HttpClient::GetAsync(const std::string& url, CompletionCallback callback, int timeout) { - // Initialize if needed - if (!m_initialized && !Initialize()) { - if (callback) { - callback(RequestResult(false, 0, "Failed to initialize HTTP client", "", 0)); - } - return; - } - - // Validate URL - if (!ValidateUrl(url)) { - if (callback) { - callback(RequestResult(false, 0, "Invalid URL: " + url, "", 0)); - } - return; - } - - // Check cache - if (m_useCache) { - RequestResult cachedResult = GetFromCacheIfAvailable(url); - if (cachedResult.m_success) { - if (callback) { - callback(cachedResult); - } - return; - } - } - - // Create completion wrapper to handle caching - CompletionCallback wrappedCallback = [this, url, callback](const RequestResult& result) { - // Cache result if successful - if (result.m_success && m_useCache) { - AddToCacheIfNeeded(url, result); - } - - // Call original callback - if (callback) { - callback(result); - } - }; - - // Send request - SendRequest(url, "GET", {}, "", timeout > 0 ? timeout : m_defaultTimeout, wrappedCallback); - } - - // Synchronous HTTP POST request - HttpClient::RequestResult HttpClient::Post(const std::string& url, const std::string& body, int timeout) { - // Initialize if needed - if (!m_initialized && !Initialize()) { - return RequestResult(false, 0, "Failed to initialize HTTP client", "", 0); - } - - // Validate URL - if (!ValidateUrl(url)) { - return RequestResult(false, 0, "Invalid URL: " + url, "", 0); - } - - // Create semaphore for synchronous request - std::mutex mutex; - std::condition_variable cv; - bool requestComplete = false; - RequestResult result; - - // Default headers for POST - std::unordered_map headers = { - {"Content-Type", "application/x-www-form-urlencoded"} - }; - - // Send async request and wait for completion - SendRequest(url, "POST", headers, body, timeout > 0 ? timeout : m_defaultTimeout, - [&mutex, &cv, &requestComplete, &result](const RequestResult& asyncResult) { - std::lock_guard lock(mutex); - result = asyncResult; - requestComplete = true; - cv.notify_one(); - }); - - // Wait for completion with timeout - { - std::unique_lock lock(mutex); - if (!cv.wait_for(lock, std::chrono::seconds(timeout > 0 ? timeout : m_defaultTimeout), - [&requestComplete]() { return requestComplete; })) { - return RequestResult(false, 0, "Request timed out: " + url, "", 0); - } - } - - return result; - } - - // Asynchronous HTTP POST request - void HttpClient::PostAsync(const std::string& url, const std::string& body, - CompletionCallback callback, int timeout) { - // Initialize if needed - if (!m_initialized && !Initialize()) { - if (callback) { - callback(RequestResult(false, 0, "Failed to initialize HTTP client", "", 0)); - } - return; - } - - // Validate URL - if (!ValidateUrl(url)) { - if (callback) { - callback(RequestResult(false, 0, "Invalid URL: " + url, "", 0)); - } - return; - } - - // Default headers for POST - std::unordered_map headers = { - {"Content-Type", "application/x-www-form-urlencoded"} - }; - - // Send request - SendRequest(url, "POST", headers, body, timeout > 0 ? timeout : m_defaultTimeout, callback); - } - - // Set the default timeout - void HttpClient::SetDefaultTimeout(int timeout) { - m_defaultTimeout = timeout; - - // Update session configuration if initialized - if (m_initialized && m_sessionConfig) { - NSURLSessionConfiguration* config = (__bridge NSURLSessionConfiguration*)m_sessionConfig; - config.timeoutIntervalForRequest = timeout; - config.timeoutIntervalForResource = timeout; - } - } - - // Get the default timeout - int HttpClient::GetDefaultTimeout() const { - return m_defaultTimeout; - } - - // Enable or disable response caching - void HttpClient::SetUseCache(bool useCache) { - m_useCache = useCache; - } - - // Check if response caching is enabled - bool HttpClient::GetUseCache() const { - return m_useCache; - } - - // Clear the response cache - void HttpClient::ClearCache() { - m_cache.clear(); - } - - // Check if a URL is cached - bool HttpClient::IsUrlCached(const std::string& url) const { - return m_cache.find(NormalizeUrl(url)) != m_cache.end(); - } - - // Send HTTP request - void HttpClient::SendRequest(const std::string& url, const std::string& method, - const std::unordered_map& headers, - const std::string& body, int timeout, CompletionCallback callback) { - @autoreleasepool { - // Start timing - auto startTime = std::chrono::high_resolution_clock::now(); - - // Create URL - NSURL* nsUrl = [NSURL URLWithString:[NSString stringWithUTF8String:url.c_str()]]; - if (!nsUrl) { - if (callback) { - callback(RequestResult(false, 0, "Invalid URL: " + url, "", 0)); - } - return; - } - - // Create request - NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; - request.HTTPMethod = [NSString stringWithUTF8String:method.c_str()]; - request.timeoutInterval = timeout; - - // Add headers - for (const auto& header : headers) { - [request setValue:[NSString stringWithUTF8String:header.second.c_str()] - forHTTPHeaderField:[NSString stringWithUTF8String:header.first.c_str()]]; - } - - // Add body if needed - if (!body.empty()) { - request.HTTPBody = [NSData dataWithBytes:body.c_str() length:body.size()]; - } - - // Get session - NSURLSession* session = (__bridge NSURLSession*)m_session; - - // Create data task - NSURLSessionDataTask* task = [session dataTaskWithRequest:request - completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { - // Get status code - NSInteger statusCode = 0; - if ([response isKindOfClass:[NSHTTPURLResponse class]]) { - statusCode = [(NSHTTPURLResponse*)response statusCode]; - } - - // Check for error - if (error) { - // Calculate request time - auto endTime = std::chrono::high_resolution_clock::now(); - uint64_t requestTime = std::chrono::duration_cast(endTime - startTime).count(); - - // Build error result - std::string errorMsg = [[error localizedDescription] UTF8String]; - if (callback) { - callback(RequestResult(false, statusCode, errorMsg, "", requestTime)); - } - return; - } - - // Get response data - std::string content; - if (data) { - content = std::string((const char*)[data bytes], [data length]); - } - - // Calculate request time - auto endTime = std::chrono::high_resolution_clock::now(); - uint64_t requestTime = std::chrono::duration_cast(endTime - startTime).count(); - - // Call callback with result - if (callback) { - callback(RequestResult(true, statusCode, "", content, requestTime)); - } - }]; - - // Start task - [task resume]; - } - } - - // Validate URL - bool HttpClient::ValidateUrl(const std::string& url) { - @autoreleasepool { - NSURL* nsUrl = [NSURL URLWithString:[NSString stringWithUTF8String:url.c_str()]]; - if (!nsUrl) { - return false; - } - - // Check scheme - NSString* scheme = [nsUrl scheme]; - if (!scheme) { - return false; - } - - // Allow HTTP and HTTPS - return [scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"]; - } - } - - // Normalize URL for caching - std::string HttpClient::NormalizeUrl(const std::string& url) const { - @autoreleasepool { - NSURL* nsUrl = [NSURL URLWithString:[NSString stringWithUTF8String:url.c_str()]]; - if (!nsUrl) { - return url; - } - - // Use absoluteString for normalized URL - return [[nsUrl absoluteString] UTF8String]; - } - } - - // Check if response should be cached - bool HttpClient::ShouldUseCache(const std::string& url, const std::string& method) { - // Only cache GET requests - return m_useCache && method == "GET"; - } - - // Add response to cache - void HttpClient::AddToCacheIfNeeded(const std::string& url, const RequestResult& result) { - if (!m_useCache) { - return; - } - - // Only cache successful responses - if (!result.m_success) { - return; - } - - // Add to cache - m_cache[NormalizeUrl(url)] = result; - } - - // Get response from cache - HttpClient::RequestResult HttpClient::GetFromCacheIfAvailable(const std::string& url) { - // Check if URL is in cache - auto it = m_cache.find(NormalizeUrl(url)); - if (it != m_cache.end()) { - return it->second; - } - - // Not in cache - return RequestResult(); - } - - // Get Lua code for HTTP functions - std::string HttpClient::GetHttpFunctionsCode() { - return R"( --- Create the game table if it doesn't exist -game = game or {} - --- Implementation of game:HttpGet function -function game:HttpGet(url, cache) - -- Default cache to true if not specified - if cache == nil then cache = true end - - -- Call native HTTP GET function - local success, result = pcall(function() - -- In a real implementation, this would call a native C++ function - -- For now, we'll simulate the result - if url and type(url) == "string" and #url > 0 then - -- Call _httpGet function if available - if _httpGet then - return _httpGet(url, cache) - else - error("HTTP request functionality not available") - end - else - error("Invalid URL") - end - end) - - -- Handle errors - if not success then - error("HttpGet failed: " .. tostring(result), 2) - end - - return result -end - --- Async variant -function game:HttpGetAsync(url, callback) - -- Argument validation - if type(url) ~= "string" or #url == 0 then - error("Invalid URL", 2) - end - - -- Use callback if provided - if callback and type(callback) == "function" then - -- Call native async function - if _httpGetAsync then - _httpGetAsync(url, function(success, result) - if success then - callback(result) - else - callback(nil, result) -- Pass error as second argument - end - end) - else - -- Fall back to sync version - local success, result = pcall(function() - return game:HttpGet(url) - end) - - if success then - callback(result) - else - callback(nil, result) - end - end - - return -- No return value for async with callback - else - -- If no callback, just use sync version - return game:HttpGet(url) - end -end - --- Implementation of game:HttpPost function -function game:HttpPost(url, data, contentType, compress) - -- Default parameters - contentType = contentType or "application/json" - compress = compress or false - - -- Call native HTTP POST function - local success, result = pcall(function() - -- In a real implementation, this would call a native C++ function - if url and type(url) == "string" and #url > 0 then - -- Call _httpPost function if available - if _httpPost then - return _httpPost(url, data, contentType, compress) - else - error("HTTP request functionality not available") - end - else - error("Invalid URL") - end - end) - - -- Handle errors - if not success then - error("HttpPost failed: " .. tostring(result), 2) - end - - return result -end - --- Async variant -function game:HttpPostAsync(url, data, contentType, compress, callback) - -- Default parameters - contentType = contentType or "application/json" - compress = compress or false - - -- Use callback if provided - if callback and type(callback) == "function" then - -- Call native async function - if _httpPostAsync then - _httpPostAsync(url, data, contentType, compress, function(success, result) - if success then - callback(result) - else - callback(nil, result) -- Pass error as second argument - end - end) - else - -- Fall back to sync version - local success, result = pcall(function() - return game:HttpPost(url, data, contentType, compress) - end) - - if success then - callback(result) - else - callback(nil, result) - end - end - - return -- No return value for async with callback - else - -- If no callback, just use sync version - return game:HttpPost(url, data, contentType, compress) - end -end - --- Create a combined loadstring + HttpGet utility function -function loadUrl(url) - local content = game:HttpGet(url) - local fn, err = loadstring(content) - if not fn then - error("Failed to load URL: " .. tostring(err), 2) - end - return fn -end - --- Return the implementations -return { - HttpGet = function(...) return game:HttpGet(...) end, - HttpGetAsync = function(...) return game:HttpGetAsync(...) end, - HttpPost = function(...) return game:HttpPost(...) end, - HttpPostAsync = function(...) return game:HttpPostAsync(...) end, - loadUrl = loadUrl -} -)"; - } - - // Check if HTTP requests are available - bool HttpClient::IsAvailable() { - @autoreleasepool { - // Check if we can create a session - NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; - if (!config) { - return false; - } - - // Try creating a session - NSURLSession* session = [NSURLSession sessionWithConfiguration:config]; - if (!session) { - return false; - } - - return true; - } - } - -} // namespace AdvancedBypass -} // namespace iOS diff --git a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak2 b/source/cpp/ios/advanced_bypass/HttpClient.mm.bak2 deleted file mode 100644 index cb35ccd8..00000000 --- a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak2 +++ /dev/null @@ -1,359 +0,0 @@ -#include "../../ios_compat.h" -#include "HttpClient.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#import - -namespace iOS { -namespace AdvancedBypass { - - // Implementation of HttpClient for iOS - - // Cleanup previous session if exists - void HttpClient::CleanupSession() { - if (m_session) { - // Use __bridge to cast the void* back to NSURLSession* with ARC - NSURLSession* session = (__bridge_transfer NSURLSession*)m_session; - m_session = nullptr; - - // No need to call release with ARC and __bridge_transfer - } - - if (m_sessionConfig) { - // Use __bridge to cast the void* back to NSURLSessionConfiguration* with ARC - NSURLSessionConfiguration* config = (__bridge_transfer NSURLSessionConfiguration*)m_sessionConfig; - m_sessionConfig = nullptr; - - // No need to call release with ARC and __bridge_transfer - } - } - - // Initialize HTTP client - void HttpClient::Initialize() { - // Create session configuration - NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; - config.timeoutIntervalForRequest = 30.0; - config.timeoutIntervalForResource = 60.0; - config.HTTPMaximumConnectionsPerHost = 5; - - // Setup cache policy - config.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData; - - // Additional headers - config.HTTPAdditionalHeaders = @{ - @"User-Agent": @"Roblox/iOS", - @"Accept": @"*/*", - @"Accept-Language": @"en-us", - @"Connection": @"keep-alive" - }; - - // Store the configuration with proper bridging - m_sessionConfig = (__bridge_retained void*)config; - - // Create the session with the delegate - NSURLSession* session = [NSURLSession sessionWithConfiguration:config - delegate:nil - delegateQueue:[NSOperationQueue mainQueue]]; - - // Store the session with proper bridging - m_session = (__bridge_retained void*)session; - } - - // Perform an HTTP request - void HttpClient::SendRequest(const std::string& url, - const std::string& method, - const std::map& headers, - const std::string& body, - const RequestCallback& callback) { - // Check if session exists - if (!m_session) { - Initialize(); - } - - // Convert URL to NSString and create NSURL - NSString* urlString = [NSString stringWithUTF8String:url.c_str()]; - NSURL* nsUrl = [NSURL URLWithString:urlString]; - - // Create the request - NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; - - // Set HTTP method - [request setHTTPMethod:[NSString stringWithUTF8String:method.c_str()]]; - - // Set headers - for (const auto& header : headers) { - NSString* key = [NSString stringWithUTF8String:header.first.c_str()]; - NSString* value = [NSString stringWithUTF8String:header.second.c_str()]; - [request setValue:value forHTTPHeaderField:key]; - } - - // Set body if not empty - if (!body.empty()) { - NSData* bodyData = [NSData dataWithBytes:body.c_str() length:body.size()]; - [request setHTTPBody:bodyData]; - } - - // Set cache policy - bool useCache = ShouldUseCache(url, method); - request.cachePolicy = useCache ? NSURLRequestReturnCacheDataElseLoad : NSURLRequestReloadIgnoringLocalCacheData; - - // Create the data task - NSURLSession* session = (__bridge NSURLSession*)m_session; - NSURLSessionDataTask* task = [session dataTaskWithRequest:request - completionHandler: -^ -(NSData* _Nullable data, NSURLResponse* _Nullable response, NSError* _Nullable error) { - // Handle the response - NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; - - // Create response object - Response resp; - resp.statusCode = (int)httpResponse.statusCode; - - // Extract headers - NSDictionary* respHeaders = httpResponse.allHeaderFields; - for (NSString* key in respHeaders) { - NSString* value = [respHeaders objectForKey:key]; - resp.headers[[key UTF8String]] = [value UTF8String]; - } - - // Extract body - if (data) { - resp.body = std::string((const char*)[data bytes], [data length]); - } - - // Handle error - if (error) { - resp.error = [[error localizedDescription] UTF8String]; - } - - // Call the callback on the main thread - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(resp); - }); - }]; - - // Start the task - [task resume]; - } - - // GET request - void HttpClient::Get(const std::string& url, const RequestCallback& callback) { - SendRequest(url, "GET", {}, "", callback); - } - - // GET request with headers - void HttpClient::Get(const std::string& url, const std::map& headers, const RequestCallback& callback) { - SendRequest(url, "GET", headers, "", callback); - } - - // POST request - void HttpClient::Post(const std::string& url, const std::string& body, const RequestCallback& callback) { - std::map headers = { - {"Content-Type", "application/x-www-form-urlencoded"} - }; - SendRequest(url, "POST", headers, body, callback); - } - - // POST request with custom headers - void HttpClient::Post(const std::string& url, const std::map& headers, - const std::string& body, const RequestCallback& callback) { - SendRequest(url, "POST", headers, body, callback); - } - - // PUT request - void HttpClient::Put(const std::string& url, const std::string& body, const RequestCallback& callback) { - std::map headers = { - {"Content-Type", "application/x-www-form-urlencoded"} - }; - SendRequest(url, "PUT", headers, body, callback); - } - - // DELETE request - void HttpClient::Delete(const std::string& url, const RequestCallback& callback) { - SendRequest(url, "DELETE", {}, "", callback); - } - - // Download file - void HttpClient::DownloadFile(const std::string& url, const std::string& destination, - const ProgressCallback& progressCallback, - const RequestCallback& callback) { - // Check if session exists - if (!m_session) { - Initialize(); - } - - // Convert URL to NSString and create NSURL - NSString* urlString = [NSString stringWithUTF8String:url.c_str()]; - NSURL* nsUrl = [NSURL URLWithString:urlString]; - - // Create the request - NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; - - // Create a download task - NSURLSession* session = (__bridge NSURLSession*)m_session; - NSURLSessionDownloadTask* task = [session downloadTaskWithRequest:request completionHandler: -^ -(NSURL* _Nullable location, NSURLResponse* _Nullable response, NSError* _Nullable error) { - - Response resp; - NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; - resp.statusCode = (int)httpResponse.statusCode; - - if (error) { - resp.error = [[error localizedDescription] UTF8String]; - callback(resp); - return; - } - - if (location) { - NSString* destPath = [NSString stringWithUTF8String:destination.c_str()]; - NSFileManager* fileManager = [NSFileManager defaultManager]; - - // Move the downloaded file to the destination - NSError* moveError = nil; - [fileManager moveItemAtURL:location toURL:[NSURL fileURLWithPath:destPath] error:&moveError]; - - if (moveError) { - resp.error = [[moveError localizedDescription] UTF8String]; - } - } - - // Call the callback on the main thread - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(resp); - }); - }]; - - // Start the task - [task resume]; - } - - // Upload file - void HttpClient::UploadFile(const std::string& url, const std::string& filePath, - const std::map& headers, - const ProgressCallback& progressCallback, - const RequestCallback& callback) { - // Check if session exists - if (!m_session) { - Initialize(); - } - - // Create multipart form data - NSString* boundary = [NSString stringWithFormat:@"Boundary-%@", [[NSUUID UUID] UUIDString]]; - NSString* contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; - - // Create the request - NSString* urlString = [NSString stringWithUTF8String:url.c_str()]; - NSURL* nsUrl = [NSURL URLWithString:urlString]; - NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; - [request setHTTPMethod:@"POST"]; - [request setValue:contentType forHTTPHeaderField:@"Content-Type"]; - - // Add custom headers - for (const auto& header : headers) { - NSString* key = [NSString stringWithUTF8String:header.first.c_str()]; - NSString* value = [NSString stringWithUTF8String:header.second.c_str()]; - [request setValue:value forHTTPHeaderField:key]; - } - - // Create the body data - NSMutableData* body = [NSMutableData data]; - - // Add the file data - NSString* fileBoundary = [NSString stringWithFormat:@"--%@\r\n", boundary]; - [body appendData:[fileBoundary dataUsingEncoding:NSUTF8StringEncoding]]; - - // Get filename from path - NSString* nsFilePath = [NSString stringWithUTF8String:filePath.c_str()]; - NSString* fileName = [[nsFilePath lastPathComponent] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]; - - // Create content disposition - NSString* contentDisposition = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", fileName]; - [body appendData:[contentDisposition dataUsingEncoding:NSUTF8StringEncoding]]; - - // Add content type - [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; - - // Read the file data - NSData* fileData = [NSData dataWithContentsOfFile:nsFilePath]; - [body appendData:fileData]; - [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; - - // Close the form data - NSString* closingBoundary = [NSString stringWithFormat:@"--%@--\r\n", boundary]; - [body appendData:[closingBoundary dataUsingEncoding:NSUTF8StringEncoding]]; - - // Set the body data - [request setHTTPBody:body]; - - // Create the upload task - NSURLSession* session = (__bridge NSURLSession*)m_session; - NSURLSessionUploadTask* task = [session uploadTaskWithRequest:request fromData:body completionHandler: -^ -(NSData* _Nullable data, NSURLResponse* _Nullable response, NSError* _Nullable error) { - - Response resp; - NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; - resp.statusCode = (int)httpResponse.statusCode; - - // Extract headers - NSDictionary* respHeaders = httpResponse.allHeaderFields; - for (NSString* key in respHeaders) { - NSString* value = [respHeaders objectForKey:key]; - resp.headers[[key UTF8String]] = [value UTF8String]; - } - - // Extract body - if (data) { - resp.body = std::string((const char*)[data bytes], [data length]); - } - - // Handle error - if (error) { - resp.error = [[error localizedDescription] UTF8String]; - } - - // Call the callback on the main thread - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(resp); - }); - }]; - - // Start the task - [task resume]; - } - - // Determine if we should use cache for this URL/method - bool HttpClient::ShouldUseCache(const std::string& url, const std::string& method) { - // Only use cache for GET requests - if (method != "GET") { - return false; - } - - // Default to false - most requests should be fresh - return false; - } - - // Destructor - HttpClient::~HttpClient() { - CleanupSession(); - } -} -} -#endif // __APPLE__ diff --git a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak3 b/source/cpp/ios/advanced_bypass/HttpClient.mm.bak3 deleted file mode 100644 index 21848910..00000000 --- a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak3 +++ /dev/null @@ -1,453 +0,0 @@ -#include "../../ios_compat.h" -#include "HttpClient.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#import - -namespace iOS { -namespace AdvancedBypass { - - // Constructor - HttpClient::HttpClient(int defaultTimeout, bool useCache) - : m_initialized(false), - m_defaultTimeout(defaultTimeout), - m_useCache(useCache), - m_sessionConfig(nullptr), - m_session(nullptr) { - } - - // Destructor - HttpClient::~HttpClient() { - // Release NSURLSession and configuration with ARC-compatible bridging - if (m_session) { - // Use __bridge_transfer to transfer ownership from C++ to ARC - NSURLSession* session = (__bridge_transfer NSURLSession*)m_session; - m_session = nullptr; - - // No need to call release with ARC and __bridge_transfer - } - - if (m_sessionConfig) { - // Use __bridge_transfer to transfer ownership from C++ to ARC - NSURLSessionConfiguration* config = (__bridge_transfer NSURLSessionConfiguration*)m_sessionConfig; - m_sessionConfig = nullptr; - - // No need to call release with ARC and __bridge_transfer - } - } - - // Initialize the HTTP client - bool HttpClient::Initialize() { - // Check if already initialized - if (m_initialized) { - return true; - } - - @try { - // Create session configuration - NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; - config.timeoutIntervalForRequest = m_defaultTimeout; - config.timeoutIntervalForResource = m_defaultTimeout * 2; - config.HTTPMaximumConnectionsPerHost = 5; - - // Setup cache policy based on settings - config.requestCachePolicy = m_useCache ? - NSURLRequestReturnCacheDataElseLoad : - NSURLRequestReloadIgnoringLocalCacheData; - - // Set up headers to mimic a normal browser - config.HTTPAdditionalHeaders = @{ - @"User-Agent": @"Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1", - @"Accept": @"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - @"Accept-Language": @"en-US,en;q=0.9" - }; - - // Store configuration with ARC-compatible bridging - m_sessionConfig = (__bridge_retained void*)config; - - // Create session with ARC-compatible bridging - NSURLSession* session = [NSURLSession sessionWithConfiguration:config]; - m_session = (__bridge_retained void*)session; - - m_initialized = true; - return true; - } - @catch (NSException* exception) { - std::cerr << "HttpClient::Initialize failed: " << [[exception reason] UTF8String] << std::endl; - return false; - } - } - - // Send HTTP request with all parameters - void HttpClient::SendRequest(const std::string& url, - const std::string& method, - const std::unordered_map& headers, - const std::string& body, - int timeout, - CompletionCallback callback) { - // Ensure initialized - if (!m_initialized && !Initialize()) { - RequestResult result; - result.success = false; - result.errorCode = -1; - result.errorMessage = "HTTP client failed to initialize"; - callback(result); - return; - } - - // Perform on background thread to avoid blocking - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), -^ -{ - @try { - // Create URL - NSString* urlString = [NSString stringWithUTF8String:url.c_str()]; - NSURL* nsUrl = [NSURL URLWithString:urlString]; - - if (!nsUrl) { - RequestResult result; - result.success = false; - result.errorCode = -1; - result.errorMessage = "Invalid URL: " + url; - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - return; - } - - // Create request - NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; - - // Set method - [request setHTTPMethod:[NSString stringWithUTF8String:method.c_str()]]; - - // Set timeout - if (timeout > 0) { - [request setTimeoutInterval:timeout]; - } - - // Set headers - for (const auto& header : headers) { - NSString* key = [NSString stringWithUTF8String:header.first.c_str()]; - NSString* value = [NSString stringWithUTF8String:header.second.c_str()]; - [request setValue:value forHTTPHeaderField:key]; - } - - // Set body if not empty - if (!body.empty()) { - NSData* bodyData = [NSData dataWithBytes:body.c_str() length:body.length()]; - [request setHTTPBody:bodyData]; - } - - // Get session using proper ARC bridging - NSURLSession* session = (__bridge NSURLSession*)m_session; - - // Create data task - NSURLSessionDataTask* task = [session dataTaskWithRequest:request - completionHandler: -^ -(NSData* data, NSURLResponse* response, NSError* error) { - // Create result object - RequestResult result; - - if (error) { - // Handle error - result.success = false; - result.errorCode = (int)[error code]; - result.errorMessage = [[error localizedDescription] UTF8String]; - } else { - // Handle success - NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; - result.success = (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300); - result.statusCode = (int)httpResponse.statusCode; - - // Get response data - if (data) { - result.data = std::vector((uint8_t*)[data bytes], (uint8_t*)[data bytes] + [data length]); - result.text = std::string((const char*)[data bytes], [data length]); - } - - // Get headers - NSDictionary* respHeaders = httpResponse.allHeaderFields; - for (NSString* key in respHeaders) { - NSString* value = [respHeaders objectForKey:key]; - result.headers[[key UTF8String]] = [value UTF8String]; - } - } - - // Call callback on main thread - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - }]; - - // Start task - [task resume]; - } - @catch (NSException* exception) { - RequestResult result; - result.success = false; - result.errorCode = -1; - result.errorMessage = [[exception reason] UTF8String]; - - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - } - }); - } - - // GET request - void HttpClient::Get(const std::string& url, CompletionCallback callback) { - SendRequest(url, "GET", {}, "", m_defaultTimeout, callback); - } - - // GET request with timeout - void HttpClient::Get(const std::string& url, int timeout, CompletionCallback callback) { - SendRequest(url, "GET", {}, "", timeout, callback); - } - - // GET request with headers - void HttpClient::Get(const std::string& url, - const std::unordered_map& headers, - CompletionCallback callback) { - SendRequest(url, "GET", headers, "", m_defaultTimeout, callback); - } - - // GET request with headers and timeout - void HttpClient::Get(const std::string& url, - const std::unordered_map& headers, - int timeout, - CompletionCallback callback) { - SendRequest(url, "GET", headers, "", timeout, callback); - } - - // POST request - void HttpClient::Post(const std::string& url, - const std::string& body, - CompletionCallback callback) { - std::unordered_map headers = { - {"Content-Type", "application/x-www-form-urlencoded"} - }; - SendRequest(url, "POST", headers, body, m_defaultTimeout, callback); - } - - // POST request with timeout - void HttpClient::Post(const std::string& url, - const std::string& body, - int timeout, - CompletionCallback callback) { - std::unordered_map headers = { - {"Content-Type", "application/x-www-form-urlencoded"} - }; - SendRequest(url, "POST", headers, body, timeout, callback); - } - - // POST request with headers - void HttpClient::Post(const std::string& url, - const std::unordered_map& headers, - const std::string& body, - CompletionCallback callback) { - SendRequest(url, "POST", headers, body, m_defaultTimeout, callback); - } - - // POST request with headers and timeout - void HttpClient::Post(const std::string& url, - const std::unordered_map& headers, - const std::string& body, - int timeout, - CompletionCallback callback) { - SendRequest(url, "POST", headers, body, timeout, callback); - } - - // Upload file - void HttpClient::UploadFile(const std::string& url, - const std::string& filePath, - CompletionCallback callback) { - UploadFile(url, filePath, {}, m_defaultTimeout, callback); - } - - // Upload file with headers - void HttpClient::UploadFile(const std::string& url, - const std::string& filePath, - const std::unordered_map& headers, - CompletionCallback callback) { - UploadFile(url, filePath, headers, m_defaultTimeout, callback); - } - - // Upload file with headers and timeout - void HttpClient::UploadFile(const std::string& url, - const std::string& filePath, - const std::unordered_map& headers, - int timeout, - CompletionCallback callback) { - // Ensure initialized - if (!m_initialized && !Initialize()) { - RequestResult result; - result.success = false; - result.errorCode = -1; - result.errorMessage = "HTTP client failed to initialize"; - callback(result); - return; - } - - // Check if file exists - NSString* nsFilePath = [NSString stringWithUTF8String:filePath.c_str()]; - if (![[NSFileManager defaultManager] fileExistsAtPath:nsFilePath]) { - RequestResult result; - result.success = false; - result.errorCode = -1; - result.errorMessage = "File not found: " + filePath; - callback(result); - return; - } - - // Perform on background thread - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), -^ -{ - @try { - // Create URL - NSString* urlString = [NSString stringWithUTF8String:url.c_str()]; - NSURL* nsUrl = [NSURL URLWithString:urlString]; - - if (!nsUrl) { - RequestResult result; - result.success = false; - result.errorCode = -1; - result.errorMessage = "Invalid URL: " + url; - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - return; - } - - // Create request - NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; - [request setHTTPMethod:@"POST"]; - - // Set timeout - if (timeout > 0) { - [request setTimeoutInterval:timeout]; - } - - // Create boundary string for multipart - NSString* boundary = [NSString stringWithFormat:@"Boundary-%@", [[NSUUID UUID] UUIDString]]; - NSString* contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; - [request setValue:contentType forHTTPHeaderField:@"Content-Type"]; - - // Set custom headers - for (const auto& header : headers) { - NSString* key = [NSString stringWithUTF8String:header.first.c_str()]; - NSString* value = [NSString stringWithUTF8String:header.second.c_str()]; - [request setValue:value forHTTPHeaderField:key]; - } - - // Create body data - NSMutableData* body = [NSMutableData data]; - - // Add start boundary - [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - - // Get filename from path - NSString* fileName = [[nsFilePath lastPathComponent] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]; - - // Add content disposition - [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]]; - - // Add content type - [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; - - // Add file data - NSData* fileData = [NSData dataWithContentsOfFile:nsFilePath]; - [body appendData:fileData]; - [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; - - // Add end boundary - [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - - // Set body - [request setHTTPBody:body]; - - // Get session using proper ARC bridging - NSURLSession* session = (__bridge NSURLSession*)m_session; - - // Create upload task - NSURLSessionUploadTask* task = [session uploadTaskWithRequest:request - fromData:body - completionHandler: -^ -(NSData* data, NSURLResponse* response, NSError* error) { - // Create result object - RequestResult result; - - if (error) { - // Handle error - result.success = false; - result.errorCode = (int)[error code]; - result.errorMessage = [[error localizedDescription] UTF8String]; - } else { - // Handle success - NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; - result.success = (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300); - result.statusCode = (int)httpResponse.statusCode; - - // Get response data - if (data) { - result.data = std::vector((uint8_t*)[data bytes], (uint8_t*)[data bytes] + [data length]); - result.text = std::string((const char*)[data bytes], [data length]); - } - - // Get headers - NSDictionary* respHeaders = httpResponse.allHeaderFields; - for (NSString* key in respHeaders) { - NSString* value = [respHeaders objectForKey:key]; - result.headers[[key UTF8String]] = [value UTF8String]; - } - } - - // Call callback on main thread - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - }]; - - // Start task - [task resume]; - } - @catch (NSException* exception) { - RequestResult result; - result.success = false; - result.errorCode = -1; - result.errorMessage = [[exception reason] UTF8String]; - - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - } - }); - } -} -} -#endif // __APPLE__ diff --git a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak4 b/source/cpp/ios/advanced_bypass/HttpClient.mm.bak4 deleted file mode 100644 index a6235008..00000000 --- a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak4 +++ /dev/null @@ -1,491 +0,0 @@ -#include "../../ios_compat.h" -#include "HttpClient.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#import - -namespace iOS { -namespace AdvancedBypass { - - // Constructor - HttpClient::HttpClient(int defaultTimeout, bool useCache) - : m_initialized(false), - m_defaultTimeout(defaultTimeout), - m_useCache(useCache), - m_sessionConfig(nullptr), - m_session(nullptr) { - } - - // Destructor - HttpClient::~HttpClient() { - // Release NSURLSession and configuration with ARC-compatible bridging - if (m_session) { - // Use __bridge_transfer to transfer ownership from C++ to ARC - NSURLSession* session = (__bridge_transfer NSURLSession*)m_session; - m_session = nullptr; - - // No need to call release with ARC and __bridge_transfer - } - - if (m_sessionConfig) { - // Use __bridge_transfer to transfer ownership from C++ to ARC - NSURLSessionConfiguration* config = (__bridge_transfer NSURLSessionConfiguration*)m_sessionConfig; - m_sessionConfig = nullptr; - - // No need to call release with ARC and __bridge_transfer - } - } - - // Initialize the HTTP client - bool HttpClient::Initialize() { - // Check if already initialized - if (m_initialized) { - return true; - } - - @try { - // Create session configuration - NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; - config.timeoutIntervalForRequest = m_defaultTimeout; - config.timeoutIntervalForResource = m_defaultTimeout * 2; - config.HTTPMaximumConnectionsPerHost = 5; - - // Setup cache policy based on settings - config.requestCachePolicy = m_useCache ? - NSURLRequestReturnCacheDataElseLoad : - NSURLRequestReloadIgnoringLocalCacheData; - - // Set up headers to mimic a normal browser - config.HTTPAdditionalHeaders = @{ - @"User-Agent": @"Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1", - @"Accept": @"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - @"Accept-Language": @"en-US,en;q=0.9" - }; - - // Store configuration with ARC-compatible bridging - m_sessionConfig = (__bridge_retained void*)config; - - // Create session with ARC-compatible bridging - NSURLSession* session = [NSURLSession sessionWithConfiguration:config]; - m_session = (__bridge_retained void*)session; - - m_initialized = true; - return true; - } - @catch (NSException* exception) { - std::cerr << "HttpClient::Initialize failed: " << [[exception reason] UTF8String] << std::endl; - return false; - } - } - - // Send HTTP request with all parameters - void HttpClient::SendRequest(const std::string& url, - const std::string& method, - const std::unordered_map& headers, - const std::string& body, - int timeout, - CompletionCallback callback) { - // Ensure initialized - if (!m_initialized && !Initialize()) { - RequestResult result; - result.m_success = false; - result.m_statusCode = -1; - result.m_error = "HTTP client failed to initialize"; - result.m_body = ""; - result.m_requestTime = 0; - result.m_content = ""; - callback(result); - return; - } - - // Get start time for performance tracking - uint64_t startTime = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - - // Perform on background thread to avoid blocking - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), -^ -{ - @try { - // Create URL - NSString* urlString = [NSString stringWithUTF8String:url.c_str()]; - NSURL* nsUrl = [NSURL URLWithString:urlString]; - - if (!nsUrl) { - RequestResult result; - result.m_success = false; - result.m_statusCode = -1; - result.m_error = "Invalid URL: " + url; - result.m_body = ""; - result.m_content = ""; - result.m_requestTime = 0; - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - return; - } - - // Create request - NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; - - // Set method - [request setHTTPMethod:[NSString stringWithUTF8String:method.c_str()]]; - - // Set timeout - if (timeout > 0) { - [request setTimeoutInterval:timeout]; - } - - // Set headers - for (const auto& header : headers) { - NSString* key = [NSString stringWithUTF8String:header.first.c_str()]; - NSString* value = [NSString stringWithUTF8String:header.second.c_str()]; - [request setValue:value forHTTPHeaderField:key]; - } - - // Set body if not empty - if (!body.empty()) { - NSData* bodyData = [NSData dataWithBytes:body.c_str() length:body.length()]; - [request setHTTPBody:bodyData]; - } - - // Get session using proper ARC bridging - NSURLSession* session = (__bridge NSURLSession*)m_session; - - // Create data task - NSURLSessionDataTask* task = [session dataTaskWithRequest:request - completionHandler: -^ -(NSData* data, NSURLResponse* response, NSError* error) { - // Calculate request time - uint64_t endTime = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - uint64_t requestTime = endTime - startTime; - - // Create result object - RequestResult result; - - if (error) { - // Handle error - result.m_success = false; - result.m_statusCode = (int)[error code]; - result.m_error = [[error localizedDescription] UTF8String]; - result.m_body = ""; - result.m_content = ""; - result.m_requestTime = requestTime; - } else { - // Handle success - NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; - result.m_success = (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300); - result.m_statusCode = (int)httpResponse.statusCode; - - // Get response data - if (data) { - // Convert data to string - std::string responseString((const char*)[data bytes], [data length]); - result.m_body = responseString; - result.m_content = responseString; - } else { - result.m_body = ""; - result.m_content = ""; - } - - result.m_requestTime = requestTime; - - // Get response headers - NSDictionary* respHeaders = httpResponse.allHeaderFields; - for (NSString* key in respHeaders) { - NSString* value = respHeaders[key]; - result.m_headers[[key UTF8String]] = [value UTF8String]; - } - } - - // Call callback on main thread - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - }]; - - // Start task - [task resume]; - } - @catch (NSException* exception) { - RequestResult result; - result.m_success = false; - result.m_statusCode = -1; - result.m_error = [[exception reason] UTF8String]; - result.m_body = ""; - result.m_content = ""; - result.m_requestTime = 0; - - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - } - }); - } - - // GET request (async) - void HttpClient::GetAsync(const std::string& url, CompletionCallback callback, int timeout) { - SendRequest(url, "GET", {}, "", timeout > 0 ? timeout : m_defaultTimeout, callback); - } - - // GET request with headers (async) - void HttpClient::GetAsync(const std::string& url, - const std::unordered_map& headers, - CompletionCallback callback, - int timeout) { - SendRequest(url, "GET", headers, "", timeout > 0 ? timeout : m_defaultTimeout, callback); - } - - // POST request (async) - void HttpClient::PostAsync(const std::string& url, - const std::string& body, - CompletionCallback callback, - int timeout) { - std::unordered_map headers = { - {"Content-Type", "application/x-www-form-urlencoded"} - }; - SendRequest(url, "POST", headers, body, timeout > 0 ? timeout : m_defaultTimeout, callback); - } - - // POST request with headers (async) - void HttpClient::PostAsync(const std::string& url, - const std::unordered_map& headers, - const std::string& body, - CompletionCallback callback, - int timeout) { - SendRequest(url, "POST", headers, body, timeout > 0 ? timeout : m_defaultTimeout, callback); - } - - // Upload file (sync) - bool HttpClient::UploadFile(const std::string& url, - const std::string& filePath, - std::string& responseText, - std::string& error) { - // Check if file exists - NSString* nsFilePath = [NSString stringWithUTF8String:filePath.c_str()]; - if (![[NSFileManager defaultManager] fileExistsAtPath:nsFilePath]) { - error = "File not found: " + filePath; - return false; - } - - // Create semaphore for sync wait - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - - // Success flag - __block bool success = false; - - // Upload the file asynchronously but wait for it to complete - UploadFileAsync(url, filePath, [&](const RequestResult& result) { - success = result.m_success; - responseText = result.m_body; - if (!result.m_success) { - error = result.m_error; - } - dispatch_semaphore_signal(semaphore); - }); - - // Wait for completion - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - return success; - } - - // Upload file async - void HttpClient::UploadFileAsync(const std::string& url, - const std::string& filePath, - CompletionCallback callback, - int timeout) { - // Ensure initialized - if (!m_initialized && !Initialize()) { - RequestResult result; - result.m_success = false; - result.m_statusCode = -1; - result.m_error = "HTTP client failed to initialize"; - result.m_body = ""; - result.m_content = ""; - result.m_requestTime = 0; - callback(result); - return; - } - - // Check if file exists - NSString* nsFilePath = [NSString stringWithUTF8String:filePath.c_str()]; - if (![[NSFileManager defaultManager] fileExistsAtPath:nsFilePath]) { - RequestResult result; - result.m_success = false; - result.m_statusCode = -1; - result.m_error = "File not found: " + filePath; - result.m_body = ""; - result.m_content = ""; - result.m_requestTime = 0; - callback(result); - return; - } - - // Get start time for performance tracking - uint64_t startTime = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - - // Perform on background thread - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), -^ -{ - @try { - // Create URL - NSString* urlString = [NSString stringWithUTF8String:url.c_str()]; - NSURL* nsUrl = [NSURL URLWithString:urlString]; - - if (!nsUrl) { - RequestResult result; - result.m_success = false; - result.m_statusCode = -1; - result.m_error = "Invalid URL: " + url; - result.m_body = ""; - result.m_content = ""; - result.m_requestTime = 0; - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - return; - } - - // Create request - NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; - [request setHTTPMethod:@"POST"]; - - // Set timeout - int actualTimeout = timeout > 0 ? timeout : m_defaultTimeout; - [request setTimeoutInterval:actualTimeout]; - - // Create boundary string for multipart - NSString* boundary = [NSString stringWithFormat:@"Boundary-%@", [[NSUUID UUID] UUIDString]]; - NSString* contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; - [request setValue:contentType forHTTPHeaderField:@"Content-Type"]; - - // Create body data - NSMutableData* body = [NSMutableData data]; - - // Add start boundary - [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - - // Get filename from path - NSString* fileName = [[nsFilePath lastPathComponent] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]; - - // Add content disposition - [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]]; - - // Add content type - [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; - - // Add file data - NSData* fileData = [NSData dataWithContentsOfFile:nsFilePath]; - [body appendData:fileData]; - [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; - - // Add end boundary - [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - - // Set body - [request setHTTPBody:body]; - - // Get session using proper ARC bridging - NSURLSession* session = (__bridge NSURLSession*)m_session; - - // Create upload task - NSURLSessionUploadTask* task = [session uploadTaskWithRequest:request - fromData:body - completionHandler: -^ -(NSData* data, NSURLResponse* response, NSError* error) { - // Calculate request time - uint64_t endTime = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - uint64_t requestTime = endTime - startTime; - - // Create result object - RequestResult result; - - if (error) { - // Handle error - result.m_success = false; - result.m_statusCode = (int)[error code]; - result.m_error = [[error localizedDescription] UTF8String]; - result.m_body = ""; - result.m_content = ""; - result.m_requestTime = requestTime; - } else { - // Handle success - NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; - result.m_success = (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300); - result.m_statusCode = (int)httpResponse.statusCode; - - // Get response data - if (data) { - std::string responseString((const char*)[data bytes], [data length]); - result.m_body = responseString; - result.m_content = responseString; - } else { - result.m_body = ""; - result.m_content = ""; - } - - result.m_requestTime = requestTime; - - // Get headers - NSDictionary* respHeaders = httpResponse.allHeaderFields; - for (NSString* key in respHeaders) { - NSString* value = [respHeaders objectForKey:key]; - result.m_headers[[key UTF8String]] = [value UTF8String]; - } - } - - // Call callback on main thread - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - }]; - - // Start task - [task resume]; - } - @catch (NSException* exception) { - RequestResult result; - result.m_success = false; - result.m_statusCode = -1; - result.m_error = [[exception reason] UTF8String]; - result.m_body = ""; - result.m_content = ""; - result.m_requestTime = 0; - - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - } - }); - } -} -} -#endif // __APPLE__ diff --git a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak5 b/source/cpp/ios/advanced_bypass/HttpClient.mm.bak5 deleted file mode 100644 index 6365c01e..00000000 --- a/source/cpp/ios/advanced_bypass/HttpClient.mm.bak5 +++ /dev/null @@ -1,278 +0,0 @@ -#include "../../ios_compat.h" -#include "HttpClient.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#import - -namespace iOS { -namespace AdvancedBypass { - - // Constructor - HttpClient::HttpClient(int defaultTimeout, bool useCache) - : m_initialized(false), - m_defaultTimeout(defaultTimeout), - m_useCache(useCache), - m_sessionConfig(nullptr), - m_session(nullptr) { - } - - // Destructor - HttpClient::~HttpClient() { - // Release NSURLSession and configuration with ARC-compatible bridging - if (m_session) { - // Use __bridge_transfer to transfer ownership from C++ to ARC - NSURLSession* session = (__bridge_transfer NSURLSession*)m_session; - m_session = nullptr; - - // No need to call release with ARC and __bridge_transfer - } - - if (m_sessionConfig) { - // Use __bridge_transfer to transfer ownership from C++ to ARC - NSURLSessionConfiguration* config = (__bridge_transfer NSURLSessionConfiguration*)m_sessionConfig; - m_sessionConfig = nullptr; - - // No need to call release with ARC and __bridge_transfer - } - } - - // Initialize the HTTP client - bool HttpClient::Initialize() { - // Check if already initialized - if (m_initialized) { - return true; - } - - @try { - // Create session configuration - NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; - config.timeoutIntervalForRequest = m_defaultTimeout; - config.timeoutIntervalForResource = m_defaultTimeout * 2; - config.HTTPMaximumConnectionsPerHost = 5; - - // Setup cache policy based on settings - config.requestCachePolicy = m_useCache ? - NSURLRequestReturnCacheDataElseLoad : - NSURLRequestReloadIgnoringLocalCacheData; - - // Set up headers to mimic a normal browser - config.HTTPAdditionalHeaders = @{ - @"User-Agent": @"Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1", - @"Accept": @"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - @"Accept-Language": @"en-US,en;q=0.9" - }; - - // Store configuration with ARC-compatible bridging - m_sessionConfig = (__bridge_retained void*)config; - - // Create session with ARC-compatible bridging - NSURLSession* session = [NSURLSession sessionWithConfiguration:config]; - m_session = (__bridge_retained void*)session; - - m_initialized = true; - return true; - } - @catch (NSException* exception) { - std::cerr << "HttpClient::Initialize failed: " << [[exception reason] UTF8String] << std::endl; - return false; - } - } - - // Send HTTP request with all parameters (private method) - void HttpClient::SendRequest(const std::string& url, - const std::string& method, - const std::unordered_map& headers, - const std::string& body, - int timeout, - CompletionCallback callback) { - // Ensure initialized - if (!m_initialized && !Initialize()) { - RequestResult result(false, -1, "HTTP client failed to initialize", "", 0); - callback(result); - return; - } - - // Get start time for performance tracking - uint64_t startTime = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - - // Perform on background thread to avoid blocking - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), -^ -{ - @try { - // Create URL - NSString* urlString = [NSString stringWithUTF8String:url.c_str()]; - NSURL* nsUrl = [NSURL URLWithString:urlString]; - - if (!nsUrl) { - RequestResult result(false, -1, "Invalid URL: " + url, "", 0); - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - return; - } - - // Create request - NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:nsUrl]; - - // Set method - [request setHTTPMethod:[NSString stringWithUTF8String:method.c_str()]]; - - // Set timeout - if (timeout > 0) { - [request setTimeoutInterval:timeout]; - } - - // Set headers - for (const auto& header : headers) { - NSString* key = [NSString stringWithUTF8String:header.first.c_str()]; - NSString* value = [NSString stringWithUTF8String:header.second.c_str()]; - [request setValue:value forHTTPHeaderField:key]; - } - - // Set body if not empty - if (!body.empty()) { - NSData* bodyData = [NSData dataWithBytes:body.c_str() length:body.length()]; - [request setHTTPBody:bodyData]; - } - - // Get session using proper ARC bridging - NSURLSession* session = (__bridge NSURLSession*)m_session; - - // Create data task - NSURLSessionDataTask* task = [session dataTaskWithRequest:request - completionHandler: -^ -(NSData* data, NSURLResponse* response, NSError* error) { - // Calculate request time - uint64_t endTime = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - uint64_t requestTime = endTime - startTime; - - // Create result object with initial values - bool success = false; - int statusCode = 0; - std::string errorStr = ""; - std::string content = ""; - std::unordered_map responseHeaders; - - if (error) { - // Handle error - success = false; - statusCode = (int)[error code]; - errorStr = [[error localizedDescription] UTF8String]; - } else { - // Handle success - NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; - success = (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300); - statusCode = (int)httpResponse.statusCode; - - // Get response data - if (data) { - // Convert data to string - content = std::string((const char*)[data bytes], [data length]); - } - - // Get response headers - NSDictionary* respHeaders = httpResponse.allHeaderFields; - for (NSString* key in respHeaders) { - NSString* value = respHeaders[key]; - responseHeaders[[key UTF8String]] = [value UTF8String]; - } - } - - // Create final result with all data - RequestResult result(success, statusCode, errorStr, content, requestTime); - result.m_headers = responseHeaders; - - // Call callback on main thread - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - }]; - - // Start task - [task resume]; - } - @catch (NSException* exception) { - RequestResult result(false, -1, [[exception reason] UTF8String], "", 0); - - dispatch_async(dispatch_get_main_queue(), -^ -{ - callback(result); - }); - } - }); - } - - // Synchronous GET request implementation - HttpClient::RequestResult HttpClient::Get(const std::string& url, int timeout) { - // Create a semaphore for synchronous wait - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - - // Response data - RequestResult result; - - // Make async call but wait for completion - GetAsync(url, [&result, &semaphore](const RequestResult& asyncResult) { - result = asyncResult; - dispatch_semaphore_signal(semaphore); - }, timeout); - - // Wait for completion - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - return result; - } - - // Asynchronous GET request - void HttpClient::GetAsync(const std::string& url, CompletionCallback callback, int timeout) { - SendRequest(url, "GET", {}, "", timeout > 0 ? timeout : m_defaultTimeout, callback); - } - - // Synchronous POST request implementation - HttpClient::RequestResult HttpClient::Post(const std::string& url, const std::string& body, int timeout) { - // Create a semaphore for synchronous wait - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - - // Response data - RequestResult result; - - // Make async call but wait for completion - PostAsync(url, body, [&result, &semaphore](const RequestResult& asyncResult) { - result = asyncResult; - dispatch_semaphore_signal(semaphore); - }, timeout); - - // Wait for completion - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - return result; - } - - // Asynchronous POST request - void HttpClient::PostAsync(const std::string& url, const std::string& body, - CompletionCallback callback, int timeout) { - std::unordered_map headers = { - {"Content-Type", "application/x-www-form-urlencoded"} - }; - SendRequest(url, "POST", headers, body, timeout > 0 ? timeout : m_defaultTimeout, callback); - } -} -} -#endif // __APPLE__ diff --git a/source/cpp/ios/advanced_bypass/MethodSwizzlingExploit.mm.bak b/source/cpp/ios/advanced_bypass/MethodSwizzlingExploit.mm.bak deleted file mode 100644 index c6fc135b..00000000 --- a/source/cpp/ios/advanced_bypass/MethodSwizzlingExploit.mm.bak +++ /dev/null @@ -1,734 +0,0 @@ - -#include "../../ios_compat.h" -#include "MethodSwizzlingExploit.h" -#include -#include -#include -#import -#import - -// Helper function to log messages -static void LogMessage(const char* format, ...) { - va_list args; - va_start(args, format); - NSLogv([NSString stringWithUTF8String:format], args); - va_end(args); -} - -// Objective-C delegate class for receiving execution callbacks -@interface SwizzleDelegate : NSObject -@property (nonatomic, assign) iOS::AdvancedBypass::MethodSwizzlingExploit* exploitInstance; -@property (nonatomic, copy) NSString* pendingScript; -@property (nonatomic, copy) NSString* executionOutput; -@property (nonatomic, assign) BOOL executionCompleted; -@end - -@implementation SwizzleDelegate - -- (id)init { - self = [super init]; - if (self) { - self.pendingScript = nil; - self.executionOutput = @""; - self.executionCompleted = NO; - } - return self; -} - -// Method to execute Lua code (simulated for prototype) -- (BOOL)executeLuaScript:(NSString*)script { - @try { - // In a real implementation, we would have a Lua interpreter here - // For this prototype, we'll simulate Lua execution with JavaScript - - // Create a controlled environment - JSContext* context = [[JSContext alloc] init]; - - // Set up console.log to capture output - context[@"consoleLog"] = ^(NSString* str) { - self.executionOutput = [self.executionOutput stringByAppendingFormat:@"%@\n", str]; - }; - - // Inject the console.log wrapper - [context evaluateScript:@"function print(message) { consoleLog(message); }"]; - - // Create a simulated game environment - NSString* gameEnvSetup = @"var game = {" - " GetService: function(name) {" - " return { Name: name };" - " }," - " Players: {" - " LocalPlayer: {" - " Name: 'Player1'," - " Character: {" - " HumanoidRootPart: {" - " Position: { X: 0, Y: 0, Z: 0 }" - " }" - " }" - " }" - " }" - "};"; - - [context evaluateScript:gameEnvSetup]; - - // Execute the script - NSString* jsScript = [script stringByReplacingOccurrencesOfString:@":" withString:@"."]; - [context evaluateScript:jsScript]; - - self.executionCompleted = YES; - return YES; - } - @catch (NSException* exception) { - self.executionOutput = [self.executionOutput stringByAppendingFormat:@"Error: %@\n", [exception reason]]; - self.executionCompleted = YES; - return NO; - } -} - -// Timer callback method -- (void)executeTimerCallback:(NSTimer*)timer { - NSString* script = timer.userInfo; - if (script) { - [self executeLuaScript:script]; - } -} - -// Notification callback method -- (void)handleNotification:(NSNotification*)notification { - NSString* script = notification.userInfo[@"script"]; - if (script) { - [self executeLuaScript:script]; - } -} - -@end - -namespace iOS { -namespace AdvancedBypass { - - // Constructor - MethodSwizzlingExploit::MethodSwizzlingExploit(Strategy strategy) - : m_strategy(strategy), - m_isInitialized(false), - m_delegateObject(nullptr), - m_timerObject(nullptr), - m_outputCallback(nullptr) { - } - - // Destructor - MethodSwizzlingExploit::~MethodSwizzlingExploit() { - // Clean up swizzled methods - RestoreOriginalMethods(); - - // Clean up delegate object (manual memory management) - if (m_delegateObject) { - SwizzleDelegate* delegate = (SwizzleDelegate*)m_delegateObject; - [delegate release]; - m_delegateObject = nullptr; - } - - // Clean up timer object (manual memory management) - if (m_timerObject) { - NSTimer* timer = (NSTimer*)m_timerObject; - [timer invalidate]; - [timer release]; - m_timerObject = nullptr; - } - } - - // Initialize the method swizzling exploit - bool MethodSwizzlingExploit::Initialize() { - // Check if already initialized - if (m_isInitialized) { - return true; - } - - // Create delegate object (manual memory management) - SwizzleDelegate* delegate = [[SwizzleDelegate alloc] init]; - delegate.exploitInstance = this; - m_delegateObject = (void*)delegate; - [delegate retain]; - - // Determine and set up the best strategy - if (m_strategy == Strategy::AutomaticBest) { - m_strategy = DetermineOptimalStrategy(); - } - - // Initialize the selected strategy - bool success = false; - - switch (m_strategy) { - case Strategy::MethodReplacement: - success = SetupMethodReplacement(); - break; - - case Strategy::MessageInterception: - success = SetupMessageInterception(); - break; - - case Strategy::DelegateHijacking: - success = SetupDelegateHijacking(); - break; - - case Strategy::TimerExecution: - success = SetupTimerExecution(); - break; - - case Strategy::NotificationCenter: - success = SetupNotificationCenter(); - break; - - default: - std::cerr << "MethodSwizzlingExploit: Unknown strategy" << std::endl; - return false; - } - - if (success) { - m_isInitialized = true; - std::cout << "MethodSwizzlingExploit: Successfully initialized with strategy: " - << StrategyToString(m_strategy) << std::endl; - } else { - std::cerr << "MethodSwizzlingExploit: Failed to initialize with strategy: " - << StrategyToString(m_strategy) << std::endl; - } - - return m_isInitialized; - } - - // Execute a Lua script using method swizzling - MethodSwizzlingExploit::ExecutionResult MethodSwizzlingExploit::Execute(const std::string& script) { - // Check if initialized - if (!m_isInitialized) { - return ExecutionResult(false, "Method swizzling exploit not initialized"); - } - - // Start timing - auto startTime = std::chrono::high_resolution_clock::now(); - - // Prepare the script - std::string preparedScript = PrepareScript(script); - - // Execute using the selected strategy - bool success = ExecuteViaStrategy(preparedScript, m_strategy); - - // Get the output - std::string output = m_executionOutput; - - // Calculate execution time - auto endTime = std::chrono::high_resolution_clock::now(); - uint64_t executionTime = std::chrono::duration_cast(endTime - startTime).count(); - - // Create result - std::string error = success ? "" : "Execution failed with strategy: " + StrategyToString(m_strategy); - return ExecutionResult(success, error, output, executionTime); - } - - // Change the execution strategy - bool MethodSwizzlingExploit::SetStrategy(Strategy strategy) { - // Cannot change strategy while initialized - if (m_isInitialized) { - // Need to reinitialize with new strategy - RestoreOriginalMethods(); - m_isInitialized = false; - } - - // Set new strategy - m_strategy = strategy; - - // Re-initialize with new strategy - return Initialize(); - } - - // Get the current execution strategy - MethodSwizzlingExploit::Strategy MethodSwizzlingExploit::GetStrategy() const { - return m_strategy; - } - - // Set output callback - void MethodSwizzlingExploit::SetOutputCallback(const OutputCallback& callback) { - m_outputCallback = callback; - } - - // Execute via the current strategy - bool MethodSwizzlingExploit::ExecuteViaStrategy(const std::string& script, Strategy strategy) { - // Get the delegate - SwizzleDelegate* delegate = (__bridge SwizzleDelegate*)m_delegateObject; - if (!delegate) { - return false; - } - - // Reset execution state - delegate.executionOutput = @""; - delegate.executionCompleted = NO; - - // Store the script - NSString* nsScript = [NSString stringWithUTF8String:script.c_str()]; - delegate.pendingScript = nsScript; - - // Use different execution methods based on strategy - switch (strategy) { - case Strategy::MethodReplacement: - case Strategy::MessageInterception: - { - // These strategies have already set up the environment for execution - // Directly execute using the delegate - return [delegate executeLuaScript:nsScript]; - } - - case Strategy::DelegateHijacking: - { - // Use a custom selector call to trigger execution - SEL executeSel = NSSelectorFromString(@"executeLuaScript:"); - if ([delegate respondsToSelector:executeSel]) { - [delegate performSelector:executeSel withObject:nsScript]; - return delegate.executionCompleted; - } - return false; - } - - case Strategy::TimerExecution: - { - // Execute via timer - if (!m_timerObject) { - // Create a timer for execution (manual memory management) - NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:0.1 - target:delegate - selector:@selector(executeTimerCallback:) - userInfo:nsScript - repeats:NO]; - m_timerObject = (void*)timer; - [timer retain]; - - // Wait for timer to fire - NSRunLoop* runLoop = [NSRunLoop currentRunLoop]; - NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow:5.0]; - - while (!delegate.executionCompleted && [timeoutDate timeIntervalSinceNow] > 0) { - [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; - } - - [timer invalidate]; - CFRelease(m_timerObject); - m_timerObject = nullptr; - - return delegate.executionCompleted; - } - return false; - } - - case Strategy::NotificationCenter: - { - // Execute via notification - [[NSNotificationCenter defaultCenter] postNotificationName:@"ExecuteLuaScript" - object:nil - userInfo:@{@"script": nsScript}]; - - // Wait for execution to complete - NSRunLoop* runLoop = [NSRunLoop currentRunLoop]; - NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow:5.0]; - - while (!delegate.executionCompleted && [timeoutDate timeIntervalSinceNow] > 0) { - [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; - } - - return delegate.executionCompleted; - } - - default: - { - return false; - } - } - } - - // Set up method replacement strategy - bool MethodSwizzlingExploit::SetupMethodReplacement() { - // This strategy replaces methods in a common Objective-C class with our own implementation - - // For this example, we'll swizzle an NSString method as it's commonly used and unlikely to break anything - - // Get the delegate - SwizzleDelegate* delegate = (__bridge SwizzleDelegate*)m_delegateObject; - if (!delegate) { - return false; - } - - @try { - // Find the method we want to swizzle - Method originalMethod = class_getInstanceMethod([NSString class], @selector(stringByAppendingString:)); - if (!originalMethod) { - std::cerr << "MethodSwizzlingExploit: Failed to find method to swizzle" << std::endl; - return false; - } - - // Store original implementation - IMP originalImplementation = method_getImplementation(originalMethod); - m_originalMethods["stringByAppendingString:"] = (void*)originalImplementation; - - // Create a block that will check for a special trigger string and execute our code if found - IMP newImplementation = imp_implementationWithBlock(^NSString*(id self, NSString* aString) { - // Check if this is our trigger - if ([aString isEqualToString:@"__EXECUTE_LUA__"] && delegate.pendingScript) { - // Execute the pending script - [delegate executeLuaScript:delegate.pendingScript]; - - // Return a normal result so nothing breaks - return ((NSString* (*)(id, SEL, NSString*))originalImplementation)(self, @selector(stringByAppendingString:), @""); - } - - // Call original implementation for normal usage - return ((NSString* (*)(id, SEL, NSString*))originalImplementation)(self, @selector(stringByAppendingString:), aString); - }); - - // Swizzle the method - method_setImplementation(originalMethod, newImplementation); - - // Add to swizzled methods list for cleanup - m_swizzledMethods.push_back((void*)originalMethod); - - // Test the swizzle - [@"test" stringByAppendingString:@"__EXECUTE_LUA__"]; - - return true; - } - @catch (NSException* exception) { - std::cerr << "MethodSwizzlingExploit: Exception during method replacement setup: " - << [[exception reason] UTF8String] << std::endl; - return false; - } - } - - // Set up message interception strategy - bool MethodSwizzlingExploit::SetupMessageInterception() { - // This strategy intercepts messages between objects - - // Get the delegate - SwizzleDelegate* delegate = (__bridge SwizzleDelegate*)m_delegateObject; - if (!delegate) { - return false; - } - - @try { - // For this example, we'll intercept alloc messages to NSObject - // This is a common message that's sent frequently - - // Get the class method - Method originalMethod = class_getClassMethod([NSObject class], @selector(alloc)); - if (!originalMethod) { - std::cerr << "MethodSwizzlingExploit: Failed to find method to intercept" << std::endl; - return false; - } - - // Store original implementation - IMP originalImplementation = method_getImplementation(originalMethod); - m_originalMethods["alloc"] = (void*)originalImplementation; - - // Create a block that will intercept the message - IMP newImplementation = imp_implementationWithBlock(^id(Class cls) { - // Trigger execution on a specific class name pattern - if ([NSStringFromClass(cls) hasSuffix:@"ExecutorTrigger"] && delegate.pendingScript) { - // Execute the pending script - [delegate executeLuaScript:delegate.pendingScript]; - } - - // Call original implementation - return ((id (*)(Class, SEL))originalImplementation)(cls, @selector(alloc)); - }); - - // Swizzle the method - method_setImplementation(originalMethod, newImplementation); - - // Add to swizzled methods list for cleanup - m_swizzledMethods.push_back((void*)originalMethod); - - return true; - } - @catch (NSException* exception) { - std::cerr << "MethodSwizzlingExploit: Exception during message interception setup: " - << [[exception reason] UTF8String] << std::endl; - return false; - } - } - - // Set up delegate hijacking strategy - bool MethodSwizzlingExploit::SetupDelegateHijacking() { - // This strategy hijacks delegate methods to execute our code - - // Get the delegate - SwizzleDelegate* delegate = (__bridge SwizzleDelegate*)m_delegateObject; - if (!delegate) { - return false; - } - - @try { - // For this example, we'll create a dummy delegate mechanism - - // Make sure our delegate responds to the execution selector - SEL executeSel = NSSelectorFromString(@"executeLuaScript:"); - if (![delegate respondsToSelector:executeSel]) { - std::cerr << "MethodSwizzlingExploit: Delegate missing required method" << std::endl; - return false; - } - - return true; - } - @catch (NSException* exception) { - std::cerr << "MethodSwizzlingExploit: Exception during delegate hijacking setup: " - << [[exception reason] UTF8String] << std::endl; - return false; - } - } - - // Set up timer execution strategy - bool MethodSwizzlingExploit::SetupTimerExecution() { - // This strategy uses timers to execute our code - - // Get the delegate - SwizzleDelegate* delegate = (__bridge SwizzleDelegate*)m_delegateObject; - if (!delegate) { - return false; - } - - @try { - // Make sure our delegate responds to the timer callback selector - SEL timerSel = @selector(executeTimerCallback:); - if (![delegate respondsToSelector:timerSel]) { - std::cerr << "MethodSwizzlingExploit: Delegate missing timer callback method" << std::endl; - return false; - } - - return true; - } - @catch (NSException* exception) { - std::cerr << "MethodSwizzlingExploit: Exception during timer execution setup: " - << [[exception reason] UTF8String] << std::endl; - return false; - } - } - - // Set up notification center strategy - bool MethodSwizzlingExploit::SetupNotificationCenter() { - // This strategy uses the notification center to execute our code - - // Get the delegate - SwizzleDelegate* delegate = (__bridge SwizzleDelegate*)m_delegateObject; - if (!delegate) { - return false; - } - - @try { - // Make sure our delegate responds to the notification handler selector - SEL notifSel = @selector(handleNotification:); - if (![delegate respondsToSelector:notifSel]) { - std::cerr << "MethodSwizzlingExploit: Delegate missing notification handler method" << std::endl; - return false; - } - - // Register for notifications - [[NSNotificationCenter defaultCenter] addObserver:delegate - selector:notifSel - name:@"ExecuteLuaScript" - object:nil]; - - return true; - } - @catch (NSException* exception) { - std::cerr << "MethodSwizzlingExploit: Exception during notification center setup: " - << [[exception reason] UTF8String] << std::endl; - return false; - } - } - - // Restore original methods - bool MethodSwizzlingExploit::RestoreOriginalMethods() { - if (m_swizzledMethods.empty()) { - return true; // Nothing to restore - } - - @try { - // Restore each swizzled method - for (const auto& methodEntry : m_originalMethods) { - // Find the method - SEL selector = NSSelectorFromString([NSString stringWithUTF8String:methodEntry.first.c_str()]); - - // Check if it's an instance or class method - bool isClassMethod = methodEntry.first == "alloc"; // example - add more as needed - - Class targetClass = [NSObject class]; // default - - if (methodEntry.first == "stringByAppendingString:") { - targetClass = [NSString class]; - } - - Method method = isClassMethod ? - class_getClassMethod(targetClass, selector) : - class_getInstanceMethod(targetClass, selector); - - if (method) { - // Restore original implementation - method_setImplementation(method, (IMP)methodEntry.second); - } - } - - // Clear swizzled methods - m_swizzledMethods.clear(); - m_originalMethods.clear(); - - return true; - } - @catch (NSException* exception) { - std::cerr << "MethodSwizzlingExploit: Exception during method restoration: " - << [[exception reason] UTF8String] << std::endl; - return false; - } - } - - // Process output - void MethodSwizzlingExploit::ProcessOutput(const std::string& output) { - // Store the output - m_executionOutput = output; - - // Call the output callback if set - if (m_outputCallback && !output.empty()) { - m_outputCallback(output); - } - } - - // Prepare script for execution - std::string MethodSwizzlingExploit::PrepareScript(const std::string& script) { - // Add a Lua environment for the script - std::string environment = CreateLuaEnvironment(); - return environment + "\n" + script; - } - - // Determine the optimal strategy for the current device - MethodSwizzlingExploit::Strategy MethodSwizzlingExploit::DetermineOptimalStrategy() { - // Get available strategies - std::vector strategies = GetAvailableStrategies(); - - // For iOS 14.5+ without JIT, timer execution tends to be the most reliable - if (@available(iOS 14.5, *)) { - if (std::find(strategies.begin(), strategies.end(), Strategy::TimerExecution) != strategies.end()) { - return Strategy::TimerExecution; - } - } - - // For older iOS versions, method replacement is often most reliable - if (std::find(strategies.begin(), strategies.end(), Strategy::MethodReplacement) != strategies.end()) { - return Strategy::MethodReplacement; - } - - // Fallback to notification center if available - if (std::find(strategies.begin(), strategies.end(), Strategy::NotificationCenter) != strategies.end()) { - return Strategy::NotificationCenter; - } - - // Last resort - return Strategy::DelegateHijacking; - } - - // Create a Lua environment for the script - std::string MethodSwizzlingExploit::CreateLuaEnvironment() { - // Create a basic Lua environment - std::stringstream env; - - env << "-- Environment setup\n"; - env << "local game = {}\n"; - env << "local workspace = {}\n"; - env << "\n"; - env << "-- Set up game functions\n"; - env << "function game:GetService(name)\n"; - env << " if name == 'Players' then\n"; - env << " return {\n"; - env << " LocalPlayer = {\n"; - env << " Name = 'Player1',\n"; - env << " Character = {\n"; - env << " HumanoidRootPart = {\n"; - env << " Position = {X=0, Y=0, Z=0}\n"; - env << " }\n"; - env << " }\n"; - env << " }\n"; - env << " }\n"; - env << " end\n"; - env << " return {Name = name}\n"; - env << "end\n"; - env << "\n"; - - return env.str(); - } - - // Check if method swizzling is available - bool MethodSwizzlingExploit::IsAvailable() { - // Method swizzling should be available on all iOS versions - return true; - } - - // Get available strategies - std::vector MethodSwizzlingExploit::GetAvailableStrategies() { - std::vector strategies; - - // These strategies should work on all iOS versions - strategies.push_back(Strategy::MethodReplacement); - strategies.push_back(Strategy::DelegateHijacking); - strategies.push_back(Strategy::TimerExecution); - strategies.push_back(Strategy::NotificationCenter); - - // Message interception might not work reliably on newer iOS versions - if (@available(iOS 14.0, *)) { - // It still works but with some limitations - } else { - strategies.push_back(Strategy::MessageInterception); - } - - return strategies; - } - - // Convert strategy enum to string - std::string MethodSwizzlingExploit::StrategyToString(Strategy strategy) { - switch (strategy) { - case Strategy::MethodReplacement: - return "MethodReplacement"; - case Strategy::MessageInterception: - return "MessageInterception"; - case Strategy::DelegateHijacking: - return "DelegateHijacking"; - case Strategy::TimerExecution: - return "TimerExecution"; - case Strategy::NotificationCenter: - return "NotificationCenter"; - case Strategy::AutomaticBest: - return "AutomaticBest"; - default: - return "Unknown"; - } - } - - // Get strategy description - std::string MethodSwizzlingExploit::GetStrategyDescription(Strategy strategy) { - switch (strategy) { - case Strategy::MethodReplacement: - return "Replaces methods in Objective-C classes to execute code"; - case Strategy::MessageInterception: - return "Intercepts messages between objects to execute code"; - case Strategy::DelegateHijacking: - return "Hijacks delegate methods to execute code"; - case Strategy::TimerExecution: - return "Uses timer callbacks to execute code"; - case Strategy::NotificationCenter: - return "Uses notification center for execution"; - case Strategy::AutomaticBest: - return "Automatically selects the best strategy for the device"; - default: - return "Unknown strategy"; - } - } - -} // namespace AdvancedBypass -} // namespace iOS - -// Implementation of missing methods -std::string iOS::AdvancedBypass::MethodSwizzlingExploit::ExecuteScript(const std::string& script) { - // Wrapper for Execute that returns just the output - ExecutionResult result = Execute(script); - return result.m_output; -} diff --git a/source/cpp/ios/advanced_bypass/WebKitExploit.mm.bak b/source/cpp/ios/advanced_bypass/WebKitExploit.mm.bak deleted file mode 100644 index 83415c83..00000000 --- a/source/cpp/ios/advanced_bypass/WebKitExploit.mm.bak +++ /dev/null @@ -1,658 +0,0 @@ - -#include "../../ios_compat.h" -#include "WebKitExploit.h" -#include -#include -#include -#import -#import - -// Bridge class for handling script messages from WKWebView -@interface ScriptMessageHandler : NSObject -@property (nonatomic, assign) iOS::AdvancedBypass::WebKitExploit* exploitInstance; -@property (nonatomic, copy) void (^outputHandler)(NSString*); -@end - -// Navigation delegate for handling page load events -@interface WebViewNavigationDelegate : NSObject -@property (nonatomic, assign) BOOL* pageLoadedPtr; -@property (nonatomic, assign) BOOL* successPtr; -@property (nonatomic, assign) WKWebView* webView; -@end - -@implementation ScriptMessageHandler -- (void)userContentController:(WKUserContentController *)userContentController - didReceiveScriptMessage:(WKScriptMessage *)message { - // Process message from JavaScript - if ([message.name isEqualToString:@"luaExecBridge"]) { - // Extract message body - NSString* output = nil; - if ([message.body isKindOfClass:[NSString class]]) { - output = (NSString*)message.body; - } else if ([message.body isKindOfClass:[NSDictionary class]]) { - NSDictionary* body = (NSDictionary*)message.body; - output = body[@"output"]; - } - - // Forward output to handler - if (output && self.outputHandler) { - self.outputHandler(output); - } - } -} -@end - -@implementation WebViewNavigationDelegate -- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { - if (self.pageLoadedPtr) { - *self.pageLoadedPtr = YES; - - // Test the bridge by executing a simple script - void (^completion)(id, NSError*) = ^(id result, NSError* error) { - if (!error && self.successPtr) { - *self.successPtr = YES; - } else { - NSLog(@"WebKitExploit: Bridge test failed: %@", error); - } - }; - - [self.webView evaluateJavaScript:@"window.LuaJSBridge.executeLua('print(\"Bridge test\")')" - completionHandler:completion]; - } -} -@end - -namespace iOS { -namespace AdvancedBypass { - - // Constructor - WebKitExploit::WebKitExploit() - : m_webView(nullptr), - m_bridgeScriptHandler(nullptr), - m_isInitialized(false), - m_isConfigured(false), - m_outputCallback(nullptr) { - } - - // Destructor - WebKitExploit::~WebKitExploit() { - // Clean up Objective-C objects - no ARC bridge transfers needed - if (m_bridgeScriptHandler) { - // In non-ARC mode, we need to manually release - ScriptMessageHandler* handler = (ScriptMessageHandler*)m_bridgeScriptHandler; - [handler release]; - m_bridgeScriptHandler = nullptr; - } - - if (m_webView) { - // In non-ARC mode, we need to manually release - WKWebView* webView = (WKWebView*)m_webView; - [webView release]; - m_webView = nullptr; - } - } - - // Initialize the WebKit execution environment - bool WebKitExploit::Initialize() { - @autoreleasepool { - // Check if already initialized - if (m_isInitialized) { - return true; - } - - // Create a script message handler - ScriptMessageHandler* handler = [[ScriptMessageHandler alloc] init]; - handler.exploitInstance = this; - handler.outputHandler = ^(NSString* output) { - if (output && this->m_outputCallback) { - this->m_outputCallback([output UTF8String]); - } - }; - - // Store handler - no ARC bridge needed in non-ARC mode - m_bridgeScriptHandler = (void*)handler; - // Manually retain the object in non-ARC mode - [handler retain]; - - // Create a web view configuration - WKWebViewConfiguration* config = [[WKWebViewConfiguration alloc] init]; - - // Configure WKWebView for best performance - config.suppressesIncrementalRendering = YES; - config.allowsInlineMediaPlayback = NO; - config.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; - - // Enable content rule list for enhanced privacy (hides from some detection) - if (@available(iOS 11.0, *)) { - if (config.websiteDataStore && [config.websiteDataStore respondsToSelector:@selector(isNonPersistent)]) { - config.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; - } - } - - // Set up JavaScript preferences - WKPreferences* preferences = [[WKPreferences alloc] init]; - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - preferences.javaScriptEnabled = YES; - #pragma clang diagnostic pop - - // Maximize JIT performance where available - if (@available(iOS 14.0, *)) { - if ([WKPreferences respondsToSelector:@selector(javaScriptCanOpenWindowsAutomatically)]) { - preferences.javaScriptCanOpenWindowsAutomatically = NO; - } - } - - config.preferences = preferences; - - // Set up user content controller for script messaging - WKUserContentController* userContentController = [[WKUserContentController alloc] init]; - [userContentController addScriptMessageHandler:handler name:@"luaExecBridge"]; - config.userContentController = userContentController; - - // Create web view with minimal size (not shown to user) - WKWebView* webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 1, 1) configuration:config]; - webView.hidden = YES; - - // Attach to view hierarchy (required for proper functioning) - UIWindow* keyWindow = nil; - if (@available(iOS 13.0, *)) { - for (UIWindowScene* scene in [[UIApplication sharedApplication] connectedScenes]) { - if (scene.activationState == UISceneActivationStateForegroundActive) { - for (UIWindow* window in scene.windows) { - if (window.isKeyWindow) { - keyWindow = window; - break; - } - } - if (keyWindow) break; - } - } - } else { - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - keyWindow = [[[UIApplication sharedApplication] windows] firstObject]; - #pragma clang diagnostic pop - } - - if (!keyWindow) { - std::cerr << "WebKitExploit: Failed to find key window" << std::endl; - return false; - } - - [keyWindow addSubview:webView]; - - // Store web view - no ARC bridge needed in non-ARC mode - m_webView = (void*)webView; - // Manually retain the object in non-ARC mode - [webView retain]; - - // Inject bridge script - m_isInitialized = InjectBridgeScript(); - - if (m_isInitialized) { - std::cout << "WebKitExploit: Successfully initialized WebKit environment" << std::endl; - } else { - std::cerr << "WebKitExploit: Failed to initialize WebKit environment" << std::endl; - } - - return m_isInitialized; - } - } - - // Inject the bridge script - bool WebKitExploit::InjectBridgeScript() { - if (!m_webView) { - return false; - } - - @autoreleasepool { - WKWebView* webView = (__bridge WKWebView*)m_webView; - - // Inject our bridge script - NSString* bridgeScript = - @"(function() {\n" - @" // LuaJS bridge for WebKit execution\n" - @" window.LuaJSBridge = {\n" - @" // Console output capture\n" - @" _output: '',\n" - @" \n" - @" // Clear captured output\n" - @" clearOutput: function() {\n" - @" this._output = '';\n" - @" },\n" - @" \n" - @" // Send output to native side\n" - @" sendOutput: function() {\n" - @" window.webkit.messageHandlers.luaExecBridge.postMessage({\n" - @" output: this._output\n" - @" });\n" - @" },\n" - @" \n" - @" // Execute Lua code\n" - @" executeLua: function(luaCode) {\n" - @" try {\n" - @" // In a real implementation, we would use a Lua-to-JS\n" - @" // bridge to execute actual Lua code\n" - @" // For this prototype, we'll simulate Lua execution\n" - @" \n" - @" // Create a controlled execution environment\n" - @" var sandbox = {\n" - @" print: function(text) {\n" - @" window.LuaJSBridge._output += text + '\\n';\n" - @" console.log(text);\n" - @" },\n" - @" game: createGameEnvironment(),\n" - @" workspace: createWorkspaceEnvironment()\n" - @" };\n" - @" \n" - @" // Simulate Lua execution by evaluating its JS equivalent\n" - @" // This is where the actual Lua->JS bridge would be used\n" - @" this.clearOutput();\n" - @" var result = evalInContext(luaCode, sandbox);\n" - @" this._output += 'Result: ' + result + '\\n';\n" - @" this.sendOutput();\n" - @" return true;\n" - @" } catch (error) {\n" - @" this._output += 'Error: ' + error.message + '\\n';\n" - @" this.sendOutput();\n" - @" return false;\n" - @" }\n" - @" }\n" - @" };\n" - @" \n" - @" // Helper function to create a controlled game environment\n" - @" function createGameEnvironment() {\n" - @" return {\n" - @" GetService: function(serviceName) {\n" - @" return createService(serviceName);\n" - @" },\n" - @" Players: createService('Players'),\n" - @" Workspace: createService('Workspace'),\n" - @" Lighting: createService('Lighting')\n" - @" };\n" - @" }\n" - @" \n" - @" // Helper function to create a workspace environment\n" - @" function createWorkspaceEnvironment() {\n" - @" return {\n" - @" // Workspace properties and methods\n" - @" FindFirstChild: function(name) {\n" - @" return { Name: name };\n" - @" }\n" - @" };\n" - @" }\n" - @" \n" - @" // Helper function to create a service\n" - @" function createService(name) {\n" - @" if (name === 'Players') {\n" - @" return {\n" - @" LocalPlayer: {\n" - @" Name: 'Player1',\n" - @" Character: {\n" - @" HumanoidRootPart: {\n" - @" Position: { X: 0, Y: 0, Z: 0 }\n" - @" }\n" - @" }\n" - @" },\n" - @" GetPlayers: function() {\n" - @" return [this.LocalPlayer];\n" - @" }\n" - @" };\n" - @" } else {\n" - @" return { Name: name };\n" - @" }\n" - @" }\n" - @" \n" - @" // Helper function to evaluate code in a controlled context\n" - @" function evalInContext(code, context) {\n" - @" // Create a function that runs in the sandbox context\n" - @" var params = Object.keys(context);\n" - @" var args = Object.values(context);\n" - @" \n" - @" // Convert Lua-like code to JavaScript\n" - @" // This is a very simplified conversion for demonstration\n" - @" var jsCode = code\n" - @" .replace(/print\\(/g, 'print(')\n" - @" .replace(/game:GetService\\(/g, 'game.GetService(')\n" - @" .replace(/\\bfunction\\s+([\\w_]+)\\s*\\(/g, 'function $1(')\n" - @" .replace(/\\bend\\b/g, '}')\n" - @" .replace(/\\bif\\s+(.+)\\s+then\\b/g, 'if ($1) {')\n" - @" .replace(/\\belse\\b/g, '} else {')\n" - @" .replace(/\\blocal\\s+/g, 'var ');\n" - @" \n" - @" var functionBody = '\"use strict\"; ' + jsCode;\n" - @" var sandboxedFunction = new Function(...params, functionBody);\n" - @" \n" - @" return sandboxedFunction(...args);\n" - @" }\n" - @" \n" - @" // Notify that the bridge is ready\n" - @" window.webkit.messageHandlers.luaExecBridge.postMessage('Bridge ready');\n" - @"})();\n"; - - // Inject script as user script for persistence - WKUserScript* userScript = [[WKUserScript alloc] - initWithSource:bridgeScript - injectionTime:WKUserScriptInjectionTimeAtDocumentStart - forMainFrameOnly:YES]; - - [webView.configuration.userContentController addUserScript:userScript]; - - // Load a minimal HTML page - NSString* html = @""; - [webView loadHTMLString:html baseURL:nil]; - - // Wait for the page to load - __block BOOL pageLoaded = NO; - __block BOOL success = NO; - - // Create and configure the navigation delegate - WebViewNavigationDelegate* navDelegate = [[WebViewNavigationDelegate alloc] init]; - navDelegate.pageLoadedPtr = &pageLoaded; - navDelegate.successPtr = &success; - navDelegate.webView = webView; - webView.navigationDelegate = navDelegate; - - // Wait for the page to load with a timeout - NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow:5.0]; - NSRunLoop* runLoop = [NSRunLoop currentRunLoop]; - - while (!pageLoaded && [timeoutDate timeIntervalSinceNow] > 0) { - [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; - } - - return success; - } - } - - // Execute a Lua script using WebKit process - WebKitExploit::ExecutionResult WebKitExploit::Execute(const std::string& script) { - // Check if initialized - if (!m_isInitialized || !m_webView) { - return ExecutionResult(false, "WebKit environment not initialized"); - } - - // Start timing - auto startTime = std::chrono::high_resolution_clock::now(); - - // Prepare the script - std::string preparedScript = PrepareScript(script); - - // Execute the script - @autoreleasepool { - WKWebView* webView = (__bridge WKWebView*)m_webView; - - // Capture output - __block bool success = false; - __block std::string output; - __block std::string error; - __block bool executionCompleted = false; - - // Sanitize script for JavaScript injection - NSString* jsScript = [NSString stringWithFormat:@"window.LuaJSBridge.executeLua(`%@`)", - [NSString stringWithUTF8String:preparedScript.c_str()]]; - - // Replace backticks in the script to avoid breaking the JS template string - jsScript = [jsScript stringByReplacingOccurrencesOfString:@"`" withString:@"\\`"]; - - // Execute in WebKit - [webView evaluateJavaScript:jsScript completionHandler:^(id result, NSError* jsError) { - if (jsError) { - error = [[jsError localizedDescription] UTF8String]; - success = false; - } else if ([result isKindOfClass:[NSNumber class]]) { - success = [(NSNumber*)result boolValue]; - } else { - success = (result != nil); - } - - executionCompleted = true; - }]; - - // Wait for completion with timeout - NSRunLoop* runLoop = [NSRunLoop currentRunLoop]; - NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow:5.0]; - - while (!executionCompleted && [timeoutDate timeIntervalSinceNow] > 0) { - [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; - } - - // Handle timeout - if (!executionCompleted) { - error = "Execution timed out"; - success = false; - } - - // Calculate execution time - auto endTime = std::chrono::high_resolution_clock::now(); - uint64_t executionTime = std::chrono::duration_cast(endTime - startTime).count(); - - return ExecutionResult(success, error, output, executionTime); - } - } - - // Execute JavaScript directly in WebKit - WebKitExploit::ExecutionResult WebKitExploit::ExecuteJavaScript(const std::string& script) { - // Check if initialized - if (!m_isInitialized || !m_webView) { - return ExecutionResult(false, "WebKit environment not initialized"); - } - - // Start timing - auto startTime = std::chrono::high_resolution_clock::now(); - - // Obfuscate the script - std::string obfuscatedScript = ObfuscateJavaScript(script); - - // Execute the script - @autoreleasepool { - WKWebView* webView = (__bridge WKWebView*)m_webView; - - __block bool success = false; - __block std::string output; - __block std::string error; - __block bool executionCompleted = false; - - NSString* jsScript = [NSString stringWithUTF8String:obfuscatedScript.c_str()]; - - // Execute in WebKit - [webView evaluateJavaScript:jsScript completionHandler:^(id result, NSError* jsError) { - if (jsError) { - error = [[jsError localizedDescription] UTF8String]; - success = false; - } else { - if ([result isKindOfClass:[NSString class]]) { - output = [(NSString*)result UTF8String]; - } else if ([result isKindOfClass:[NSNumber class]]) { - output = [[(NSNumber*)result stringValue] UTF8String]; - } - success = true; - } - - executionCompleted = true; - }]; - - // Wait for completion with timeout - NSRunLoop* runLoop = [NSRunLoop currentRunLoop]; - NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow:5.0]; - - while (!executionCompleted && [timeoutDate timeIntervalSinceNow] > 0) { - [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; - } - - // Handle timeout - if (!executionCompleted) { - error = "Execution timed out"; - success = false; - } - - // Calculate execution time - auto endTime = std::chrono::high_resolution_clock::now(); - uint64_t executionTime = std::chrono::duration_cast(endTime - startTime).count(); - - return ExecutionResult(success, error, output, executionTime); - } - } - - // Check if the WebKit environment is ready - bool WebKitExploit::IsReady() const { - return m_isInitialized && m_webView != nullptr; - } - - // Set a callback for execution output - void WebKitExploit::SetOutputCallback(const OutputCallback& callback) { - m_outputCallback = callback; - } - - // Set a user script to be preloaded - bool WebKitExploit::SetUserScript(const std::string& script) { - if (!m_isInitialized) { - return false; - } - - m_userScript = script; - return true; - } - - // Clear any preloaded user script - void WebKitExploit::ClearUserScript() { - m_userScript.clear(); - } - - // Prepare a script for execution - std::string WebKitExploit::PrepareScript(const std::string& script) { - // Combine user script with provided script - std::string fullScript = script; - if (!m_userScript.empty()) { - fullScript = m_userScript + "\n\n" + script; - } - - // Wrap the script in an execution wrapper - return GenerateExecutionWrapper(fullScript); - } - - // Generate an execution wrapper for the script - std::string WebKitExploit::GenerateExecutionWrapper(const std::string& script) { - std::stringstream wrapper; - - // Add utility functions - wrapper << "-- Utility functions added by the Executor\n"; - wrapper << "local function printTable(t, indent)\n"; - wrapper << " indent = indent or 0\n"; - wrapper << " local spaces = string.rep(' ', indent * 2)\n"; - wrapper << " for k, v in pairs(t) do\n"; - wrapper << " if type(v) == 'table' then\n"; - wrapper << " print(spaces .. k .. ' = {')\n"; - wrapper << " printTable(v, indent + 1)\n"; - wrapper << " print(spaces .. '}')\n"; - wrapper << " else\n"; - wrapper << " print(spaces .. k .. ' = ' .. tostring(v))\n"; - wrapper << " end\n"; - wrapper << " end\n"; - wrapper << "end\n\n"; - - // Add try-catch wrapper - wrapper << "-- Error handling wrapper\n"; - wrapper << "local status, result = pcall(function()\n"; - wrapper << script << "\n"; - wrapper << "end)\n\n"; - - // Add error reporting - wrapper << "if not status then\n"; - wrapper << " print('Error: ' .. tostring(result))\n"; - wrapper << "end\n"; - wrapper << "return status\n"; - - return wrapper.str(); - } - - // Obfuscate JavaScript - std::string WebKitExploit::ObfuscateJavaScript(const std::string& script) { - // This is a simplified obfuscation for demonstration - // A real implementation would use more sophisticated obfuscation - - // Create a wrapper that adds a layer of indirection - std::stringstream obfuscated; - - // Add a self-executing function wrapper - obfuscated << "(function() {\n"; - obfuscated << " var _e = function(c) { return eval(c); };\n"; - obfuscated << " var _r = _e('" << script << "');\n"; - obfuscated << " return _r;\n"; - obfuscated << "})();\n"; - - return obfuscated.str(); - } - - // Process output from script execution - void WebKitExploit::ProcessOutput(const std::string& output) { - if (m_outputCallback && !output.empty()) { - m_outputCallback(output); - } - } - - // Generate a CSP bypass script - std::string WebKitExploit::GenerateCSPBypassScript() { - // This helps bypass Content Security Policy restrictions - return R"( - (function() { - // Attempt to modify CSP settings - var meta = document.createElement('meta'); - meta.setAttribute('http-equiv', 'Content-Security-Policy'); - meta.setAttribute('content', "default-src * 'unsafe-inline' 'unsafe-eval'"); - document.head.appendChild(meta); - - // Override the CSP reporting function - if (window.CSPViolationReporter) { - window.CSPViolationReporter.reportViolation = function() {}; - } - - // Try to hook SecurityPolicyViolationEvent - window.addEventListener('securitypolicyviolation', function(e) { - e.stopImmediatePropagation(); - return false; - }, true); - - return "CSP bypass applied"; - })(); - )"; - } - - // Check if WebKit JIT compilation is available - bool WebKitExploit::IsJITAvailable() { - // Starting in iOS 14.5, JIT is disabled by default but can be enabled in some contexts - @autoreleasepool { - JSContext* context = [[JSContext alloc] init]; - - // Try to execute a complex function that would benefit from JIT - NSString* jitTestScript = - @"(function() {\n" - @" var start = Date.now();\n" - @" var result = 0;\n" - @" for (var i = 0; i < 1000000; i++) {\n" - @" result += Math.sin(i * 0.01) * Math.cos(i * 0.01);\n" - @" }\n" - @" var end = Date.now();\n" - @" return (end - start) < 500; // If JIT is enabled, this should complete within 500ms\n" - @"})();\n"; - - JSValue* result = [context evaluateScript:jitTestScript]; - return [result toBool]; - } - } - -} // namespace AdvancedBypass -} // namespace iOS - -// Implementation of missing methods -bool iOS::AdvancedBypass::WebKitExploit::IsAvailable() const { - // Combine IsJITAvailable with IsReady status - return IsJITAvailable() && IsReady(); -} - -std::string iOS::AdvancedBypass::WebKitExploit::ExecuteScript(const std::string& script) { - // Wrapper for Execute that returns just the output - ExecutionResult result = Execute(script); - return result.m_output; -} diff --git a/source/cpp/ios/ai_features/AIIntegration.mm.backup b/source/cpp/ios/ai_features/AIIntegration.mm.backup deleted file mode 100644 index f33966be..00000000 --- a/source/cpp/ios/ai_features/AIIntegration.mm.backup +++ /dev/null @@ -1,698 +0,0 @@ - -#include "../../ios_compat.h" -#include "AIIntegration.h" -#include "AIConfig.h" -#include "AISystemInitializer.h" -#include "ScriptAssistant.h" -#include "SignatureAdaptation.h" -#include "local_models/ScriptGenerationModel.h" -#include "vulnerability_detection/VulnerabilityDetector.h" -#include "HybridAISystem.h" -#include "OfflineAISystem.h" -#include "../../filesystem_utils.h" - -// UI includes -#include -#include - -namespace iOS { -namespace AIFeatures { - -/** - * @class AIIntegration - * @brief Integrates AI features with the rest of the executor - * - * This class serves as a bridge between the AI components and the rest of the system, - * handling initialization, memory management, and coordination between components. - */ -class AIIntegration { -private: - // Member variables with consistent m_ prefix - std::shared_ptr m_scriptAssistant; - std::shared_ptr m_signatureAdaptation; - std::shared_ptr m_mainViewController; - std::shared_ptr m_vulnerabilityViewController; - std::shared_ptr m_scriptGenerationModel; - std::shared_ptr m_vulnerabilityDetector; - std::shared_ptr m_hybridAI; - std::shared_ptr m_offlineAI; - bool m_aiInitialized; - bool m_modelsLoaded; - bool m_isInLowMemoryMode; - std::string m_modelsPath; - - // Singleton instance - static AIIntegration* s_instance; - - // Private constructor for singleton - AIIntegration() - : m_aiInitialized(false), - m_modelsLoaded(false), - m_isInLowMemoryMode(false) { - - // Set up models path - NSBundle* mainBundle = [NSBundle mainBundle]; - m_modelsPath = [[mainBundle resourcePath] UTF8String]; - m_modelsPath += "/Models"; - - // Ensure models directory exists (it will be empty, models are trained locally) - NSFileManager* fileManager = [NSFileManager defaultManager]; - NSString* modelsPath = [NSString stringWithUTF8String:m_modelsPath.c_str()]; - - if (![fileManager fileExistsAtPath:modelsPath]) { - [fileManager createDirectoryAtPath:modelsPath - withIntermediateDirectories:YES - attributes:nil - error:nil]; - } - - // Register for memory warnings using a C function - static auto memoryWarningCallback = ^(NSNotification *note) { - iOS::AIFeatures::AIIntegration::GetSharedInstance()->HandleMemoryWarning(); - }; - - [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidReceiveMemoryWarningNotification - object:nil - queue:[NSOperationQueue mainQueue] - usingBlock:memoryWarningCallback]; - } - -public: - /** - * @brief Get shared instance - * @return Shared instance - */ - static AIIntegration* GetSharedInstance() { - if (!s_instance) { - s_instance = new AIIntegration(); - } - return s_instance; - } - - /** - * @brief Destructor - */ - ~AIIntegration() { - // Don't try to remove specific observer, just clean up what's needed - // The block-based observer is automatically removed when it goes out of scope - } - - /** - * @brief Initialize AI components - * @param progressCallback Function to call with initialization progress (0.0-1.0) - * @return True if initialization succeeded, false otherwise - */ - bool Initialize(std::function progressCallback = nullptr) { - if (m_aiInitialized) { - return true; - } - - try { - // Create necessary directories - std::string aiDataPath = FileUtils::JoinPaths(FileUtils::GetDocumentsPath(), "AIData"); - if (!FileUtils::Exists(aiDataPath)) { - FileUtils::CreateDirectory(aiDataPath); - } - - if (progressCallback) progressCallback(0.1f); - - // Create directory for locally trained models - std::string localModelsPath = FileUtils::JoinPaths(FileUtils::GetDocumentsPath(), "AIData/LocalModels"); - if (!FileUtils::Exists(localModelsPath)) { - FileUtils::CreateDirectory(localModelsPath); - } - - // Create directory for vulnerability detection - std::string vulnerabilitiesPath = FileUtils::JoinPaths(FileUtils::GetDocumentsPath(), "AIData/Vulnerabilities"); - if (!FileUtils::Exists(vulnerabilitiesPath)) { - FileUtils::CreateDirectory(vulnerabilitiesPath); - } - - if (progressCallback) progressCallback(0.2f); - - // Initialize local script generation model - m_scriptGenerationModel = std::make_shared(); - bool scriptGenInitialized = m_scriptGenerationModel->Initialize(localModelsPath + "/script_generator"); - - if (!scriptGenInitialized) { - std::cerr << "AIIntegration: Warning - Failed to initialize script generation model" << std::endl; - // Continue anyway, as we can recover later - } - - if (progressCallback) progressCallback(0.3f); - - // Initialize vulnerability detector - m_vulnerabilityDetector = std::make_shared(); - bool vulnerabilityInitialized = m_vulnerabilityDetector->Initialize(vulnerabilitiesPath); - - if (!vulnerabilityInitialized) { - std::cerr << "AIIntegration: Warning - Failed to initialize vulnerability detector" << std::endl; - // Continue anyway, as we can recover later - } - - if (progressCallback) progressCallback(0.4f); - - // Initialize hybrid AI system (works both online and offline) - m_hybridAI = std::make_shared(); - bool hybridInitialized = m_hybridAI->Initialize( - localModelsPath, // Local model path - "", // No API endpoint (fully local) - "" // No API key (fully local) - ); - - if (!hybridInitialized) { - std::cerr << "AIIntegration: Warning - Failed to initialize hybrid AI" << std::endl; - } - - if (progressCallback) progressCallback(0.5f); - - // Initialize offline AI system (works completely offline) - m_offlineAI = std::make_shared(); - bool offlineInitialized = m_offlineAI->Initialize(localModelsPath); - - if (!offlineInitialized) { - std::cerr << "AIIntegration: Warning - Failed to initialize offline AI" << std::endl; - } - - if (progressCallback) progressCallback(0.6f); - - // Initialize script assistant - m_scriptAssistant = std::make_shared(); - bool assistantInitialized = m_scriptAssistant->Initialize(); - - if (!assistantInitialized) { - std::cerr << "AIIntegration: Failed to initialize script assistant" << std::endl; - // Continue anyway, we'll try to recover or use fallbacks - } - - if (progressCallback) progressCallback(0.7f); - - // Initialize signature adaptation - m_signatureAdaptation = std::make_shared(); - bool adaptationInitialized = m_signatureAdaptation->Initialize(); - - if (!adaptationInitialized) { - std::cerr << "AIIntegration: Failed to initialize signature adaptation" << std::endl; - // Continue anyway, we'll try to recover or use fallbacks - } - - if (progressCallback) progressCallback(0.8f); - - // Initialize vulnerability view controller - m_vulnerabilityViewController = std::make_shared(); - bool vulnerabilityVCInitialized = m_vulnerabilityViewController->Initialize(); - - if (vulnerabilityVCInitialized) { - m_vulnerabilityViewController->SetVulnerabilityDetector(m_vulnerabilityDetector); - } else { - std::cerr << "AIIntegration: Failed to initialize vulnerability view controller" << std::endl; - } - - if (progressCallback) progressCallback(0.9f); - - m_aiInitialized = true; - m_modelsLoaded = true; // Models are now generated locally, not loaded - std::cout << "AIIntegration: Successfully initialized" << std::endl; - - if (progressCallback) progressCallback(1.0f); - - return true; - } catch (const std::exception& e) { - std::cerr << "AIIntegration: Exception during initialization: " << e.what() << std::endl; - if (progressCallback) progressCallback(1.0f); - return false; - } - } - - /** - * @brief Set up UI for AI features - * @param mainViewController Main view controller - */ - void SetupUI(std::shared_ptr mainViewController) { - m_mainViewController = mainViewController; - - if (!m_aiInitialized) { - std::cerr << "AIIntegration: Cannot set up UI before initialization" << std::endl; - return; - } - - // Connect script assistant to UI - m_mainViewController->SetScriptAssistant(m_scriptAssistant); - - // Set up script assistant callbacks using the correct signature - if (m_scriptAssistant) { - m_scriptAssistant->SetResponseCallback([this](const std::string& message, bool success) { - // Handle assistant responses - // In a real implementation, this would update the UI - std::cout << "ScriptAssistant: " << message << (success ? " (success)" : " (failed)") << std::endl; - }); - } - - // Add vulnerability view controller to main UI - if (m_vulnerabilityViewController && m_vulnerabilityViewController->GetViewController()) { - // In a real implementation, this would add the vulnerability view controller - // to the main view controller's navigation stack or tab bar - - // Set up vulnerability scan callback - m_vulnerabilityViewController->SetScanButtonCallback([this]() { - // Start vulnerability scan - if (m_vulnerabilityDetector) { - // Get current game ID and name (placeholder implementation) - std::string gameId = "current_game"; - std::string gameName = "Current Game"; - - m_vulnerabilityViewController->StartScan(gameId, gameName); - } - }); - - // Set up vulnerability exploit callback - m_vulnerabilityViewController->SetExploitButtonCallback([this]( - const VulnerabilityDetection::VulnerabilityDetector::Vulnerability& vulnerability) { - // Exploit vulnerability - if (m_scriptAssistant) { - m_scriptAssistant->ExecuteScript(vulnerability.m_exploitCode); - std::cout << "Executed exploit: " << vulnerability.m_name << std::endl; - } - }); - } - - std::cout << "AIIntegration: Set up UI integration" << std::endl; - } - - /** - * @brief Handle memory warning - */ - void HandleMemoryWarning() { - std::cout << "AIIntegration: Handling memory warning" << std::endl; - - // Set low memory mode - m_isInLowMemoryMode = true; - - // Release non-essential resources - if (m_scriptAssistant) { - } - - if (m_hybridAI) { - m_hybridAI->HandleMemoryWarning(); - } - - if (m_offlineAI) { - m_offlineAI->HandleMemoryWarning(); - } - - if (m_vulnerabilityDetector) { - // Cancel any active scan - m_vulnerabilityDetector->CancelScan(); - } - } - - /** - * @brief Handle app entering foreground - */ - void HandleAppForeground() { - std::cout << "AIIntegration: Handling app foreground" << std::endl; - - // Reset low memory mode - m_isInLowMemoryMode = false; - - // Network status may have changed, update hybrid AI - if (m_hybridAI) { - m_hybridAI->HandleNetworkStatusChange(true); - } - } - - /** - * @brief Get script assistant - * @return Script assistant instance - */ - std::shared_ptr GetScriptAssistant() const { - return m_scriptAssistant; - } - - /** - * @brief Get signature adaptation - * @return Signature adaptation instance - */ - std::shared_ptr GetSignatureAdaptation() const { - return m_signatureAdaptation; - } - - /** - * @brief Get vulnerability detector - * @return Vulnerability detector instance - */ - std::shared_ptr GetVulnerabilityDetector() const { - return m_vulnerabilityDetector; - } - - /** - * @brief Get vulnerability view controller - * @return Vulnerability view controller instance - */ - std::shared_ptr GetVulnerabilityViewController() const { - return m_vulnerabilityViewController; - } - - /** - * @brief Check if AI is initialized - * @return True if initialized, false otherwise - */ - bool IsInitialized() const { - return m_aiInitialized; - } - - /** - * @brief Check if models are loaded - * @return True if loaded, false otherwise - */ - bool AreModelsLoaded() const { - return m_modelsLoaded; - } - - /** - * @brief Get memory usage - * @return Memory usage in bytes - */ - uint64_t GetMemoryUsage() const { - uint64_t total = 0; - - if (m_scriptAssistant) { - // Placeholder - would calculate actual memory usage - total += 10 * 1024 * 1024; // Assume 10MB - } - - if (m_signatureAdaptation) { - // Placeholder - would calculate actual memory usage - total += 5 * 1024 * 1024; // Assume 5MB - } - - if (m_hybridAI) { - total += m_hybridAI->GetMemoryUsage(); - } - - if (m_offlineAI) { - total += m_offlineAI->GetMemoryUsage(); - } - - if (m_vulnerabilityDetector) { - // Placeholder - would calculate actual memory usage - total += 15 * 1024 * 1024; // Assume 15MB - } - - return total; - } - - /** - * @brief Process an AI query - * @param query User query - * @param callback Callback function for response - */ - void ProcessQuery(const std::string& query, std::function callback) { - if (!m_aiInitialized) { - if (callback) { - callback("AI system not initialized"); - } - return; - } - - // Check if in low memory mode - if (m_isInLowMemoryMode) { - // Use offline AI in low memory mode - if (m_offlineAI) { - m_offlineAI->ProcessQuery(query, callback); - return; - } - } - - // Use hybrid AI normally - if (m_hybridAI) { - m_hybridAI->ProcessQuery(query, callback); - } else if (m_offlineAI) { - // Fall back to offline AI if hybrid not available - m_offlineAI->ProcessQuery(query, callback); - } else if (callback) { - callback("AI processing not available"); - } - } - - /** - * @brief Generate a script - * @param description Script description - * @param callback Callback function for the generated script - */ - void GenerateScript(const std::string& description, std::function callback) { - if (!m_aiInitialized) { - if (callback) { - callback("AI system not initialized"); - } - return; - } - - // Check if in low memory mode - if (m_isInLowMemoryMode) { - // Use offline AI in low memory mode - if (m_offlineAI) { - m_offlineAI->GenerateScript(description, "", callback); - return; - } - } - - // Use script generation model directly if available - if (m_scriptGenerationModel) { - try { - LocalModels::ScriptGenerationModel::GeneratedScript script = - m_scriptGenerationModel->GenerateScript(description); - - if (callback) { - callback(script.m_code); - } - return; - } catch (const std::exception& e) { - // Fall back to hybrid AI on error - std::cerr << "AIIntegration: Error generating script: " << e.what() << std::endl; - } - } - - // Fall back to hybrid AI - if (m_hybridAI) { - m_hybridAI->GenerateScript(description, "", callback); - } else if (m_offlineAI) { - m_offlineAI->GenerateScript(description, "", callback); - } else if (callback) { - callback("Script generation not available"); - } - } - - /** - * @brief Debug a script - * @param script Script to debug - * @param callback Callback function for debug results - */ - void DebugScript(const std::string& script, std::function callback) { - if (!m_aiInitialized) { - if (callback) { - callback("AI system not initialized"); - } - return; - } - - // Check if in low memory mode - if (m_isInLowMemoryMode) { - // Use offline AI in low memory mode - if (m_offlineAI) { - m_offlineAI->DebugScript(script, callback); - return; - } - } - - // Use hybrid AI - if (m_hybridAI) { - m_hybridAI->DebugScript(script, callback); - } else if (m_offlineAI) { - m_offlineAI->DebugScript(script, callback); - } else if (callback) { - callback("Script debugging not available"); - } - } - - /** - * @brief Scan current game for vulnerabilities - * @param gameId Game ID - * @param gameName Game name - * @param progressCallback Callback for scan progress - * @param completeCallback Callback for scan completion - * @return True if scan started successfully - */ - bool ScanForVulnerabilities( - const std::string& gameId, - const std::string& gameName, - std::function progressCallback = nullptr, - std::function completeCallback = nullptr) { - - if (!m_aiInitialized || !m_vulnerabilityDetector) { - if (completeCallback) { - completeCallback(false); - } - return false; - } - - // Create game object (placeholder) - auto gameRoot = std::make_shared( - "Game", "DataModel"); - - // Set up callbacks - VulnerabilityDetection::VulnerabilityDetector::ScanProgressCallback progress = nullptr; - if (progressCallback) { - progress = [progressCallback]( - const VulnerabilityDetection::VulnerabilityDetector::ScanProgress& scanProgress) { - progressCallback(scanProgress.m_progress, scanProgress.m_currentActivity); - }; - } - - VulnerabilityDetection::VulnerabilityDetector::ScanCompleteCallback complete = nullptr; - if (completeCallback) { - complete = [completeCallback]( - const VulnerabilityDetection::VulnerabilityDetector::ScanResult& result) { - completeCallback(result.m_scanComplete); - }; - } - - // Start scan - return m_vulnerabilityDetector->StartScan(gameId, gameName, gameRoot, progress, complete); - } -}; - -// Initialize static instance -AIIntegration* AIIntegration::s_instance = nullptr; - -} // namespace AIFeatures -} // namespace iOS - -// We don't need this Objective-C category anymore since we're using a block directly - -// Expose C functions for integration -extern "C" { - -void* InitializeAI(void (*progressCallback)(float)) { - auto integration = iOS::AIFeatures::AIIntegration::GetSharedInstance(); - - // Convert C function pointer to C++ function - std::function progressFunc = progressCallback ? - [progressCallback](float progress) { progressCallback(progress); } : - std::function(); - - // Initialize AI - integration->Initialize(progressFunc); - - // Return opaque pointer to integration for future calls - return integration; -} - -void SetupAIWithUI(void* integration, void* viewController) { - auto aiIntegration = static_cast(integration); - auto mainVC = *static_cast*>(viewController); - - aiIntegration->SetupUI(mainVC); -} - -void* GetScriptAssistant(void* integration) { - auto aiIntegration = static_cast(integration); - // Store in a static variable to avoid returning address of temporary - static std::shared_ptr scriptAssistant; - scriptAssistant = aiIntegration->GetScriptAssistant(); - return &scriptAssistant; -} - -void* GetSignatureAdaptation(void* integration) { - auto aiIntegration = static_cast(integration); - // Store in a static variable to avoid returning address of temporary - static std::shared_ptr signatureAdaptation; - signatureAdaptation = aiIntegration->GetSignatureAdaptation(); - return &signatureAdaptation; -} - -uint64_t GetAIMemoryUsage(void* integration) { - auto aiIntegration = static_cast(integration); - return aiIntegration->GetMemoryUsage(); -} - -void HandleAppForeground(void* integration) { - auto aiIntegration = static_cast(integration); - aiIntegration->HandleAppForeground(); -} - -void HandleAppMemoryWarning(void* integration) { - auto aiIntegration = static_cast(integration); - aiIntegration->HandleMemoryWarning(); -} - -void ProcessAIQuery(void* integration, const char* query, void (*callback)(const char*)) { - auto aiIntegration = static_cast(integration); - - // Create C++ callback that forwards to C callback - auto cppCallback = [callback](const std::string& response) { - callback(response.c_str()); - }; - - aiIntegration->ProcessQuery(query, cppCallback); -} - -void GenerateScript(void* integration, const char* description, void (*callback)(const char*)) { - auto aiIntegration = static_cast(integration); - - // Create C++ callback that forwards to C callback - auto cppCallback = [callback](const std::string& script) { - callback(script.c_str()); - }; - - aiIntegration->GenerateScript(description, cppCallback); -} - -void DebugScript(void* integration, const char* script, void (*callback)(const char*)) { - auto aiIntegration = static_cast(integration); - - // Create C++ callback that forwards to C callback - auto cppCallback = [callback](const std::string& results) { - callback(results.c_str()); - }; - - aiIntegration->DebugScript(script, cppCallback); -} - -void* GetVulnerabilityViewController(void* integration) { - auto aiIntegration = static_cast(integration); - // Store in a static variable to avoid returning address of temporary - static std::shared_ptr vulnerabilityViewController; - vulnerabilityViewController = aiIntegration->GetVulnerabilityViewController(); - return &vulnerabilityViewController; -} - -bool ScanForVulnerabilities(void* integration, const char* gameId, const char* gameName, - void (*progressCallback)(float, const char*), - void (*completeCallback)(bool)) { - auto aiIntegration = static_cast(integration); - - // Create C++ callbacks - std::function progress = nullptr; - if (progressCallback) { - progress = [progressCallback](float progressValue, const std::string& status) { - progressCallback(progressValue, status.c_str()); - }; - } - - std::function complete = nullptr; - if (completeCallback) { - complete = [completeCallback](bool success) { - completeCallback(success); - }; - } - - return aiIntegration->ScanForVulnerabilities( - gameId ? gameId : "", - gameName ? gameName : "", - progress, - complete - ); -} - -} // extern "C" diff --git a/source/cpp/ios/ai_features/AIIntegration.mm.orig b/source/cpp/ios/ai_features/AIIntegration.mm.orig deleted file mode 100644 index f33966be..00000000 --- a/source/cpp/ios/ai_features/AIIntegration.mm.orig +++ /dev/null @@ -1,698 +0,0 @@ - -#include "../../ios_compat.h" -#include "AIIntegration.h" -#include "AIConfig.h" -#include "AISystemInitializer.h" -#include "ScriptAssistant.h" -#include "SignatureAdaptation.h" -#include "local_models/ScriptGenerationModel.h" -#include "vulnerability_detection/VulnerabilityDetector.h" -#include "HybridAISystem.h" -#include "OfflineAISystem.h" -#include "../../filesystem_utils.h" - -// UI includes -#include -#include - -namespace iOS { -namespace AIFeatures { - -/** - * @class AIIntegration - * @brief Integrates AI features with the rest of the executor - * - * This class serves as a bridge between the AI components and the rest of the system, - * handling initialization, memory management, and coordination between components. - */ -class AIIntegration { -private: - // Member variables with consistent m_ prefix - std::shared_ptr m_scriptAssistant; - std::shared_ptr m_signatureAdaptation; - std::shared_ptr m_mainViewController; - std::shared_ptr m_vulnerabilityViewController; - std::shared_ptr m_scriptGenerationModel; - std::shared_ptr m_vulnerabilityDetector; - std::shared_ptr m_hybridAI; - std::shared_ptr m_offlineAI; - bool m_aiInitialized; - bool m_modelsLoaded; - bool m_isInLowMemoryMode; - std::string m_modelsPath; - - // Singleton instance - static AIIntegration* s_instance; - - // Private constructor for singleton - AIIntegration() - : m_aiInitialized(false), - m_modelsLoaded(false), - m_isInLowMemoryMode(false) { - - // Set up models path - NSBundle* mainBundle = [NSBundle mainBundle]; - m_modelsPath = [[mainBundle resourcePath] UTF8String]; - m_modelsPath += "/Models"; - - // Ensure models directory exists (it will be empty, models are trained locally) - NSFileManager* fileManager = [NSFileManager defaultManager]; - NSString* modelsPath = [NSString stringWithUTF8String:m_modelsPath.c_str()]; - - if (![fileManager fileExistsAtPath:modelsPath]) { - [fileManager createDirectoryAtPath:modelsPath - withIntermediateDirectories:YES - attributes:nil - error:nil]; - } - - // Register for memory warnings using a C function - static auto memoryWarningCallback = ^(NSNotification *note) { - iOS::AIFeatures::AIIntegration::GetSharedInstance()->HandleMemoryWarning(); - }; - - [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidReceiveMemoryWarningNotification - object:nil - queue:[NSOperationQueue mainQueue] - usingBlock:memoryWarningCallback]; - } - -public: - /** - * @brief Get shared instance - * @return Shared instance - */ - static AIIntegration* GetSharedInstance() { - if (!s_instance) { - s_instance = new AIIntegration(); - } - return s_instance; - } - - /** - * @brief Destructor - */ - ~AIIntegration() { - // Don't try to remove specific observer, just clean up what's needed - // The block-based observer is automatically removed when it goes out of scope - } - - /** - * @brief Initialize AI components - * @param progressCallback Function to call with initialization progress (0.0-1.0) - * @return True if initialization succeeded, false otherwise - */ - bool Initialize(std::function progressCallback = nullptr) { - if (m_aiInitialized) { - return true; - } - - try { - // Create necessary directories - std::string aiDataPath = FileUtils::JoinPaths(FileUtils::GetDocumentsPath(), "AIData"); - if (!FileUtils::Exists(aiDataPath)) { - FileUtils::CreateDirectory(aiDataPath); - } - - if (progressCallback) progressCallback(0.1f); - - // Create directory for locally trained models - std::string localModelsPath = FileUtils::JoinPaths(FileUtils::GetDocumentsPath(), "AIData/LocalModels"); - if (!FileUtils::Exists(localModelsPath)) { - FileUtils::CreateDirectory(localModelsPath); - } - - // Create directory for vulnerability detection - std::string vulnerabilitiesPath = FileUtils::JoinPaths(FileUtils::GetDocumentsPath(), "AIData/Vulnerabilities"); - if (!FileUtils::Exists(vulnerabilitiesPath)) { - FileUtils::CreateDirectory(vulnerabilitiesPath); - } - - if (progressCallback) progressCallback(0.2f); - - // Initialize local script generation model - m_scriptGenerationModel = std::make_shared(); - bool scriptGenInitialized = m_scriptGenerationModel->Initialize(localModelsPath + "/script_generator"); - - if (!scriptGenInitialized) { - std::cerr << "AIIntegration: Warning - Failed to initialize script generation model" << std::endl; - // Continue anyway, as we can recover later - } - - if (progressCallback) progressCallback(0.3f); - - // Initialize vulnerability detector - m_vulnerabilityDetector = std::make_shared(); - bool vulnerabilityInitialized = m_vulnerabilityDetector->Initialize(vulnerabilitiesPath); - - if (!vulnerabilityInitialized) { - std::cerr << "AIIntegration: Warning - Failed to initialize vulnerability detector" << std::endl; - // Continue anyway, as we can recover later - } - - if (progressCallback) progressCallback(0.4f); - - // Initialize hybrid AI system (works both online and offline) - m_hybridAI = std::make_shared(); - bool hybridInitialized = m_hybridAI->Initialize( - localModelsPath, // Local model path - "", // No API endpoint (fully local) - "" // No API key (fully local) - ); - - if (!hybridInitialized) { - std::cerr << "AIIntegration: Warning - Failed to initialize hybrid AI" << std::endl; - } - - if (progressCallback) progressCallback(0.5f); - - // Initialize offline AI system (works completely offline) - m_offlineAI = std::make_shared(); - bool offlineInitialized = m_offlineAI->Initialize(localModelsPath); - - if (!offlineInitialized) { - std::cerr << "AIIntegration: Warning - Failed to initialize offline AI" << std::endl; - } - - if (progressCallback) progressCallback(0.6f); - - // Initialize script assistant - m_scriptAssistant = std::make_shared(); - bool assistantInitialized = m_scriptAssistant->Initialize(); - - if (!assistantInitialized) { - std::cerr << "AIIntegration: Failed to initialize script assistant" << std::endl; - // Continue anyway, we'll try to recover or use fallbacks - } - - if (progressCallback) progressCallback(0.7f); - - // Initialize signature adaptation - m_signatureAdaptation = std::make_shared(); - bool adaptationInitialized = m_signatureAdaptation->Initialize(); - - if (!adaptationInitialized) { - std::cerr << "AIIntegration: Failed to initialize signature adaptation" << std::endl; - // Continue anyway, we'll try to recover or use fallbacks - } - - if (progressCallback) progressCallback(0.8f); - - // Initialize vulnerability view controller - m_vulnerabilityViewController = std::make_shared(); - bool vulnerabilityVCInitialized = m_vulnerabilityViewController->Initialize(); - - if (vulnerabilityVCInitialized) { - m_vulnerabilityViewController->SetVulnerabilityDetector(m_vulnerabilityDetector); - } else { - std::cerr << "AIIntegration: Failed to initialize vulnerability view controller" << std::endl; - } - - if (progressCallback) progressCallback(0.9f); - - m_aiInitialized = true; - m_modelsLoaded = true; // Models are now generated locally, not loaded - std::cout << "AIIntegration: Successfully initialized" << std::endl; - - if (progressCallback) progressCallback(1.0f); - - return true; - } catch (const std::exception& e) { - std::cerr << "AIIntegration: Exception during initialization: " << e.what() << std::endl; - if (progressCallback) progressCallback(1.0f); - return false; - } - } - - /** - * @brief Set up UI for AI features - * @param mainViewController Main view controller - */ - void SetupUI(std::shared_ptr mainViewController) { - m_mainViewController = mainViewController; - - if (!m_aiInitialized) { - std::cerr << "AIIntegration: Cannot set up UI before initialization" << std::endl; - return; - } - - // Connect script assistant to UI - m_mainViewController->SetScriptAssistant(m_scriptAssistant); - - // Set up script assistant callbacks using the correct signature - if (m_scriptAssistant) { - m_scriptAssistant->SetResponseCallback([this](const std::string& message, bool success) { - // Handle assistant responses - // In a real implementation, this would update the UI - std::cout << "ScriptAssistant: " << message << (success ? " (success)" : " (failed)") << std::endl; - }); - } - - // Add vulnerability view controller to main UI - if (m_vulnerabilityViewController && m_vulnerabilityViewController->GetViewController()) { - // In a real implementation, this would add the vulnerability view controller - // to the main view controller's navigation stack or tab bar - - // Set up vulnerability scan callback - m_vulnerabilityViewController->SetScanButtonCallback([this]() { - // Start vulnerability scan - if (m_vulnerabilityDetector) { - // Get current game ID and name (placeholder implementation) - std::string gameId = "current_game"; - std::string gameName = "Current Game"; - - m_vulnerabilityViewController->StartScan(gameId, gameName); - } - }); - - // Set up vulnerability exploit callback - m_vulnerabilityViewController->SetExploitButtonCallback([this]( - const VulnerabilityDetection::VulnerabilityDetector::Vulnerability& vulnerability) { - // Exploit vulnerability - if (m_scriptAssistant) { - m_scriptAssistant->ExecuteScript(vulnerability.m_exploitCode); - std::cout << "Executed exploit: " << vulnerability.m_name << std::endl; - } - }); - } - - std::cout << "AIIntegration: Set up UI integration" << std::endl; - } - - /** - * @brief Handle memory warning - */ - void HandleMemoryWarning() { - std::cout << "AIIntegration: Handling memory warning" << std::endl; - - // Set low memory mode - m_isInLowMemoryMode = true; - - // Release non-essential resources - if (m_scriptAssistant) { - } - - if (m_hybridAI) { - m_hybridAI->HandleMemoryWarning(); - } - - if (m_offlineAI) { - m_offlineAI->HandleMemoryWarning(); - } - - if (m_vulnerabilityDetector) { - // Cancel any active scan - m_vulnerabilityDetector->CancelScan(); - } - } - - /** - * @brief Handle app entering foreground - */ - void HandleAppForeground() { - std::cout << "AIIntegration: Handling app foreground" << std::endl; - - // Reset low memory mode - m_isInLowMemoryMode = false; - - // Network status may have changed, update hybrid AI - if (m_hybridAI) { - m_hybridAI->HandleNetworkStatusChange(true); - } - } - - /** - * @brief Get script assistant - * @return Script assistant instance - */ - std::shared_ptr GetScriptAssistant() const { - return m_scriptAssistant; - } - - /** - * @brief Get signature adaptation - * @return Signature adaptation instance - */ - std::shared_ptr GetSignatureAdaptation() const { - return m_signatureAdaptation; - } - - /** - * @brief Get vulnerability detector - * @return Vulnerability detector instance - */ - std::shared_ptr GetVulnerabilityDetector() const { - return m_vulnerabilityDetector; - } - - /** - * @brief Get vulnerability view controller - * @return Vulnerability view controller instance - */ - std::shared_ptr GetVulnerabilityViewController() const { - return m_vulnerabilityViewController; - } - - /** - * @brief Check if AI is initialized - * @return True if initialized, false otherwise - */ - bool IsInitialized() const { - return m_aiInitialized; - } - - /** - * @brief Check if models are loaded - * @return True if loaded, false otherwise - */ - bool AreModelsLoaded() const { - return m_modelsLoaded; - } - - /** - * @brief Get memory usage - * @return Memory usage in bytes - */ - uint64_t GetMemoryUsage() const { - uint64_t total = 0; - - if (m_scriptAssistant) { - // Placeholder - would calculate actual memory usage - total += 10 * 1024 * 1024; // Assume 10MB - } - - if (m_signatureAdaptation) { - // Placeholder - would calculate actual memory usage - total += 5 * 1024 * 1024; // Assume 5MB - } - - if (m_hybridAI) { - total += m_hybridAI->GetMemoryUsage(); - } - - if (m_offlineAI) { - total += m_offlineAI->GetMemoryUsage(); - } - - if (m_vulnerabilityDetector) { - // Placeholder - would calculate actual memory usage - total += 15 * 1024 * 1024; // Assume 15MB - } - - return total; - } - - /** - * @brief Process an AI query - * @param query User query - * @param callback Callback function for response - */ - void ProcessQuery(const std::string& query, std::function callback) { - if (!m_aiInitialized) { - if (callback) { - callback("AI system not initialized"); - } - return; - } - - // Check if in low memory mode - if (m_isInLowMemoryMode) { - // Use offline AI in low memory mode - if (m_offlineAI) { - m_offlineAI->ProcessQuery(query, callback); - return; - } - } - - // Use hybrid AI normally - if (m_hybridAI) { - m_hybridAI->ProcessQuery(query, callback); - } else if (m_offlineAI) { - // Fall back to offline AI if hybrid not available - m_offlineAI->ProcessQuery(query, callback); - } else if (callback) { - callback("AI processing not available"); - } - } - - /** - * @brief Generate a script - * @param description Script description - * @param callback Callback function for the generated script - */ - void GenerateScript(const std::string& description, std::function callback) { - if (!m_aiInitialized) { - if (callback) { - callback("AI system not initialized"); - } - return; - } - - // Check if in low memory mode - if (m_isInLowMemoryMode) { - // Use offline AI in low memory mode - if (m_offlineAI) { - m_offlineAI->GenerateScript(description, "", callback); - return; - } - } - - // Use script generation model directly if available - if (m_scriptGenerationModel) { - try { - LocalModels::ScriptGenerationModel::GeneratedScript script = - m_scriptGenerationModel->GenerateScript(description); - - if (callback) { - callback(script.m_code); - } - return; - } catch (const std::exception& e) { - // Fall back to hybrid AI on error - std::cerr << "AIIntegration: Error generating script: " << e.what() << std::endl; - } - } - - // Fall back to hybrid AI - if (m_hybridAI) { - m_hybridAI->GenerateScript(description, "", callback); - } else if (m_offlineAI) { - m_offlineAI->GenerateScript(description, "", callback); - } else if (callback) { - callback("Script generation not available"); - } - } - - /** - * @brief Debug a script - * @param script Script to debug - * @param callback Callback function for debug results - */ - void DebugScript(const std::string& script, std::function callback) { - if (!m_aiInitialized) { - if (callback) { - callback("AI system not initialized"); - } - return; - } - - // Check if in low memory mode - if (m_isInLowMemoryMode) { - // Use offline AI in low memory mode - if (m_offlineAI) { - m_offlineAI->DebugScript(script, callback); - return; - } - } - - // Use hybrid AI - if (m_hybridAI) { - m_hybridAI->DebugScript(script, callback); - } else if (m_offlineAI) { - m_offlineAI->DebugScript(script, callback); - } else if (callback) { - callback("Script debugging not available"); - } - } - - /** - * @brief Scan current game for vulnerabilities - * @param gameId Game ID - * @param gameName Game name - * @param progressCallback Callback for scan progress - * @param completeCallback Callback for scan completion - * @return True if scan started successfully - */ - bool ScanForVulnerabilities( - const std::string& gameId, - const std::string& gameName, - std::function progressCallback = nullptr, - std::function completeCallback = nullptr) { - - if (!m_aiInitialized || !m_vulnerabilityDetector) { - if (completeCallback) { - completeCallback(false); - } - return false; - } - - // Create game object (placeholder) - auto gameRoot = std::make_shared( - "Game", "DataModel"); - - // Set up callbacks - VulnerabilityDetection::VulnerabilityDetector::ScanProgressCallback progress = nullptr; - if (progressCallback) { - progress = [progressCallback]( - const VulnerabilityDetection::VulnerabilityDetector::ScanProgress& scanProgress) { - progressCallback(scanProgress.m_progress, scanProgress.m_currentActivity); - }; - } - - VulnerabilityDetection::VulnerabilityDetector::ScanCompleteCallback complete = nullptr; - if (completeCallback) { - complete = [completeCallback]( - const VulnerabilityDetection::VulnerabilityDetector::ScanResult& result) { - completeCallback(result.m_scanComplete); - }; - } - - // Start scan - return m_vulnerabilityDetector->StartScan(gameId, gameName, gameRoot, progress, complete); - } -}; - -// Initialize static instance -AIIntegration* AIIntegration::s_instance = nullptr; - -} // namespace AIFeatures -} // namespace iOS - -// We don't need this Objective-C category anymore since we're using a block directly - -// Expose C functions for integration -extern "C" { - -void* InitializeAI(void (*progressCallback)(float)) { - auto integration = iOS::AIFeatures::AIIntegration::GetSharedInstance(); - - // Convert C function pointer to C++ function - std::function progressFunc = progressCallback ? - [progressCallback](float progress) { progressCallback(progress); } : - std::function(); - - // Initialize AI - integration->Initialize(progressFunc); - - // Return opaque pointer to integration for future calls - return integration; -} - -void SetupAIWithUI(void* integration, void* viewController) { - auto aiIntegration = static_cast(integration); - auto mainVC = *static_cast*>(viewController); - - aiIntegration->SetupUI(mainVC); -} - -void* GetScriptAssistant(void* integration) { - auto aiIntegration = static_cast(integration); - // Store in a static variable to avoid returning address of temporary - static std::shared_ptr scriptAssistant; - scriptAssistant = aiIntegration->GetScriptAssistant(); - return &scriptAssistant; -} - -void* GetSignatureAdaptation(void* integration) { - auto aiIntegration = static_cast(integration); - // Store in a static variable to avoid returning address of temporary - static std::shared_ptr signatureAdaptation; - signatureAdaptation = aiIntegration->GetSignatureAdaptation(); - return &signatureAdaptation; -} - -uint64_t GetAIMemoryUsage(void* integration) { - auto aiIntegration = static_cast(integration); - return aiIntegration->GetMemoryUsage(); -} - -void HandleAppForeground(void* integration) { - auto aiIntegration = static_cast(integration); - aiIntegration->HandleAppForeground(); -} - -void HandleAppMemoryWarning(void* integration) { - auto aiIntegration = static_cast(integration); - aiIntegration->HandleMemoryWarning(); -} - -void ProcessAIQuery(void* integration, const char* query, void (*callback)(const char*)) { - auto aiIntegration = static_cast(integration); - - // Create C++ callback that forwards to C callback - auto cppCallback = [callback](const std::string& response) { - callback(response.c_str()); - }; - - aiIntegration->ProcessQuery(query, cppCallback); -} - -void GenerateScript(void* integration, const char* description, void (*callback)(const char*)) { - auto aiIntegration = static_cast(integration); - - // Create C++ callback that forwards to C callback - auto cppCallback = [callback](const std::string& script) { - callback(script.c_str()); - }; - - aiIntegration->GenerateScript(description, cppCallback); -} - -void DebugScript(void* integration, const char* script, void (*callback)(const char*)) { - auto aiIntegration = static_cast(integration); - - // Create C++ callback that forwards to C callback - auto cppCallback = [callback](const std::string& results) { - callback(results.c_str()); - }; - - aiIntegration->DebugScript(script, cppCallback); -} - -void* GetVulnerabilityViewController(void* integration) { - auto aiIntegration = static_cast(integration); - // Store in a static variable to avoid returning address of temporary - static std::shared_ptr vulnerabilityViewController; - vulnerabilityViewController = aiIntegration->GetVulnerabilityViewController(); - return &vulnerabilityViewController; -} - -bool ScanForVulnerabilities(void* integration, const char* gameId, const char* gameName, - void (*progressCallback)(float, const char*), - void (*completeCallback)(bool)) { - auto aiIntegration = static_cast(integration); - - // Create C++ callbacks - std::function progress = nullptr; - if (progressCallback) { - progress = [progressCallback](float progressValue, const std::string& status) { - progressCallback(progressValue, status.c_str()); - }; - } - - std::function complete = nullptr; - if (completeCallback) { - complete = [completeCallback](bool success) { - completeCallback(success); - }; - } - - return aiIntegration->ScanForVulnerabilities( - gameId ? gameId : "", - gameName ? gameName : "", - progress, - complete - ); -} - -} // extern "C" diff --git a/source/cpp/ios/ai_features/AIIntegration.mm.patch b/source/cpp/ios/ai_features/AIIntegration.mm.patch deleted file mode 100644 index e09e9c87..00000000 --- a/source/cpp/ios/ai_features/AIIntegration.mm.patch +++ /dev/null @@ -1,16 +0,0 @@ ---- AIIntegration.mm.original -+++ AIIntegration.mm -@@ -1,8 +1,12 @@ - #include "AIIntegration.h" - #include "AIConfig.h" - #include "AISystemInitializer.h" -+ -+// For CI build -+#include "../ui/VulnerabilityViewController.h" -+#include "../ui/MainViewController.h" - #include "ScriptAssistant.h" - - // Use a native-code define for CI to avoid preprocessor issues with non-native code --#ifdef CI_BUILD -+#define CI_SAFE_BUILD - diff --git a/source/cpp/ios/ai_features/AIIntegration.mm.rej b/source/cpp/ios/ai_features/AIIntegration.mm.rej deleted file mode 100644 index e09e9c87..00000000 --- a/source/cpp/ios/ai_features/AIIntegration.mm.rej +++ /dev/null @@ -1,16 +0,0 @@ ---- AIIntegration.mm.original -+++ AIIntegration.mm -@@ -1,8 +1,12 @@ - #include "AIIntegration.h" - #include "AIConfig.h" - #include "AISystemInitializer.h" -+ -+// For CI build -+#include "../ui/VulnerabilityViewController.h" -+#include "../ui/MainViewController.h" - #include "ScriptAssistant.h" - - // Use a native-code define for CI to avoid preprocessor issues with non-native code --#ifdef CI_BUILD -+#define CI_SAFE_BUILD - diff --git a/source/cpp/ios/ai_features/AISystemInitializer.h.backup2 b/source/cpp/ios/ai_features/AISystemInitializer.h.backup2 deleted file mode 100644 index 306ca1c3..00000000 --- a/source/cpp/ios/ai_features/AISystemInitializer.h.backup2 +++ /dev/null @@ -1,271 +0,0 @@ -#pragma once - -#include "../../objc_isolation.h" -#include "AIConfig.h" -#include "AIIntegration.h" -#include "local_models/VulnerabilityDetectionModel.h" -#include "local_models/ScriptGenerationModel.h" -#include "local_models/GeneralAssistantModel.h" -#include "SelfModifyingCodeSystem.h" - -#include -#include -#include -#include -#include -#include - -namespace iOS { -namespace AIFeatures { - -/** - * @class AISystemInitializer - * @brief Initializes and manages the AI system lifecycle - * - * This class handles the initialization of the AI system on first use, - * ensures models are created locally, provides fallback systems during - * training, and coordinates continuous self-improvement. It ensures - * the AI system works completely offline without any cloud dependencies. - */ -class AISystemInitializer { -public: - // Initialization state enumeration - enum class InitState { - NotStarted, // Initialization not started - InProgress, // Initialization in progress - Completed, // Initialization completed - Failed // Initialization failed - }; - - // Model status update callback - using ModelStatusCallback = std::function; - - // Error callback - using ErrorCallback = std::function; - - // Model update callback - using ModelUpdateCallback = std::function; - -private: - // Singleton instance - static std::unique_ptr s_instance; - static std::mutex s_instanceMutex; - - // Configuration - AIConfig m_config; - std::string m_dataPath; - std::string m_modelDataPath; - - // Initialization state - InitState m_initState; - float m_initProgress; - - // Callbacks - ModelStatusCallback m_modelStatusCallback; - ErrorCallback m_errorCallback; - - // Thread safety - mutable std::mutex m_mutex; - - // Models - std::shared_ptr m_vulnDetectionModel; - std::shared_ptr m_generalAssistantModel; - std::shared_ptr m_scriptGenModel; - - // Self-modifying code system - std::shared_ptr m_selfModifyingSystem; - - // Script assistant - std::shared_ptr m_scriptAssistant; - - // Model statuses - struct ModelStatus { - InitState state; - float progress; - float accuracy; - - ModelStatus() : state(InitState::NotStarted), progress(0.0f), accuracy(0.0f) {} - }; - - std::map m_modelStatuses; - - // Private constructor (singleton) - AISystemInitializer(); - - // Initialize components - bool InitializeDataPaths(); - bool InitializeModels(); - bool InitializeScriptAssistant(); - - // Update model status - void UpdateModelStatus(const std::string& modelName, InitState state, float progress, float accuracy); - -public: - /** - * @brief Destructor - */ - ~AISystemInitializer(); - - /** - * @brief Get singleton instance - * @return Instance - */ - static AISystemInitializer* GetInstance(); - - /** - * @brief Initialize the AI system - * @param config AI configuration - * @param progressCallback Progress callback - * @return True if initialization succeeded or was already complete - */ - bool Initialize(const AIConfig& config, std::function progressCallback = nullptr); - - /** - * @brief Set model status callback - * @param callback Callback to invoke when model status changes - */ - void SetModelStatusCallback(ModelStatusCallback callback); - - /** - * @brief Set error callback - * @param callback Callback to invoke when errors occur - */ - void SetErrorCallback(ErrorCallback callback); - - /** - * @brief Get initialization state - * @return Current initialization state - */ - InitState GetInitState() const; - - /** - * @brief Get initialization progress - * @return Progress value (0.0-1.0) - */ - float GetInitProgress() const; - - /** - * @brief Get configuration - * @return AI configuration - */ - const AIConfig& GetConfig() const; - - /** - * @brief Update configuration - * @param config New configuration - * @return True if update was successful - */ - bool UpdateConfig(const AIConfig& config); - - /** - * @brief Get model data path - * @return Path to model data - */ - const std::string& GetModelDataPath() const; - - /** - * @brief Get model status - * @param modelName Model name - * @return Model status - */ - ModelStatus GetModelStatus(const std::string& modelName) const; - - /** - * @brief Get vulnerability detection model - * @return Shared pointer to vulnerability detection model - */ - std::shared_ptr GetVulnerabilityDetectionModel(); - - /** - * @brief Get script generation model - * @return Shared pointer to script generation model - */ - std::shared_ptr GetScriptGenerationModel(); - - /** - * @brief Get general assistant model - * @return Shared pointer to general assistant model - */ - std::shared_ptr GetGeneralAssistantModel() const; - - /** - * @brief Get self-modifying code system - * @return Shared pointer to self-modifying code system - */ - std::shared_ptr GetSelfModifyingSystem(); - - /** - * @brief Get script assistant - * @return Shared pointer to script assistant - */ - std::shared_ptr GetScriptAssistant(); - - /** - * @brief Detect vulnerabilities in script - * @param script Script content - * @param onComplete Completion callback - */ - void DetectVulnerabilities(const std::string& script, std::function&)> onComplete); - - /** - * @brief Generate script from description - * @param description Script description - * @param onComplete Completion callback - */ - void GenerateScript(const std::string& description, std::function onComplete); - - /** - * @brief Improve script - * @param script Original script - * @param instructions Improvement instructions - * @param onComplete Completion callback - */ - void ImproveScript(const std::string& script, const std::string& instructions, std::function onComplete); - - /** - * @brief Process script with AI model - * @param script Script to process - * @param action Action to perform - * @param onComplete Completion callback - */ - void ProcessScript(const std::string& script, const std::string& action, std::function onComplete); - - /** - * @brief Release unused resources to reduce memory usage - */ - void ReleaseUnusedResources(); - - /** - * @brief Calculate total memory usage of AI components - * @return Memory usage in bytes - */ - uint64_t CalculateMemoryUsage() const; - - /** - * @brief Get the current model improvement mode - * @return Model improvement mode - */ - AIConfig::ModelImprovement GetModelImprovementMode() const; - - /** - * @brief Set model improvement mode - * @param mode Model improvement mode - */ - void SetModelImprovementMode(AIConfig::ModelImprovement mode); - - /** - * @brief Check if models are available for offline use - * @return True if all required models are available - */ - bool AreModelsAvailableOffline() const; - - /** - * @brief Train models with available data - * @param updateCallback Progress update callback - * @return True if training started successfully - */ - bool TrainModels(ModelUpdateCallback updateCallback = nullptr); -}; - -} // namespace AIFeatures -} // namespace iOS diff --git a/source/cpp/ios/ai_features/AISystemInitializer.h.bak b/source/cpp/ios/ai_features/AISystemInitializer.h.bak deleted file mode 100644 index 306ca1c3..00000000 --- a/source/cpp/ios/ai_features/AISystemInitializer.h.bak +++ /dev/null @@ -1,271 +0,0 @@ -#pragma once - -#include "../../objc_isolation.h" -#include "AIConfig.h" -#include "AIIntegration.h" -#include "local_models/VulnerabilityDetectionModel.h" -#include "local_models/ScriptGenerationModel.h" -#include "local_models/GeneralAssistantModel.h" -#include "SelfModifyingCodeSystem.h" - -#include -#include -#include -#include -#include -#include - -namespace iOS { -namespace AIFeatures { - -/** - * @class AISystemInitializer - * @brief Initializes and manages the AI system lifecycle - * - * This class handles the initialization of the AI system on first use, - * ensures models are created locally, provides fallback systems during - * training, and coordinates continuous self-improvement. It ensures - * the AI system works completely offline without any cloud dependencies. - */ -class AISystemInitializer { -public: - // Initialization state enumeration - enum class InitState { - NotStarted, // Initialization not started - InProgress, // Initialization in progress - Completed, // Initialization completed - Failed // Initialization failed - }; - - // Model status update callback - using ModelStatusCallback = std::function; - - // Error callback - using ErrorCallback = std::function; - - // Model update callback - using ModelUpdateCallback = std::function; - -private: - // Singleton instance - static std::unique_ptr s_instance; - static std::mutex s_instanceMutex; - - // Configuration - AIConfig m_config; - std::string m_dataPath; - std::string m_modelDataPath; - - // Initialization state - InitState m_initState; - float m_initProgress; - - // Callbacks - ModelStatusCallback m_modelStatusCallback; - ErrorCallback m_errorCallback; - - // Thread safety - mutable std::mutex m_mutex; - - // Models - std::shared_ptr m_vulnDetectionModel; - std::shared_ptr m_generalAssistantModel; - std::shared_ptr m_scriptGenModel; - - // Self-modifying code system - std::shared_ptr m_selfModifyingSystem; - - // Script assistant - std::shared_ptr m_scriptAssistant; - - // Model statuses - struct ModelStatus { - InitState state; - float progress; - float accuracy; - - ModelStatus() : state(InitState::NotStarted), progress(0.0f), accuracy(0.0f) {} - }; - - std::map m_modelStatuses; - - // Private constructor (singleton) - AISystemInitializer(); - - // Initialize components - bool InitializeDataPaths(); - bool InitializeModels(); - bool InitializeScriptAssistant(); - - // Update model status - void UpdateModelStatus(const std::string& modelName, InitState state, float progress, float accuracy); - -public: - /** - * @brief Destructor - */ - ~AISystemInitializer(); - - /** - * @brief Get singleton instance - * @return Instance - */ - static AISystemInitializer* GetInstance(); - - /** - * @brief Initialize the AI system - * @param config AI configuration - * @param progressCallback Progress callback - * @return True if initialization succeeded or was already complete - */ - bool Initialize(const AIConfig& config, std::function progressCallback = nullptr); - - /** - * @brief Set model status callback - * @param callback Callback to invoke when model status changes - */ - void SetModelStatusCallback(ModelStatusCallback callback); - - /** - * @brief Set error callback - * @param callback Callback to invoke when errors occur - */ - void SetErrorCallback(ErrorCallback callback); - - /** - * @brief Get initialization state - * @return Current initialization state - */ - InitState GetInitState() const; - - /** - * @brief Get initialization progress - * @return Progress value (0.0-1.0) - */ - float GetInitProgress() const; - - /** - * @brief Get configuration - * @return AI configuration - */ - const AIConfig& GetConfig() const; - - /** - * @brief Update configuration - * @param config New configuration - * @return True if update was successful - */ - bool UpdateConfig(const AIConfig& config); - - /** - * @brief Get model data path - * @return Path to model data - */ - const std::string& GetModelDataPath() const; - - /** - * @brief Get model status - * @param modelName Model name - * @return Model status - */ - ModelStatus GetModelStatus(const std::string& modelName) const; - - /** - * @brief Get vulnerability detection model - * @return Shared pointer to vulnerability detection model - */ - std::shared_ptr GetVulnerabilityDetectionModel(); - - /** - * @brief Get script generation model - * @return Shared pointer to script generation model - */ - std::shared_ptr GetScriptGenerationModel(); - - /** - * @brief Get general assistant model - * @return Shared pointer to general assistant model - */ - std::shared_ptr GetGeneralAssistantModel() const; - - /** - * @brief Get self-modifying code system - * @return Shared pointer to self-modifying code system - */ - std::shared_ptr GetSelfModifyingSystem(); - - /** - * @brief Get script assistant - * @return Shared pointer to script assistant - */ - std::shared_ptr GetScriptAssistant(); - - /** - * @brief Detect vulnerabilities in script - * @param script Script content - * @param onComplete Completion callback - */ - void DetectVulnerabilities(const std::string& script, std::function&)> onComplete); - - /** - * @brief Generate script from description - * @param description Script description - * @param onComplete Completion callback - */ - void GenerateScript(const std::string& description, std::function onComplete); - - /** - * @brief Improve script - * @param script Original script - * @param instructions Improvement instructions - * @param onComplete Completion callback - */ - void ImproveScript(const std::string& script, const std::string& instructions, std::function onComplete); - - /** - * @brief Process script with AI model - * @param script Script to process - * @param action Action to perform - * @param onComplete Completion callback - */ - void ProcessScript(const std::string& script, const std::string& action, std::function onComplete); - - /** - * @brief Release unused resources to reduce memory usage - */ - void ReleaseUnusedResources(); - - /** - * @brief Calculate total memory usage of AI components - * @return Memory usage in bytes - */ - uint64_t CalculateMemoryUsage() const; - - /** - * @brief Get the current model improvement mode - * @return Model improvement mode - */ - AIConfig::ModelImprovement GetModelImprovementMode() const; - - /** - * @brief Set model improvement mode - * @param mode Model improvement mode - */ - void SetModelImprovementMode(AIConfig::ModelImprovement mode); - - /** - * @brief Check if models are available for offline use - * @return True if all required models are available - */ - bool AreModelsAvailableOffline() const; - - /** - * @brief Train models with available data - * @param updateCallback Progress update callback - * @return True if training started successfully - */ - bool TrainModels(ModelUpdateCallback updateCallback = nullptr); -}; - -} // namespace AIFeatures -} // namespace iOS diff --git a/source/cpp/ios/ai_features/local_models/GeneralAssistantModel.h.bak b/source/cpp/ios/ai_features/local_models/GeneralAssistantModel.h.bak deleted file mode 100644 index c2d193be..00000000 --- a/source/cpp/ios/ai_features/local_models/GeneralAssistantModel.h.bak +++ /dev/null @@ -1,249 +0,0 @@ -#pragma once - -#include "LocalModelBase.h" -#include -#include -#include -#include -#include - -namespace iOS { -namespace AIFeatures { -namespace LocalModels { - -/** - * @class GeneralAssistantModel - * @brief AI assistant model for general user interaction - * - * This model serves as a general-purpose assistant that helps users with - * all aspects of the executor. It integrates with other AI models and - * adapts to user behavior and preferences over time. The assistant provides - * personalized responses based on user proficiency level and interaction history, - * continuously improving its capabilities through self-learning. - */ -class GeneralAssistantModel : public ::iOS::AIFeatures::LocalModels::LocalModelBase { -public: - // Message type enumeration - enum class MessageType { - System, // System message (internal context) - User, // User message (user input) - Assistant, // Assistant response (model output) - Tool // Tool output (system events, actions) - }; - - // User proficiency level - enum class UserProficiency { - Beginner, // New to scripting/exploiting (0-10 interactions) - Intermediate, // Some experience (11-30 interactions) - Advanced, // Experienced user (31-100 interactions) - Expert // Expert user with deep knowledge (100+ interactions) - }; - - // Interaction context - struct Interaction { - std::string m_content; // Message content - MessageType m_type; // Message type - uint64_t m_timestamp; // Timestamp (microseconds since epoch) - - Interaction() : m_timestamp(0) {} - - Interaction(const std::string& content, MessageType type, uint64_t timestamp) - : m_content(content), m_type(type), m_timestamp(timestamp) {} - }; - - // User profile - struct UserProfile { - std::string m_userId; // User identifier - UserProficiency m_proficiency; // User proficiency - std::vector m_interests; // User interests (script types, games) - std::unordered_map m_preferences; // Feature preferences - uint64_t m_lastActive; // Last active timestamp - uint32_t m_interactionCount; // Number of interactions - - UserProfile() : m_proficiency(UserProficiency::Beginner), m_lastActive(0), m_interactionCount(0) {} - }; - -private: - // Private implementation - UserProfile m_currentProfile; // Current user profile - std::vector m_interactionHistory; // Interaction history - std::unordered_map m_userProfiles; // Stored profiles - - bool m_isInitialized; // Whether model is initialized - std::string m_storagePath; // Path to model storage - void* m_internalModel; // Pointer to internal model implementation - mutable std::mutex m_mutex; // Mutex for thread safety - - // Response generation context - struct GenerationContext { - UserProficiency proficiency; // User proficiency - std::vector interests; // User interests - std::unordered_map preferences; // User preferences - std::vector recentInteractions; // Recent interactions - - GenerationContext() : proficiency(UserProficiency::Beginner) {} - }; - - // Private helper methods - void UpdateUserProfile(const Interaction& interaction); - void SaveUserProfiles(); - void LoadUserProfiles(); - void AdaptModelToUser(const UserProfile& profile); - std::string GenerateContextAwareResponse(const std::string& input, const GenerationContext& context); - std::vector GetRelevantInteractionHistory(size_t maxItems = 10) const; - std::string DetectIntent(const std::string& input) const; - std::string GetResponseForIntent(const std::string& intent, const GenerationContext& context) const; - std::vector ExtractEntities(const std::string& input) const; - std::vector FindRelevantTopics(const std::string& input) const; - -public: - /** - * @brief Constructor - */ - GeneralAssistantModel(); - - /** - * @brief Destructor - */ - ~GeneralAssistantModel(); - - /** - * @brief Initialize the model - * @param modelPath Path to model data - * @return True if initialization is successful - */ - bool Initialize(const std::string& modelPath); - - /** - * @brief Process user input and generate a response - * @param input User input - * @param userId User identifier (optional) - * @return Assistant response - */ - std::string ProcessInput(const std::string& input, const std::string& userId = ""); - - /** - * @brief Process user input with system context - * @param input User input - * @param systemContext Additional context for the assistant - * @param userId User identifier (optional) - * @return Assistant response - */ - std::string ProcessInputWithContext(const std::string& input, const std::string& systemContext, const std::string& userId = ""); - - /** - * @brief Set current user - * @param userId User identifier - * @return True if user profile was loaded or created - */ - bool SetCurrentUser(const std::string& userId); - - /** - * @brief Add system message to context - * @param message System message - */ - void AddSystemMessage(const std::string& message); - - /** - * @brief Add tool output to context - * @param toolName Tool name - * @param output Tool output - */ - void AddToolOutput(const std::string& toolName, const std::string& output); - - /** - * @brief Get user proficiency - * @return User proficiency level - */ - UserProficiency GetUserProficiency() const; - - /** - * @brief Check if model is initialized - * @return True if initialized - */ - bool IsInitialized() const; - - /** - * @brief Set model path - * @param path Path to model files - * @return True if path was valid and set - */ - bool SetModelPath(const std::string& path); - - /** - * @brief Reset conversation history - * Resets user conversation while preserving system context - */ - void ResetConversation(); - - /** - * @brief Get model version - * @return Model version string - */ - std::string GetVersion() const; - - /** - * @brief Get memory usage in bytes - * @return Memory usage - */ - uint64_t GetMemoryUsage() const; - - /** - * @brief Release unused memory resources - */ - void ReleaseUnusedResources(); - - /** - * @brief Provide information about another AI model - * @param modelName Model name - * @param modelDescription Model description - * @param modelCapabilities Model capabilities - */ - void AddModelAwareness(const std::string& modelName, - const std::string& modelDescription, - const std::vector& modelCapabilities); - - /** - * @brief Notify of executor feature usage - * @param featureName Feature name - * @param context Usage context - */ - void NotifyFeatureUsage(const std::string& featureName, const std::string& context); - - /** - * @brief Train the model on new data - * @return True if training was successful - */ - bool Train() override; - - /** - * @brief Set user interests - * @param interests User interests - */ - void SetUserInterests(const std::vector& interests); - - /** - * @brief Get user interests - * @return User interests - */ - std::vector GetUserInterests() const; - - /** - * @brief Set user preference - * @param preference Preference name - * @param value Preference value (0.0-1.0) - */ - void SetUserPreference(const std::string& preference, float value); - - /** - * @brief Get user preference - * @param preference Preference name - * @param defaultValue Default value if preference not found - * @return Preference value - */ - float GetUserPreference(const std::string& preference, float defaultValue = 0.5f) const; -}; - -} // namespace LocalModels -} // namespace AIFeatures -} // namespace iOS diff --git a/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.backup3 b/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.backup3 deleted file mode 100644 index 6dc49ab8..00000000 --- a/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.backup3 +++ /dev/null @@ -1,126 +0,0 @@ -#pragma once - -#include "LocalModelBase.h" -#include -#include -#include - -namespace iOS { -namespace AIFeatures { -namespace LocalModels { - -/** - * @enum ScriptCategory - * @brief Categories of scripts that can be generated - */ -enum class ScriptCategory { - GENERAL, - GUI, - GAMEPLAY, - UTILITY, - NETWORKING, - OPTIMIZATION, - CUSTOM -}; - -/** - * @class ScriptGenerationModel - * @brief Model for generating and enhancing scripts - * - * This model generates Lua scripts based on natural language prompts - * and can enhance existing scripts with additional functionality. - */ -class ScriptGenerationModel : public LocalModelBase { -public: - /** - * @brief Constructor - */ - ScriptGenerationModel(); - - /** - * @brief Destructor - */ - virtual ~ScriptGenerationModel(); - - /** - * @brief Initialize the model - * @param path Path to model files - * @return True if initialization succeeded - */ - bool Initialize(const std::string& path); - - /** - * @brief Load the model from disk - * @return True if load succeeded - */ - bool Load(); - - /** - * @brief Save the model to disk - * @return True if save succeeded - */ - bool Save(); - - /** - * @brief Train the model - * @return True if training succeeded - */ - bool Train(); - - /** - * @brief Generate a script from a prompt - * @param prompt User prompt - * @return Generated script - */ - std::string GenerateScript(const std::string& prompt); - - /** - * @brief Generate a script from a prompt with specific category - * @param prompt User prompt - * @param category Script category - * @return Generated script - */ - std::string GenerateScript(const std::string& prompt, ScriptCategory category); - - /** - * @brief Enhance an existing script - * @param script Original script - * @param prompt Enhancement instructions - * @return Enhanced script - */ - std::string EnhanceScript(const std::string& script, const std::string& prompt); - - /** - * @brief Generate script asynchronously - * @param prompt User prompt - * @param callback Callback to invoke when generation completes - */ - void GenerateScriptAsync(const std::string& prompt, std::function callback); - - /** - * @brief Enhance script asynchronously - * @param script Original script - * @param prompt Enhancement instructions - * @param callback Callback to invoke when enhancement completes - */ - void EnhanceScriptAsync(const std::string& script, const std::string& prompt, - std::function callback); - - /** - * @brief Convert script category to string - * @param category Script category - * @return String representation - */ - static std::string CategoryToString(ScriptCategory category); - - /** - * @brief Convert string to script category - * @param str String representation - * @return Script category - */ - static ScriptCategory StringToCategory(const std::string& str); -}; - -} // namespace LocalModels -} // namespace AIFeatures -} // namespace iOS diff --git a/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak b/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak deleted file mode 100644 index a8e6ef54..00000000 --- a/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak +++ /dev/null @@ -1,220 +0,0 @@ - -#include "../../../objc_isolation.h" -#pragma once - -#include "LocalModelBase.h" -#include -#include -#include -#include -#include - -namespace iOS { -namespace AIFeatures { -namespace LocalModels { - -/** - * @class ScriptGenerationModel - * @brief Model for generating Lua scripts based on user descriptions - * - * This model learns from user interactions to generate custom Lua scripts - * for Roblox games. It's trained locally on device with script samples - * collected during normal usage. - */ -class ScriptGenerationModel : public LocalModelBase { -public: - // Script category enumeration - enum class ScriptCategory { - Movement, // Speed, teleport, noclip, etc. - Combat, // Aimbot, ESP, hitbox extenders, etc. - Visual, // ESP, wallhack, chams, etc. - Automation, // Auto farm, auto collect, etc. - ServerSide, // Server-side execution exploits - Utility, // General purpose utility scripts - Custom // User-defined category - }; - - // Script template structure - struct ScriptTemplate { - std::string m_name; // Template name - std::string m_description; // Template description - std::string m_code; // Template code - std::vector m_tags; // Template tags - ScriptCategory m_category; // Script category - float m_complexity; // Script complexity (0-1) - - ScriptTemplate() - : m_category(ScriptCategory::Utility), m_complexity(0.5f) {} - }; - - // Generated script structure - struct GeneratedScript { - std::string m_code; // Generated code - std::string m_description; // Script description - ScriptCategory m_category; // Script category - std::vector m_tags; // Script tags - float m_confidence; // Generation confidence (0-1) - std::string m_basedOn; // Source template if applicable - - GeneratedScript() - : m_category(ScriptCategory::Utility), m_confidence(0.0f) {} - }; - -private: - // Training data - std::unordered_map m_templates; // Script templates - std::vector> m_patternPairs; // Intent-script pairs - std::unordered_map m_wordFrequency; // Vocabulary - uint32_t m_vocabularySize; // Vocabulary size - std::vector m_weights; // Model weights - - // Model state - std::unordered_map m_featureWeights; // Feature weights - std::unordered_map m_categoryWeights; // Category weights - - // Implementation of abstract methods - bool InitializeModel() override; - bool TrainModel(TrainingProgressCallback progressCallback = nullptr) override; - std::string PredictInternal(const std::string& input) override; - std::vector FeaturizeInput(const std::string& input) override; - std::string ProcessOutput(const std::vector& output) override; - - // Helper methods - void AddDefaultTemplates(); - void BuildVocabulary(); - ScriptTemplate FindBestTemplateMatch(const std::string& description); - GeneratedScript GenerateScriptFromTemplate(const ScriptTemplate& templ, const std::string& description); - GeneratedScript GenerateScriptFromScratch(const std::string& description); - std::vector ExtractKeywords(const std::string& text); - ScriptCategory DetermineCategory(const std::string& description); - std::vector GenerateTags(const std::string& description); - std::vector TokenizeInput(const std::string& input); - float CalculateSimilarity(const std::vector& v1, const std::vector& v2); - std::string CustomizeScript(const std::string& templateCode, const std::string& description); - std::string ExtractIntents(const std::string& description); - -public: - /** - * @brief Constructor - */ - ScriptGenerationModel(); - - /** - * @brief Destructor - */ - ~ScriptGenerationModel(); - - /** - * @brief Generate a script based on description - * @param description Script description - * @param context Optional context information - * @return Generated script - */ - GeneratedScript GenerateScript(const std::string& description, const std::string& context = ""); - - /** - * @brief Analyze a script for bugs or improvements - * @param script Script to analyze - * @return Analysis result - */ - std::string AnalyzeScript(const std::string& script); - - /** - * @brief Generate a response to a general query - * @param query User's query - * @param context Optional context information - * @return Generated response - */ - std::string GenerateResponse(const std::string& query, const std::string& context = ""); - - /** - * @brief Add a script template - * @param templ Script template - * @return True if template was added - */ - bool AddTemplate(const ScriptTemplate& templ); - - /** - * @brief Get all script templates - * @return Map of template names to templates - */ - std::unordered_map GetTemplates() const; - - /** - * @brief Get templates by category - * @param category Script category - * @return Vector of templates - */ - std::vector GetTemplatesByCategory(ScriptCategory category); - - /** - * @brief Get templates by tag - * @param tag Template tag - * @return Vector of templates - */ - std::vector GetTemplatesByTag(const std::string& tag); - - /** - * @brief Add an intent-script pair - * @param intent User intent - * @param script Script code - * @return True if pair was added - */ - bool AddIntentScriptPair(const std::string& intent, const std::string& script); - - /** - * @brief Learn from user feedback - * @param description Script description - * @param generatedScript Generated script - * @param userScript User-modified script - * @param rating User rating (0-1) - * @return True if learning succeeded - */ - bool LearnFromFeedback(const std::string& description, - const std::string& generatedScript, - const std::string& userScript, - float rating); - - /** - * @brief Get vocabulary size - * @return Vocabulary size - */ - uint32_t GetVocabularySize() const; - - /** - * @brief Convert category to string - * @param category Script category - * @return String representation - */ - static std::string CategoryToString(ScriptCategory category); - - /** - /** - * @brief Check if the model is initialized - * @return True if initialized - */ - bool IsInitialized() const; - - /** - * @brief Set model path - * @param path Path to model files - * @return True if path was valid and set - */ - bool SetModelPath(const std::string& path); - * @brief Convert string to category - * @param str String representation - * @return Script category - */ -} // 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 - */ diff --git a/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak2 b/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak2 deleted file mode 100644 index 7143fffc..00000000 --- a/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak2 +++ /dev/null @@ -1,126 +0,0 @@ -#pragma once - -#include "LocalModelBase.h" -#include -#include -#include - -namespace iOS { -namespace AIFeatures { -namespace LocalModels { - -/** - * @enum ScriptCategory - * @brief Categories of scripts that can be generated - */ -enum class ScriptCategory { - GENERAL, - GUI, - GAMEPLAY, - UTILITY, - NETWORKING, - OPTIMIZATION, - CUSTOM -}; - -/** - * @class ScriptGenerationModel - * @brief Model for generating and enhancing scripts - * - * This model generates Lua scripts based on natural language prompts - * and can enhance existing scripts with additional functionality. - */ -class ScriptGenerationModel : public LocalModelBase { -public: - /** - * @brief Constructor - */ - ScriptGenerationModel(); - - /** - * @brief Destructor - */ - virtual ~ScriptGenerationModel(); - - /** - * @brief Initialize the model - * @param path Path to model files - * @return True if initialization succeeded - */ - bool Initialize(const std::string& path) override; - - /** - * @brief Load the model from disk - * @return True if load succeeded - */ - bool Load() override; - - /** - * @brief Save the model to disk - * @return True if save succeeded - */ - bool Save() override; - - /** - * @brief Train the model - * @return True if training succeeded - */ - bool Train() override; - - /** - * @brief Generate a script from a prompt - * @param prompt User prompt - * @return Generated script - */ - std::string GenerateScript(const std::string& prompt); - - /** - * @brief Generate a script from a prompt with specific category - * @param prompt User prompt - * @param category Script category - * @return Generated script - */ - std::string GenerateScript(const std::string& prompt, ScriptCategory category); - - /** - * @brief Enhance an existing script - * @param script Original script - * @param prompt Enhancement instructions - * @return Enhanced script - */ - std::string EnhanceScript(const std::string& script, const std::string& prompt); - - /** - * @brief Generate script asynchronously - * @param prompt User prompt - * @param callback Callback to invoke when generation completes - */ - void GenerateScriptAsync(const std::string& prompt, std::function callback); - - /** - * @brief Enhance script asynchronously - * @param script Original script - * @param prompt Enhancement instructions - * @param callback Callback to invoke when enhancement completes - */ - void EnhanceScriptAsync(const std::string& script, const std::string& prompt, - std::function callback); - - /** - * @brief Convert script category to string - * @param category Script category - * @return String representation - */ - static std::string CategoryToString(ScriptCategory category); - - /** - * @brief Convert string to script category - * @param str String representation - * @return Script category - */ - static ScriptCategory StringToCategory(const std::string& str); -}; - -} // namespace LocalModels -} // namespace AIFeatures -} // namespace iOS diff --git a/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak4 b/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak4 deleted file mode 100644 index a6dcafa1..00000000 --- a/source/cpp/ios/ai_features/local_models/ScriptGenerationModel.h.bak4 +++ /dev/null @@ -1,134 +0,0 @@ -#pragma once - -#include "LocalModelBase.h" -#include -#include -#include - -namespace iOS { -namespace AIFeatures { -namespace LocalModels { - -/** - * @enum ScriptCategory - * @brief Categories of scripts that can be generated - */ -enum class ScriptCategory { - GENERAL, - GUI, - GAMEPLAY, - UTILITY, - NETWORKING, - OPTIMIZATION, - CUSTOM -}; - -/** - * @class ScriptGenerationModel - * @brief Model for generating and enhancing scripts - * - * This model generates Lua scripts based on natural language prompts - * and can enhance existing scripts with additional functionality. - */ -class ScriptGenerationModel : public LocalModelBase { -public: - /** - * @brief Constructor - */ - ScriptGenerationModel(); - - /** - * @brief Destructor - */ - virtual ~ScriptGenerationModel(); - - /** - * @brief Initialize the model - * @param path Path to model files - * @return True if initialization succeeded - */ - bool Initialize(const std::string& path); - - /** - * @brief Load the model from disk - * @return True if load succeeded - */ - bool Load(); - - /** - * @brief Save the model to disk - * @return True if save succeeded - */ - bool Save(); - - /** - * @brief Train the model - * @return True if training succeeded - */ - bool Train(); - - /** - * @brief Generate a script from a prompt - * @param prompt User prompt - * @return Generated script - */ - std::string GenerateScript(const std::string& prompt); - - /** - * @brief Generate a script from a prompt with specific category - * @param prompt User prompt - * @param category Script category - * @return Generated script - */ - std::string GenerateScript(const std::string& prompt, ScriptCategory category); - - /** - * @brief Enhance an existing script - * @param script Original script - * @param prompt Enhancement instructions - * @return Enhanced script - */ - std::string EnhanceScript(const std::string& script, const std::string& prompt); - - /** - * @brief Generate script asynchronously - * @param prompt User prompt - * @param callback Callback to invoke when generation completes - */ - void GenerateScriptAsync(const std::string& prompt, std::function callback); - - /** - * @brief Enhance script asynchronously - * @param script Original script - * @param prompt Enhancement instructions - * @param callback Callback to invoke when enhancement completes - */ - void EnhanceScriptAsync(const std::string& script, const std::string& prompt, - std::function callback); - - /** - * @brief Convert script category to string - * @param category Script category - * @return String representation - */ - static std::string CategoryToString(ScriptCategory category); - - /** - * @brief Convert string to script category - * @param str String representation - * @return Script category - */ - static ScriptCategory StringToCategory(const std::string& str); - -protected: - // Implement the pure virtual methods from LocalModelBase - virtual bool InitializeModel() override; - virtual bool TrainModel(TrainingProgressCallback progressCallback = nullptr) override; - virtual std::string PredictInternal(const std::string& input) override; - virtual std::vector FeaturizeInput(const std::string& input) override; - virtual std::string ProcessOutput(const std::vector& output) override; -}; - -} // namespace LocalModels -} // namespace AIFeatures -} // namespace iOS diff --git a/source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.backup b/source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.backup deleted file mode 100644 index 7775204a..00000000 --- a/source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.backup +++ /dev/null @@ -1,520 +0,0 @@ - -#include "../../../objc_isolation.h" -#pragma once - -#include "LocalModelBase.h" -#include -#include -#include -#include -#include -#include - -namespace iOS { -namespace AIFeatures { -namespace LocalModels { - -/** - * @class VulnerabilityDetectionModel - * @brief Comprehensive model for detecting ALL types of vulnerabilities in Roblox games - * - * This advanced model identifies ALL security vulnerabilities in Roblox Lua code, - * from common issues to highly sophisticated and obscure exploits. It employs multiple - * detection strategies including pattern matching, data flow analysis, semantic understanding, - * and heuristic detection to ensure complete coverage of the vulnerability space. - */ -class VulnerabilityDetectionModel : public LocalModelBase { -public: - // Comprehensive vulnerability type enumeration - covering ALL possible vulnerabilities - enum class VulnType { - // Code Execution Vulnerabilities - ScriptInjection, // Script injection vulnerability - DynamicCodeExecution, // Dynamic code execution - StringManipulation, // String manipulation to bypass filters - LoadstringExploitation, // Loadstring exploitation - CoroutineInjection, // Coroutine-based code injection - FunctionReassignment, // Function reassignment/hijacking - MetatableExploitation, // Metatable exploitation - EnvironmentManipulation, // Environment (_G, _ENV) manipulation - ProxyObjectExploitation, // Proxy object exploitation - GetfenvExploitation, // Getfenv exploitation - SetfenvExploitation, // Setfenv exploitation - JITExploitation, // JIT compilation exploitation - MemoryCorruption, // Memory corruption in Lua VM - - // Network Vulnerabilities - RemoteEvent, // Insecure RemoteEvent usage - RemoteFunction, // Insecure RemoteFunction usage - RemoteSignal, // Remote signal vulnerabilities - InsecureHttpService, // Insecure HttpService usage - WebSocketVulnerability, // WebSocket vulnerabilities - NetworkSpoofing, // Network traffic spoofing - CrossServerVulnerability, // Cross-server vulnerabilities - ReplicationLag, // Replication lag exploitation - NetworkFlooding, // Network flooding attacks - TrafficInjection, // Traffic injection - PacketManipulation, // Packet manipulation - - // Data Vulnerabilities - DataStore, // DataStore vulnerabilities - UnsafeDeserialization, // Unsafe deserialization of data - DataLeakage, // Data leakage vulnerabilities - SQLInjection, // SQL-like injection in data stores - JSONInjection, // JSON injection - UnvalidatedDataStorage, // Unvalidated data storage - ClientDataManipulation, // Client data manipulation - ServerDataExposure, // Server data exposure - - // Authentication Vulnerabilities - AccessControl, // Access control issues - IdentitySpoofing, // Identity spoofing - SessionExploitation, // Session exploitation - PrivilegeEscalation, // Privilege escalation - AuthenticationBypass, // Authentication bypass - RoleImpersonation, // Role impersonation - TokenManipulation, // Security token manipulation - - // Input Vulnerabilities - TaintedInput, // Tainted input processing - CommandInjection, // Command injection - ArgumentInjection, // Function argument injection - InsecureValidation, // Insecure validation - RegexVulnerability, // Regular expression vulnerabilities - FormatStringVulnerability,// Format string vulnerabilities - TypeConfusion, // Type confusion attacks - - // Module Vulnerabilities - UnsafeRequire, // Unsafe require() calls - ModuleInjection, // Module injection - ModuleHijacking, // Module hijacking - PathTraversal, // Path traversal in module loading - RequiredDependencyAttack, // Required dependency attacks - - // Game Logic Vulnerabilities - LogicFlaw, // Logic flaws (e.g., teleportation exploits) - TimingAttack, // Timing-based attacks - RaceCondition, // Race conditions - StateManipulation, // Game state manipulation - PhysicsExploitation, // Physics engine exploitation - CollisionBypass, // Collision detection bypass - TeleportExploitation, // Teleport exploitation - CharacterStateManipulation,// Character state manipulation - - // Event System Vulnerabilities - EventHijacking, // Event hijacking - EventSpoofing, // Event spoofing - EventFlooding, // Event flooding - EventSequencing, // Event sequencing attacks - EventCallbackManipulation,// Event callback manipulation - - // UI Vulnerabilities - UIVulnerability, // UI-based vulnerabilities - ClickjackingVulnerability,// Clickjacking vulnerability - UserInterfaceSpoofing, // User interface spoofing - ScreenManipulation, // Screen manipulation - - // Resource Vulnerabilities - ResourceExhaustion, // Resource exhaustion - InfiniteYield, // Infinite yield exploitation - MemoryLeakExploitation, // Memory leak exploitation - AssetExploitation, // Asset exploitation - - // Anti-Cheat Bypass Vulnerabilities - AntiCheatBypass, // Anti-cheat system bypass - DetectionEvasion, // Detection evasion techniques - HookingVulnerability, // Hooking vulnerability - ObfuscationTechnique, // Malicious obfuscation technique - - // Environment Vulnerabilities - SandboxEscape, // Sandbox escape - PlatformSpecificExploit, // Platform-specific exploit - OperatingSystemBypass, // Operating system security bypass - HardwareExploitation, // Hardware exploitation - - // Zero-Day Category - ZeroDayVulnerability, // Unknown/zero-day vulnerabilities - AdvancedPersistentThreat, // Advanced persistent threat techniques - - // General Categories - Other, // Other vulnerabilities - Custom // Custom vulnerability type - }; - - // Vulnerability severity enumeration - enum class VulnSeverity { - Critical, // Critical severity - high impact, easy to exploit - High, // High severity - high impact, moderate to exploit - Medium, // Medium severity - moderate impact or difficulty - Low, // Low severity - low impact or high difficulty - Info // Informational - potential issues, not directly exploitable - }; - - // Enhanced vulnerability structure with additional context - struct Vulnerability { - VulnType m_type; // Vulnerability type - VulnSeverity m_severity; // Vulnerability severity - std::string m_description; // Vulnerability description - std::string m_affectedCode; // Affected code snippet - int m_lineNumber; // Line number (if known) - std::string m_mitigation; // Suggested mitigation - float m_confidence; // Detection confidence (0-1) - std::string m_technicalDetails; // Technical details - std::vector m_dataFlowPath; // Data flow path (if applicable) - std::vector m_relatedVulns; // Related vulnerabilities - - Vulnerability() : m_type(VulnType::Other), m_severity(VulnSeverity::Info), - m_lineNumber(0), m_confidence(1.0f) {} - }; - - // Enhanced context information for vulnerability scanning - struct ScanContext { - std::string m_gameType; // Type of Roblox game - std::vector m_knownScripts; // Known scripts in the game - std::unordered_map> m_remoteEvents; // Remote events and handlers - bool m_isServerScript; // Whether script is run on server - std::set m_usedServices; // Roblox services used - std::set m_importedModules; // Imported modules - std::vector m_dataStores; // DataStores accessed - std::unordered_map m_variableTypes; // Variable type information - std::vector> m_dataFlows; // Data flow information - std::string m_securityContext; // Security context - bool m_hasAuthentication; // Has authentication - bool m_usesEncryption; // Uses encryption - - ScanContext() : m_isServerScript(false), m_hasAuthentication(false), m_usesEncryption(false) {} - }; - - // Detection strategy enumeration - enum class DetectionStrategy { - PatternMatching, // Regular expression pattern matching - DataFlowAnalysis, // Data flow tracking analysis - SemanticAnalysis, // Semantic understanding analysis - ContextualAnalysis, // Context-aware analysis - HeuristicAnalysis, // Heuristic-based analysis - BehavioralAnalysis, // Behavior-based analysis - MachineLearning, // Machine learning-based detection - ZeroDayDetection, // Zero-day vulnerability detection - HybridDetection // Hybrid approach combining multiple strategies - }; - -private: - // Enhanced vulnerability signature structure - struct VulnSignature { - VulnType m_type; // Vulnerability type - VulnSeverity m_severity; // Default severity - std::string m_pattern; // Pattern to match - std::string m_description; // Description template - std::string m_mitigation; // Mitigation template - std::vector m_contexts; // Applicable contexts - std::vector m_antiPatterns; // Patterns that indicate it's NOT this vulnerability - DetectionStrategy m_strategy; // Preferred detection strategy - float m_baseConfidence; // Base confidence score - - VulnSignature() : m_type(VulnType::Other), m_severity(VulnSeverity::Info), - m_strategy(DetectionStrategy::PatternMatching), m_baseConfidence(0.8f) {} - }; - - // Advanced signature for complex vulnerabilities - struct AdvancedSignature { - VulnType m_type; // Vulnerability type - VulnSeverity m_severity; // Default severity - std::vector m_patterns; // Multiple patterns to match - bool m_requiresAllPatterns; // Whether all patterns must match - std::string m_description; // Description template - std::string m_mitigation; // Mitigation template - DetectionStrategy m_primaryStrategy; // Primary detection strategy - DetectionStrategy m_secondaryStrategy;// Secondary detection strategy - std::function m_customValidator; // Custom validation - - AdvancedSignature() : m_type(VulnType::Other), m_severity(VulnSeverity::Info), - m_requiresAllPatterns(false), - m_primaryStrategy(DetectionStrategy::PatternMatching), - m_secondaryStrategy(DetectionStrategy::ContextualAnalysis) {} - }; - - // Data flow node for tracking tainted data - struct DataFlowNode { - std::string m_variableName; // Variable name - std::vector m_sources; // Data sources - std::vector m_sinks; // Data sinks - bool m_isTainted; // Is data tainted - std::vector m_sanitizers; // Applied sanitizers - - DataFlowNode() : m_isTainted(false) {} - }; - - // Member variables - std::vector m_signatures; // Basic vulnerability signatures - std::vector m_advSignatures; // Advanced vulnerability signatures - std::unordered_map m_severityWeights; // Severity adjustment weights - std::unordered_map m_patternOverrides; // Pattern overrides - - // Enhanced detection capabilities - std::unordered_map> m_dataFlowGraphs; // Data flow graphs - std::unordered_map>> m_semanticRules; // Semantic rules - std::unordered_map> m_contextVulnMap; // Context to vulnerability mapping - - // Roblox API Context - mapping of API calls to security impact - std::unordered_map m_apiSecurityImpact; - - // Contextual security knowledge for object types - std::unordered_map> m_secureUsagePatterns; - - // Self-improvement data - struct ImprovementData { - int m_truePositives; // True positive detections - int m_falsePositives; // False positive detections - int m_falseNegatives; // False negative detections - std::unordered_map m_patternSuccesses; // Successful patterns - std::unordered_map m_patternFailures; // Failed patterns - std::unordered_map m_typeAccuracy; // Accuracy by type - std::unordered_map m_strategyEffectiveness; // Strategy effectiveness - - ImprovementData() : m_truePositives(0), m_falsePositives(0), m_falseNegatives(0) {} - }; - - ImprovementData m_improvementData; // Self-improvement data - - // Zero-day vulnerability detection - struct ZeroDayDetector { - std::vector m_anomalyPatterns; // Anomaly patterns - std::unordered_map m_baseline; // Baseline metrics - float m_anomalyThreshold; // Anomaly threshold - - ZeroDayDetector() : m_anomalyThreshold(0.85f) {} - }; - - ZeroDayDetector m_zeroDayDetector; // Zero-day detector - - // Detection configuration - bool m_enableDataFlowAnalysis; // Whether to enable data flow analysis - bool m_enableSemanticAnalysis; // Whether to enable semantic analysis - bool m_enableZeroDayDetection; // Whether to enable zero-day detection - bool m_enableAllVulnerabilityTypes; // Whether to enable detection of ALL types - float m_detectionThreshold; // Detection confidence threshold - - // Initialize context data - bool InitializeContextData(); - - // Initialize advanced detection capabilities - bool InitializeAdvancedDetection(); - - // Load signatures from file - bool LoadSignatures(); - - // Save signatures to file - bool SaveSignatures(); - - // Override methods from LocalModelBase - bool InitializeModel() override; - bool TrainModel(TrainingProgressCallback progressCallback = nullptr) override; - std::string PredictInternal(const std::string& input) override; - std::vector FeaturizeInput(const std::string& input) override; - std::string ProcessOutput(const std::vector& output) override; - - // Pattern matching - bool MatchesPattern(const std::string& code, const std::string& pattern); - - // Advanced pattern matching - bool MatchesAdvancedPattern(const std::string& code, const std::vector& patterns, bool requireAll); - - // Extract context from script - ScanContext ExtractContext(const std::string& script); - - // Generate vulnerability report - std::string GenerateVulnerabilityReport(const std::vector& vulnerabilities); - - // Analyze code for vulnerabilities - internal implementation - std::vector AnalyzeCodeInternal(const std::string& code, const ScanContext& context); - - // Specialized analysis methods - std::vector PerformPatternAnalysis(const std::string& code, const ScanContext& context); - std::vector PerformDataFlowAnalysis(const std::string& code, const ScanContext& context); - std::vector PerformSemanticAnalysis(const std::string& code, const ScanContext& context); - std::vector PerformZeroDayDetection(const std::string& code, const ScanContext& context); - - // Self-improvement methods - void UpdateSignaturesFromFeedback(); - void GenerateNewSignatures(); - void OptimizePatterns(); - void AdjustSeverities(); - void ImproveDetectionStrategies(); - void LearnFromFalseNegatives(); - void GenerateZeroDayDetectors(); - - // Helper methods - std::vector MergeAndDeduplicateResults(const std::vector>& results); - float CalculateConfidenceScore(const Vulnerability& vuln, const ScanContext& context); - -public: - /** - * @brief Constructor - */ - VulnerabilityDetectionModel(); - - /** - * @brief Destructor - */ - ~VulnerabilityDetectionModel(); - - /** - * @brief Analyze code for ALL types of vulnerabilities - * @param code Code to analyze - * @param context Optional context information - * @return List of detected vulnerabilities - */ - std::vector AnalyzeCode(const std::string& code, const ScanContext& context = ScanContext()); - - /** - * @brief Analyze code for ALL types of vulnerabilities - * @param code Code to analyze - * @param gameType Type of Roblox game - * @param isServerScript Whether script is run on server - * @return List of detected vulnerabilities - */ - std::vector AnalyzeCode(const std::string& code, const std::string& gameType, bool isServerScript = false); - - /** - * @brief Perform deep scan for ALL possible vulnerabilities - * @param code Code to analyze - * @param gameType Type of Roblox game - * @param isServerScript Whether script is run on server - * @param enableDataFlow Whether to enable data flow analysis - * @param enableZeroDay Whether to enable zero-day detection - * @return List of detected vulnerabilities - */ - std::vector DeepScanAllVulnerabilities( - const std::string& code, - const std::string& gameType = "Generic", - bool isServerScript = false, - bool enableDataFlow = true, - bool enableZeroDay = true); - - /** - * @brief Provide feedback on detection results - * @param code Code that was analyzed - * @param vulnerabilities Vulnerabilities that were detected - * @param correctDetections Map of vulnerability index to correctness (true if correct) - * @return True if feedback was processed successfully - */ - bool ProvideFeedback(const std::string& code, - const std::vector& vulnerabilities, - const std::unordered_map& correctDetections); - - /** - * @brief Get vulnerability type string - * @param type Vulnerability type - * @return String representation - */ - static std::string GetVulnTypeString(VulnType type); - - /** - * @brief Get vulnerability severity string - * @param severity Vulnerability severity - * @return String representation - */ - static std::string GetVulnSeverityString(VulnSeverity severity); - - /** - * @brief Generate mitigation advice for a vulnerability - * @param vulnerability Vulnerability to mitigate - * @return Mitigation advice - */ - std::string GenerateMitigationAdvice(const Vulnerability& vulnerability); - - /** - * @brief Add a custom signature - * @param type Vulnerability type - * @param pattern Pattern to match - * @param description Description template - * @param mitigation Mitigation template - * @param severity Default severity - * @return True if signature was added successfully - */ - bool AddCustomSignature(VulnType type, - const std::string& pattern, - const std::string& description, - const std::string& mitigation, - VulnSeverity severity = VulnSeverity::Medium); - - /** - * @brief Add an advanced signature for complex vulnerabilities - * @param type Vulnerability type - * @param patterns Multiple patterns to match - * @param requireAllPatterns Whether all patterns must match - * @param description Description template - * @param mitigation Mitigation template - * @param severity Default severity - * @return True if signature was added successfully - */ - bool AddAdvancedSignature(VulnType type, - const std::vector& patterns, - bool requireAllPatterns, - const std::string& description, - const std::string& mitigation, - VulnSeverity severity = VulnSeverity::High); - - /** - * @brief Force self-improvement cycle - * @return True if improvement was successful - */ - bool ForceSelfImprovement(); - - /** - * @brief Get detection accuracy - * @return Accuracy (0-1) - */ - float GetDetectionAccuracy() const; - - /** - * @brief Configure detection options - * @param enableDataFlow Whether to enable data flow analysis - * @param enableSemantic Whether to enable semantic analysis - * @param enableZeroDay Whether to enable zero-day detection - * @param enableAllVulnTypes Whether to enable ALL vulnerability types - * @param detectionThreshold Confidence threshold (0-1) - */ - void ConfigureDetection(bool enableDataFlow, - bool enableSemantic, - bool enableZeroDay, - bool enableAllVulnTypes = true, - float detectionThreshold = 0.5f); - - /** - * @brief Enable detection of ALL vulnerability types - * This ensures the model checks for every possible vulnerability - */ - void EnableAllVulnerabilityTypes(); - - /** - * @brief Get all detectable vulnerability types - * @return Set of all vulnerability types the model can detect - /** - * @brief Check if the model is initialized - * @return True if initialized - */ - bool IsInitialized() const; - - /** - * @brief 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 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 - */ diff --git a/source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.backup3 b/source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.backup3 deleted file mode 100644 index 846d03b7..00000000 --- a/source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.backup3 +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once - -#include "LocalModelBase.h" -#include -#include -#include -#include -#include - -namespace iOS { -namespace AIFeatures { -namespace LocalModels { - -/** - * @enum VulnType - * @brief Types of vulnerabilities that can be detected - */ -enum class VulnType { - SQL_INJECTION, - XSS, - CODE_INJECTION, - COMMAND_INJECTION, - BUFFER_OVERFLOW, - PATH_TRAVERSAL, - DENIAL_OF_SERVICE, - UNAUTHORIZED_ACCESS, - INSECURE_SERIALIZATION, - MEMORY_LEAKS, - INFORMATION_DISCLOSURE, - PRIVILEGE_ESCALATION, - UNSANITIZED_INPUT, - OTHER -}; - -/** - * @brief Convert vulnerability type to string - * @param type Vulnerability type - * @return String representation - */ -std::string VulnTypeToString(VulnType type); - -/** - * @brief Convert string to vulnerability type - * @param str String representation - * @return Vulnerability type or VulnType::OTHER if not recognized - */ -VulnType StringToVulnType(const std::string& str); - -/** - * @class VulnerabilityDetectionModel - * @brief Model for detecting potential vulnerabilities in code - * - * This model analyzes scripts and identifies potential security vulnerabilities - * using a combination of pattern matching and more advanced ML techniques. - */ -class VulnerabilityDetectionModel : public LocalModelBase { -public: - /** - * @struct Vulnerability - * @brief Represents a detected vulnerability - */ - struct Vulnerability { - VulnType type; // Type of vulnerability - int lineNumber; // Line number where vulnerability was detected - std::string description; // Description of the vulnerability - std::string snippet; // Code snippet containing the vulnerability - int severity; // Severity level (1-5, 5 being most severe) - std::string recommendation; // Recommended fix - - Vulnerability() - : type(VulnType::OTHER), lineNumber(-1), severity(1) {} - - Vulnerability(VulnType t, int line, const std::string& desc, - const std::string& snip, int sev, const std::string& rec) - : type(t), lineNumber(line), description(desc), - snippet(snip), severity(sev), recommendation(rec) {} - }; - - /** - * @brief Constructor - */ - VulnerabilityDetectionModel(); - - /** - * @brief Destructor - */ - virtual ~VulnerabilityDetectionModel(); - - /** - * @brief Initialize the model - * @param path Path to model files - * @return True if initialization succeeded - */ - bool Initialize(const std::string& path); - - /** - * @brief Load the model from disk - * @return True if load succeeded - */ - bool Load(); - - /** - * @brief Save the model to disk - * @return True if save succeeded - */ - bool Save(); - - /** - * @brief Train the model - * @return True if training succeeded - */ - bool Train(); - - /** - * @brief Detect vulnerabilities in a script - * @param script Script to analyze - * @return Vector of detected vulnerabilities - */ - std::vector DetectVulnerabilities(const std::string& script); - - /** - * @brief Get all detectable vulnerability types - * @return Set of all vulnerability types the model can detect - */ - std::set GetAllDetectableVulnerabilityTypes() const; -}; - -} // namespace LocalModels -} // namespace AIFeatures -} // namespace iOS diff --git a/source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.bak2 b/source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.bak2 deleted file mode 100644 index 0c1b85f5..00000000 --- a/source/cpp/ios/ai_features/local_models/VulnerabilityDetectionModel.h.bak2 +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once - -#include "LocalModelBase.h" -#include -#include -#include -#include -#include - -namespace iOS { -namespace AIFeatures { -namespace LocalModels { - -/** - * @enum VulnType - * @brief Types of vulnerabilities that can be detected - */ -enum class VulnType { - SQL_INJECTION, - XSS, - CODE_INJECTION, - COMMAND_INJECTION, - BUFFER_OVERFLOW, - PATH_TRAVERSAL, - DENIAL_OF_SERVICE, - UNAUTHORIZED_ACCESS, - INSECURE_SERIALIZATION, - MEMORY_LEAKS, - INFORMATION_DISCLOSURE, - PRIVILEGE_ESCALATION, - UNSANITIZED_INPUT, - OTHER -}; - -/** - * @brief Convert vulnerability type to string - * @param type Vulnerability type - * @return String representation - */ -std::string VulnTypeToString(VulnType type); - -/** - * @brief Convert string to vulnerability type - * @param str String representation - * @return Vulnerability type or VulnType::OTHER if not recognized - */ -VulnType StringToVulnType(const std::string& str); - -/** - * @class VulnerabilityDetectionModel - * @brief Model for detecting potential vulnerabilities in code - * - * This model analyzes scripts and identifies potential security vulnerabilities - * using a combination of pattern matching and more advanced ML techniques. - */ -class VulnerabilityDetectionModel : public LocalModelBase { -public: - /** - * @struct Vulnerability - * @brief Represents a detected vulnerability - */ - struct Vulnerability { - VulnType type; // Type of vulnerability - int lineNumber; // Line number where vulnerability was detected - std::string description; // Description of the vulnerability - std::string snippet; // Code snippet containing the vulnerability - int severity; // Severity level (1-5, 5 being most severe) - std::string recommendation; // Recommended fix - - Vulnerability() - : type(VulnType::OTHER), lineNumber(-1), severity(1) {} - - Vulnerability(VulnType t, int line, const std::string& desc, - const std::string& snip, int sev, const std::string& rec) - : type(t), lineNumber(line), description(desc), - snippet(snip), severity(sev), recommendation(rec) {} - }; - - /** - * @brief Constructor - */ - VulnerabilityDetectionModel(); - - /** - * @brief Destructor - */ - virtual ~VulnerabilityDetectionModel(); - - /** - * @brief Initialize the model - * @param path Path to model files - * @return True if initialization succeeded - */ - bool Initialize(const std::string& path) override; - - /** - * @brief Load the model from disk - * @return True if load succeeded - */ - bool Load() override; - - /** - * @brief Save the model to disk - * @return True if save succeeded - */ - bool Save() override; - - /** - * @brief Train the model - * @return True if training succeeded - */ - bool Train() override; - - /** - * @brief Detect vulnerabilities in a script - * @param script Script to analyze - * @return Vector of detected vulnerabilities - */ - std::vector DetectVulnerabilities(const std::string& script); - - /** - * @brief Get all detectable vulnerability types - * @return Set of all vulnerability types the model can detect - */ - std::set GetAllDetectableVulnerabilityTypes() const; -}; - -} // namespace LocalModels -} // namespace AIFeatures -} // namespace iOS diff --git a/source/cpp/memory/signature.hpp.bak b/source/cpp/memory/signature.hpp.bak deleted file mode 100644 index 269d1fef..00000000 --- a/source/cpp/memory/signature.hpp.bak +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include "mem.hpp" - -namespace Memory { - - // Pattern scanning utilities - class PatternScanner { - public: - // Convert a pattern string like "48 8B 05 ?? ?? ?? ??" to bytes vector - static std::vector PatternToBytes(const char* pattern) { - std::vector bytes; - char* start = const_cast(pattern); - char* end = start + strlen(pattern); - - for (char* current = start; current < end; ++current) { - if (*current == '?') { - // Skip wildcard and add a placeholder - bytes.push_back(0); - if (*(current + 1) == '?') current++; // Skip if double wildcard - } else if (*current == ' ') { - // Skip spaces - continue; - } else { - // Read a hex byte - char byte[3] = { current[0], current[1], 0 }; - bytes.push_back(static_cast(strtol(byte, nullptr, 16))); - current++; - } - } - return bytes; - } - - // Scan a memory region for a pattern - static uintptr_t FindPattern(uintptr_t moduleBase, size_t moduleSize, const char* pattern) { - auto patternBytes = PatternToBytes(pattern); - auto moduleEnd = moduleBase + moduleSize - patternBytes.size(); - - for (auto addr = moduleBase; addr < moduleEnd; addr++) { - bool found = true; - - for (size_t i = 0; i < patternBytes.size(); i++) { - // If current pattern byte is 0, it's a wildcard - skip comparison - if (patternBytes[i] != 0 && *reinterpret_cast(addr + i) != patternBytes[i]) { - found = false; - break; - } - } - - if (found) return addr; - } - - return 0; - } - - // Get Roblox function address by pattern - static uintptr_t GetAddressByPattern(const char* pattern) { - // Get Roblox module info - uintptr_t base = getLibBase("libroblox.so"); - if (!base) return 0; - - // Approximate module size - in real implementation, should get actual size - // This is a placeholder. In a full implementation, you'd get the actual module size - constexpr size_t ESTIMATED_MODULE_SIZE = 50 * 1024 * 1024; // 50MB estimate - - // Find pattern - return FindPattern(base, ESTIMATED_MODULE_SIZE, pattern); - } - - // Get a relative address (used for x86_64 RIP-relative addressing) - static uintptr_t GetRelativeAddress(uintptr_t address, int offset, int instructionSize) { - return *reinterpret_cast(address + offset) + address + instructionSize; - } - }; - - // Known patterns for Roblox functions (these would need to be updated and tested) - namespace Patterns { - // These are example patterns - you would need to analyze Roblox binary to find actual patterns - constexpr const char* STARTSCRIPT = "55 8B EC 83 E4 F8 83 EC 18 56 8B 75 08 85 F6 74 ?? 57"; - constexpr const char* GETSTATE = "55 8B EC 56 8B 75 0C 83 FE 08 77 ?? 8B 45 08"; - constexpr const char* NEWTHREAD = "55 8B EC 56 8B 75 08 8B 46 ?? 83 F8 ?? 0F 8C ?? ?? ?? ??"; - constexpr const char* LUAULOAD = "55 8B EC 83 EC ?? 53 56 8B 75 08 8B 46 ?? 83 F8 ?? 0F 8C"; - constexpr const char* SPAWN = "55 8B EC 83 EC ?? 56 8B 75 08 8B 46 ?? 83 F8 ?? 0F 8C"; - } -} diff --git a/source/cpp/native-lib.cpp.old b/source/cpp/native-lib.cpp.old deleted file mode 100644 index 1ee40f75..00000000 --- a/source/cpp/native-lib.cpp.old +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -#include "utility.h" -// Skip iOS framework integration in CI builds to avoid compilation issues -#ifndef SKIP_IOS_INTEGRATION -#include "ios/ExecutionEngine.h" -#include "ios/ScriptManager.h" -#endif - -#include "hooks/hooks.hpp" -#include "memory/mem.hpp" - -// Entry point for the dylib -extern "C" { - __attribute__((constructor)) - void dylib_initializer() { - std::cout << "Roblox Executor dylib initialized" << std::endl; - - // Initialize hooks - Hooks::HookEngine::Initialize(); - - // Initialize memory system - Memory::Initialize(); - - #ifndef SKIP_IOS_INTEGRATION - // iOS-specific initialization (skipped in CI) - std::cout << "Initializing iOS integration" << std::endl; - #endif - } - - __attribute__((destructor)) - void dylib_finalizer() { - std::cout << "Roblox Executor dylib shutting down" << std::endl; - - // Clean up hooks - Hooks::HookEngine::ClearAllHooks(); - } - - // Lua module entry point - int luaopen_mylibrary(void* L) { - UNUSED_PARAM(L); - std::cout << "Lua module loaded: mylibrary" << std::endl; - - // This will be called when the Lua state loads our library - // Perform any Lua-specific initialization here - - return 1; // Return 1 to indicate success - } -} diff --git a/source/cpp/objc_isolation.h.bak b/source/cpp/objc_isolation.h.bak deleted file mode 100644 index b0b47094..00000000 --- a/source/cpp/objc_isolation.h.bak +++ /dev/null @@ -1,187 +0,0 @@ -// objc_isolation.h - Isolation layer for Objective-C and C++ interoperability -#pragma once - -// Standard library includes -#include -#include -#include - -// Include iOS compatibility header first -#include "ios_compat.h" - -// Base headers for Objective-C interactions -#ifdef __APPLE__ -#import - -// Hide Objective-C in C++ context -#ifdef __cplusplus -// Forward declarations of Objective-C classes to avoid including full headers in C++ code -@class UIView; -@class UIWindow; -@class UIButton; -@class UIViewController; -@class UIApplication; -@class UIControl; -@class UILabel; -@class UITextField; -@class UITextView; -@class UITableView; -@class UIScrollView; -@class UIImage; -@class UIImageView; -@class UIColor; -@class UIFont; -@class UIGestureRecognizer; -@class UIAlertController; -@class UIAlertAction; -@class UIActivityIndicatorView; -@class UISwitch; -@class CALayer; -@class NSString; -@class NSArray; -@class NSMutableArray; -@class NSDictionary; -@class NSMutableDictionary; -@class NSData; -@class NSMutableData; -@class NSNumber; -@class NSObject; -@class NSError; -@class NSTimer; -@class NSThread; -@class NSDate; -@class NSURLSession; -@class NSURLSessionDataTask; -@class NSURLRequest; -@class NSMutableURLRequest; -@class NSUserDefaults; -@class NSNotificationCenter; -@class NSCache; -@class NSFileManager; -@class NSBundle; -@class NSRunLoop; - -// Helper functions to convert between C++ and Objective-C types -namespace ObjCBridge { - // String conversion - NSString* CPPStringToNSString(const std::string& str); - std::string NSStringToCPPString(NSString* str); - - // Arrays - NSArray* CPPVectorToNSArray(const std::vector& vec); - std::vector NSArrayToCPPVector(NSArray* array); - - // Dictionaries - NSDictionary* CPPMapToNSDictionary(const std::map& map); - std::map NSDictionaryToCPPMap(NSDictionary* dict); - - // Opaque pointer wrapper for Objective-C objects to be used in C++ code - class ObjCWrapper { - private: - void* m_object; - - public: - ObjCWrapper() : m_object(nullptr) {} - ObjCWrapper(void* obj) : m_object(obj) {} - - void* get() const { return m_object; } - void set(void* obj) { m_object = obj; } - - bool isValid() const { return m_object != nullptr; } - void release(); - }; -} - -// Implementation of inline functions -inline NSString* ObjCBridge::CPPStringToNSString(const std::string& str) { - return [NSString stringWithUTF8String:str.c_str()]; -} - -inline std::string ObjCBridge::NSStringToCPPString(NSString* str) { - return str ? [str UTF8String] : ""; -} - -inline void ObjCBridge::ObjCWrapper::release() { - if (m_object) { - #if __has_feature(objc_arc) - // In ARC mode, we use CFBridgingRelease for proper memory management - // The cast is safe because we're releasing our ownership - CFRelease(m_object); - #else - // In non-ARC mode, we can call release directly - [(NSObject*)m_object release]; - #endif - m_object = nullptr; - } -} - -// Macro to safely bridge between C++ and Objective-C -#if __has_feature(objc_arc) -// ARC-specific bridging macros -#define OBJC_BRIDGE(objctype, cppvar) ((__bridge objctype*)(cppvar.get())) -#define OBJC_BRIDGE_CONST(objctype, cppvar) ((__bridge objctype*)(cppvar.get())) -#define CPP_BRIDGE(cppvar, objcvar) ((cppvar).set((__bridge void*)(objcvar))) -#define CPP_BRIDGE_TRANSFER(cppvar, objcvar) ((cppvar).set(CFBridgingRetain(objcvar))) -#else -// Non-ARC bridging macros -#define OBJC_BRIDGE(objctype, cppvar) ((__bridge objctype*)(cppvar.get())) -#define OBJC_BRIDGE_CONST(objctype, cppvar) ((__bridge objctype*)(cppvar.get())) -#define CPP_BRIDGE(cppvar, objcvar) ((cppvar).set((__bridge_retained void*)(objcvar))) -#define CPP_BRIDGE_TRANSFER(cppvar, objcvar) ((cppvar).set((__bridge_transfer void*)(objcvar))) -#endif - -#endif // __cplusplus -#endif // __APPLE__ - -// Define common constants and interfaces that can be used in both C++ and Objective-C -#ifdef __cplusplus -extern "C" { -#endif - -// Error codes -typedef enum { - kErrorNone = 0, - kErrorGeneric = -1, - kErrorInvalidArgument = -2, - kErrorMemoryAllocation = -3, - kErrorNotImplemented = -4, - kErrorNotSupported = -5, - kErrorPermissionDenied = -6, - kErrorTimeout = -7, - kErrorNotFound = -8, - kErrorAlreadyExists = -9, - kErrorNetworkFailure = -10 -} ErrorCode; - -// Platform detection (using a unique name to avoid conflicts with system headers) -#ifdef __APPLE__ - #define EXECUTOR_PLATFORM_IOS 1 -#else - #define EXECUTOR_PLATFORM_IOS 0 -#endif - -// Common function prototypes for platform abstraction -typedef void (*CallbackFunc)(void* context, int status, const char* message); - -#ifdef __cplusplus -} -#endif - -// Include platform-specific headers when not in Objective-C++ mode -#if !defined(__OBJC__) && defined(__APPLE__) - // Include minimal C declarations for iOS functions without requiring Objective-C - #ifdef __cplusplus - extern "C" { - #endif - // Declare minimal iOS functions we might need to call from C++ - int UIApplicationMain(int argc, char* argv[], void* principalClassName, void* delegateClassName); - void* UIGraphicsGetCurrentContext(void); - void UIGraphicsPushContext(void* context); - void UIGraphicsPopContext(void); - void UIGraphicsBeginImageContext(struct CGSize size); - void* UIGraphicsGetImageFromCurrentImageContext(void); - void UIGraphicsEndImageContext(void); - #ifdef __cplusplus - } - #endif -#endif