-
Notifications
You must be signed in to change notification settings - Fork 219
/
vdex_backend_019.c
504 lines (435 loc) · 20.6 KB
/
vdex_backend_019.c
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/*
vdexExtractor
-----------------------------------------
Anestis Bechtsoudis <anestis@census-labs.com>
Copyright 2017 - 2018 by CENSUS S.A. All Rights Reserved.
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.
*/
#include <sys/mman.h>
#include "../out_writer.h"
#include "../utils.h"
#include "vdex_backend_019.h"
#include "vdex_decompiler_019.h"
static const u1 *quickening_info_ptr;
static const unaligned_u4 *current_code_item_ptr;
static const unaligned_u4 *current_code_item_end;
static void QuickeningInfoItInit(u4 dex_file_idx,
u4 numberOfDexFiles,
const u1 *quicken_ptr,
u4 quicken_size) {
quickening_info_ptr = quicken_ptr;
const unaligned_u4 *dex_file_indices =
(unaligned_u4 *)(quicken_ptr + quicken_size - numberOfDexFiles * sizeof(u4));
current_code_item_end = (dex_file_idx == numberOfDexFiles - 1)
? dex_file_indices
: (unaligned_u4 *)(quicken_ptr + dex_file_indices[dex_file_idx + 1]);
current_code_item_ptr = (unaligned_u4 *)(quicken_ptr + dex_file_indices[dex_file_idx]);
}
static bool QuickeningInfoItDone() { return current_code_item_ptr == current_code_item_end; }
static void QuickeningInfoItAdvance() { current_code_item_ptr += 2; }
static u4 QuickeningInfoItGetCurrentCodeItemOffset() { return current_code_item_ptr[0]; }
static const u1 *QuickeningInfoItGetCurrentPtr() {
return quickening_info_ptr + current_code_item_ptr[1] + sizeof(u4);
}
static u4 QuickeningInfoItGetCurrentSize() {
return *(unaligned_u4 *)(quickening_info_ptr + current_code_item_ptr[1]);
}
static inline u4 decodeUint32WithOverflowCheck(const u1 **in, const u1 *end) {
CHECK_LT(*in, end);
return dex_readULeb128(in);
}
static void decodeDepStrings(const u1 **in, const u1 *end, vdexDepStrings_019 *depStrings) {
u4 numOfEntries = decodeUint32WithOverflowCheck(in, end);
depStrings->strings = utils_calloc(numOfEntries * sizeof(char *));
depStrings->numberOfStrings = numOfEntries;
for (u4 i = 0; i < numOfEntries; ++i) {
CHECK_LT(*in, end);
const char *stringStart = (const char *)(*in);
depStrings->strings[i] = stringStart;
*in += strlen(stringStart) + 1;
}
}
static void decodeDepTypeSet(const u1 **in, const u1 *end, vdexDepTypeSet_019 *pVdexDepTypeSet) {
u4 numOfEntries = decodeUint32WithOverflowCheck(in, end);
pVdexDepTypeSet->pVdexDepSets = utils_malloc(numOfEntries * sizeof(vdexDepSet_019));
pVdexDepTypeSet->numberOfEntries = numOfEntries;
for (u4 i = 0; i < numOfEntries; ++i) {
pVdexDepTypeSet->pVdexDepSets[i].dstIndex = decodeUint32WithOverflowCheck(in, end);
pVdexDepTypeSet->pVdexDepSets[i].srcIndex = decodeUint32WithOverflowCheck(in, end);
}
}
static void decodeDepClasses(const u1 **in,
const u1 *end,
vdexDepClassResSet_019 *pVdexDepClassResSet) {
u4 numOfEntries = decodeUint32WithOverflowCheck(in, end);
pVdexDepClassResSet->pVdexDepClasses = utils_malloc(numOfEntries * sizeof(vdexDepClassRes_019));
pVdexDepClassResSet->numberOfEntries = numOfEntries;
for (u4 i = 0; i < numOfEntries; ++i) {
pVdexDepClassResSet->pVdexDepClasses[i].typeIdx = decodeUint32WithOverflowCheck(in, end);
pVdexDepClassResSet->pVdexDepClasses[i].accessFlags = decodeUint32WithOverflowCheck(in, end);
}
}
static void decodeDepFields(const u1 **in,
const u1 *end,
vdexDepFieldResSet_019 *pVdexDepFieldResSet) {
u4 numOfEntries = decodeUint32WithOverflowCheck(in, end);
pVdexDepFieldResSet->pVdexDepFields = utils_malloc(numOfEntries * sizeof(vdexDepFieldRes_019));
pVdexDepFieldResSet->numberOfEntries = numOfEntries;
for (u4 i = 0; i < pVdexDepFieldResSet->numberOfEntries; ++i) {
pVdexDepFieldResSet->pVdexDepFields[i].fieldIdx = decodeUint32WithOverflowCheck(in, end);
pVdexDepFieldResSet->pVdexDepFields[i].accessFlags = decodeUint32WithOverflowCheck(in, end);
pVdexDepFieldResSet->pVdexDepFields[i].declaringClassIdx =
decodeUint32WithOverflowCheck(in, end);
}
}
static void decodeDepMethods(const u1 **in,
const u1 *end,
vdexDepMethodResSet_019 *pVdexDepMethodResSet) {
u4 numOfEntries = decodeUint32WithOverflowCheck(in, end);
pVdexDepMethodResSet->pVdexDepMethods = utils_malloc(numOfEntries * sizeof(vdexDepMethodRes_019));
pVdexDepMethodResSet->numberOfEntries = numOfEntries;
for (u4 i = 0; i < numOfEntries; ++i) {
pVdexDepMethodResSet->pVdexDepMethods[i].methodIdx = decodeUint32WithOverflowCheck(in, end);
pVdexDepMethodResSet->pVdexDepMethods[i].accessFlags = decodeUint32WithOverflowCheck(in, end);
pVdexDepMethodResSet->pVdexDepMethods[i].declaringClassIdx =
decodeUint32WithOverflowCheck(in, end);
}
}
static void decodeDepUnvfyClasses(const u1 **in,
const u1 *end,
vdexDepUnvfyClassesSet_019 *pVdexDepUnvfyClassesSet) {
u4 numOfEntries = decodeUint32WithOverflowCheck(in, end);
pVdexDepUnvfyClassesSet->pVdexDepUnvfyClasses =
utils_malloc(numOfEntries * sizeof(vdexDepUnvfyClass_019));
pVdexDepUnvfyClassesSet->numberOfEntries = numOfEntries;
for (u4 i = 0; i < numOfEntries; ++i) {
pVdexDepUnvfyClassesSet->pVdexDepUnvfyClasses[i].typeIdx =
decodeUint32WithOverflowCheck(in, end);
}
}
static const char *getStringFromId(const vdexDepData_019 *pVdexDepData,
u4 stringId,
const u1 *dexFileBuf) {
vdexDepStrings_019 extraStrings = pVdexDepData->extraStrings;
u4 numIdsInDex = dex_getStringIdsSize(dexFileBuf);
if (stringId < numIdsInDex) {
return dex_getStringDataByIdx(dexFileBuf, stringId);
} else {
// Adjust offset
stringId -= numIdsInDex;
CHECK_LT(stringId, extraStrings.numberOfStrings);
return extraStrings.strings[stringId];
}
}
static vdexDeps_019 *initDepsInfo(const u1 *vdexFileBuf) {
if (vdex_019_GetVerifierDepsDataSize(vdexFileBuf) == 0) {
// Return eagerly, as the first thing we expect from VerifierDeps data is
// the number of created strings, even if there is no dependency.
return NULL;
}
vdexDeps_019 *pVdexDeps = utils_malloc(sizeof(vdexDeps_019));
const vdexHeader_019 *pVdexHeader = (const vdexHeader_019 *)vdexFileBuf;
pVdexDeps->numberOfDexFiles = pVdexHeader->numberOfDexFiles;
pVdexDeps->pVdexDepData = utils_malloc(sizeof(vdexDepData_019) * pVdexDeps->numberOfDexFiles);
const u1 *dexFileBuf = NULL;
u4 offset = 0;
const u1 *depsDataStart = vdex_019_GetVerifierDepsData(vdexFileBuf);
const u1 *depsDataEnd = depsDataStart + vdex_019_GetVerifierDepsDataSize(vdexFileBuf);
for (u4 i = 0; i < pVdexDeps->numberOfDexFiles; ++i) {
dexFileBuf = vdex_019_GetNextDexFileData(vdexFileBuf, &offset);
if (dexFileBuf == NULL) {
LOGMSG(l_FATAL, "Failed to extract Dex file buffer from loaded Vdex");
}
// Process encoded extra strings
decodeDepStrings(&depsDataStart, depsDataEnd, &pVdexDeps->pVdexDepData[i].extraStrings);
// Process encoded assignable types
decodeDepTypeSet(&depsDataStart, depsDataEnd, &pVdexDeps->pVdexDepData[i].assignTypeSets);
// Process encoded unassignable types
decodeDepTypeSet(&depsDataStart, depsDataEnd, &pVdexDeps->pVdexDepData[i].unassignTypeSets);
// Process encoded classes
decodeDepClasses(&depsDataStart, depsDataEnd, &pVdexDeps->pVdexDepData[i].classes);
// Process encoded fields
decodeDepFields(&depsDataStart, depsDataEnd, &pVdexDeps->pVdexDepData[i].fields);
// Process encoded methods
decodeDepMethods(&depsDataStart, depsDataEnd, &pVdexDeps->pVdexDepData[i].methods);
// Process encoded unverified classes
decodeDepUnvfyClasses(&depsDataStart, depsDataEnd, &pVdexDeps->pVdexDepData[i].unvfyClasses);
}
CHECK_LE(depsDataStart, depsDataEnd);
return pVdexDeps;
}
static void destroyDepsInfo(const vdexDeps_019 *pVdexDeps) {
for (u4 i = 0; i < pVdexDeps->numberOfDexFiles; ++i) {
free((void *)pVdexDeps->pVdexDepData[i].extraStrings.strings);
free((void *)pVdexDeps->pVdexDepData[i].assignTypeSets.pVdexDepSets);
free((void *)pVdexDeps->pVdexDepData[i].unassignTypeSets.pVdexDepSets);
free((void *)pVdexDeps->pVdexDepData[i].classes.pVdexDepClasses);
free((void *)pVdexDeps->pVdexDepData[i].fields.pVdexDepFields);
free((void *)pVdexDeps->pVdexDepData[i].methods.pVdexDepMethods);
free((void *)pVdexDeps->pVdexDepData[i].unvfyClasses.pVdexDepUnvfyClasses);
}
free((void *)pVdexDeps->pVdexDepData);
free((void *)pVdexDeps);
}
void vdex_backend_019_dumpDepsInfo(const u1 *vdexFileBuf) {
// Not all Vdex files have Dex data to process
if (!vdex_019_hasDexSection(vdexFileBuf)) {
LOGMSG(l_DEBUG, "Vdex has no Dex data - skipping");
return;
}
// Initialize depsInfo structs
vdexDeps_019 *pVdexDeps = initDepsInfo(vdexFileBuf);
if (pVdexDeps == NULL) {
LOGMSG(l_WARN, "Empty verified dependency data");
return;
}
log_dis("------- Vdex Deps Info -------\n");
const u1 *dexFileBuf = NULL;
u4 offset = 0;
for (u4 i = 0; i < pVdexDeps->numberOfDexFiles; ++i) {
const vdexDepData_019 *pVdexDepData = &pVdexDeps->pVdexDepData[i];
log_dis("dex file #%" PRIu32 "\n", i);
dexFileBuf = vdex_019_GetNextDexFileData(vdexFileBuf, &offset);
if (dexFileBuf == NULL) {
LOGMSG(l_ERROR, "Failed to extract Dex file buffer from loaded Vdex");
return;
}
vdexDepStrings_019 strings = pVdexDepData->extraStrings;
log_dis(" extra strings: number_of_strings=%" PRIu32 "\n", strings.numberOfStrings);
for (u4 i = 0; i < strings.numberOfStrings; ++i) {
log_dis(" %04" PRIu32 ": '%s'\n", i, strings.strings[i]);
}
vdexDepTypeSet_019 aTypes = pVdexDepData->assignTypeSets;
log_dis(" assignable type sets: number_of_sets=%" PRIu32 "\n", aTypes.numberOfEntries);
for (u4 i = 0; i < aTypes.numberOfEntries; ++i) {
log_dis(" %04" PRIu32 ": '%s' must be assignable to '%s'\n", i,
getStringFromId(pVdexDepData, aTypes.pVdexDepSets[i].srcIndex, dexFileBuf),
getStringFromId(pVdexDepData, aTypes.pVdexDepSets[i].dstIndex, dexFileBuf));
}
vdexDepTypeSet_019 unTypes = pVdexDepData->unassignTypeSets;
log_dis(" unassignable type sets: number_of_sets=%" PRIu32 "\n", unTypes.numberOfEntries);
for (u4 i = 0; i < unTypes.numberOfEntries; ++i) {
log_dis(" %04" PRIu32 ": '%s' must not be assignable to '%s'\n", i,
getStringFromId(pVdexDepData, unTypes.pVdexDepSets[i].srcIndex, dexFileBuf),
getStringFromId(pVdexDepData, unTypes.pVdexDepSets[i].dstIndex, dexFileBuf));
}
log_dis(" class dependencies: number_of_classes=%" PRIu32 "\n",
pVdexDepData->classes.numberOfEntries);
for (u4 i = 0; i < pVdexDepData->classes.numberOfEntries; ++i) {
u2 accessFlags = pVdexDepData->classes.pVdexDepClasses[i].accessFlags;
log_dis(" %04" PRIu32 ": '%s' '%s' be resolved with access flags '%" PRIu16 "'\n", i,
dex_getStringByTypeIdx(dexFileBuf, pVdexDepData->classes.pVdexDepClasses[i].typeIdx),
accessFlags == kUnresolvedMarker ? "must not" : "must", accessFlags);
}
log_dis(" field dependencies: number_of_fields=%" PRIu32 "\n",
pVdexDepData->fields.numberOfEntries);
for (u4 i = 0; i < pVdexDepData->fields.numberOfEntries; ++i) {
vdexDepFieldRes_019 fieldRes = pVdexDepData->fields.pVdexDepFields[i];
const dexFieldId *pDexFieldId = dex_getFieldId(dexFileBuf, fieldRes.fieldIdx);
log_dis(" %04" PRIu32 ": '%s'->'%s':'%s' is expected to be ", i,
dex_getFieldDeclaringClassDescriptor(dexFileBuf, pDexFieldId),
dex_getFieldName(dexFileBuf, pDexFieldId),
dex_getFieldTypeDescriptor(dexFileBuf, pDexFieldId));
if (fieldRes.accessFlags == kUnresolvedMarker) {
log_dis("unresolved\n");
} else {
log_dis("in class '%s' and have the access flags '%" PRIu16 "'\n",
getStringFromId(pVdexDepData, fieldRes.declaringClassIdx, dexFileBuf),
fieldRes.accessFlags);
}
}
log_dis(" method dependencies: number_of_methods=%" PRIu32 "\n",
pVdexDepData->methods.numberOfEntries);
for (u4 i = 0; i < pVdexDepData->methods.numberOfEntries; ++i) {
const dexMethodId *pDexMethodId =
dex_getMethodId(dexFileBuf, pVdexDepData->methods.pVdexDepMethods[i].methodIdx);
u2 accessFlags = pVdexDepData->methods.pVdexDepMethods[i].accessFlags;
const char *methodSig = dex_getMethodSignature(dexFileBuf, pDexMethodId);
log_dis(" %04" PRIu32 ": '%s'->'%s':'%s' is expected to be ", i,
dex_getMethodDeclaringClassDescriptor(dexFileBuf, pDexMethodId),
dex_getMethodName(dexFileBuf, pDexMethodId), methodSig);
free((void *)methodSig);
if (accessFlags == kUnresolvedMarker) {
log_dis("unresolved\n");
} else {
log_dis(
"in class '%s', have the access flags '%" PRIu16 "'\n",
getStringFromId(pVdexDepData,
pVdexDepData->methods.pVdexDepMethods[i].declaringClassIdx, dexFileBuf),
accessFlags);
}
}
log_dis(" unverified classes: number_of_classes=%" PRIu32 "\n",
pVdexDepData->unvfyClasses.numberOfEntries);
for (u4 i = 0; i < pVdexDepData->unvfyClasses.numberOfEntries; ++i) {
log_dis(" %04" PRIu32 ": '%s' is expected to be verified at runtime\n", i,
dex_getStringByTypeIdx(dexFileBuf,
pVdexDepData->unvfyClasses.pVdexDepUnvfyClasses[i].typeIdx));
}
}
log_dis("----- EOF Vdex Deps Info -----\n");
// Cleanup
destroyDepsInfo(pVdexDeps);
}
int vdex_backend_019_process(const char *VdexFileName,
const u1 *cursor,
size_t bufSz,
const runArgs_t *pRunArgs) {
// Basic size checks
if (!vdex_019_SanityCheck(cursor, bufSz)) {
LOGMSG(l_ERROR, "Malformed Vdex file");
return -1;
}
// Not all Vdex files have Dex data to process
if (!vdex_019_hasDexSection(cursor)) {
LOGMSG(l_DEBUG, "Vdex has no Dex data - skipping");
return 0;
}
const vdexHeader_019 *pVdexHeader = (const vdexHeader_019 *)cursor;
const u1 *dexFileBuf = NULL;
u4 offset = 0;
// For each Dex file
for (size_t dex_file_idx = 0; dex_file_idx < pVdexHeader->numberOfDexFiles; ++dex_file_idx) {
QuickeningInfoItInit(dex_file_idx, pVdexHeader->numberOfDexFiles,
vdex_019_GetQuickeningInfo(cursor),
vdex_019_GetQuickeningInfoSize(cursor));
dexFileBuf = vdex_019_GetNextDexFileData(cursor, &offset);
if (dexFileBuf == NULL) {
LOGMSG(l_ERROR, "Failed to extract 'classes%zu.dex' - skipping", dex_file_idx);
continue;
}
// Check if valid Dex or CompactDex file
dex_dumpHeaderInfo(dexFileBuf);
if (!dex_isValidDex(dexFileBuf) && !dex_isValidCDex(dexFileBuf)) {
LOGMSG(l_ERROR, "'classes%zu.dex' is an invalid Dex file - skipping", dex_file_idx);
continue;
}
// For each class
log_dis("file #%zu: classDefsSize=%" PRIu32 "\n", dex_file_idx,
dex_getClassDefsSize(dexFileBuf));
for (u4 i = 0; i < dex_getClassDefsSize(dexFileBuf); ++i) {
const dexClassDef *pDexClassDef = dex_getClassDef(dexFileBuf, i);
dex_dumpClassInfo(dexFileBuf, i);
// Cursor for currently processed class data item
const u1 *curClassDataCursor;
if (pDexClassDef->classDataOff == 0) {
continue;
} else {
curClassDataCursor = dex_getDataAddr(dexFileBuf) + pDexClassDef->classDataOff;
}
dexClassDataHeader pDexClassDataHeader;
memset(&pDexClassDataHeader, 0, sizeof(dexClassDataHeader));
dex_readClassDataHeader(&curClassDataCursor, &pDexClassDataHeader);
// Skip static fields
for (u4 j = 0; j < pDexClassDataHeader.staticFieldsSize; ++j) {
dexField pDexField;
memset(&pDexField, 0, sizeof(dexField));
dex_readClassDataField(&curClassDataCursor, &pDexField);
}
// Skip instance fields
for (u4 j = 0; j < pDexClassDataHeader.instanceFieldsSize; ++j) {
dexField pDexField;
memset(&pDexField, 0, sizeof(dexField));
dex_readClassDataField(&curClassDataCursor, &pDexField);
}
// For each direct method
for (u4 j = 0; j < pDexClassDataHeader.directMethodsSize; ++j) {
dexMethod curDexMethod;
memset(&curDexMethod, 0, sizeof(dexMethod));
dex_readClassDataMethod(&curClassDataCursor, &curDexMethod);
dex_dumpMethodInfo(dexFileBuf, &curDexMethod, j, "direct");
// Skip empty methods
if (curDexMethod.codeOff == 0) {
continue;
}
if (pRunArgs->unquicken) {
// TODO: Port to Vdex 019 QueckiningInfo struct
LOGMSG(l_FATAL, "Decompiler is under development");
const u1 *quickening_ptr = QuickeningInfoItGetCurrentPtr();
u4 quickening_size = QuickeningInfoItGetCurrentSize();
if (!QuickeningInfoItDone() &&
curDexMethod.codeOff == QuickeningInfoItGetCurrentCodeItemOffset()) {
QuickeningInfoItAdvance();
} else {
quickening_ptr = NULL;
quickening_size = 0;
}
if (!vdex_decompiler_019_decompile(dexFileBuf, &curDexMethod, quickening_ptr,
quickening_size, true)) {
LOGMSG(l_ERROR, "Failed to decompile Dex file");
return -1;
}
} else {
vdex_decompiler_019_walk(dexFileBuf, &curDexMethod);
}
}
// For each virtual method
for (u4 j = 0; j < pDexClassDataHeader.virtualMethodsSize; ++j) {
dexMethod curDexMethod;
memset(&curDexMethod, 0, sizeof(dexMethod));
dex_readClassDataMethod(&curClassDataCursor, &curDexMethod);
dex_dumpMethodInfo(dexFileBuf, &curDexMethod, j, "virtual");
// Skip native or abstract methods
if (curDexMethod.codeOff == 0) {
continue;
}
if (pRunArgs->unquicken) {
// TODO: Port to Vdex 019 QueckiningInfo struct
LOGMSG(l_FATAL, "Decompiler is under development");
const u1 *quickening_ptr = QuickeningInfoItGetCurrentPtr();
u4 quickening_size = QuickeningInfoItGetCurrentSize();
if (!QuickeningInfoItDone() &&
curDexMethod.codeOff == QuickeningInfoItGetCurrentCodeItemOffset()) {
QuickeningInfoItAdvance();
} else {
quickening_ptr = NULL;
quickening_size = 0;
}
if (!vdex_decompiler_019_decompile(dexFileBuf, &curDexMethod, quickening_ptr,
quickening_size, true)) {
LOGMSG(l_ERROR, "Failed to decompile Dex file");
return -1;
}
} else {
vdex_decompiler_019_walk(dexFileBuf, &curDexMethod);
}
}
}
if (pRunArgs->unquicken) {
// All QuickeningInfo data should have been consumed
if (!QuickeningInfoItDone()) {
LOGMSG(l_ERROR, "Failed to use all quickening info");
return -1;
}
// If unquicken was successful original checksum should verify
u4 curChecksum = dex_computeDexCRC(dexFileBuf, dex_getFileSize(dexFileBuf));
if (curChecksum != dex_getChecksum(dexFileBuf)) {
// If ignore CRC errors is enabled, repair CRC (see issue #3)
if (pRunArgs->ignoreCrc) {
dex_repairDexCRC(dexFileBuf, dex_getFileSize(dexFileBuf));
} else {
LOGMSG(l_ERROR,
"Unexpected checksum (%" PRIx32 " vs %" PRIx32 ") - failed to unquicken Dex file",
curChecksum, dex_getChecksum(dexFileBuf));
return -1;
}
}
} else {
// Repair CRC if not decompiling so we can still run Dex parsing tools against output
dex_repairDexCRC(dexFileBuf, dex_getFileSize(dexFileBuf));
}
if (!outWriter_DexFile(pRunArgs, VdexFileName, dex_file_idx, dexFileBuf,
dex_getFileSize(dexFileBuf))) {
return -1;
}
}
return pVdexHeader->numberOfDexFiles;
}