-
Notifications
You must be signed in to change notification settings - Fork 7
/
obfuscated.sh
executable file
·79 lines (67 loc) · 1.96 KB
/
obfuscated.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
TABLENAME=symbols
SYMBOL_DB_FILE="symbols"
STRING_SYMBOL_FILE="obfuscation.list"
TIME=`date "+%Y%m%d%H_%M"`
HEAD_FILE="codeObfuscation.h"
export LC_CTYPE=C
#维护数据库方便日后作排重
createTable() {
echo "create table $TABLENAME(src text, des text);" | sqlite3 $SYMBOL_DB_FILE
}
insertValue() {
echo "insert into $TABLENAME values('$1' ,'$2');" | sqlite3 $SYMBOL_DB_FILE
}
query() {
echo "select * from $TABLENAME where src='$1';" | sqlite3 $SYMBOL_DB_FILE
}
isUnique() {
echo "select count(*) from $TABLENAME where des='$1';" | sqlite3 $SYMBOL_DB_FILE
}
randomString() {
random=`openssl rand -base64 64 | tr -cd 'a-zA-Z' |head -c 16`
count=`isUnique $random`
if [[ $count == 0 ]]; then
echo $random
else
randomString
fi
}
codeObfuscation() {
if [[ ! -e "$SYMBOL_DB_FILE" ]]; then
echo "***create table***"
createTable
fi
if [[ ! -e "${HEAD_FILE}" ]]; then
echo "***touch $HEAD_FILE***"
touch $HEAD_FILE
echo '#ifndef Demo_codeObfuscation_h
#define Demo_codeObfuscation_h' >> $HEAD_FILE
else
echo $TIME
sed -i.bak '/#endif/d' $HEAD_FILE
rm $HEAD_FILE.bak
fi
isNewDefine=0
cat "$STRING_SYMBOL_FILE" | while read -ra line; do
if grep -q " $line " "$HEAD_FILE"; then
echo "already exist $line"
else
if [[ ! -z "$line" ]]; then
if [[ $isNewDefine == 0 ]]; then
isNewDefine=1
sed -i.$TIME.bak $HEAD_FILE
echo "//confuse string at `date`" >> $HEAD_FILE
fi
ramdom=`randomString`
echo "***define $line $ramdom***"
insertValue $line $ramdom
echo "#define $line $ramdom" >> $HEAD_FILE
fi
fi
done
echo "#endif" >> $HEAD_FILE
echo "***sqlite dump $SYMBOL_DB_FILE***"
sqlite3 $SYMBOL_DB_FILE .dump
}
codeObfuscation