Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # set -x
- ## Description: hack charles script!!
- ## Project layout:
- ## charles.hack* -- Main script (bash)
- ## naming.resource -- version def
- ## temp.java -- template of java code
- ## Parameter: First parameter should be version number
- ## Optional option:
- ## -s | --save -- save new version to resource file
- ## -m | --manual -- input manual name of file, and method A, B, C
- ## Usage:
- ## $project/charles.hack
- ## -- auto get version from 'Application' folder
- ## $project/charles.hack v4.2.1
- ## -- support version
- ## $project/charles.hack v1.1 -m asdf fdsa qwer vcxz
- ## -- manual version, by 'name&method'
- ## $project/charles.hack v1.1 --save -m asdf fdsa qwer vcxz
- ## -- manual version with 'save' new declare to resource file
- ## How to get 'name&method'
- ## 1. Look for file which contain 'Unregistered' string.
- ## 2. It should have a lot of declare variable
- ## 3. that will be my file name, It's it match following condition
- ## 4. find the 'public' method that have 2 duplication name
- ## 4.1. one get 'zero' parameter and return 'boolean'
- ## 4.2. one get '2' parameter and return 'string'
- ## 5. last method get 'zero' parameter and return 'string'
- ## The --manual should be "3" "5" "4.1" "4.2"
- ## Creator: KC
- ## Date: 19/01/61 - DD/MM/YY
- script_location="$(cd "$(dirname "$0")" || exit 1 && pwd)"
- this="${script_location}/charles.hack"
- resource="${script_location}/naming.resource"
- java_tmp="${script_location}/temp.java"
- java_extension=".java"
- class_extension=".class"
- app="/Applications/Charles.app"
- app_content="${app}/Contents"
- charles="$app_content/Java/charles.jar"
- dir=/tmp/charles_crack
- # resource use to hack charles
- # 1 - version
- # 2 - license, java file name
- # 3 - user register name, method name
- # 4 - check license status, method name
- # 5 - update license, method name
- java_resource_name=("v0.0.0" "xxxx.java" "aaaa" "bbbb" "cccc")
- ret=1
- _load_resource() {
- if ! result="$(grep "$1 " <"$resource")"; then
- java_resource_name=("$1")
- echo "not support version $1" && return 1
- fi
- arr=($result)
- if [ "${#arr[@]}" -ne 4 ] && [ "${#arr[@]}" -ne 5 ]; then
- echo "Invalid resource @$result" && exit 2
- fi
- v="${arr[0]}"
- m1="${arr[1]}"
- m2="${arr[2]}"
- m3="${arr[3]}"
- m4="${arr[4]}"
- java_resource_name=("$v" "${m1}${java_extension}" "$m2" "$m3" "$m4")
- }
- _save_resource() {
- echo "${java_resource_name[*]}" >>"$resource"
- }
- _get_version() {
- echo "${java_resource_name[0]}"
- }
- _get_app_version() {
- grep CFBundleVersion -A 1 <"${app_content}/Info.plist" | grep -Eo "[0-9.]+"
- }
- _get_filename() {
- echo "${java_resource_name[1]}"
- }
- _get_name() {
- echo "${java_resource_name[1]//$java_extension/}"
- }
- _update_java() {
- local content name m1 m2 m3
- name="%{name}"
- m1="%{method1}"
- m2="%{method2}"
- m3="%{method3}"
- content="$(cat "$java_tmp")"
- content="${content//$name/${java_resource_name[1]//$java_extension/}}"
- content="${content//$m1/${java_resource_name[2]}}"
- content="${content//$m2/${java_resource_name[3]}}"
- [ -z "${java_resource_name[4]}" ] &&
- content="${content//$m3/${java_resource_name[3]}}" ||
- content="${content//$m3/${java_resource_name[4]}}"
- # dry run
- # echo "$content"
- # exit 123
- echo "$content" >"${dir}/${java_resource_name[1]}"
- }
- manual=false
- save=false
- while [ ${#@} -ne 0 ]; do
- # start with v and follow with number or dot
- if [[ $1 =~ v[0-9.] ]]; then
- _load_resource "$1" || manual=true
- elif [[ $1 == "--save" ]] || [[ $1 == "-s" ]]; then
- save=true
- elif [[ $1 == "--manual" ]] || [[ $1 == "-m" ]]; then
- ! $manual && break
- shift
- java_resource_name+=($@)
- if [ "${#java_resource_name[@]}" -ne 4 ] && [ "${#java_resource_name[@]}" -ne 5 ]; then
- echo "Invalid resource @${java_resource_name[*]}" && exit 2
- fi
- else
- grep "^## " <"$0" | tr -d "#" && exit 0
- fi
- shift
- done
- [[ $(_get_version) == "v0.0.0" ]] &&
- _load_resource "$(_get_app_version)" || manual=true
- header="Automatic"
- if $manual; then
- if [ ${#java_resource_name[@]} -eq 1 ]; then
- echo "Never manual assign name!!" && exit 4
- else
- header="Manual"
- fi
- fi
- printf '%20s version -- %s\n' "$header" "${java_resource_name[0]}"
- printf '%20s filename -- %s\n' "$header" "${java_resource_name[1]}"
- printf '%20s m-user -- %s\n' "$header" "${java_resource_name[2]}"
- printf '%20s m-valid -- %s\n' "$header" "${java_resource_name[3]}"
- printf '%20s m-sign -- %s\n' "$header" "${java_resource_name[4]}"
- read -r
- mkdir "$dir" 2>/dev/null || echo "crack exist!"
- cd "$dir" || exit 1
- printf "%20s -- " "Create java"
- _update_java && echo "COMPLETE!" && ret=0 || echo "FAILURE!"
- printf "%20s -- " "Recompack jar file"
- 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!"
- if [ $ret -eq 0 ]; then
- cd "$HOME" || exit 5
- rm -r "$dir"
- fi
- $save && _save_resource
- exit "$ret"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement