Dex2C-Backend — springmusk.dev

README.md files (31)

// project

Dex2C-Backend

Dex2C Backend is the server-side processing engine for the Dex2C ecosystem

31 stars 12 forks Watching: 31 Open issues: 0
  • JavaScript
  • Updated Oct 9, 2025

Built for learning and research.

Open on GitHub

Dex2C Backend

Enterprise-grade APK processing service with advanced compilation techniques

Node.js Express MongoDB License

Dex2C Backend is the server-side processing engine for the Dex2C ecosystem. This robust Node.js service handles APK file processing, job management, and C++ code generation using advanced obfuscation and compilation techniques. Built with enterprise-grade architecture principles, it provides a scalable foundation for transforming Android applications into optimized native code.

Note: This is the backend service for the Dex2C project. The Android client is available in a separate repository: dex2c-android

Features

Core Processing

  • APK to C++ Conversion: Transform Android applications into native C++ code
  • Advanced Obfuscation: String obfuscation, method protection, and code transformation
  • Intelligent Filtering: Custom protection rules with filter file support
  • Job Management: Complete job lifecycle with status tracking and cancellation
  • File Processing: Secure file upload, processing, and download management

Enterprise Features

  • Docker Ready: Complete containerization with all dependencies pre-installed
  • Scalable Architecture: Clean separation of concerns with MVC pattern
  • Database Integration: MongoDB with Mongoose ODM for job persistence
  • Security First: Rate limiting, CORS, Helmet security headers
  • Monitoring: Health checks, statistics, and comprehensive logging
  • Error Handling: Professional error management with detailed reporting

Architecture

Dex2C Backend follows Clean Architecture principles with enterprise-grade patterns:

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Controllers   │    │     Services    │    │      Models     │
│                 │    │                 │    │                 │
│ • HTTP Handlers │◄──►│ • Business Logic│◄──►│ • Data Schemas  │
│ • Request/Resp  │    │ • Job Processing│    │ • Job Tracking  │
│ • Validation    │    │ • File Management│    │ • Status Mgmt   │
└─────────────────┘    └─────────────────┘    └─────────────────┘

Tech Stack

  • Runtime: Node.js 18+ with Express.js
  • Database: MongoDB with Mongoose ODM
  • File Processing: Multer for uploads, native fs for management
  • Security: Helmet, CORS, Rate Limiting
  • Logging: Winston with structured logging
  • Testing: Jest with comprehensive coverage
  • Code Quality: ESLint, Prettier, JSDoc

Getting Started

Prerequisites

  • Docker & Docker Compose (Recommended - includes all dependencies)
  • OR Manual setup:
    • Node.js 18.0.0 or later (required for MongoDB driver compatibility)
    • MongoDB 5.0 or later
    • Python 3.10+ (for Dex2C tool)
    • Java 17+ (for Android development)
    • Android NDK r25b

Quick Start with Docker (Recommended)

One-command deployment:

# Clone and start the complete service
git clone https://github.com/springmusk026/dex2c-backend.git
cd dex2c-backend
docker-compose up -d

# Service will be available at http://localhost:3000

Verify deployment:

# Check service health
curl http://localhost:3000/health

# View service logs
docker-compose logs -f dex2c

Manual Installation (Alternative)

If you prefer manual setup without Docker:

  1. Clone the repository

    git clone https://github.com/springmusk026/dex2c-backend.git
    cd dex2c-backend
  2. Install Node.js dependencies

    npm install
  3. Environment setup

    cp .env.example .env
    # Edit .env with your configuration
  4. Start MongoDB

    # Using Docker (easiest)
    docker run -d -p 27017:27017 --name mongodb mongo:latest
    
    # Or install MongoDB locally
  5. Install Dex2C dependencies

    # Install Python dependencies
    pip3 install -r requirements.txt
    
    # Download Android NDK
    # Download apktool
    # Configure dcc.cfg
  6. Start the application

    # Development
    npm run dev
    
    # Production
    npm start

Development Setup

# Install dependencies
npm install

# Run tests
npm test

# Run linting
npm run lint

# Format code
npm run format

# Build for production
npm run build

Configuration

Environment Variables

Configure the service using environment variables in .env:

# Server Configuration
NODE_ENV=development
PORT=3000

# Database
MONGODB_URI=mongodb://localhost:27017/dex2c-api

# File Upload
MAX_FILE_SIZE=52428800
UPLOAD_FOLDER=/tmp/dcc_uploads
OUTPUT_FOLDER=/tmp/dcc_outputs
CLEANUP_INTERVAL=3600000

# CORS
CORS_ORIGIN=http://localhost:3000

# Process Configuration
PROCESS_TIMEOUT=600000
DCC_SCRIPT=dcc.py

# Security
RATE_LIMIT_WINDOW=900000
RATE_LIMIT_MAX=100

Processing Options

Configure default processing options in the API:

// Example processing parameters
{
  dynamic_register: true,      // Dynamic register natives
  skip_synthetic: false,       // Skip synthetic methods
  no_build: false,            // Disable build process
  force_keep_libs: false,     // Force keep libraries
  disable_signing: false,     // Disable APK signing
  filter: "custom_filter.txt", // Custom filter file
  custom_loader: "MyLoader",   // Custom loader class
  source_dir: "/path/to/src",  // Source directory
  project_archive: "project.zip" // Project archive
}

API Documentation

Core Endpoints

Method Endpoint Description Parameters
GET / Service information -
GET /health Health check -
POST /process Process APK file file, options
GET /status/:job_id Get job status job_id
GET /download/:job_id Download processed file job_id
DELETE /jobs/:job_id Cancel job job_id
DELETE /jobs/:job_id/cleanup Cleanup job job_id
GET /stats Get job statistics -

Usage Examples

Process an APK file:

curl -X POST http://localhost:3000/process 
  -F "[email protected]" 
  -F "dynamic_register=true" 
  -F "skip_synthetic=true" 
  -F "filter=@custom_filter.txt"

Check job status:

curl http://localhost:3000/status/550e8400-e29b-41d4-a716-446655440000

Download processed file:

curl -O http://localhost:3000/download/550e8400-e29b-41d4-a716-446655440000

Get service statistics:

curl http://localhost:3000/stats

Docker Deployment

Dex2C Backend comes with complete Docker support, including a production-ready Dockerfile and Docker Compose configuration. The Docker setup includes all necessary dependencies for APK processing, including Python, Java, Android NDK, and the Dex2C toolchain.

Quick Start with Docker

Option 1: Docker Compose (Recommended)

# Clone and start the service
git clone https://github.com/springmusk026/dex2c-backend.git
cd dex2c-backend
docker-compose up -d

# Check service status
docker-compose ps

# View logs
docker-compose logs -f dex2c

Option 2: Manual Docker Build

# Build the Docker image
docker build -t dex2c-backend .

# Run the container
docker run -d 
  --name dex2c-backend 
  -p 3000:3000 
  -v $(pwd)/uploads:/tmp/dcc_uploads 
  -v $(pwd)/outputs:/tmp/dcc_outputs 
  dex2c-backend

Docker Configuration

The included Dockerfile provides a complete development environment:

  • Base Image: Ubuntu 22.04 LTS
  • Python 3.10: For Dex2C toolchain execution
  • Java 17: OpenJDK for Android development
  • Android NDK r25b: Native development kit
  • Node.js: Runtime for the API service
  • Dex2C Toolchain: Pre-configured with all dependencies

Docker Compose Services

# docker-compose.yml
version: '3.9'

services:
  dex2c:
    build: .
    container_name: dex2c_app
    ports:
      - "3000:3000"  # Host:Container port mapping
    tty: true
    volumes:
      - ./uploads:/tmp/dcc_uploads
      - ./outputs:/tmp/dcc_outputs
    environment:
      - NODE_ENV=production
      - PORT=3000

Environment Configuration

The Docker setup uses environment variables from your .env file. Create a .env file with your configuration:

# Server Configuration
NODE_ENV=production
PORT=3000

# Database
MONGODB_URI=mongodb://mongodb:27017/dex2c-api

# File Upload
MAX_FILE_SIZE=52428800
UPLOAD_FOLDER=/tmp/dcc_uploads
OUTPUT_FOLDER=/tmp/dcc_outputs
CLEANUP_INTERVAL=3600000

# CORS
CORS_ORIGIN=http://localhost:3000

# Process Configuration
PROCESS_TIMEOUT=600000
DCC_SCRIPT=dcc.py

# Security
RATE_LIMIT_WINDOW=900000
RATE_LIMIT_MAX=100

Docker Commands

Development Commands:

# Start services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

# Rebuild and restart
docker-compose up --build -d

# Execute commands in container
docker-compose exec dex2c bash

Production Commands:

# Deploy with production environment
NODE_ENV=production docker-compose up -d

# Scale services (if needed)
docker-compose up --scale dex2c=3 -d

# Update services
docker-compose pull
docker-compose up -d

Docker Features

  • Complete Environment: All dependencies pre-installed (Python, Java, Android NDK, Node.js)
  • Environment Variables: Uses .env file for configuration
  • Volume Mounting: Persistent storage for uploads and outputs
  • Health Checks: Automatic service health monitoring
  • Network Isolation: Custom network for service communication
  • MongoDB Integration: Included database service

Testing

Test Suite

# Run all tests
npm test

# Run tests with coverage
npm run test -- --coverage

# Run specific test files
npm test -- --testNamePattern="JobController"

# Run tests in watch mode
npm run test:watch

Test Coverage

# Generate coverage report
npm run test:coverage

# View coverage report
open coverage/lcov-report/index.html

API Testing

# Test API endpoints
curl -X POST http://localhost:3000/process 
  -F "[email protected]" 
  -F "dynamic_register=true"

# Health check
curl http://localhost:3000/health

Security

Security Features

  • Rate Limiting: Configurable request limits per IP
  • File Validation: Type and size restrictions for uploads
  • Security Headers: Helmet.js protection against common attacks
  • CORS: Configurable cross-origin resource sharing
  • Input Sanitization: Comprehensive parameter validation
  • Process Isolation: Secure subprocess execution with timeouts

Security Headers

// Helmet configuration
helmet({
  contentSecurityPolicy: {
    directives: {
      defaultSrc: ["'self'"],
      styleSrc: ["'self'", "'unsafe-inline'"],
      scriptSrc: ["'self'"],
      imgSrc: ["'self'", "data:", "https:"],
    },
  },
  crossOriginEmbedderPolicy: false,
})

Performance

Optimizations

  • Memory Management: Efficient file handling with streaming
  • Process Management: Timeout and cancellation for long-running jobs
  • Database Optimization: Indexed queries and connection pooling
  • File Cleanup: Automatic cleanup of temporary files
  • Caching: Strategic caching for frequently accessed data

Benchmarks

  • File Processing: Supports APKs up to 50MB
  • Concurrent Jobs: Handles 100+ simultaneous processing jobs
  • Memory Usage: Optimized for servers with 2GB+ RAM
  • Response Time: Sub-second response for status checks

Monitoring

Health Checks

# Basic health check
curl http://localhost:3000/health

# Detailed status
curl http://localhost:3000/stats

Logging

  • Structured Logging: Winston with multiple log levels
  • Request Tracking: HTTP request/response logging
  • Error Tracking: Comprehensive error logging with stack traces
  • Performance Metrics: Processing time and resource usage

Metrics

  • Job Statistics: Total jobs, status breakdown, active processes
  • Performance Metrics: Average processing time, success rate
  • Resource Usage: Memory, CPU, and disk usage monitoring

Contributing

We welcome contributions! This project is built by developers for developers, and we appreciate any help in making it better.

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Run the test suite: npm test
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

Code Style

Bug Reports

Found a bug? Please report it! We appreciate constructive feedback and help in fixing issues. Remember, we're all learning and improving together.

Dependencies

Core Dependencies

{
  "express": "^4.18.2",
  "mongoose": "^8.0.3",
  "multer": "^1.4.5-lts.1",
  "cors": "^2.8.5",
  "helmet": "^7.1.0",
  "express-rate-limit": "^7.1.5",
  "winston": "^3.11.0",
  "dotenv": "^16.3.1",
  "uuid": "^9.0.1"
}

Development Dependencies

{
  "jest": "^29.7.0",
  "supertest": "^6.3.3",
  "eslint": "^8.55.0",
  "prettier": "^3.1.1",
  "nodemon": "^3.0.2"
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Node.js Team for the amazing runtime and ecosystem
  • Express.js team for the robust web framework
  • MongoDB team for the excellent database
  • Open Source Community for the incredible tools and libraries

Troubleshooting

Common Issues

Node.js Version Error:

SyntaxError: Unexpected token '?'

This error occurs when using Node.js < 18.0.0 with modern MongoDB drivers. The Docker setup automatically installs Node.js 18+, but if running manually, ensure you have Node.js 18.0.0 or later.

Solution:

# Check Node.js version
node --version

# If < 18.0.0, upgrade Node.js
# Using nvm (recommended)
nvm install 18
nvm use 18

# Or download from nodejs.org

MongoDB Connection Issues:

# Check if MongoDB is running
docker-compose ps

# View MongoDB logs
docker-compose logs mongodb

# Restart MongoDB
docker-compose restart mongodb

File Permission Issues:

# Fix upload/output directory permissions
sudo chown -R $USER:$USER ./uploads ./outputs
chmod -R 755 ./uploads ./outputs

Support

Related Projects


Built with ❤️ by [Basanta Sapkota](https://github.com/springmusk026)

⬆️ Back to Top

main JavaScript 31 Updated Oct 9, 2025 Built for learning and research.

DeepSeek-Chat-API-Client

A Node.js client library that demonstrates API interaction with chat.deepseek.com

  • JavaScript

who-is

A professional WHOIS data scraping module with structured parsing and batch processing capabilities.

  • JavaScript