How m3rcer/irvana works
Project Type and Purpose
• IRvana is a command‐line, multi‐module framework for automating cross‐language LLVM IR generation, applying OLLVM obfuscation, and running IR in memory via various JIT interpreters.
• Primary use cases:
• IR generation pipelines for C, C++, Rust, and Nim
• IR obfuscation via OLLVM passes
• In‐memory IR execution (lli, MCJIT, ORCJIT)
• Malware development POCs (encrypted IR payload, remote IR staging)
High‐Level Architecture Layers
A. Environment & Toolchain Layer (Bottom)
• Windows SDK & MSVC runtime (detected by detect_sdk.bat → vs_env.mk)
• LLVM‐18.1.5 distribution (clang, clang++, llvm‐link, opt, lli, etc.)
• Nim 1.6.6 standalone compiler
• Rust nightly‐2024‐06‐26 toolchain
• Build tools: GNU Make, CMake, Visual Studio
B. IR Generation Layer
• IRgen orchestrator (IRvana.cpp / IRvana.sln)
• Per‐language modules under IRgen/ (c, cxx, nim, rust) each with:
– detect_sdk.bat & vs_env.mk → environment config
– Makefile.ir.mk → invokes frontend compiler (clang/clang‐cl, rustc, nim)
– src/ → user source
– ir_bin/ → outputs (*.ll or *.bc)
C. IR Transformation & Obfuscation Layer
• LLVM‐link & opt to combine IR modules
• OLLVM plugin (OLLVM/ollvm-pass) loaded by opt:
– Control‐flow flattening, string encryption, indirect branch/call, etc.
• Final IR output (final-obf.ll or final-obf.bc)
D. Execution & Interpreter Layer (Top)
• Built‐in interpreter: lli (LLVM toolchain)
• Custom C++ interpreters:
– MCJIT (Interpreters/cxx - MCJIT)
– ORCJIT (Interpreters/cxx - ORC JIT)
• Rust interpreter (Interpreters/Rust - MCJIT via Inkwell)
• Maldev POCs:
– IREncryption (AES decrypt IR in memory)
– RemoteLoad (HTTP‐fetch obfuscated IR, decrypt, JIT‐execute)
Data Flow & Component Interactions
1. User writes source in IRgen/*/src
2. IRvana.exe (or Makefile) triggers detect_sdk.bat → populates vs_env.mk
3. Makefile.ir.mk calls compiler with flags:
clang/clang‐cl -S -emit-llvm → .ll
rustc --emit=llvm-ir → .ll
nim c --cc:clang --opt:size → .ll
4. LLVM‐link merges per‐file IR → single IR module
5. opt loads OLLVM DLL → applies obfuscation passes
6. opt outputs final-obf.ll (text) or bitcode
7. Final IR can be:
• Saved to disk (ir_bin)
• Piped to lli for immediate execution
• Loaded by custom MCJIT/ORCJIT interpreters
• Embedded in Maldev executables (encrypted or remote)
8. In Maldev/RemoteLoad, HTTP client fetches encrypted IR → decrypt → feed to MCJIT/ORCJIT
Architectural Patterns & Principles
• Layered pipeline: clear separation of concerns (environment setup → IRgen → IR transform → execution)
• Plugin architecture: OLLVM as a dynamically‐loaded opt pass
• Cross‐language polymorphism: unified IR output consumed by same tool/exec layers
• Extensible modules: per‐language IRgen and interpreter backends as interchangeable components
• Reuse of open‐source tooling (LLVM, Make, CMake, rustc, nim)
In‐Depth IR Generation Details
• detect_sdk.bat → reads Windows SDK & MSVC paths → writes vs_env.mk
• Makefile.ir.mk invokes:
clang-cl –nologo –O2 –emit-llvm –S –o $(IR_BIN)/final.ll $(SRC)
• llvm-link $(IR_BIN)/*.bc –o merged.bc
• opt -load DLL -flatten -indirect-branch … –o final-obf.ll
• Optionally call llc to compile to native code or feed to JIT APIs
• For Rust, specify cargo +nightly llvm-ir or rustc --emit=llvm-bc