@zsa233/frida-analykit-agent 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,217 @@
1
+
2
+
3
+ export enum IndirectRefKind {
4
+ kHandleScopeOrInvalid = 0, // <<stack indirect reference table or invalid reference>>
5
+ kLocal = 1, // <<local reference>>
6
+ kGlobal = 2, // <<global reference>>
7
+ kWeakGlobal = 3, // <<weak global reference>>
8
+ kLastKind = kWeakGlobal
9
+ }
10
+
11
+
12
+ export enum JNI_VT {
13
+ FindClass = 6,
14
+ FromReflectedMethod = 7,
15
+ ToReflectedMethod = 9,
16
+ GetSuperclass = 10,
17
+ Throw = 13,
18
+ ThrowNew = 14,
19
+ ExceptionOccurred = 15,
20
+ ExceptionDescribe = 16,
21
+ ExceptionClear = 17,
22
+ FatalError = 18,
23
+
24
+ PushLocalFrame = 19,
25
+ PopLocalFrame = 20,
26
+
27
+ NewGlobalRef = 21,
28
+ DeleteGlobalRef = 22,
29
+ DeleteLocalRef = 23,
30
+ NewLocalRef = 23,
31
+ IsSameObject = 24,
32
+ NewObject = 28,
33
+ NewObjectV = 29,
34
+ NewObjectA = 30,
35
+ GetObjectClass = 31,
36
+ GetMethodID = 33,
37
+
38
+ CallObjectMethod = 34,
39
+ CallObjectMethodV = 35,
40
+ CallObjectMethodA = 36,
41
+
42
+ CallBooleanMethod = 37,
43
+ CallBooleanMethodV = 38,
44
+ CallBooleanMethodA = 39,
45
+
46
+ CallByteMethod = 40,
47
+ CallByteMethodV = 41,
48
+ CallByteMethodA = 42,
49
+
50
+ CallCharMethod = 43,
51
+ CallCharMethodV = 44,
52
+ CallCharMethodA = 45,
53
+
54
+ CallShortMethod = 46,
55
+ CallShortMethodV = 47,
56
+ CallShortMethodA = 48,
57
+
58
+ CallIntMethod = 49,
59
+ CallIntMethodV = 50,
60
+ CallIntMethodA = 51,
61
+
62
+ CallLongMethod = 52,
63
+ CallLongMethodV = 53,
64
+ CallLongMethodA = 54,
65
+
66
+ CallFloatMethod = 55,
67
+ CallFloatMethodV = 56,
68
+ CallFloatMethodA = 57,
69
+
70
+ CallDoubleMethod = 58,
71
+ CallDoubleMethodV = 59,
72
+ CallDoubleMethodA = 60,
73
+
74
+ CallVoidMethod = 61,
75
+ CallVoidMethodV = 62,
76
+ CallVoidMethodA = 63,
77
+
78
+ CallNonvirtualObjectMethod = 64,
79
+ CallNonvirtualObjectMethodV = 65,
80
+ CallNonvirtualObjectMethodA = 66,
81
+
82
+ CallNonvirtualBooleanMethod = 67,
83
+ CallNonvirtualBooleanMethodV = 68,
84
+ CallNonvirtualBooleanMethodA = 69,
85
+
86
+ CallNonvirtualByteMethod = 70,
87
+ CallNonvirtualByteMethodV = 71,
88
+ CallNonvirtualByteMethodA = 72,
89
+
90
+ CallNonvirtualCharMethod = 73,
91
+ CallNonvirtualCharMethodV = 74,
92
+ CallNonvirtualCharMethodA = 75,
93
+
94
+ CallNonvirtualShortMethod = 76,
95
+ CallNonvirtualShortMethodV = 77,
96
+ CallNonvirtualShortMethodA = 78,
97
+
98
+ CallNonvirtualIntMethod = 79,
99
+ CallNonvirtualIntMethodV = 80,
100
+ CallNonvirtualIntMethodA = 81,
101
+
102
+ CallNonvirtualLongMethod = 82,
103
+ CallNonvirtualLongMethodV = 83,
104
+ CallNonvirtualLongMethodA = 84,
105
+
106
+ CallNonvirtualFloatMethod = 85,
107
+ CallNonvirtualFloatMethodV = 86,
108
+ CallNonvirtualFloatMethodA = 87,
109
+
110
+ CallNonvirtualDoubleMethod = 88,
111
+ CallNonvirtualDoubleMethodV = 89,
112
+ CallNonvirtualDoubleMethodA = 90,
113
+
114
+ CallNonvirtualVoidMethod = 91,
115
+ CallNonvirtualVoidMethodV = 92,
116
+ CallNonvirtualVoidMethodA = 93,
117
+
118
+ GetFieldID = 94,
119
+ GetObjectField = 95,
120
+ GetBooleanField = 96,
121
+ GetByteField = 97,
122
+ GetCharField = 98,
123
+ GetShortField = 99,
124
+ GetIntField = 100,
125
+ GetLongField = 101,
126
+ GetFloatField = 102,
127
+ GetDoubleField = 103,
128
+
129
+ GetStaticMethodID = 113,
130
+
131
+ CallStaticObjectMethod = 114,
132
+ CallStaticObjectMethodV = 115,
133
+ CallStaticObjectMethodA = 116,
134
+
135
+ CallStaticBooleanMethod = 117,
136
+ CallStaticBooleanMethodV = 118,
137
+ CallStaticBooleanMethodA = 119,
138
+
139
+ CallStaticByteMethod = 120,
140
+ CallStaticByteMethodV = 121,
141
+ CallStaticByteMethodA = 122,
142
+
143
+ CallStaticCharMethod = 123,
144
+ CallStaticCharMethodV = 124,
145
+ CallStaticCharMethodA = 125,
146
+
147
+ CallStaticShortMethod = 126,
148
+ CallStaticShortMethodV = 127,
149
+ CallStaticShortMethodA = 128,
150
+
151
+ CallStaticIntMethod = 129,
152
+ CallStaticIntMethodV = 130,
153
+ CallStaticIntMethodA = 131,
154
+
155
+ CallStaticLongMethod = 132,
156
+ CallStaticLongMethodV = 133,
157
+ CallStaticLongMethodA = 134,
158
+
159
+ CallStaticFloatMethod = 135,
160
+ CallStaticFloatMethodV = 136,
161
+ CallStaticFloatMethodA = 137,
162
+
163
+ CallStaticDoubleMethod = 138,
164
+ CallStaticDoubleMethodV = 139,
165
+ CallStaticDoubleMethodA = 140,
166
+
167
+ CallStaticVoidMethod = 141,
168
+ CallStaticVoidMethodV = 142,
169
+ CallStaticVoidMethodA = 143,
170
+
171
+ GetStaticFieldID = 144,
172
+ GetStaticObjectField = 145,
173
+ GetStaticBooleanField = 146,
174
+ GetStaticByteField = 147,
175
+ GetStaticCharField = 148,
176
+ GetStaticShortField = 149,
177
+ GetStaticIntField = 150,
178
+ GetStaticLongField = 151,
179
+ GetStaticFloatField = 152,
180
+ GetStaticDoubleField = 153,
181
+
182
+ GetStringLength = 164,
183
+ GetStringChars = 165,
184
+ ReleaseStringChars = 166,
185
+
186
+ GetStringUTFLength = 168,
187
+ GetStringUTFChars = 169,
188
+ ReleaseStringUTFChars = 170,
189
+
190
+ GetArrayLength = 171,
191
+ GetObjectArrayElement = 173,
192
+
193
+ GetBooleanArrayElements = 183,
194
+ GetByteArrayElements = 184,
195
+ GetCharArrayElements = 185,
196
+ GetShortArrayElements = 186,
197
+ GetIntArrayElements = 187,
198
+ GetLongArrayElements = 188,
199
+ GetFloatArrayElements = 189,
200
+ GetDoubleArrayElements = 190,
201
+
202
+ ReleaseBooleanArrayElements = 191,
203
+ ReleaseByteArrayElements = 192,
204
+ ReleaseCharArrayElements = 193,
205
+ ReleaseShortArrayElements = 194,
206
+ ReleaseIntArrayElements = 195,
207
+ ReleaseLongArrayElements = 196,
208
+ ReleaseFloatArrayElements = 197,
209
+ ReleaseDoubleArrayElements = 198,
210
+
211
+ RegisterNatives = 215,
212
+ UnregisterNatives = 216,
213
+
214
+ GetStringCritical = 224,
215
+ DeleteWeakGlobalRef = 227,
216
+ ExceptionCheck = 228,
217
+ }
@@ -0,0 +1,161 @@
1
+ import { mustType } from "../utils/utils.js"
2
+ import { nativeFunctionOptions } from "../consts.js"
3
+
4
+
5
+ const PROP_VALUE_MAX = 92
6
+
7
+
8
+ export class Libc {
9
+ constructor() {
10
+ return new Proxy(this, {
11
+ get(target: any, prop: string) {
12
+ if (prop in target) {
13
+ return target[prop];
14
+ }
15
+ if (prop[0] !== '$') {
16
+ return target['$' + prop]
17
+ } else {
18
+ return target[prop.substring(1)]
19
+ }
20
+ }
21
+ })
22
+ }
23
+
24
+ static readonly $libc = Process.findModuleByName('libc.so') || Module.load('libc.so')
25
+
26
+
27
+ $lazyLoadFunc<RetType extends NativeFunctionReturnType, ArgTypes extends NativeFunctionArgumentType[] | []>(
28
+ symName: string, retType: RetType, argTypes: ArgTypes,
29
+ ): NativeFunction<GetNativeFunctionReturnValue<RetType>, ResolveVariadic<Extract<GetNativeFunctionArgumentValue<ArgTypes>, unknown[]>>> & { $handle: NativePointer | undefined } {
30
+ let func: any = null
31
+ const wrapper = ((...args: any) => {
32
+ if (func === null) {
33
+ func = this.$nativeFunc(symName, retType, argTypes)
34
+ }
35
+ const ret = func(...args)
36
+ return ret
37
+ }) as any
38
+
39
+ Object.defineProperty(wrapper, '$handle', {
40
+ get() {
41
+ if (func === null) {
42
+ func = this.$nativeFunc(symName, retType, argTypes)
43
+ }
44
+ return func.$handle
45
+ },
46
+ enumerable: true,
47
+ })
48
+
49
+ return wrapper
50
+ }
51
+
52
+
53
+
54
+ $nativeFunc<RetType extends NativeFunctionReturnType, ArgTypes extends NativeFunctionArgumentType[] | []>(
55
+ symName: string, retType: RetType, argTypes: ArgTypes,
56
+ ): NativeFunction<GetNativeFunctionReturnValue<RetType>, ResolveVariadic<Extract<GetNativeFunctionArgumentValue<ArgTypes>, unknown[]>>> & { $handle: NativePointer | undefined } {
57
+ const handle = mustType(Libc.$libc.findExportByName(symName))
58
+ const fn: any = new NativeFunction(
59
+ handle,
60
+ retType, argTypes, nativeFunctionOptions,
61
+ )
62
+ fn.$handle = handle
63
+ return fn
64
+ }
65
+
66
+ // ssize_t readlink(const char *pathname, char *buf, size_t bufsiz);
67
+ readonly $readlink = this.$lazyLoadFunc('readlink', 'int', ['pointer', 'pointer', 'size_t'])
68
+ readlink(pathname: string, bufsize: number = 256): string | null {
69
+ const cfdPath = Memory.allocUtf8String(pathname)
70
+ const resolvedPath = Memory.alloc(bufsize)
71
+ const result = this.$readlink(cfdPath, resolvedPath, bufsize)
72
+ let link: string | null = null
73
+ if (result !== -1) {
74
+ link = resolvedPath.readCString()
75
+ }
76
+ return link
77
+ }
78
+
79
+ // DIR *opendir(const char *name);
80
+ readonly $opendir = this.$lazyLoadFunc('opendir', 'pointer', ['pointer'])
81
+ opendir(path: string) {
82
+ const cpath = Memory.allocUtf8String(path)
83
+ const dir = this.$opendir(cpath)
84
+ return dir
85
+ }
86
+
87
+ // FILE *fopen(const char *pathname, const char *mode);
88
+ readonly $fopen = this.$lazyLoadFunc('fopen', 'pointer', ['pointer', 'pointer'])
89
+ fopen(pathname: string, mode: string): NativePointer {
90
+ return this.$fopen(Memory.allocUtf8String(pathname), Memory.allocUtf8String(mode))
91
+ }
92
+
93
+ // int fclose(FILE *stream);
94
+ readonly fclose = this.$lazyLoadFunc('fclose', 'int', ['pointer'])
95
+
96
+ // int fputs(const char *str, FILE *stream);
97
+ readonly $fputs = this.$lazyLoadFunc('fputs', 'int', ['pointer', 'pointer'])
98
+ fputs(str: string, file: NativePointer) {
99
+ return this.$fputs(Memory.allocUtf8String(str), file)
100
+ }
101
+
102
+ // int fflush(FILE *stream);
103
+ readonly fflush = this.$lazyLoadFunc('fflush', 'int', ['pointer'])
104
+
105
+ // struct dirent *readdir(DIR *dirp);
106
+ readonly readdir = this.$lazyLoadFunc('readdir', 'pointer', ['pointer'])
107
+
108
+ // int closedir(DIR *dirp);
109
+ readonly closedir = this.$lazyLoadFunc('closedir', 'int', ['pointer'])
110
+
111
+ // int fileno(FILE *stream);
112
+ readonly fileno = this.$lazyLoadFunc('fileno', 'int', ['pointer'])
113
+
114
+ // pthread_t pthread_self(void);
115
+ readonly pthread_self = this.$lazyLoadFunc('pthread_self', 'int64', [])
116
+
117
+
118
+ // pid_t getpid(void);
119
+ readonly getpid = this.$lazyLoadFunc('getpid', 'uint', [])
120
+
121
+ // uid_t getuid(void);
122
+ readonly getuid = this.$lazyLoadFunc('getuid', 'uint', [])
123
+
124
+ // pid_t gettid(void);
125
+ readonly gettid = this.$lazyLoadFunc('gettid', 'uint', [])
126
+
127
+ // int clock_gettime(clockid_t clk_id, struct timespec *tp);
128
+ readonly $clock_gettime = this.$lazyLoadFunc('clock_gettime', 'int', ['int', 'pointer'])
129
+ clock_gettime(clk_id: number): {tv_sec: number, tv_nsec: number } | null {
130
+ const ps = Process.pointerSize
131
+ const tv = Memory.alloc(ps * 2)
132
+ const ret = this.$clock_gettime(clk_id, tv)
133
+ if(ret != 0) {
134
+ return null
135
+ }
136
+ return {
137
+ tv_sec: Number(tv[ps === 8 ? 'readU64' : 'readU32']()),
138
+ tv_nsec: Number(tv.add(ps)[ps === 8 ? 'readU64' : 'readU32']()),
139
+ }
140
+ }
141
+
142
+ // int __system_property_get(const char *name, char *value);
143
+ readonly $__system_property_get = this.$lazyLoadFunc('__system_property_get', 'int', ['pointer', 'pointer'])
144
+ __system_property_get(name: string): string {
145
+ const sdk_version_value = Memory.alloc(PROP_VALUE_MAX)
146
+ const ret = this.$__system_property_get(Memory.allocUtf8String(name), sdk_version_value)
147
+ if(ret < 0) {
148
+ console.error(`[__system_property_get] name[${name}] error[${ret}]`)
149
+ }
150
+ return sdk_version_value.readCString(ret) || ''
151
+ }
152
+
153
+ // char *getcwd(char *buf, size_t size);
154
+ readonly $getcwd = this.$lazyLoadFunc('getcwd', 'pointer', ['pointer', 'size_t'])
155
+ getcwd(): string | null {
156
+ const buff_size = 256
157
+ const buff = Memory.alloc(buff_size)
158
+ return this.$getcwd(buff, buff_size).readCString()
159
+ }
160
+
161
+ }
@@ -0,0 +1,95 @@
1
+
2
+ import { ElfModuleX, ElfFileFixer } from "../elf/module.js"
3
+ import { nativeFunctionOptions } from "../consts.js"
4
+
5
+
6
+ export class Libssl {
7
+ static $modx?: ElfModuleX
8
+
9
+ static $getModule(): ElfModuleX {
10
+ if (!this.$modx) {
11
+ let isNewLoad = false
12
+ const libsslModule = Process.findModuleByName('libssl.so') || (isNewLoad = true, Module.load('libssl.so'))
13
+ if (isNewLoad) {
14
+ console.error(`[libssl.so]为新加载module.`)
15
+ }
16
+ this.$modx = new ElfModuleX(
17
+ libsslModule,
18
+ [new ElfFileFixer(libsslModule.path)],
19
+ { symbolScanLimit: 50000 },
20
+ )
21
+ }
22
+ return this.$modx
23
+ }
24
+
25
+
26
+ static $nativeFunc<RetType extends NativeFunctionReturnType, ArgTypes extends NativeFunctionArgumentType[] | []>(
27
+ symName: string, retType: RetType, argTypes: ArgTypes,
28
+ ): NativeFunction<GetNativeFunctionReturnValue<RetType>, ResolveVariadic<Extract<GetNativeFunctionArgumentValue<ArgTypes>, unknown[]>>> & { $handle: NativePointer | undefined } {
29
+ const sym = this.$getModule().findSymbol(symName)
30
+ if (!sym || !sym.implPtr) {
31
+ // throw error if call
32
+ const throwFunc = function () {
33
+ throw new Error(`[Libssl] symbol[${symName}] Not Found!`)
34
+ } as any
35
+ throwFunc.$handle = null
36
+ return throwFunc
37
+ }
38
+
39
+ const handle = sym.implPtr
40
+
41
+ const fn: any = new NativeFunction(
42
+ handle,
43
+ retType, argTypes, nativeFunctionOptions,
44
+ )
45
+ fn.$handle = handle
46
+ return fn
47
+ }
48
+
49
+ static $lazyLoadFunc<RetType extends NativeFunctionReturnType, ArgTypes extends NativeFunctionArgumentType[] | []>(
50
+ symName: string, retType: RetType, argTypes: ArgTypes,
51
+ ): NativeFunction<GetNativeFunctionReturnValue<RetType>, ResolveVariadic<Extract<GetNativeFunctionArgumentValue<ArgTypes>, unknown[]>>> & { $handle: NativePointer | undefined } {
52
+ let func: any = null
53
+ const getFunc = () => {
54
+ if (func === null) { func = this.$nativeFunc(symName, retType, argTypes) }
55
+ return func
56
+ }
57
+
58
+ const wrapper = ((...args: any) => {
59
+ return getFunc()(...args)
60
+ }) as any
61
+
62
+ Object.defineProperty(wrapper, '$handle', {
63
+ get() { return getFunc().$handle },
64
+ })
65
+ return wrapper
66
+ }
67
+
68
+
69
+
70
+ // // int bssl::ssl_log_secret(const SSL *ssl, const char *label, const uint8_t *secret, size_t secret_len)
71
+ // static readonly ssl_log_secret = this.$lazyLoadFunc(
72
+ // '_ZN4bssl14ssl_log_secretEPK6ssl_stPKcPKhm', 'bool', ['pointer', 'pointer', 'pointer', 'size_t']
73
+ // )
74
+
75
+ // void SSL_CTX_set_keylog_callback(SSL_CTX *ctx, void(*cb)(const SSL *ssl, const char *line))
76
+ static readonly SSL_CTX_set_keylog_callback = this.$lazyLoadFunc(
77
+ 'SSL_CTX_set_keylog_callback', 'void', ['pointer', 'pointer']
78
+ )
79
+
80
+ // void (*SSL_CTX_get_keylog_callback(const SSL_CTX *ctx))(const SSL *ssl, const char *line)
81
+ static readonly SSL_CTX_get_keylog_callback = this.$lazyLoadFunc(
82
+ 'SSL_CTX_get_keylog_callback', 'pointer', ['pointer']
83
+ )
84
+
85
+ // int SSL_connect(SSL *ssl)
86
+ static readonly SSL_connect = this.$lazyLoadFunc(
87
+ 'SSL_connect', 'int', ['pointer']
88
+ )
89
+
90
+ // SSL *SSL_new(SSL_CTX *ctx)
91
+ static readonly SSL_new = this.$lazyLoadFunc(
92
+ 'SSL_new', 'pointer', ['pointer']
93
+ )
94
+
95
+ }
package/src/message.ts ADDED
@@ -0,0 +1,26 @@
1
+
2
+
3
+
4
+
5
+ export enum RPCMsgType {
6
+ BATCH = 'BATCH',
7
+ SCOPE_CALL = 'SCOPE_CALL',
8
+ SCOPE_EVAL = 'SCOPE_EVAL',
9
+ SCOPE_GET = 'SCOPE_GET',
10
+ ENUMERATE_OBJ_PROPS = 'ENUMERATE_OBJ_PROPS',
11
+ INIT_CONFIG = 'INIT_CONFIG',
12
+ SAVE_FILE = 'SAVE_FILE',
13
+ SSL_SECRET = 'SSL_SECRET',
14
+ PROGRESSING = 'PROGRESSING',
15
+ }
16
+
17
+
18
+ export enum batchSendSource {
19
+ }
20
+
21
+
22
+ export enum saveFileSource {
23
+ procMaps = 'procMaps',
24
+ textFile = 'textFile',
25
+ elfModule = 'elfModule',
26
+ }