<divclass="textblock"><p><aclass="anchor"id="md_README"></a> Theodosius (Theo for short) is a jit linker created for obfuscation. The project is extremely modular in design and supports both kernel and usermode projects. Theo works with static libraries rather than completely compiled binaries. This allows it to easily position, obfuscate, and scatter symbols anywhere as the project takes the place of the linker.</p>
<p>Then navigate into <code>dependencies/xed/</code> and run <code>python3 mfile.py</code>. Building XED can be tricky on windows, I suggest you use the visual studios console since it has env vars to everything needed to build XED. linux seems to build it just fine...</p>
<p>A linker is a program which takes object files produces by a compiler and generates a final executable native to the operating system. A linker interfaces with not only object files but also static libraries, "lib" files. What is a "lib" file? Well a lib file is just an archive of obj's. You can invision it as a zip/rar without any compression, just concatination of said object files.</p>
<p>Theo is a jit linker, which means it will link objs together and map them into memory all at once. For usability however, instead of handling object files, Theo can parse entire lib files and extract the objects out of the lib.</p>
<p>If you define a c++ file called "main.cpp" the compiler will generate an object file by the name of "main.obj". When you refer to data or code defined in another c/c++ file, the linker uses a symbol table to resolve the address of said code/data. In this situation I am the linker and I resolve all of your symbols :).</p>
<p>Static linking is when the linker links entire routines not created by you, into your code. Say <code>memcpy</code> (if its not inlined), will be staticlly linked with the CRT. Static linking also allows for your code to be more independant as all the code you need you bring with you. However, with Theo, you cannot link static libraries which are not compiled with <code>mcmodel=large</code>. Theo supports actual static linking, in other words, using multiple static libraries at the same time.</p>
<p>Dynamic linking is when external symbols are resolved at runtime. This is done by imports and exports in DLL's (dynamiclly linked libraries). Theo supports "dynamic linking", or in better terms, linking against exported routines. You can see examples of this inside of both usermode and kernelmode examples.</p>
<p>For integration with visual studios please open install <ahref="https://marketplace.visualstudio.com/items?itemName=MarekAniola.mangh-llvm2019">llvm2019</a> extension, or <ahref="https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm-toolchain">llvm2017</a> extension. Once installed, create or open a visual studio project which you want to use with LLVM-Obfuscator and Theo. Open <em><b>Properties</b></em> --><em><b>Configuration Properties</b></em>—><em><b>General</b></em>, then set <em><b>Platform Toolset</b></em> to <em><b>LLVM</b></em>.</p>
<p>Once LLVM is selected, under the <em><b>LLVM</b></em> tab change the clang-cl location to the place where you extracted <ahref="https://githacks.org/_xeroxz/theodosius/-/blob/cc9496ccceba3d1f0916859ddb2583be9362c908/resources/clang-cl.rar">clang-cl.rar</a>. Finally under <em><b>Additional Compiler Options</b></em> (same LLVM tab), set the following: <code>-Xclang -std=c++1z -Xclang -mcode-model -Xclang large -Xclang -fno-jump-tables -mllvm -split -mllvm -split_num=4 -mllvm -sub_loop=4</code>.</p>
<p>Please refer to the <ahref="https://github.com/obfuscator-llvm/obfuscator/wiki">LLVM-Obfuscator Wiki</a> for more information on commandline arguments.</p>
<p>In order to allow for a routine to be scattered throughout a 64bit address space, RIP relative addressing must not be used. In order to facilitate this, a very special version of clang-cl is used which can use <code>mcmodel=large</code>. This will generate instructions which do not use RIP relative addressing when referencing symbols outside of the routine in which the instruction itself resides. The only exception to this is JCC instructions, (besides call) also known as branching instructions. Take this c++ code for an example:</p>
</div><!-- fragment --><p>This c++ function, compiled by clang-cl with <code>mcmodel=large</code>, will generate a routine with the following instructions:</p>
</div><!-- fragment --><p>As you can see from the code above, (sorry for the terrible syntax highlighting), references to strings and calls to functions are done by first loading the address of the symbol into a register and then interfacing with the symbol.</p>
<li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>
<li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</li>
<li>Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.</li>
<p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. </p>