-
Notifications
You must be signed in to change notification settings - Fork 91
/
hidex.sh
executable file
·180 lines (170 loc) · 4.57 KB
/
hidex.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env bash
#####################################
# 编译环境监测
#param1 输出路径
#####################################
function check_env(){
#jdk
hash java 2>/dev/null || { echo >&2 "java not installed. Aborting."; exit 1;}
#dx
hash dx 2>/dev/null || { echo >&2 "dx not installed. Aborting."; exit 1;}
#output
if [ ! -d $1 ]
then
mkdir $1
fi
}
#####################################
# 编译module
#param1 编译module名
#param2 生成文件名
#param3 存放路径
#####################################
function build_module(){
echo -e "\nBuild $1 default release"
./gradlew -q -p $1 assembleRelease
if [ -f $1/build/intermediates/bundles/release/classes.jar ]
then
echo "Copy classes.jar to $3/$2"
cp $1/build/intermediates/bundles/release/classes.jar $3/$2
fi
if [ -f $1/build/libs/$1.jar ]
then
echo "Copy $1.jar to $3/$2"
cp -r $1/build/libs/ $3/
fi
}
#####################################
# jar to dex
#param1 输入文件
#param2 生成文件名
#param3 存放路径
#####################################
function jar2dex(){
echo -e "\nTransition $3/$1 to $3/$2"
dx --dex --output=$3/$2 $3/$1
}
#####################################
# dex to jar
#param1 输入文件
#param2 生成文件名
#param3 存放路径
#####################################
function dex2jar(){
if [ -f $3/$1 ]
then
echo -e "\nTransition $3/$1 to $3/$2"
d2j-dex2jar.sh -f $3/$1 -o $3/$2
else
echo -e "\nDex $3/$1 not exist"
fi
}
#####################################
# dex to jar
#param1 操作
#param2 输入文件名
#param3 工具名
#param4 目标目录
#param5 配置文件
#####################################
function hack_dex(){
echo -e "\n$1 $2 to $1-$2"
java -jar $4/$3 $1 $4/$2 $4/$5
}
#####################################
# copy dex to hidex-demo
#####################################
function copy_dex(){
echo -e "\nCopy dex to hidex-demo"
assets_dir="hidex-demo/src/main/assets"
if [[ ! -d ${assets_dir} ]]
then
mkdir -p ${assets_dir}
fi
rm ${assets_dir}/*.dex
cp -r output/*.dex ${assets_dir}
rm ${assets_dir}/redex-**.dex
}
#####################################
# dex to smali
#param1 输入文件
#param2 生成文件名
#param3 存放路径
#####################################
function dex2smali(){
echo -e "\nDisassembles a dex file: $3/$1 -> $3/$2"
baksmali d $3/$1 -o $3/$2
}
#####################################
# 清空编译
#####################################
function clean_output(){
echo -e "\nClean module and output"
./gradlew -q clean
cd output
ls | grep -v *.conf | xargs rm -rf
cd ..
}
echo "################## start ##################"
#module
module_demo="hidex-demo"
module_libs="hidex-libs"
module_samp="hidex-samp"
module_tool="hidex-tool"
#source file
source_samp_jar="samp.jar"
source_samp_dex="samp.dex"
target_tool_jar="hidex-tool.jar"
#hidex file
hidex_samp_dex="hidex-samp.dex"
redex_samp_dex="redex-hidex-samp.dex"
#reverse file
reverse_source_samp_jar="reverse-samp.jar"
reverse_hidex_samp_jar="reverse-hidex-samp.jar"
reverse_redex_samp_jar="reverse-redex-hidex-samp.jar"
#smali file
smali_source_samp="smali-samp"
smali_hidex_samp="smali-hidex-samp"
smali_redex_samp="smali-redex-samp"
#action
action_hidex="hidex"
action_redex="redex"
#config
hidex_conf="hidex.conf"
#output
output_dir="output"
#环境检测
check_env ${output_dir}
case $1 in
clean)
clean_output
;;
build)
build_module ${module_samp} ${source_samp_jar} ${output_dir}
build_module ${module_tool} ${target_tool_jar} ${output_dir}
jar2dex ${source_samp_jar} ${source_samp_dex} ${output_dir}
;;
hidex)
hack_dex ${action_hidex} ${source_samp_dex} ${target_tool_jar} ${output_dir} ${hidex_conf}
;;
redex)
hack_dex ${action_redex} ${hidex_samp_dex} ${target_tool_jar} ${output_dir}
;;
d2j)
dex2jar ${source_samp_dex} ${reverse_source_samp_jar} ${output_dir}
dex2jar ${hidex_samp_dex} ${reverse_hidex_samp_jar} ${output_dir}
dex2jar ${redex_samp_dex} ${reverse_redex_samp_jar} ${output_dir}
;;
d2s)
dex2smali ${source_samp_dex} ${smali_source_samp} ${output_dir}
dex2smali ${hidex_samp_dex} ${smali_hidex_samp} ${output_dir}
dex2smali ${redex_samp_dex} ${smali_redex_samp} ${output_dir}
;;
copy)
copy_dex
;;
*)
echo -e "\nUsage:xxx {clean|build|hidex|redex|d2j|copy}"
;;
esac
echo -e "\n################## end ##################"