-
Notifications
You must be signed in to change notification settings - Fork 11
/
oat.ps1
171 lines (153 loc) · 6.71 KB
/
oat.ps1
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
# ref https://source.android.com/docs/core/runtime/jit-compiler?hl=zh-cn
# ref https://www.cnblogs.com/ClientInfra/p/15379050.html
$packageName = Read-Host "Input PackageName"
$packageName = $packageName.Trim()
$debuggable = adb shell getprop ro.debuggable
$commandSU = ""
if ($debuggable -eq "1") {
$commandSU = ""
# $commandSU = "su -c"
}
function getOatPath($packageName) {
$runtimePackageName = & adb shell $commandSU "ls /data/app/" | Select-String $packageName
if (-not $runtimePackageName) {
# adb shell pm path packageName -> package:/data/app/~~K1q-KAt6CSBAPEc2w6TXLQ==/com.mobirate.rcr2.gplay-kJZPvno6tzkKYEtNWwEimg==/base.apk
# get ~~K1q-KAt6CSBAPEc2w6TXLQ==
$runtimePackageName = & adb shell $commandSU "pm path $packageName"
$pmPathOutput = adb shell $commandSU "pm path $packageName"
$pattern = "package:(.*?)base.apk"
$runtimePackageName = $pmPathOutput | Select-String -Pattern $pattern -AllMatches
if ($runtimePackageName.Matches.Count -gt 0) {
$packagePath = $runtimePackageName.Matches[0].Groups[1].Value + "oat"
$lib_arch_path = adb shell $commandSU ls $packagePath
$oatPath = $packagePath + "/" + $lib_arch_path
}
else {
Write-Error "Package $packageName | Matches Fail"
exit 1
}
}
else {
# libpath = "/data/data/" + packageName + "/lib"
$packagePath = "/data/app/" + $runtimePackageName + "/oat"
# adb shell $commandSU ls libpath
$lib_arch_path = adb shell $commandSU ls $packagePath
$oatPath = $packagePath + "/" + $lib_arch_path
}
return $oatPath
}
function printOATFiles($oatPath) {
# get oat file
$files = adb shell $commandSU ls $oatPath
$files = $files -split "\r\n"
$filesSize = @{}
foreach ($file in $files) {
$fileSize = adb shell $commandSU ls -l $oatPath/$file
$fileSize = $fileSize -split "\r\n"
$fileSize = $fileSize[0].Split(" ", [StringSplitOptions]::RemoveEmptyEntries)
$filesSize.Add($file, $fileSize[4])
}
# Write-Host filename and filesize
Write-Host "`nOAT Files" -ForegroundColor Cyan
foreach ($file in $files) {
Write-Host "$($file) : $($filesSize[$file]) B / $($filesSize[$file]/1024/1024) MB" -ForegroundColor Yellow
}
}
$oatPath = getOatPath($packageName)
Write-Host "`nOAT Path : $oatPath" -ForegroundColor Green
printOATFiles($oatPath)
# adb shell setprop dalvik.vm.usejit
$JniStatus = adb shell getprop dalvik.vm.usejit
Write-Host "`ngetprop dalvik.vm.usejit => $JniStatus" -ForegroundColor Green
# dex2oat TIPS MEMU
# DISPLAY Current PackageName -> package
# 0. clear -> adb shell cmd package compile --reset package
# 1. compile interpret-only -> adb shell cmd package compile package -m interpret-only
# 2. compile space-profile -> adb shell cmd package compile package -m space-profile
# 3. compile space -> adb shell cmd package compile package -m space
# 4. compile speed-profile -> adb shell cmd package compile package -m speed-profile
# 5. compile speed -> adb shell cmd package compile package -m speed
# 6. compile everything -> adb shell cmd package compile package -m everything
# 7. clear all -> adb shell cmd package compile --reset -a
# 8. compile all -> adb shell cmd package compile -a
# 9. Quit
$option = -1
while ($option -ne 9) {
Write-Host "`ndex2oat MENU OPTIONS" -ForegroundColor Cyan
Write-Host "1. compile interpret-only" -ForegroundColor Yellow
Write-Host "2. compile space-profile" -ForegroundColor Yellow -m
Write-Host "3. compile space" -ForegroundColor Yellow
Write-Host "4. compile speed-profile" -ForegroundColor Yellow
Write-Host "5. compile speed" -ForegroundColor Yellow
Write-Host "6. compile everything" -ForegroundColor Yellow
Write-Host "7. clear" -ForegroundColor Yellow
Write-Host "8. set dalvik.vm.usejit" -ForegroundColor Yellow
Write-Host "9. pull oat files" -ForegroundColor Yellow
Write-Host "0. quit" -ForegroundColor Yellow
$option = Read-Host "Select an option"
$option = $option.Trim()
switch ($option) {
"1" {
Write-Host "execute -> cmd package compile -m interpret-only $packageName" -ForegroundColor Green
$result = adb shell cmd package compile -m interpret-only $packageName
}
"2" {
Write-Host "execute -> cmd package compile -m space-profile $packageName" -ForegroundColor Green
$result = adb shell cmd package compile -m space-profile $packageName
}
"3" {
Write-Host "execute -> cmd package compile -m space $packageName" -ForegroundColor Green
$result = adb shell cmd package compile -m space $packageName
}
"4" {
Write-Host "execute -> cmd package compile -m speed-profile $packageName" -ForegroundColor Green
$result = adb shell cmd package compile -m speed-profile $packageName
}
"5" {
Write-Host "execute -> cmd package compile -m speed $packageName" -ForegroundColor Green
$result = adb shell cmd package compile -m speed $packageName
}
"6" {
Write-Host "execute -> cmd package compile -m everything $packageName --host" -ForegroundColor Green
$result = adb shell cmd package compile -m everything $packageName -oat-symbols=/data/local/tmp/oat.sym
}
"7" {
Write-Host "execute -> cmd package compile --reset $packageName" -ForegroundColor Green
# $result = adb shell cmd package compile --reset $packageName
adb shell $commandSU rm -rf $oatPath
return
}
"8" {
# Set dalvik.vm.usejit to true or false
$useJit = Read-Host "Set dalvik.vm.usejit (true/false)"
$useJit = $useJit.Trim()
adb shell setprop dalvik.vm.usejit $useJit
}
"9" {
# pull oat files
$oatPathLocal = Read-Host "Input host oat path"
$oatFiles = adb shell $commandSU ls $oatPath
$oatFiles = $oatFiles -split "\r\n"
adb shell $commandSU chmod 777 $oatPath/*
foreach ($oatFile in $oatFiles) {
adb shell $commandSU cp $oatPath/$oatFile /data/local/tmp
adb pull /data/local/tmp/$oatFile $oatPathLocal
adb shell $commandSU rm -rf /data/local/tmp/$oatFile
}
$result = "Success"
}
"0" {
return
}
default {
Write-Host "Invalid option. Please select a valid option." -ForegroundColor Red
}
}
if ($result -match "Success") {
return $result
}
else {
Write-Host "Fail" -ForegroundColor Red
}
}
printOATFiles($oatPath)