Welcome to the Witchcraft Compiler Collection !
WCC is a collection of compilation tools to perform binary black magic on the GNU/Linux and other POSIX platforms.
The WCC user manual is available online at : https://github.com/endrazine/wcc/wiki
The Witchcraft Compiler Collection requires the following software to be installed:
Under Ubuntu/Debian those dependencies can be installed with the following commands (tested on Ubuntu 22.04):
This will download the code of wcc from the internet to a directory named wcc in the current working directory:
You can then enter this directory with:
From your root wcc directory, type:
From your root wcc directory, type:
Then to install wcc, type:
WCC makes use of doxygen to generate its documentation. From the root wcc directory, type
The following commands constitute the core of the Witchcraft Compiler Collection.
wld takes an ELF executable as an input and modifies it to create a shared library.
The following example libifies the executable /bin/ls into a shared library named /tmp/ls.so.
wld currently only works on ELF binaries. However wld can process ELF executables irrelevant of their architecture or operating system. wld could for instance process Intel, ARM or SPARC executables from Android, Linux, BSD or UNIX operating systems and transform them into "non relocatable shared libraries". Feel free to refer to the documentation under the /doc directory for more ample details.
The wcc compiler takes binaries (ELF, PE, ...) as an input and creates valid ELF binaries as an output. It can be used to create relocatable object files from executables or shared libraries.
The primary use of wcc is to "unlink" (undo the work of a linker) ELF binaries, either executables or shared libraries, back into relocatable shared objects. The following command line attempts to unlink the binary /bin/ls (from GNU binutils) into a relocatable file named /tmp/ls.o
This relocatable file can then be used as if it had been directly produced by a compiler. The following command would use the gcc compiler to link /tmp/ls.o into a shared library /tmp/ls.so
wcc will process any file supported by libbfd and produce ELF files that will contain the same mapping when relinked and executed. This includes PE or OSX COFF files in 32 or 64 bits. However, rebuilding relocations is currently supported only for Intel ELF x86_64 binaries. Transforming a PE into an ELF and invoking pure functions is for instance supported.
The witchcraft shell accepts ELF shared libraries, ELF ET_DYN executables and Witchcraft Shell Scripts written in Punk-C as an input. It loads all the executables in its own address space and makes their API available for programming in its embedded interpreter. This provides for binaries functionalities similar to those provided via reflection on languages like Java.
The following command loads the /usr/sbin/apache2 executable within wsh, calls the ap_get_server_banner() function within apache to retrieve its banner and displays it within the wsh interpreter.
To get help at any time from the wsh interpreter, simply type help. To get help on a particular topic, type help("topic").
The following example illustrates how to display the main wsh help from the interpreter and how to get detailed help on the grep command by calling help("grep") from the wsh interpreter.
The combination of a full lua interpreter in the same address space as the loaded executables and shared libraries in combination with the reflection like capabilities of wsh allow calling any function loaded in the address space from the wsh interpreter transparently. The resulting API, a powerful combination of lua and C API is called Punk-C. Wsh is fully scriptable in Punk-C, and executes Punk-C on the fly via its dynamic interpreter. Scripts in Punk C can be invoked by specifying the full path to wsh in the magic bytes of a wsh shell. The following command displays the content of a Witchcraft shell script:
To run this script using the API made available inside the address space of sshd, simply run:
wsh can only load shared libraries and ET_DYN dynamically linked ELF executables directly. This means ET_EXEC executables may need to be libified using wld before use in wsh. Binaries in other file formats might need to be turned into ELF files using wcc.
Note: Analysing and Executing ARM/SPARC/MIPS binaries "natively" on Intel x86_64 cpus via JIT binary translation
wsh can be cross compiled to ARM, SPARC, MIPS and other platforms and used in association with the qemu's user space emulation mode to provide JIT binary translation on the fly and analyse shared libraries and binaries from other cpus without requiring emulation of a full operating system in a virtual machine. The analyzed binaries are translated from one CPU to an other, and the analysed binaries, the wsh cross compiled analyser and the qemu binary translator share the address space of a single program. This significantly diminishes the complexity of analysing binaries across different hardware by seemingly allowing to run ARM or SPARC binaries on a linux x86_64 machine natively and transparently.
The following auxiliary commands are available with WCC. They are typically simple scripts built on top of WCC.
wldd : print shared libraries compilation flags
When compiling C code, it is often required to pass extra arguments to the compiler to signify which shared libraries should be explicitly linked against the compile code. Figuring out those compilation parameters can be cumbersome. The wldd commands displays the shared libraries compilation flags given at compile time for any given ELF binary.
The following command displays shared libraries compilation flags as passed to gcc when compiling /bin/ls from GNU binutils:
The wcch command takes an ELF binary path as a command line, and outputs a minimal C header file declaring all the exported global variables and functions from the input binary. This automates prototypes declaration when writing C code and linking with a binary for which C header files are not available.
The following command instructs wcch to generate C headers from the apache2 executable and redirects the output from the standard output to a file named /tmp/apache2.h ready for use as a header in a C application.
The official codebase of the Witchcraft Compiler Collection is hosted on github at https://github.com/endrazine/wcc/ . It uses git modules, so some extra steps are needed to fetch all the code including dependencies. To download the source code of wcc, in a terminal, type:
This will create a directory named wcc and fetch all required source code in it.
The Witchcraft Compiler Collection uses the following amazing Open Source third party software:
- Capstone, a lightweight multi-platform, multi-architecture disassembly framework http://www.capstone-engine.org/
- Linenoise, A small self-contained alternative to readline and libedit https://github.com/antirez/linenoise
- Openlibm, High quality system independent, portable, open source libm implementation https://github.com/JuliaMath/openlibm
- Lua, The Programming Language Lua https://www.lua.org/
- LuaJit, a Just-In-Time Compiler for Lua http://luajit.org/
- Qemu, in particular its user space mode : https://qemu-project.gitlab.io/qemu/user/main.html
- Uthash and Utlist, Hash tables and linked list implemented as C headers https://troydhanson.github.io/uthash/
The following companion repository exsists to help test WCC: https://github.com/endrazine/wcc-tests
The Witchcraft Compiler Collection is published under the MIT License. Please refer to the file named LICENSE for more information.
.png)

