Home / Documentation / API Reference

RedBoxVM API Reference

Complete API documentation for integrating RedBoxVM into your applications. This reference covers all public APIs, interfaces, and integration patterns.

SDK Version: This documentation covers RedBoxVM SDK v2.1.0 and later.

Core Classes

LazyVMCore

The main entry point for all RedBoxVM operations and virtualization management.

public class LazyVMCore extends ClientConfiguration {
    // Singleton instance
    public static LazyVMCore get()
    
    // Get application context
    public static Context getContext()
    
    // Get package manager
    public static PackageManager getPackageManager()
    
    // Get host package name
    public static String getHostPkg()
    
    // Get host UID
    public static int getHostUid()
    
    // Get host user ID
    public static int getHostUserId()
    
    // Check if services are available
    public boolean areServicesAvailable()
    
    // Get system service binder
    public IBinder getService(String name)
    
    // Enhanced UID management
    public void setCurrentAppUid(int uid, String packageName)
    public int getCurrentAppUid()
    public String getCurrentAppPackage()
    public boolean isSandboxedEnvironment()
}

Usage Example

// Get LazyVMCore instance
LazyVMCore core = LazyVMCore.get();

// Get application context
Context context = LazyVMCore.getContext();

// Get host package information
String hostPkg = LazyVMCore.getHostPkg();
int hostUid = LazyVMCore.getHostUid();

// Set current virtual app information
core.setCurrentAppUid(10123, "com.whatsapp");

// Check if running in sandboxed environment
if (core.isSandboxedEnvironment()) {
    Log.d("RedBox", "Running in virtual environment for: " + core.getCurrentAppPackage());
}

NativeCore

Native operations and low-level virtualization controls.

public class NativeCore {
    // Initialize native core with API level
    public static native void init(int apiLevel)
    
    // Enable I/O redirection
    public static native void enableIO()
    
    // Add I/O redirection rule
    public static native void addIORule(String targetPath, String relocatePath)
    
    // Hide Xposed framework
    public static native void hideXposed()
    
    // Disable hidden API restrictions
    public static native boolean disableHiddenApi()
    
    // System properties management
    public static native void nativeSetProp(String key, String value)
    public static native String nativeGetProp(String key)
    public static native void nativeClearProps()
    
    // Dynamic configuration
    public static native void setHostPackageName(String packageName)
    public static native void setVirtualAppInfo(String packageName, int processId, int userId)
    public static native String getHostPackageName()
    public static native String getVirtualPackageName()
    public static native boolean isHostProcess()
    public static native boolean isVirtualProcess()
    
    // Network virtualization
    public static native void enableNativeSSLBypass(boolean enable)
    public static native void enableNativeNetworkVirtualization(boolean enable)
    public static native void setNetworkInterface(String interfaceName, String macAddress, String ipAddress)
    
    // Authentication system
    public static native boolean initializeAuth()
    public static native boolean setClientLicense(String licenseKey)
    public static native boolean checkAuthStatus()
    public static native boolean checkAuthStatusForPackage(String packageName)
}

BActivityThread

Virtual activity thread management for app lifecycle control.

public class BActivityThread {
    // Get current virtual activity thread
    public static BActivityThread currentActivityThread()
    
    // Get application context
    public Application getApplication()
    
    // Get system context
    public Context getSystemContext()
    
    // Install virtual application
    public void installApplication(ApplicationInfo appInfo)
    
    // Handle virtual app lifecycle
    public void handleBindApplication(AppBindData data)
    
    // Process virtual app commands
    public void scheduleTransaction(ClientTransaction transaction)
}

Framework Classes

BPackageManager

Virtual package manager for handling app installations and queries.

public class BPackageManager {
    // Get virtual package manager instance
    public static BPackageManager get()
    
    // Install virtual application
    public InstallResult installPackage(String apkPath, InstallOption option)
    
    // Uninstall virtual application
    public boolean uninstallPackage(String packageName)
    
    // Get installed virtual packages
    public List<PackageInfo> getInstalledPackages(int flags)
    
    // Get package information
    public PackageInfo getPackageInfo(String packageName, int flags)
    
    // Get application information
    public ApplicationInfo getApplicationInfo(String packageName, int flags)
    
    // Check if package is installed
    public boolean isPackageInstalled(String packageName)
}

BUserManager

Virtual user management for multi-user virtualization.

public class BUserManager {
    // Get virtual user manager instance
    public static BUserManager get()
    
    // Create virtual user
    public BUserInfo createUser(String name, int flags)
    
    // Remove virtual user
    public boolean removeUser(int userId)
    
    // Get all virtual users
    public List<BUserInfo> getUsers()
    
    // Get current virtual user
    public BUserInfo getCurrentUser()
    
    // Switch to virtual user
    public boolean switchUser(int userId)
}

Implementation Example

// Install virtual app
BPackageManager pm = BPackageManager.get();
InstallOption option = new InstallOption();
option.userId = 0;
option.installFlags = PackageManager.INSTALL_REPLACE_EXISTING;

InstallResult result = pm.installPackage("/path/to/app.apk", option);
if (result.isSuccess()) {
    Log.d("RedBox", "App installed successfully: " + result.packageName);
} else {
    Log.e("RedBox", "Installation failed: " + result.error);
}

// Create virtual user
BUserManager um = BUserManager.get();
BUserInfo user = um.createUser("Virtual User 1", 0);
if (user != null) {
    Log.d("RedBox", "Created virtual user: " + user.name + " with ID: " + user.id);
}

API Flow Diagram

Understanding the typical API usage flow:

sequenceDiagram participant App as Your App participant Core as LazyVMCore participant Native as NativeCore participant PM as BPackageManager participant AT as BActivityThread App->>Core: LazyVMCore.get() App->>Native: NativeCore.init(apiLevel) Native->>Native: Initialize Hooks & I/O App->>PM: BPackageManager.get() App->>PM: installPackage(apkPath, option) PM->>Native: addIORule(targetPath, relocatePath) PM->>App: Return InstallResult App->>AT: BActivityThread.currentActivityThread() AT->>Native: setVirtualAppInfo(pkg, pid, uid) AT->>Core: Launch Virtual App Process Core->>App: Virtual App Running

Advanced APIs

IOCore

File system virtualization and I/O redirection management.

public class IOCore {
    // Get IOCore instance
    public static IOCore get()
    
    // Redirect file path
    public String redirectPath(String path)
    public File redirectPath(File path)
    
    // Add I/O redirection rule
    public void addRule(String targetPath, String relocatePath)
    
    // Enable I/O redirection
    public void enable()
    
    // Get virtual file system root
    public String getVirtualRoot()
    
    // Check if path is redirected
    public boolean isRedirected(String path)
}

BEnvironment

Virtual environment management and configuration.

public class BEnvironment {
    // Get virtual environment for user
    public static BEnvironment getVirtualEnvironment(int userId)
    
    // Get external storage directory
    public File getExternalStorageDirectory()
    
    // Get data directory for package
    public File getDataDirectory(String packageName)
    
    // Get cache directory for package
    public File getCacheDirectory(String packageName)
    
    // Get virtual system directory
    public File getSystemDirectory()
    
    // Check if environment is initialized
    public boolean isInitialized()
}

ServiceManager

Virtual system service management.

public class ServiceManager {
    // Get virtual service by name
    public static IBinder getService(String name)
    
    // Add virtual service
    public static void addService(String name, IBinder service)
    
    // Remove virtual service
    public static void removeService(String name)
    
    // List all virtual services
    public static String[] listServices()
    
    // Check if service exists
    public static boolean checkService(String name)
}

Error Handling

Exception Types

Exception Description Common Causes
RuntimeException General runtime error in virtualization Native core not initialized, hook installation failed
SecurityException Security or permission error Insufficient permissions, authentication failed
IllegalStateException Invalid virtualization state Services not available, invalid process state
UnsupportedOperationException Operation not supported Unsupported Android version, missing native library

Error Handling Example

try {
    // Initialize LazyVM core
    LazyVMCore core = LazyVMCore.get();
    NativeCore.init(Build.VERSION.SDK_INT);
    
    // Install virtual app
    BPackageManager pm = BPackageManager.get();
    InstallResult result = pm.installPackage("/path/to/app.apk", new InstallOption());
    
    if (!result.isSuccess()) {
        throw new RuntimeException("Installation failed: " + result.error);
    }
    
} catch (SecurityException e) {
    Log.e("RedBox", "Security error", e);
    // Handle authentication or permission issues
    if (!NativeCore.checkAuthStatus()) {
        showAuthenticationDialog();
    }
    
} catch (IllegalStateException e) {
    Log.e("RedBox", "Invalid state error", e);
    // Handle service availability issues
    if (!core.areServicesAvailable()) {
        showServiceUnavailableMessage();
    }
    
} catch (Exception e) {
    Log.e("RedBox", "Unexpected error", e);
    // Handle unexpected errors
    Slog.e("RedBox", "Critical error in virtualization", e);
}

Configuration Options

ClientConfiguration

public class ClientConfiguration {
    // Host package name
    public String getHostPackageName()
    
    // Virtual app package name
    public String getAppPackageName()
    
    // Process type (Main, BlackDaemon, etc.)
    public ProcessType getProcessType()
    
    // Enable debugging features
    public boolean isDebugMode()
    
    // Get configuration for specific package
    public AppConfig getAppConfig(String packageName)
}

InstallOption

public class InstallOption {
    // Target user ID for installation
    public int userId = 0;
    
    // Installation flags
    public int installFlags = 0;
    
    // Custom data directory
    public String customDataDir = null;
    
    // Enable external storage
    public boolean enableExternalStorage = true;
    
    // Copy APK to virtual environment
    public boolean copyApk = true;
    
    // Skip signature verification
    public boolean skipVerification = false;
}

System Properties Configuration

// Set system property for virtual environment
NativeCore.nativeSetProp("ro.build.version.release", "13");
NativeCore.nativeSetProp("ro.product.model", "Virtual Device");

// Get system property
String androidVersion = NativeCore.nativeGetProp("ro.build.version.release");

// Clear all custom properties
NativeCore.nativeClearProps();

// Network interface configuration
NativeCore.setNetworkInterface("wlan0", "02:00:00:00:00:00", "192.168.1.100");

// Enable SSL bypass for debugging
NativeCore.enableNativeSSLBypass(true);

// Enable network virtualization
NativeCore.enableNativeNetworkVirtualization(true);

Performance Monitoring

StealthMemoryReader

public class StealthMemoryReader {
    // Initialize stealth memory system
    public static boolean initialize()
    
    // Shutdown stealth memory system
    public static boolean shutdown()
    
    // Check if system is healthy
    public static boolean isReady()
    
    // Read memory from target process
    public byte[] readMemory(int pid, long address, int size)
    
    // Write memory to target process
    public boolean writeMemory(int pid, long address, byte[] data)
}

Performance Utilities

// Initialize stealth memory system
if (NativeCore.initializeStealthMemorySystem()) {
    Log.d("RedBox", "Stealth memory system initialized");
} else {
    Log.w("RedBox", "Failed to initialize stealth memory system");
}

// Check system health
boolean isHealthy = NativeCore.isStealthMemorySystemHealthy();
Log.d("RedBox", "Memory system health: " + isHealthy);

// Monitor virtual app performance
LazyVMCore core = LazyVMCore.get();
if (core.isSandboxedEnvironment()) {
    String currentApp = core.getCurrentAppPackage();
    int currentUid = core.getCurrentAppUid();
    Log.d("RedBox", "Monitoring app: " + currentApp + " (UID: " + currentUid + ")");
}

// Shutdown when done
NativeCore.shutdownStealthMemorySystem();

Process Information

// Check process type
if (NativeCore.isHostProcess()) {
    Log.d("RedBox", "Running in host process");
} else if (NativeCore.isVirtualProcess()) {
    Log.d("RedBox", "Running in virtual process");
    String virtualPkg = NativeCore.getVirtualPackageName();
    Log.d("RedBox", "Virtual package: " + virtualPkg);
}

// Get host information
String hostPkg = NativeCore.getHostPackageName();
Log.d("RedBox", "Host package: " + hostPkg);

Integration Patterns

Singleton Pattern

public class MyRedBoxIntegration {
    private static MyRedBoxIntegration instance;
    private LazyVMCore lazyVMCore;
    
    private MyRedBoxIntegration() {
        lazyVMCore = LazyVMCore.get();
        // Initialize native core
        NativeCore.init(Build.VERSION.SDK_INT);
    }
    
    public static MyRedBoxIntegration getInstance() {
        if (instance == null) {
            synchronized (MyRedBoxIntegration.class) {
                if (instance == null) {
                    instance = new MyRedBoxIntegration();
                }
            }
        }
        return instance;
    }
    
    public LazyVMCore getCore() {
        return lazyVMCore;
    }
}

Virtual App Management Pattern

public class VirtualAppManager {
    private final LazyVMCore core;
    private final BPackageManager packageManager;
    private final Map<String, InstallResult> installedApps;
    
    public VirtualAppManager() {
        core = LazyVMCore.get();
        packageManager = BPackageManager.get();
        installedApps = new HashMap<>();
    }
    
    public boolean installApp(String apkPath, String packageName) {
        try {
            InstallOption option = new InstallOption();
            option.userId = 0;
            option.copyApk = true;
            
            InstallResult result = packageManager.installPackage(apkPath, option);
            if (result.isSuccess()) {
                installedApps.put(packageName, result);
                Log.d("RedBox", "Successfully installed: " + packageName);
                return true;
            } else {
                Log.e("RedBox", "Installation failed: " + result.error);
                return false;
            }
        } catch (Exception e) {
            Log.e("RedBox", "Error installing app: " + packageName, e);
            return false;
        }
    }
    
    public boolean isAppInstalled(String packageName) {
        return packageManager.isPackageInstalled(packageName);
    }
    
    public List<PackageInfo> getInstalledApps() {
        return packageManager.getInstalledPackages(0);
    }
}
Thread Safety: LazyVMCore and NativeCore APIs are thread-safe, but package installation and I/O operations should be performed on background threads to avoid blocking the UI.

Authentication System

License Management

// Initialize authentication system
if (NativeCore.initializeAuth()) {
    Log.d("RedBox", "Authentication system initialized");
    
    // Set client license
    String licenseKey = "your-license-key-here";
    if (NativeCore.setClientLicense(licenseKey)) {
        Log.d("RedBox", "License validated successfully");
    } else {
        Log.e("RedBox", "License validation failed");
    }
} else {
    Log.e("RedBox", "Failed to initialize authentication");
}

// Check authentication status
boolean isAuthenticated = NativeCore.checkAuthStatus();
if (isAuthenticated) {
    Log.d("RedBox", "Client is authenticated");
} else {
    Log.w("RedBox", "Client authentication required");
}

// Check authentication for specific package
boolean canRunPackage = NativeCore.checkAuthStatusForPackage("com.example.app");
if (!canRunPackage) {
    Log.w("RedBox", "Package is not authorized to run");
}