Skip to content

gbfdhenr/Janus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Janus

Janus Native Bridge - ARM64/ARM32 to x86_64 Binary Translation Layer

Overview

Janus is a dynamic binary translation (DBT) library that enables running ARM64 and ARM32 (AArch32) binaries on x86_64 platforms. It implements the Android Native Bridge interface, allowing seamless execution of ARM libraries on x86_64 systems.

Features

  • ARM64 to x86_64 Translation: Full AArch64 instruction set translation including:

    • Data processing instructions (ADD, SUB, AND, ORR, etc.)
    • Load/store instructions
    • Control flow (branches, conditional branches, CBZ/CBNZ, TBZ/TBNZ)
    • SIMD/NEON instructions
    • Floating-point operations (VFP)
    • Atomic operations (LDAXR/STLXR, CAS, LDADD, etc.)
    • System instructions (MRS/MSR, barriers)
  • ARM32/Thumb to x86_64 Translation: Complete ARM32 and Thumb-16/32 support:

    • ARM32 data processing, load/store, multiply
    • VFP/NEON instructions
    • Thumb-16/32 instruction sets
    • CPSR state management
  • ELF Loading: Full ELF binary loading with:

    • Dynamic symbol resolution
    • Relocation handling (AARCH64 and ARM32)
    • Symbol versioning support
    • Auto-detection of binary architecture
  • Native Bridge API: Android-compatible interface:

    • NativeBridgeInitialize()
    • NativeBridgeLoadLibrary()
    • NativeBridgeGetTrampoline()
    • NativeBridgeIsSupported()
    • And more...
  • JNI Capture & Simulation: Advanced JNI debugging tools:

    • Real-time JNI call capture and logging
    • Native method call recording and replay
    • JNI simulation for testing
    • Method signature analysis and validation

Building

Prerequisites

  • GCC or compatible C compiler
  • GNU Make

Build Commands

# Build shared library
make

# Build with debug info
make debug

# Build with AVX support
make avx

# Clean build artifacts
make clean

The build produces libjanus.so, a shared library that can be loaded by compatible hosts.

API Usage

Initialization

janus_Context ctx;
janus_init(&ctx, "/path/to/arm/libs", "guest_cmd");

Mode Selection

// Set execution mode explicitly
janus_set_mode(&ctx, JANUS_MODE_ARM64);  // ARM64
janus_set_mode(&ctx, JANUS_MODE_ARM32);  // ARM32
janus_set_mode(&ctx, JANUS_MODE_THUMB);  // Thumb
janus_set_mode(&ctx, JANUS_MODE_AUTO);   // Auto-detect

Binary Translation

uint8_t *x86_code = NULL;
size_t x86_size = 0;
janus_convert(&ctx, arm_code, arm_code_size, &x86_code, &x86_size);
// ... execute x86_code ...
free(x86_code);  // Caller must free

ELF Loading

ElfModule *module;
ElfLoad("/path/to/arm/library.so", &module);
ElfRelocate(module);

void *symbol;
ElfGetSymbol(module, "function_name", &symbol);

Native Bridge Interface

NativeBridgeInitialize();
void *handle = NativeBridgeLoadLibrary("/path/to/lib.so", RTLD_NOW);
void *func = NativeBridgeGetTrampoline(handle, "function_name", NULL, 0);

Architecture

Project Structure

janus/
├── janus.c                  # Main integration file
├── janus.h                  # Public API and definitions
├── Makefile                 # Build system
├── LICENSE                  # LGPL v3+ license
└── modules/                 # Translation modules
    ├── janus_cpufeat.c      # CPU feature detection
    ├── janus_jumptable.c    # Jump table management
    ├── janus_arm64_32.c     # ARM64/ARM32 translation
    ├── janus_sve.c          # SVE instruction support
    ├── janus_jni_capture.c  # JNI call capture and recording
    ├── janus_jni_sim.c      # JNI call simulation
    └── janus_decode64.c     # Instruction decoding

Key Components

  • Instruction Decoder: Parses ARM64/ARM32/Thumb instructions into intermediate representation
  • Code Generator: Translates decoded instructions to x86_64 machine code
  • ELF Loader: Handles binary loading, relocation, and symbol resolution
  • DBT Runtime: Dynamic translation cache and execution engine
  • Native Bridge: Android-compatible API layer

License

This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0+). See the LICENSE file for details.

The LGPL license allows you to:

  • Use this library in proprietary applications
  • Link against the library without disclosing your source code
  • Modify the library itself (changes to the library must be released under LGPL)

About

ARM-to-x86_64 dynamic binary translation library. A libhoudini alternative for Android Translation Layer.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors