Skip to content

Commit 2e9280d

Browse files
committed
fix: lab8 no angr
1 parent f894e1a commit 2e9280d

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

.github/workflows/lab-autograding.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,7 @@ jobs:
5656
if [ ${{ steps.lab.outputs.result }} -eq 6 ]; then
5757
sudo apt install -y llvm-14
5858
fi
59+
if [ ${{ steps.lab.outputs.result }} -eq 8 ]; then
60+
python3 -m pip install angr
61+
fi
5962
./validate.sh

lab6/llvm-pass.so.cc

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "llvm/Passes/PassPlugin.h"
22
#include "llvm/Passes/PassBuilder.h"
33
#include "llvm/IR/IRBuilder.h"
4-
#include "llvm/IR/Constants.h"
5-
#include "llvm/IR/GlobalVariable.h"
64

75
using namespace llvm;
86

@@ -13,38 +11,13 @@ struct LLVMPass : public PassInfoMixin<LLVMPass> {
1311
PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
1412
LLVMContext &Ctx = M.getContext();
1513
IntegerType *Int32Ty = IntegerType::getInt32Ty(Ctx);
16-
PointerType *Int8PtrTy = Type::getInt8PtrTy(Ctx);
17-
18-
FunctionType *DebugTy = FunctionType::get(Type::getVoidTy(Ctx), {Int32Ty}, false);
19-
FunctionCallee debug_func = M.getOrInsertFunction("debug", DebugTy);
14+
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
2015
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
2116

22-
Constant *StrConstant = ConstantDataArray::getString(Ctx, "hayaku... motohayaku!", true);
23-
GlobalVariable *StrVar = new GlobalVariable(M, StrConstant->getType(), true,
24-
GlobalValue::PrivateLinkage, StrConstant, ".str.hayaku");
25-
Constant *Zero = ConstantInt::get(Int32Ty, 0);
26-
Constant *Indices[] = {Zero, Zero};
27-
Constant *StrPtr = ConstantExpr::getGetElementPtr(StrConstant->getType(), StrVar, Indices);
28-
2917
for (auto &F : M) {
30-
if (F.getName() != "main")
31-
continue;
32-
33-
errs() << "Instrumenting function: " << F.getName() << "\n";
34-
IRBuilder<> Builder(&*F.getEntryBlock().getFirstInsertionPt());
35-
36-
Builder.CreateCall(debug_func, {debug_arg});
18+
errs() << "func: " << F.getName() << "\n";
3719

38-
auto ArgIter = F.arg_begin();
39-
Argument *argcArg = ArgIter++;
40-
Argument *argvArg = ArgIter;
41-
42-
Value *Argv1Ptr = Builder.CreateGEP(Int8PtrTy, argvArg, ConstantInt::get(Int32Ty, 1));
43-
Builder.CreateStore(StrPtr, Argv1Ptr);
44-
45-
argcArg->replaceAllUsesWith(debug_arg);
4620
}
47-
4821
return PreservedAnalyses::none();
4922
}
5023

@@ -58,3 +31,4 @@ llvmGetPassPluginInfo() {
5831
});
5932
}};
6033
}
34+

0 commit comments

Comments
 (0)