Skip to content

Commit e8ae1ce

Browse files
committed
fix: lab8 no angr
1 parent 29a97cc commit e8ae1ce

File tree

4 files changed

+25
-111
lines changed

4 files changed

+25
-111
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

lab3/main_test.js

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,4 @@ const {describe, it} = require('node:test');
22
const assert = require('assert');
33
const { Calculator } = require('./main');
44

5-
describe('Calculator', () => {
6-
const calc = new Calculator();
7-
8-
// ---- exp(x) tests ----
9-
it('exp(0) should return 1', () => {
10-
assert.strictEqual(calc.exp(0), 1);
11-
});
12-
13-
it('exp(1) should return ~2.718', () => {
14-
assert.ok(Math.abs(calc.exp(1) - Math.E) < 1e-10);
15-
});
16-
17-
it('exp(Infinity) should throw unsupported operand type', () => {
18-
assert.throws(() => calc.exp(Infinity), {
19-
message: 'unsupported operand type'
20-
});
21-
});
22-
23-
it('exp(1000) should throw overflow', () => {
24-
assert.throws(() => calc.exp(1000), {
25-
message: 'overflow'
26-
});
27-
});
28-
29-
// ---- log(x) tests ----
30-
it('log(1) should return 0', () => {
31-
assert.strictEqual(calc.log(1), 0);
32-
});
33-
34-
it('log(0) should throw math domain error (1)', () => {
35-
assert.throws(() => calc.log(0), {
36-
message: 'math domain error (1)'
37-
});
38-
});
39-
40-
it('log(-5) should throw math domain error (2)', () => {
41-
assert.throws(() => calc.log(-5), {
42-
message: 'math domain error (2)'
43-
});
44-
});
45-
46-
it('log(NaN) should throw unsupported operand type', () => {
47-
assert.throws(() => calc.log(NaN), {
48-
message: 'unsupported operand type'
49-
});
50-
});
51-
});
5+
// TODO: write your tests here

lab5/antiasan.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#include <string.h>
2-
#include <stdio.h>
3-
42

53
void antiasan(unsigned long addr)
64
{
7-
unsigned long s_addr = (addr >> 3) + 0x7FFF8000;
8-
unsigned long off = 0;
9-
for (int i = 0; i < 240; i++){
10-
*((char*)(s_addr + off + i)) = 0;
11-
}
5+
126
}

lab6/llvm-pass.so.cc

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,34 @@
11
#include "llvm/Passes/PassPlugin.h"
22
#include "llvm/Passes/PassBuilder.h"
3-
#include "llvm/IR/PassManager.h"
43
#include "llvm/IR/IRBuilder.h"
5-
#include "llvm/IR/Instructions.h"
6-
#include "llvm/IR/Constants.h"
7-
#include "llvm/IR/Module.h"
84

95
using namespace llvm;
106

117
struct LLVMPass : public PassInfoMixin<LLVMPass> {
12-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM) {
13-
LLVMContext &Ctx = M.getContext();
14-
IntegerType *Int32Ty = Type::getInt32Ty(Ctx);
15-
PointerType *Int8PtrTy = Type::getInt8PtrTy(Ctx);
16-
17-
// Declare: void debug(int)
18-
FunctionCallee debugFunc = M.getOrInsertFunction("debug", FunctionType::get(Type::getVoidTy(Ctx), {Int32Ty}, false));
19-
ConstantInt *debugID = ConstantInt::get(Int32Ty, 48763);
20-
21-
for (auto &F : M) {
22-
if (F.getName() == "main") {
23-
IRBuilder<> Builder(&*F.getEntryBlock().getFirstInsertionPt());
24-
25-
// Inject debug(48763);
26-
Builder.CreateCall(debugFunc, {debugID});
27-
28-
// Get main args
29-
auto args = F.args().begin();
30-
Argument *argcArg = args++;
31-
Argument *argvArg = args;
32-
33-
// === Overwrite argc to 48763 ===
34-
// Allocate space and overwrite
35-
AllocaInst *argcAlloca = Builder.CreateAlloca(Int32Ty, nullptr, "argc.fake");
36-
Builder.CreateStore(ConstantInt::get(Int32Ty, 48763), argcAlloca);
8+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
9+
};
3710

38-
// Replace all uses of argcArg with loaded value
39-
for (auto &BB : F) {
40-
for (auto &I : BB) {
41-
for (unsigned i = 0; i < I.getNumOperands(); ++i) {
42-
if (I.getOperand(i) == argcArg) {
43-
IRBuilder<> tmpBuilder(&I);
44-
LoadInst *argcLoad = tmpBuilder.CreateLoad(Int32Ty, argcAlloca);
45-
I.setOperand(i, argcLoad);
46-
}
47-
}
48-
}
49-
}
11+
PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
12+
LLVMContext &Ctx = M.getContext();
13+
IntegerType *Int32Ty = IntegerType::getInt32Ty(Ctx);
14+
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
15+
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
5016

51-
// === Overwrite argv[1] ===
52-
Value *index1 = ConstantInt::get(Int32Ty, 1);
53-
Value *argv1Ptr = Builder.CreateGEP(argvArg->getType()->getPointerElementType(), argvArg, index1);
54-
Value *newStr = Builder.CreateGlobalStringPtr("hayaku... motohayaku!");
55-
Builder.CreateStore(newStr, argv1Ptr);
56-
}
57-
}
17+
for (auto &F : M) {
18+
errs() << "func: " << F.getName() << "\n";
5819

59-
return PreservedAnalyses::none();
6020
}
61-
};
21+
return PreservedAnalyses::none();
22+
}
6223

63-
extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo llvmGetPassPluginInfo() {
24+
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
25+
llvmGetPassPluginInfo() {
6426
return {LLVM_PLUGIN_API_VERSION, "LLVMPass", "1.0",
65-
[](PassBuilder &PB) {
66-
PB.registerOptimizerLastEPCallback(
67-
[](ModulePassManager &MPM, OptimizationLevel OL) {
68-
MPM.addPass(LLVMPass());
69-
});
70-
}};
27+
[](PassBuilder &PB) {
28+
PB.registerOptimizerLastEPCallback(
29+
[](ModulePassManager &MPM, OptimizationLevel OL) {
30+
MPM.addPass(LLVMPass());
31+
});
32+
}};
7133
}
34+

0 commit comments

Comments
 (0)