confuse.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. # confuse.sh
  3. # SDKDemo
  4. #
  5. # Created by fq on 2021/1/28.
  6. #
  7. TABLENAME=symbols
  8. SYMBOL_DB_FILE="$PROJECT_DIR/CodeObfuscation/symbols"
  9. STRING_SYMBOL_FILE="$PROJECT_DIR/CodeObfuscation/func.list"
  10. HEAD_FILE="$PROJECT_DIR/CodeObfuscation/codeObfuscation.h"
  11. export LC_CTYPE=C
  12. #维护数据库方便日后作排重
  13. createTable()
  14. {
  15. echo "create table $TABLENAME(src text, des text);" | sqlite3 $SYMBOL_DB_FILE
  16. }
  17. insertValue()
  18. {
  19. echo "insert into $TABLENAME values('$1' ,'$2');" | sqlite3 $SYMBOL_DB_FILE
  20. }
  21. query()
  22. {
  23. echo "select * from $TABLENAME where src='$1';" | sqlite3 $SYMBOL_DB_FILE
  24. }
  25. ramdomString()
  26. {
  27. openssl rand -base64 64 | tr -cd 'a-zA-Z' |head -c 16
  28. }
  29. rm -f $SYMBOL_DB_FILE
  30. rm -f $HEAD_FILE
  31. createTable
  32. touch $HEAD_FILE
  33. echo '#ifndef Demo_codeObfuscation_h
  34. #define Demo_codeObfuscation_h' >> $HEAD_FILE
  35. echo "//confuse string at `date`" >> $HEAD_FILE
  36. cat "$STRING_SYMBOL_FILE" | while read -ra line; do
  37. if [[ ! -z "$line" ]]; then
  38. ramdom=`ramdomString`
  39. echo $line $ramdom
  40. insertValue $line $ramdom
  41. echo "#define $line $ramdom" >> $HEAD_FILE
  42. fi
  43. done
  44. echo "#endif" >> $HEAD_FILE
  45. sqlite3 $SYMBOL_DB_FILE .dump