<div dir="ltr"><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">I have a project with a number of large
constraints, and am uncertain of the optimal means of completion. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">Sorry if this question is answered elsewhere on
the forum, I couldn't find specifically what I was looking for. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif"> </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">Project Abstract: </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">Arbitrary code injection on a specified library
using clang and DYLD_INSERT_LIBRARIES (LD_PRELOAD) </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif"> </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">Project In English: </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">With the primary operating system being MacOS, I
want to be able to point at the include header or include directory for a
library of interest (Metal, OpenGL, OpenCL, Vulkan, DX). Clang will parse
through and collect all class and function decls (and any necessary typedefs
and enums) and spit out a YAML of all functions. The user would then specify
what code to be injected for which functions. Later, during runtime runtime for an
application that uses that library, apply dynamic library injection to shim those
function calls and execute the user's arbitrary code. This project can be
thought of as a very lightweight general shim. The primary application is
performance capture for graphics applications. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif"> </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">Constraints </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">1. Installing LLVM or clang with "make"
is not an option, more specifically, nothing can be copied to /usr and no
aliases or links can be made. Only libraries and tools included with Xcode are
viable. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">2. The arbitrary code will always be c++, but the
library includes can be any of the clang family languages (c, c++, obj-c, ...).
</span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">3. Xcode is only expected on Mac, but this must
work on all the three primary OSes (Win, Mac, Linux). i.e. the subset of clang
on Win, Linux, and constraint #1. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">4. The person doing arbitrary code execution
should be allowed as limited an understanding of clang and LLVM as possible,
ideally nothing (they are expected to understand the consequence of code
injection). </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif"> </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">Effectively I want one large AST where there are
no incomplete types, and everything is packaged as one. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">I would then parse through this AST scraping all
Decls. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">The YAML and code execution stuff has already been
completed. This project is a generalization of an existing project that is
specific to one graphics API. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif"> </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">So my questions: </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">1. Is there any way to get Libtooling to work with
the native Xcode (w/o violating constraint #1)? </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">2. For the Metal API there is a single header file
Metal.h that an application would #include in its source. This Metal.h file
#import(s) all of the other metal header files. Is there any way to run
libclang in a manner similar to "-fsyntax-only" where the
preprocessor is run and those other metal files are included in the AST? </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">3. If question #2 is a no, is there any one to use
the preprocessor for includes and imports with libclang? I can't seem to get
the AST of #imported files? </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">4. If libtooling is a no, and libclang is a no,
would it be a mistake to just string parse over the "-ast-dump"
output? Cause that's my backup. </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif"> </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">Thank you, </span></p>
<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt;font-family:Georgia,serif">Trevor</span></p></div>