Skip to content

Commit ddbe02e

Browse files
committed
fix: lab8 no angr
1 parent 836eca9 commit ddbe02e

3 files changed

Lines changed: 16 additions & 42 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

lab5/antiasan.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,5 @@
22

33
void antiasan(unsigned long addr)
44
{
5-
// Calculate shadow memory address for gS (after gBadBuf)
6-
unsigned long shadow_addr = ((addr + 0x87) >> 3) + 0x7fff8000;
7-
8-
// Mark 16 bytes of shadow memory as valid (covers gS[0x17] to gS[0x27])
9-
for (int i = 0; i < 16; i++) {
10-
*(char *)(shadow_addr + i) = 0;
11-
}
5+
126
}

lab6/llvm-pass.so.cc

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#include "llvm/IR/Constants.h"
2-
#include "llvm/IR/IRBuilder.h"
3-
#include "llvm/IR/Type.h"
4-
#include "llvm/Passes/PassBuilder.h"
51
#include "llvm/Passes/PassPlugin.h"
2+
#include "llvm/Passes/PassBuilder.h"
3+
#include "llvm/IR/IRBuilder.h"
64

75
using namespace llvm;
86

@@ -13,45 +11,24 @@ 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-
17-
// Get or insert the debug function with correct type
18-
FunctionType *debugTy =
19-
FunctionType::get(Type::getVoidTy(Ctx), {Int32Ty}, false);
20-
FunctionCallee debug_func = M.getOrInsertFunction("debug", debugTy);
14+
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
2115
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
2216

2317
for (auto &F : M) {
24-
if (F.getName() == "main") {
25-
// Get the first insertion point in the entry block
26-
BasicBlock::iterator IP = F.getEntryBlock().getFirstInsertionPt();
27-
IRBuilder<> Builder(&(*IP));
18+
errs() << "func: " << F.getName() << "\n";
2819

29-
// Call debug function with 48763
30-
Builder.CreateCall(debug_func, {debug_arg});
31-
32-
// Get argc and argv arguments
33-
Argument *argc = F.getArg(0);
34-
Argument *argv = F.getArg(1);
35-
36-
// Replace all uses of argc with 48763
37-
argc->replaceAllUsesWith(debug_arg);
38-
39-
// Create argv[1] pointer and store our string
40-
Value *argv1_ptr = Builder.CreateGEP(Builder.getInt8PtrTy(), argv,
41-
ConstantInt::get(Int32Ty, 1));
42-
Value *new_str = Builder.CreateGlobalStringPtr("hayaku... motohayaku!");
43-
Builder.CreateStore(new_str, argv1_ptr);
44-
}
4520
}
4621
return PreservedAnalyses::none();
4722
}
4823

4924
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
5025
llvmGetPassPluginInfo() {
51-
return {LLVM_PLUGIN_API_VERSION, "LLVMPass", "1.0", [](PassBuilder &PB) {
52-
PB.registerOptimizerLastEPCallback(
53-
[](ModulePassManager &MPM, OptimizationLevel OL) {
54-
MPM.addPass(LLVMPass());
55-
});
56-
}};
26+
return {LLVM_PLUGIN_API_VERSION, "LLVMPass", "1.0",
27+
[](PassBuilder &PB) {
28+
PB.registerOptimizerLastEPCallback(
29+
[](ModulePassManager &MPM, OptimizationLevel OL) {
30+
MPM.addPass(LLVMPass());
31+
});
32+
}};
5733
}
34+

0 commit comments

Comments
 (0)