Skip to content

Commit

Permalink
Hikari RNG seeded to ensure test replicability
Browse files Browse the repository at this point in the history
  • Loading branch information
Quois committed Feb 19, 2024
1 parent 9eeef43 commit 4ed15eb
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 27 deletions.
4 changes: 4 additions & 0 deletions example/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

clang main.c -o example
clang main.c -o example_obf -mllvm --enable-bcfobf -mllvm --bcf_prob=100 -mllvm --enable-indibran -mllvm --enable-subobf -mllvm --sub_prob=100 -mllvm --sub_loop=1 -mllvm --aesSeed=1337
Binary file added example/example
Binary file not shown.
Binary file added example/example_obf
Binary file not shown.
29 changes: 29 additions & 0 deletions example/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void function() {
srand(time(NULL));

for (int i = 0; i < 10; i++) {
int n = rand() % 100;
if (n == 0) {
puts("Number is zero!");
}

if (n % 2 == 0) {
if (n % 10 == 0) {
puts("Number is divisible by 10!");
} else {
puts("Number is even!");
}
}

puts("Number is odd!");
}
}

int main(int argc, char** argv) {
function();
return 0;
}
10 changes: 5 additions & 5 deletions tests/chudnovsky/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
clang gmp-chudnovsky.c -o test_orig -lgmp -lm
clang gmp-chudnovsky.c -o test_sub_1 -lgmp -lm -mllvm --enable-subobf -mllvm --sub_prob=100 -mllvm --sub_loop=1
clang gmp-chudnovsky.c -o test_sub_2 -lgmp -lm -mllvm --enable-subobf -mllvm --sub_prob=100 -mllvm --sub_loop=2
clang gmp-chudnovsky.c -o test_cff -lgmp -lm -mllvm --enable-cffobf
clang gmp-chudnovsky.c -o test_indir -lgmp -lm -mllvm --enable-indibran
clang gmp-chudnovsky.c -o test_bcf -lgmp -lm -mllvm --enable-bcfobf -mllvm --bcf_prob=100
clang gmp-chudnovsky.c -o test_sub_1 -lgmp -lm -mllvm --enable-subobf -mllvm --sub_prob=100 -mllvm --sub_loop=1 -mllvm --aesSeed=1337
clang gmp-chudnovsky.c -o test_sub_2 -lgmp -lm -mllvm --enable-subobf -mllvm --sub_prob=100 -mllvm --sub_loop=2 -mllvm --aesSeed=1337
clang gmp-chudnovsky.c -o test_cff -lgmp -lm -mllvm --enable-cffobf -mllvm --aesSeed=1337
clang gmp-chudnovsky.c -o test_indir -lgmp -lm -mllvm --enable-indibran -mllvm --aesSeed=1337
clang gmp-chudnovsky.c -o test_bcf -lgmp -lm -mllvm --enable-bcfobf -mllvm --bcf_prob=100 -mllvm --aesSeed=1337
10 changes: 5 additions & 5 deletions tests/chudnovsky/results.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_bcf,0.946
test_cff,0.702
test_indir,1.464
test_bcf,0.984
test_cff,0.728
test_indir,1.400
test_orig,0.596
test_sub_1,0.591
test_sub_2,0.646
test_sub_1,0.611
test_sub_2,0.686
Binary file modified tests/chudnovsky/test_bcf
Binary file not shown.
Binary file modified tests/chudnovsky/test_cff
Binary file not shown.
Binary file modified tests/chudnovsky/test_indir
Binary file not shown.
Binary file modified tests/chudnovsky/test_sub_1
Binary file not shown.
Binary file modified tests/chudnovsky/test_sub_2
Binary file not shown.
37 changes: 37 additions & 0 deletions tests/compile_percentages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

rm -f results_percentage.csv

chudnovsky_orig=0
quicksort_orig=0

while read line
do
if [[ $line == 'Original'* ]]; then
while IFS="," read -r c1 c2 c3
do
chudnovsky_orig=$c2
quicksort_orig=$c3
echo "Chudnovsky Original: $chudnovsky_orig"
echo "Quicksort Original: $quicksort_orig"
done < <(echo $line)
break
fi
done < results.csv

while read line
do
if [[ $line == 'Method'* ]]; then
echo $line >> results_percentage.csv
continue
fi

while IFS="," read -r c1 c2 c3
do
chudnovsky=$(printf "%.1f" $(echo "scale=4; ($c2/$chudnovsky_orig)*100" | bc))
quicksort=$(printf "%.1f" $(echo "scale=4; ($c3/$quicksort_orig)*100" | bc))
echo "Chudnovsky: $chudnovsky"
echo "Quicksort: $quicksort"
echo "$c1,$chudnovsky,$quicksort" >> results_percentage.csv
done < <(echo $line)
done < results.csv
10 changes: 5 additions & 5 deletions tests/quicksort/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
clang src-quicksort.c -o test_orig -lgmp -lm
clang src-quicksort.c -o test_sub_1 -lgmp -lm -mllvm --enable-subobf -mllvm --sub_prob=100 -mllvm --sub_loop=1
clang src-quicksort.c -o test_sub_2 -lgmp -lm -mllvm --enable-subobf -mllvm --sub_prob=100 -mllvm --sub_loop=2
clang src-quicksort.c -o test_cff -lgmp -lm -mllvm --enable-cffobf
clang src-quicksort.c -o test_indir -lgmp -lm -mllvm --enable-indibran
clang src-quicksort.c -o test_bcf -lgmp -lm -mllvm --enable-bcfobf -mllvm --bcf_prob=100
clang src-quicksort.c -o test_sub_1 -lgmp -lm -mllvm --enable-subobf -mllvm --sub_prob=100 -mllvm --sub_loop=1 -mllvm --aesSeed=1337
clang src-quicksort.c -o test_sub_2 -lgmp -lm -mllvm --enable-subobf -mllvm --sub_prob=100 -mllvm --sub_loop=2 -mllvm --aesSeed=1337
clang src-quicksort.c -o test_cff -lgmp -lm -mllvm --enable-cffobf -mllvm --aesSeed=1337
clang src-quicksort.c -o test_indir -lgmp -lm -mllvm --enable-indibran -mllvm --aesSeed=1337
clang src-quicksort.c -o test_bcf -lgmp -lm -mllvm --enable-bcfobf -mllvm --bcf_prob=100 -mllvm --aesSeed=1337
12 changes: 6 additions & 6 deletions tests/quicksort/results.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_bcf,10.229
test_cff,21.746
test_indir,15.041
test_orig,4.664
test_sub_1,4.761
test_sub_2,5.208
test_bcf,8.442
test_cff,27.886
test_indir,13.257
test_orig,4.669
test_sub_1,4.784
test_sub_2,5.358
Binary file modified tests/quicksort/test_bcf
Binary file not shown.
Binary file modified tests/quicksort/test_cff
Binary file not shown.
Binary file modified tests/quicksort/test_indir
Binary file not shown.
Binary file modified tests/quicksort/test_sub_1
Binary file not shown.
Binary file modified tests/quicksort/test_sub_2
Binary file not shown.
12 changes: 6 additions & 6 deletions tests/results.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Method,Chudnovsky,Quicksort
Original,0.596,4.664,
Control Flow Flattening,0.702,21.746,
Indirect Branching,1.464,15.041,
Bogus Control Flow,0.946,10.229,
Instruction Substitution (1 pass),0.591,4.761,
Instruction Substitution (2 passes),0.646,5.208,
Original,0.596,4.669
Control Flow Flattening,0.728,27.886
Indirect Branching,1.400,13.257
Bogus Control Flow,0.984,8.442
Instruction Substitution (1 pass),0.611,4.784
Instruction Substitution (2 passes),0.686,5.358
7 changes: 7 additions & 0 deletions tests/results_percentage.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Method,Chudnovsky,Quicksort
Original,100.0,100.0
Control Flow Flattening,122.1,597.2
Indirect Branching,234.9,283.9
Bogus Control Flow,165.1,180.8
Instruction Substitution (1 pass),102.5,102.5
Instruction Substitution (2 passes),115.1,114.8

0 comments on commit 4ed15eb

Please sign in to comment.