-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsyscert_setup.exp
executable file
·101 lines (89 loc) · 2.85 KB
/
syscert_setup.exp
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
#!/usr/bin/expect -f
# Copyright 2023 SJTU X-Lance Lab
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Created by Danyang Zhang @X-Lance.
if {$argc >= 1} {
set emulator_path [lindex $argv 0]
} else {
set emulator_path "$env(HOME)/Android/Sdk/emulator"
}
if {$argc >= 2} {
set avd_name [lindex $argv 1]
} else {
set avd_name "Pixel_2_API_30_x64"
}
if {$argc >= 3} {
set certificate_path [lindex $argv 2]
} else {
set certificate_path "$env(HOME)/.mitmproxy/mitmproxy-ca-cert.cer"
}
set env(LD_LIBRARY_PATH) "$emulator_path/lib64:$emulator_path/lib64/qt/lib:$emulator_path/lib64/gles_swiftshader"
set adb $emulator_path/../platform-tools/adb
spawn $emulator_path/emulator -writable-system -no-snapshot -no-skin -no-window -no-audio -verbose -avd $avd_name -ports 33375,5555
set emulator_process $spawn_id
set timeout 300
proc wait_for_adb {adb} {
while {[catch {exec $adb get-state} results]} {
puts "\x1b\[5;31m$results\x1b\[0m"
sleep 1
}
if {$results == "device"} {
return true
} else {
return false
}
}
proc wait_for_launch {emulator_process adb} {
expect {
timeout {
puts "\x1b\[5;31mTIMEOUT!\x1b\[0m"
exit
}
-i $emulator_process -re {[Bb]oot completed} {
puts "\x1b\[32mBOOTED!\x1b\[0m"
sleep 1
}
}
wait_for_adb $adb
}
proc execute_step args {
set results [eval exec $args]
puts "\x1b\[32mSTEP: \x1b\[0m$results"
sleep 1
}
wait_for_launch $emulator_process $adb
execute_step $adb root
wait_for_adb $adb
execute_step $adb shell avbctl disable-verification
execute_step $adb reboot
wait_for_launch $emulator_process $adb
execute_step $adb root
wait_for_adb $adb
catch {exec $adb remount} results
puts "\x1b\[32mSTEP: \x1b\[0m$results"
sleep 1
execute_step $adb reboot
set certificate_hash [exec openssl x509 -noout -subject_hash_old -in $certificate_path]
puts "\x1b\[32mHASH: \x1b\[0m$certificate_hash"
wait_for_launch $emulator_process $adb
execute_step $adb root
wait_for_adb $adb
execute_step $adb remount
execute_step $adb push $certificate_path "/system/etc/security/cacerts/$certificate_hash.0"
execute_step $adb shell chmod 664 "/system/etc/security/cacerts/$certificate_hash.0"
execute_step $adb reboot
wait_for_launch $emulator_process $adb
puts "\x1b\[32mSysCert Configured Successfully!\x1b\[0m"
#interact
exit