Skip to content

Commit ad2cb5b

Browse files
authored
Merge branch '512558007' into lab4
2 parents 7cd1562 + 37d0775 commit ad2cb5b

File tree

13 files changed

+196
-1
lines changed

13 files changed

+196
-1
lines changed

.github/workflows/lab-autograding.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number });
4646
const changedFiles = files.data.map((file) => file.filename);
4747
const allowedFileRegex = /^lab\d+\/main_test.js$/;
48-
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c"];
48+
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md", "lab7/sol.py"];
4949
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) {
5050
core.setFailed('The PR contains changes to files other than the allowed files.');
5151
}

lab3/main_test.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { describe, it } = require('node:test');
2+
const assert = require('assert');
3+
const { Calculator } = require('./main');
4+
5+
// TODO: write your tests here

lab6/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fuzz/
2+
src/bmpcomp

lab6/Answer.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Name:
2+
ID:
3+
4+
### Fuzz Monitor
5+
```
6+
7+
```
8+
9+
### Run Crash Result
10+
```
11+
12+
```

lab6/src/1.bmp

987 KB
Binary file not shown.

lab6/src/hw0302.c

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <stdio.h>
2+
#include <stdint.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
typedef struct _BMPHeader {
6+
char BM[2];
7+
uint32_t size;
8+
uint32_t reserve;
9+
uint32_t offset;
10+
uint32_t header_size;
11+
uint32_t width;
12+
uint32_t height;
13+
uint16_t planes;
14+
uint16_t bpp;
15+
uint32_t compression;
16+
uint32_t bitmap_size;
17+
uint32_t h_res;
18+
uint32_t v_res;
19+
uint32_t palette;
20+
uint32_t important;
21+
}__attribute__((__packed__)) Header;
22+
int main(int argc, char **argv) {
23+
FILE *pF[9];
24+
char *filename = argv[1];
25+
for ( int i=0; i<9; ++i ) {
26+
pF[i] = fopen(filename, "rb");
27+
if ( pF[i] == NULL ) {
28+
printf("error! file %s doesn't exist.\n", filename);
29+
return 0;
30+
}
31+
}
32+
char output[11] = {'o', 'u', 't', 'p', 'u', 't', '.', 'b', 'm', 'p', '\0'};
33+
FILE *pR = fopen(output, "wb");
34+
Header H[9], res;
35+
printf("size of Herder %d\n", sizeof(Header));
36+
for ( int i=0; i<9; ++i ) fread(H+i, sizeof(Header), 1, pF[i]);
37+
res = H[0];
38+
res.height = H[0].height + H[3].height + H[6].height;
39+
res.width = H[0].width + H[1].width + H[2].width;
40+
res.bitmap_size = res.height*res.width*3+(res.width%4*res.height);
41+
res.size = res.bitmap_size + res.offset;
42+
fwrite(&res, sizeof(Header), 1, pR);
43+
for ( int i=2; i<9; i+=3 ) {
44+
for ( int j=0; j<H[i].height; ++j ) {
45+
for ( int k=0; k<3; ++k ) {
46+
uint8_t data[H[i-k].width*3];
47+
fread(data, sizeof(uint8_t), H[i-k].width*3, pF[i-k]);
48+
fwrite(data, sizeof(uint8_t), H[i-k].width*3, pR);
49+
fseek(pF[i-k], H[i-k].width%4, SEEK_CUR);
50+
}
51+
uint8_t padding;
52+
for ( int k=0; k<res.width%4; ++k ) fwrite(&padding, sizeof(uint8_t), 1, pR);
53+
}
54+
}
55+
for ( int i=0; i<9; ++i ) fclose(pF[i]);
56+
fclose(pR);
57+
puts("done!");
58+
return 0;
59+
}

lab6/src/makefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bmpcomp: hw0302.c
2+
$(CC) $< -std=c11 -lm -o $@

lab6/validate.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Check for unwanted files
4+
for file in *; do
5+
if [[ $file != "src" && $file != "src/makefile" && $file != "src/hw0302.c" && $file != "src/1.bmp" && $file != "Answer.md" && $file != "validate.sh" ]]; then
6+
echo "[!] Unwanted file detected: $file."
7+
exit 1
8+
fi
9+
done
10+
11+
echo "[V] Pass"
12+
13+
exit 0
14+
15+
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:

lab7/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
login: login.o
2+
3+
login.o: login.c
4+
5+
.PHONY: clean
6+
clean:
7+
rm login login.o

lab7/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Lab7
2+
3+
## Introduction
4+
5+
In this lab, you will write a python script with Angr to find the password in executalbe file named 'login'.
6+
7+
## Preparation (Important!!!)
8+
9+
1. Sync fork your branch (e.g., `SQLab:311XXXXXX`)
10+
2. `git checkout -b lab7` (**NOT** your student ID !!!)
11+
12+
## Requirement
13+
14+
1. (100%) Detect the condition that login will print 'Login successful' if login success and print 'Login failed' if login fail, find the input of successful condition by Angr.
15+
16+
Please note that you must not alter files other than `sol.py` or just print the input. You will get 0 points if
17+
18+
1. you modify other files to achieve requirements.
19+
2. you can't pass all CI on your PR.
20+
21+
## Submission
22+
23+
You need to open a pull request to your branch (e.g. 311XXXXXX, your student number) and contain the code that satisfies the abovementioned requirements.
24+
25+
Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places.

lab7/login.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
int encrypt(int a1, int a2) {
6+
if ( a1 <= 0x40 || a1 > 90 ) {
7+
puts("Login failed");
8+
exit(1);
9+
}
10+
return (0x1F * a2 + a1 - 65) % 26 + 65;
11+
}
12+
13+
int main(void) {
14+
char secret[0x20] = "VXRRJEURXDASBFHM";
15+
char pwd[0x20] = {0};
16+
17+
printf("Enter the password: ");
18+
scanf("%16s", pwd);
19+
for ( int j = 0; j < 0x10; ++j )
20+
pwd[j] = encrypt(pwd[j], j + 8);
21+
if ( !strcmp(secret, pwd) )
22+
puts("Login successful");
23+
else
24+
puts("Login failed");
25+
return 0;
26+
}

lab7/sol.py

Whitespace-only changes.

lab7/validate.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Check for unwanted files
4+
for file in *; do
5+
if [[ $file != "login.c" && $file != "sol.py" && $file != "Makefile" && $file != "README.md" && $file != "validate.sh" ]]; then
6+
echo "[!] Unwanted file detected: $file."
7+
exit 1
8+
fi
9+
done
10+
11+
test_path="${BASH_SOURCE[0]}"
12+
solution_path="$(realpath .)"
13+
tmp_dir=$(mktemp -d -t lab7-XXXXXXXXXX)
14+
answer=""
15+
16+
cd $tmp_dir
17+
18+
pip install angr
19+
rm -rf *
20+
cp $solution_path/Makefile .
21+
cp $solution_path/*.c .
22+
cp $solution_path/sol.py .
23+
24+
make
25+
result=$(python3 sol.py)
26+
if [[ $result != "b'HETOBRCUVWOBFEBB'" ]]; then
27+
echo "[!] Expected: "
28+
echo "b'HETOBRCUVWOBFEBB'"
29+
echo ""
30+
echo "[!] Actual: "
31+
echo $result
32+
echo ""
33+
exit 1
34+
else
35+
echo "[V] Pass"
36+
fi
37+
38+
rm -rf $tmp_dir
39+
40+
exit 0
41+
42+
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:

0 commit comments

Comments
 (0)