Skip to content

Main Application Documentation

Overview

The main.cpp file serves as the entry point for the NewScanmem application. It demonstrates basic module integration and provides a foundation for the memory scanning utility.

File Structure

import sets;

int main() {
    Set val;
    return 0;
}

Current Implementation

The current main function is minimal and serves as a placeholder for:

  1. Module Integration Testing: Demonstrates that the sets module can be successfully imported and used
  2. Basic Framework: Provides a starting point for application development
  3. Compilation Verification: Ensures all modules compile correctly together

Planned Features

Command Line Interface

// Future implementation
int main(int argc, char* argv[]) {
    // Parse command line arguments
    // Initialize modules
    // Start memory scanning
    // Display results
}

Integration Points

The main application will integrate all modules:

  1. Process Management (process_checker)
  2. Target process selection
  3. Process state monitoring
  4. Permission checking

  5. Memory Analysis (targetmem)

  6. Memory region scanning
  7. Value matching
  8. Pattern detection

  9. Data Types (value)

  10. Multi-type value support
  11. Endianness handling
  12. Byte array operations

  13. Utilities (sets, endianness, show_message)

  14. Set operations for results
  15. Byte order conversion
  16. User messaging and logging

Usage Examples

Basic Execution

# Current usage
./newscanmem

# Future usage examples
./newscanmem --pid 1234 --type int32 --value 42
./newscanmem --pid 1234 --range 0x1000-0x2000 --string "hello"
./newscanmem --pid 1234 --float --tolerance 0.001

Development Roadmap

Phase 1: Basic Framework

  • [ ] Command line argument parsing
  • [ ] Process selection and validation
  • [ ] Basic memory scanning
  • [ ] Result display

Phase 2: Advanced Features

  • [ ] Multiple value type support
  • [ ] Memory region filtering
  • [ ] Pattern matching
  • [ ] Interactive mode

Phase 3: Optimization

  • [ ] Performance tuning
  • [ ] Memory usage optimization
  • [ ] Parallel processing
  • [ ] Result caching

Phase 4: UI/UX

  • [ ] Progress indicators
  • [ ] Color output
  • [ ] Export formats
  • [ ] Configuration files

Module Integration Example

// Future main.cpp structure
import process_checker;
import targetmem;
import value;
import show_message;
import sets;
import endianness;

int main(int argc, char* argv[]) {
    MessagePrinter printer;

    // Parse arguments
    if (argc < 2) {
        printer.error("Usage: {} --pid <pid> [...]", argv[0]);
        return 1;
    }

    // Check process
    pid_t pid = std::stoi(argv[2]);
    if (ProcessChecker::is_process_dead(pid)) {
        printer.error("Process {} is not running", pid);
        return 1;
    }

    // Initialize scanner
    printer.info("Scanning process {}...", pid);

    // Perform scan
    MatchesAndOldValuesArray matches(get_memory_size(pid));
    // ... scanning logic ...

    // Display results
    printer.info("Found {} matches", get_total_matches(matches));

    return 0;
}

Build Instructions

Current Build

# Build the project
mkdir build && cd build
cmake ..
make

# Run the application
./newscanmem

Module Dependencies

The main application depends on all modules:

  • sets - Set operations and parsing
  • process_checker - Process state checking
  • targetmem - Memory analysis structures
  • value - Value type definitions
  • endianness - Byte order handling
  • show_message - Message and logging system

Testing Framework

Unit Tests

// Test basic functionality
void test_main_integration() {
    Set test_set;
    bool parse_result = parse_uintset("1,2,3", test_set, 100);
    assert(parse_result == true);
    assert(test_set.size() == 3);

    std::cout << "Main integration test passed!\n";
}

int main() {
    test_main_integration();
    return 0;
}

Configuration

Environment Variables

Future versions may support:

  • SCANMEM_DEBUG: Enable debug mode
  • SCANMEM_BACKEND: Enable backend mode
  • SCANMEM_LOG_FILE: Log file path

Configuration Files

# ~/.scanmemrc example
[general]
debug=true
backend=false

[scanning]
default_type=int32
batch_size=1000
timeout=30

Error Handling

Current Error Handling

The current implementation provides minimal error handling through:

  • Module import verification
  • Basic compilation checks
  • Placeholder return codes

Future Error Handling

enum class ScanError {
    SUCCESS = 0,
    INVALID_PID,
    PROCESS_NOT_FOUND,
    PERMISSION_DENIED,
    MEMORY_ACCESS_FAILED,
    INVALID_ARGUMENTS,
    OUT_OF_MEMORY
};

ScanError perform_scan(const ScanConfig& config);

Security Considerations

Current Security

  • No elevated privileges required
  • Read-only memory access
  • Process permission validation

Future Security

  • Capability checking
  • Sandboxing considerations
  • Secure memory access patterns
  • Input validation

Performance Metrics

Current Metrics

  • Compilation time: ~2-3 seconds
  • Binary size: ~50KB (minimal)
  • Memory usage: ~1MB (minimal)

Target Metrics

  • Scan speed: 1GB/sec for basic types
  • Memory usage: <100MB for large processes
  • Response time: <1 second for initial results

Platform Compatibility

Current Support

  • Linux: Full support (primary platform)
  • macOS: Planned support
  • Windows: Not currently supported

System Requirements

  • OS: Linux with /proc filesystem
  • Compiler: C++23 with modules support
  • Memory: 64MB minimum, 1GB recommended
  • Permissions: Read access to target process memory

Debugging

Debug Build

# Build with debug symbols
cmake -DCMAKE_BUILD_TYPE=Debug ..
make

# Run with debugger
gdb ./newscanmem
(gdb) run --pid 1234

Logging

// Enable debug logging
MessageContext ctx{.debugMode = true};
MessagePrinter printer(ctx);
printer.debug("Starting scan for PID: {}", pid);

Future API Design

Future API Command Line Interface

# Basic scan
./newscanmem --pid 1234 --int32 42

# Advanced scan
./newscanmem --pid 1234 --range 0x1000-0xFFFF --float 3.14 --tolerance 0.001

# Interactive mode
./newscanmem --interactive

# Batch mode
./newscanmem --pid 1234 --batch --output results.json

Programmatic API

// Future C++ API
class ScanManager {
public:
    ScanResult scan(const ScanConfig& config);
    void set_progress_callback(ProgressCallback callback);
    void cancel_scan();
};

See Also

Contributing

Development Setup

# Clone repository
git clone https://github.com/your-org/newscanmem.git
cd newscanmem

# Install dependencies
sudo apt install build-essential cmake libboost-all-dev

# Build and test
mkdir build && cd build
cmake ..
make test

Code Style

  • Use modern C++23 features
  • Follow RAII principles
  • Prefer compile-time checks
  • Use modules for encapsulation
  • Document public APIs

This project is part of the NewScanmem memory scanning utility. See individual module documentation for specific licensing information.

Support

For issues and questions:

  • Check individual module documentation
  • Review build requirements
  • Verify system compatibility
  • Test with minimal examples

CLI and REPL Integration

The main application now integrates a Command-Line Interface (CLI) with a REPL loop. This allows users to interactively execute commands for memory scanning and analysis. The main.cpp file initializes the REPL and registers commands such as help, quit, and pid.