Advertisement
kamontat

ch-main

Jan 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.31 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # set -x
  3.  
  4. ## Description: hack charles script!!
  5. ## Project layout:
  6. ##      charles.hack*    -- Main script (bash)
  7. ##      naming.resource  -- version def
  8. ##      temp.java        -- template of java code
  9. ## Parameter: First parameter should be version number
  10. ## Optional option:
  11. ##      -s | --save      -- save new version to resource file
  12. ##      -m | --manual    -- input manual name of file, and method A, B, C
  13. ## Usage:
  14. ##      $project/charles.hack
  15. ##                       -- auto get version from 'Application' folder
  16. ##      $project/charles.hack v4.2.1
  17. ##                       -- support version
  18. ##      $project/charles.hack v1.1 -m asdf fdsa qwer vcxz
  19. ##                       -- manual version, by 'name&method'
  20. ##      $project/charles.hack v1.1 --save -m asdf fdsa qwer vcxz
  21. ##                       -- manual version with 'save' new declare to resource file
  22. ## How to get 'name&method'
  23. ## 1.   Look for file which contain 'Unregistered' string.
  24. ## 2.   It should have a lot of declare variable
  25. ## 3.   that will be my file name, It's it match following condition
  26. ## 4.   find the 'public' method that have 2 duplication name
  27. ## 4.1. one get 'zero' parameter and return 'boolean'
  28. ## 4.2. one get '2' parameter and return 'string'
  29. ## 5.   last method get 'zero' parameter and return 'string'
  30. ## The --manual should be "3" "5" "4.1" "4.2"
  31. ## Creator: KC
  32. ## Date:    19/01/61 - DD/MM/YY
  33.  
  34. script_location="$(cd "$(dirname "$0")" || exit 1 && pwd)"
  35. this="${script_location}/charles.hack"
  36. resource="${script_location}/naming.resource"
  37. java_tmp="${script_location}/temp.java"
  38. java_extension=".java"
  39. class_extension=".class"
  40.  
  41. app="/Applications/Charles.app"
  42. app_content="${app}/Contents"
  43. charles="$app_content/Java/charles.jar"
  44. dir=/tmp/charles_crack
  45.  
  46. # resource use to hack charles
  47. # 1 - version
  48. # 2 - license, java file name
  49. # 3 - user register name, method name
  50. # 4 - check license status, method name
  51. # 5 - update license, method name
  52. java_resource_name=("v0.0.0" "xxxx.java" "aaaa" "bbbb" "cccc")
  53.  
  54. ret=1
  55.  
  56. _load_resource() {
  57.    if ! result="$(grep "$1 " <"$resource")"; then
  58.        java_resource_name=("$1")
  59.        echo "not support version $1" && return 1
  60.    fi
  61.  
  62.    arr=($result)
  63.    if [ "${#arr[@]}" -ne 4 ] && [ "${#arr[@]}" -ne 5 ]; then
  64.        echo "Invalid resource @$result" && exit 2
  65.    fi
  66.  
  67.    v="${arr[0]}"
  68.    m1="${arr[1]}"
  69.    m2="${arr[2]}"
  70.    m3="${arr[3]}"
  71.    m4="${arr[4]}"
  72.  
  73.    java_resource_name=("$v" "${m1}${java_extension}" "$m2" "$m3" "$m4")
  74. }
  75.  
  76. _save_resource() {
  77.    echo "${java_resource_name[*]}" >>"$resource"
  78. }
  79.  
  80. _get_version() {
  81.    echo "${java_resource_name[0]}"
  82. }
  83.  
  84. _get_app_version() {
  85.    grep CFBundleVersion -A 1 <"${app_content}/Info.plist" | grep -Eo "[0-9.]+"
  86. }
  87.  
  88. _get_filename() {
  89.    echo "${java_resource_name[1]}"
  90. }
  91.  
  92. _get_name() {
  93.    echo "${java_resource_name[1]//$java_extension/}"
  94. }
  95.  
  96. _update_java() {
  97.    local content name m1 m2 m3
  98.  
  99.    name="%{name}"
  100.    m1="%{method1}"
  101.    m2="%{method2}"
  102.    m3="%{method3}"
  103.  
  104.    content="$(cat "$java_tmp")"
  105.    content="${content//$name/${java_resource_name[1]//$java_extension/}}"
  106.    content="${content//$m1/${java_resource_name[2]}}"
  107.    content="${content//$m2/${java_resource_name[3]}}"
  108.    [ -z "${java_resource_name[4]}" ] &&
  109.        content="${content//$m3/${java_resource_name[3]}}" ||
  110.        content="${content//$m3/${java_resource_name[4]}}"
  111.  
  112.    # dry run
  113.    # echo "$content"
  114.    # exit 123
  115.    echo "$content" >"${dir}/${java_resource_name[1]}"
  116. }
  117.  
  118. manual=false
  119. save=false
  120. while [ ${#@} -ne 0 ]; do
  121.    # start with v and follow with number or dot
  122.    if [[ $1 =~ v[0-9.] ]]; then
  123.        _load_resource "$1" || manual=true
  124.    elif [[ $1 == "--save" ]] || [[ $1 == "-s" ]]; then
  125.        save=true
  126.    elif [[ $1 == "--manual" ]] || [[ $1 == "-m" ]]; then
  127.        ! $manual && break
  128.        shift
  129.        java_resource_name+=($@)
  130.        if [ "${#java_resource_name[@]}" -ne 4 ] && [ "${#java_resource_name[@]}" -ne 5 ]; then
  131.            echo "Invalid resource @${java_resource_name[*]}" && exit 2
  132.        fi
  133.    else
  134.        grep "^## " <"$0" | tr -d "#" && exit 0
  135.     fi
  136.     shift
  137. done
  138.  
  139. [[ $(_get_version) == "v0.0.0" ]] &&
  140.     _load_resource "$(_get_app_version)" || manual=true
  141.  
  142. header="Automatic"
  143.  
  144. if $manual; then
  145.     if [ ${#java_resource_name[@]} -eq 1 ]; then
  146.         echo "Never manual assign name!!" && exit 4
  147.     else
  148.         header="Manual"
  149.     fi
  150. fi
  151.  
  152. printf '%20s version  -- %s\n' "$header" "${java_resource_name[0]}"
  153. printf '%20s filename -- %s\n' "$header" "${java_resource_name[1]}"
  154. printf '%20s m-user   -- %s\n' "$header" "${java_resource_name[2]}"
  155. printf '%20s m-valid  -- %s\n' "$header" "${java_resource_name[3]}"
  156. printf '%20s m-sign   -- %s\n' "$header" "${java_resource_name[4]}"
  157. read -r
  158.  
  159. mkdir "$dir" 2>/dev/null || echo "crack exist!"
  160. cd "$dir" || exit 1
  161.  
  162. printf "%20s          -- " "Create java"
  163. _update_java && echo "COMPLETE!" && ret=0 || echo "FAILURE!"
  164. printf "%20s          -- " "Recompack jar file"
  165. javac -encoding UTF-8 "$(_get_filename)" -d . && jar -uvf $charles "com/xk72/charles/$(_get_name)$class_extension" &>/tmp/ch.log && echo "COMPLETE!" && ret=0 || echo "FAILURE!"
  166.  
  167. if [ $ret -eq 0 ]; then
  168.     cd "$HOME" || exit 5
  169.     rm -r "$dir"
  170. fi
  171.  
  172. $save && _save_resource
  173.  
  174. exit "$ret"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement