Skip to content

Remove macros for old compiler versions from split-* and injection passes #2477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 6 additions & 126 deletions instrumentation/injection-pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@

#include "llvm/ADT/Statistic.h"
#include "llvm/IR/IRBuilder.h"
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/PassManager.h"
#else
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#endif
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Expand All @@ -46,15 +41,8 @@
#include "llvm/Analysis/ValueTracking.h"

#include "llvm/IR/IRBuilder.h"
#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
#include "llvm/IR/Verifier.h"
#include "llvm/IR/DebugInfo.h"
#else
#include "llvm/Analysis/Verifier.h"
#include "llvm/DebugInfo.h"
#define nullptr 0
#endif
#include "llvm/IR/Verifier.h"
#include "llvm/IR/DebugInfo.h"

#include <set>
#include "afl-llvm-common.h"
Expand All @@ -63,42 +51,16 @@ using namespace llvm;

namespace {

#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
class InjectionRoutines : public PassInfoMixin<InjectionRoutines> {

public:
InjectionRoutines() {

#else
class InjectionRoutines : public ModulePass {

public:
static char ID;
InjectionRoutines() : ModulePass(ID) {

#endif

initInstrumentList();

}

#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
#else
bool runOnModule(Module &M) override;

#if LLVM_VERSION_MAJOR >= 4
StringRef getPassName() const override {

#else
const char *getPassName() const override {

#endif
return "Injection routines";

}

#endif

private:
bool hookRtns(Module &M);
Expand All @@ -111,17 +73,13 @@ class InjectionRoutines : public ModulePass {

} // namespace

#if LLVM_MAJOR >= 11
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {

return {LLVM_PLUGIN_API_VERSION, "Injectionroutines", "v0.1",
/* lambda to insert our pass into the pass pipeline. */
[](PassBuilder &PB) {

#if LLVM_VERSION_MAJOR <= 13
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
#endif
PB.registerOptimizerLastEPCallback([](ModulePassManager &MPM,
OptimizationLevel OL
#if LLVM_VERSION_MAJOR >= 20
Expand All @@ -138,10 +96,6 @@ llvmGetPassPluginInfo() {

}

#else
char InjectionRoutines::ID = 0;
#endif

bool InjectionRoutines::hookRtns(Module &M) {

std::vector<CallInst *> calls, llvmStdStd, llvmStdC, gccStdStd, gccStdC,
Expand All @@ -152,62 +106,22 @@ bool InjectionRoutines::hookRtns(Module &M) {
IntegerType *Int8Ty = IntegerType::getInt8Ty(C);
PointerType *i8PtrTy = PointerType::get(Int8Ty, 0);

#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
#else
Constant *
#endif
c1 = M.getOrInsertFunction("__afl_injection_sql", VoidTy, i8PtrTy
#if LLVM_VERSION_MAJOR < 5
,
NULL
#endif
);
#if LLVM_VERSION_MAJOR >= 9
FunctionCallee sqlfunc = c1;
#else
Function *sqlfunc = cast<Function>(c1);
#endif

#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
#else
Constant *
#endif
c2 = M.getOrInsertFunction("__afl_injection_ldap", VoidTy, i8PtrTy
#if LLVM_VERSION_MAJOR < 5
,
NULL
#endif
);
#if LLVM_VERSION_MAJOR >= 9
FunctionCallee ldapfunc = c2;
#else
Function *ldapfunc = cast<Function>(c2);
#endif

#if LLVM_VERSION_MAJOR >= 9
FunctionCallee
#else
Constant *
#endif
c3 = M.getOrInsertFunction("__afl_injection_xss", VoidTy, i8PtrTy
#if LLVM_VERSION_MAJOR < 5
,
NULL
#endif
);
#if LLVM_VERSION_MAJOR >= 9
FunctionCallee xssfunc = c3;
#else
Function *xssfunc = cast<Function>(c3);
#endif

#if LLVM_VERSION_MAJOR >= 9
FunctionCallee FuncPtr;
#else
Function *FuncPtr;
#endif

bool ret = false;

Expand Down Expand Up @@ -311,15 +225,9 @@ bool InjectionRoutines::hookRtns(Module &M) {

}

#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
PreservedAnalyses InjectionRoutines::run(Module &M,
ModuleAnalysisManager &MAM) {

#else
bool InjectionRoutines::runOnModule(Module &M) {

#endif

if (getenv("AFL_QUIET") == NULL)
printf("Running injection-pass by Marc Heuse (mh@mh-sec.de)\n");
else
Expand All @@ -339,36 +247,8 @@ bool InjectionRoutines::runOnModule(Module &M) {
bool ret = hookRtns(M);
verifyModule(M);

#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
if (ret == false)
return PreservedAnalyses::all();
else
return PreservedAnalyses();
#else
return ret;
#endif

}

#if LLVM_VERSION_MAJOR < 11 /* use old pass manager */
static void registerInjectionRoutinesPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {

auto p = new InjectionRoutines();
PM.add(p);

}

static RegisterStandardPasses RegisterInjectionRoutinesPass(
PassManagerBuilder::EP_OptimizerLast, registerInjectionRoutinesPass);

static RegisterStandardPasses RegisterInjectionRoutinesPass0(
PassManagerBuilder::EP_EnabledOnOptLevel0, registerInjectionRoutinesPass);

#if LLVM_VERSION_MAJOR >= 11
static RegisterStandardPasses RegisterInjectionRoutinesPassLTO(
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
registerInjectionRoutinesPass);
#endif
#endif

}
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy