-
Notifications
You must be signed in to change notification settings - Fork 27
/
conscrypt.ts
146 lines (119 loc) · 6.24 KB
/
conscrypt.ts
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
import { devlog, log } from "../util/log.js";
import { getAndroidVersion } from "../util/process_infos.js";
function findProviderInstallerImplFromClassloaders(currentClassLoader: Java.Wrapper, backupImplementation: any) : Java.Wrapper | null {
var providerInstallerImpl = null;
var classLoaders = Java.enumerateClassLoadersSync()
for (var cl of classLoaders) {
try {
var classFactory = Java.ClassFactory.get(cl)
providerInstallerImpl = classFactory.use("com.google.android.gms.common.security.ProviderInstallerImpl")
break
} catch (error) {
if(!error.toString().includes("java.lang.ClassNotFoundException")){
devlog("Error in hooking ProviderInstallerImpl (findProviderInstallerImplFromClassloaders):")
devlog("[-] Error message: (findProviderInstallerImplFromClassloaders): "+error);
}
providerInstallerImpl = null;
// On error we return null
}
}
var version = getAndroidVersion()
if (version <= 12){
//Revert the implementation to avoid an infinitloop of "Loadclass"
currentClassLoader.loadClass.overload("java.lang.String").implementation = backupImplementation
}
return providerInstallerImpl
}
function findProviderInstallerFromClassloaders(currentClassLoader: Java.Wrapper, backupImplementation: any) : Java.Wrapper | null {
var providerInstaller = null
var classLoaders = Java.enumerateClassLoadersSync()
for (var cl of classLoaders) {
try {
var classFactory = Java.ClassFactory.get(cl)
providerInstaller = classFactory.use("com.google.android.gms.security.ProviderInstaller")
break
} catch (error) {
if(!error.toString().includes("java.lang.ClassNotFoundException")){
devlog("Error in hooking ProviderInstallerImpl (findProviderInstallerFromClassloaders):")
devlog("[-] Error message (findProviderInstallerFromClassloaders): "+error);
}
providerInstaller = null;
// On error we return null
}
}
var version = getAndroidVersion()
//log("is here the error")
//log(typeof version)
if (version <= 12){
//Revert the implementation to avoid an infinitloop of "Loadclass"
currentClassLoader.loadClass.overload("java.lang.String").implementation = backupImplementation
}
return providerInstaller
}
export function execute() {
//We have to hook multiple entrypoints: ProviderInstallerImpl and ProviderInstaller
Java.perform(function () {
//Part one: Hook ProviderInstallerImpl
var javaClassLoader = Java.use("java.lang.ClassLoader")
var backupImplementation = javaClassLoader.loadClass.overload("java.lang.String").implementation
//The classloader for ProviderInstallerImpl might not be present on startup, so we hook the loadClass method.
javaClassLoader.loadClass.overload("java.lang.String").implementation = function (className: string) {
let retval = this.loadClass(className)
if (className.endsWith("ProviderInstallerImpl")) {
log("Process is loading ProviderInstallerImpl")
var providerInstallerImpl = findProviderInstallerImplFromClassloaders(javaClassLoader, backupImplementation)
if (providerInstallerImpl === null) {
log("ProviderInstallerImpl could not be found, although it has been loaded")
} else {
providerInstallerImpl.insertProvider.implementation = function () {
log("ProviderinstallerImpl redirection/blocking")
}
}
}
return retval
}
//Part two: Hook Providerinstaller
try {
var providerInstaller = Java.use("com.google.android.gms.security.ProviderInstaller")
providerInstaller.installIfNeeded.implementation = function (context: any) {
devlog("Providerinstaller redirection/blocking")
}
providerInstaller.installIfNeededAsync.implementation = function (context: any, callback: any) {
devlog("ProviderinstallerAsncy redirection/blocking")
callback.onProviderInstalled()
}
} catch (error) {
try {
// probably class wasn't loaded by the app's main class loader therefore we load it
var providerInstallerImpl = null;
var providerInstallerFromClassloder = findProviderInstallerFromClassloaders(javaClassLoader, backupImplementation)
if (providerInstallerFromClassloder === null){
providerInstallerImpl = findProviderInstallerImplFromClassloaders(javaClassLoader, backupImplementation)
}
if (providerInstallerFromClassloder === null && providerInstallerImpl === null || providerInstallerFromClassloder === undefined) {
devlog("ProviderInstaller could not be found, although it has been loaded")
}else{
if(providerInstallerImpl !== null){
providerInstallerImpl.insertProvider.implementation = function () {
devlog("ProviderinstallerImpl redirection/blocking")
}
}else{
providerInstallerFromClassloder.installIfNeeded.implementation = function (context: any) {
devlog("Providerinstaller redirection/blocking")
}
providerInstallerFromClassloder.installIfNeededAsync.implementation = function (context: any, callback: any) {
devlog("ProviderinstallerAsync redirection/blocking")
callback.onProviderInstalled()
}
}
}
}catch (error) {
devlog("Some error in hooking the Providerinstaller")
if(!error.toString().includes("java.lang.ClassNotFoundException")){
devlog("[-] Error message: "+error);
}
// As it is not available, do nothing
}
}
})
}