Skip to content

Commit 1c68373

Browse files
committed
fix: lab8 no angr
1 parent 973359e commit 1c68373

2 files changed

Lines changed: 4 additions & 29 deletions

File tree

.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: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,11 @@ PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
1414
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
1515
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
1616

17-
bool Modified = false;
18-
1917
for (auto &F : M) {
2018
errs() << "func: " << F.getName() << "\n";
2119

22-
if (F.getName() != "main") continue;
23-
BasicBlock &EntryBB = F.getEntryBlock();
24-
IRBuilder<> Builder(&*EntryBB.getFirstInsertionPt());
25-
// 1:Insert debug(48763)
26-
Builder.CreateCall(debug_func, {debug_arg});
27-
28-
// 2:Set argv[1] to "hayaku... motohayaku!"
29-
Constant *StrConst = ConstantDataArray::getString(Ctx, "hayaku... motohayaku!");
30-
GlobalVariable *StrVar = new GlobalVariable(
31-
M, StrConst->getType(), true, GlobalValue::PrivateLinkage, StrConst, ".str");
32-
Constant *StrPtr = ConstantExpr::getPointerCast(StrVar, Type::getInt8PtrTy(Ctx));
33-
34-
// Get argv[1]
35-
Value *Argv = F.getArg(1);
36-
// Calculate the address of argv[1](argv + 1)
37-
Value *Argv1Ptr = Builder.CreateGEP(Type::getInt8PtrTy(Ctx), Argv,
38-
ConstantInt::get(Type::getInt64Ty(Ctx), 1));
39-
// Set argv[1] to new string
40-
Builder.CreateStore(StrPtr, Argv1Ptr);
41-
42-
// 3:Set argc to 48763
43-
Value *Argc = F.getArg(0);
44-
Value *ArgcPtr = Builder.CreateAlloca(Int32Ty, nullptr, "argc.ptr");
45-
Builder.CreateStore(debug_arg, ArgcPtr);
46-
Argc->replaceAllUsesWith(Builder.CreateLoad(Int32Ty, ArgcPtr));
47-
Modified = true;
4820
}
49-
return Modified ? PreservedAnalyses::none() : PreservedAnalyses::all();
21+
return PreservedAnalyses::none();
5022
}
5123

5224
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK

0 commit comments

Comments
 (0)