Enterprise-grade APK processing service with advanced compilation techniques
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
- 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
- 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
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 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- 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
- 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
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:3000Verify deployment:
# Check service health
curl http://localhost:3000/health
# View service logs
docker-compose logs -f dex2cIf you prefer manual setup without Docker:
-
Clone the repository
git clone https://github.com/springmusk026/dex2c-backend.git cd dex2c-backend -
Install Node.js dependencies
npm install
-
Environment setup
cp .env.example .env # Edit .env with your configuration -
Start MongoDB
# Using Docker (easiest) docker run -d -p 27017:27017 --name mongodb mongo:latest # Or install MongoDB locally
-
Install Dex2C dependencies
# Install Python dependencies pip3 install -r requirements.txt # Download Android NDK # Download apktool # Configure dcc.cfg
-
Start the application
# Development npm run dev # Production npm start
# Install dependencies
npm install
# Run tests
npm test
# Run linting
npm run lint
# Format code
npm run format
# Build for production
npm run buildConfigure 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=100Configure 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
}| 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 | - |
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-446655440000Download processed file:
curl -O http://localhost:3000/download/550e8400-e29b-41d4-a716-446655440000Get service statistics:
curl http://localhost:3000/statsDex2C 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.
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 dex2cOption 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-backendThe 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.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=3000The 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=100Development 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 bashProduction 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- Complete Environment: All dependencies pre-installed (Python, Java, Android NDK, Node.js)
- Environment Variables: Uses
.envfile 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
# 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# Generate coverage report
npm run test:coverage
# View coverage report
open coverage/lcov-report/index.html# Test API endpoints
curl -X POST http://localhost:3000/process
-F "[email protected]"
-F "dynamic_register=true"
# Health check
curl http://localhost:3000/health- 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
// Helmet configuration
helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
styleSrc: ["'self'", "'unsafe-inline'"],
scriptSrc: ["'self'"],
imgSrc: ["'self'", "data:", "https:"],
},
},
crossOriginEmbedderPolicy: false,
})- 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
- 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
# Basic health check
curl http://localhost:3000/health
# Detailed status
curl http://localhost:3000/stats- 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
- Job Statistics: Total jobs, status breakdown, active processes
- Performance Metrics: Average processing time, success rate
- Resource Usage: Memory, CPU, and disk usage monitoring
We welcome contributions! This project is built by developers for developers, and we appreciate any help in making it better.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run the test suite:
npm test - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow JavaScript Standard Style
- Use ESLint for code quality
- Write comprehensive tests for new features
- Update documentation for API changes
- Use JSDoc for function documentation
Found a bug? Please report it! We appreciate constructive feedback and help in fixing issues. Remember, we're all learning and improving together.
{
"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"
}{
"jest": "^29.7.0",
"supertest": "^6.3.3",
"eslint": "^8.55.0",
"prettier": "^3.1.1",
"nodemon": "^3.0.2"
}This project is licensed under the MIT License - see the LICENSE file for details.
- 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
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.orgMongoDB Connection Issues:
# Check if MongoDB is running
docker-compose ps
# View MongoDB logs
docker-compose logs mongodb
# Restart MongoDB
docker-compose restart mongodbFile Permission Issues:
# Fix upload/output directory permissions
sudo chown -R $USER:$USER ./uploads ./outputs
chmod -R 755 ./uploads ./outputs- Documentation: Wiki
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Developer Channel: Telegram - Layout_musk
- Developer Profile: GitHub - springmusk026
- Android Client: dex2c-android
- Developer Portfolio: Basanta Sapkota