-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path3220-DexHeaderFormatAnalyzer-do-not-fail-when-severa.patch
More file actions
146 lines (141 loc) · 8.41 KB
/
Copy path3220-DexHeaderFormatAnalyzer-do-not-fail-when-severa.patch
File metadata and controls
146 lines (141 loc) · 8.41 KB
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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nicolas Iooss <nicolas.iooss@ledger.fr>
Date: Thu, 15 Jul 2021 16:20:07 +0200
Subject: [PATCH] 3220: DexHeaderFormatAnalyzer: do not fail when several
methods refer to the same metadata
Some Android applications use the same class annotations metadata
structure for several annotations. This makes `processClassAnnotations()`
create a structure twice at the same location. As `setItem.toDataType()`
always creates a new structure which is not "compatible" with any
existing one, `createData()` fails:
Could not create Data at address 007f35f8
java.lang.RuntimeException: Could not create Data at address 007f35f8
at ghidra.file.analyzers.FileFormatAnalyzer.createData(FileFormatAnalyzer.java:211)
at ghidra.file.formats.android.dex.analyzer.DexHeaderFormatAnalyzer.processClassAnnotations(DexHeaderFormatAnalyzer.java:640)
at ghidra.file.formats.android.dex.analyzer.DexHeaderFormatAnalyzer.processClassDefs(DexHeaderFormatAnalyzer.java:373)
at ghidra.file.formats.android.dex.analyzer.DexHeaderFormatAnalyzer.analyze(DexHeaderFormatAnalyzer.java:76)
at ghidra.file.analyzers.FileFormatAnalyzer.added(FileFormatAnalyzer.java:52)
at ghidra.app.plugin.core.analysis.AnalysisScheduler.runAnalyzer(AnalysisScheduler.java:186)
at ghidra.app.plugin.core.analysis.AnalysisTask.applyTo(AnalysisTask.java:39)
at ghidra.app.plugin.core.analysis.AutoAnalysisManager$AnalysisTaskWrapper.run(AutoAnalysisManager.java:688)
at ghidra.app.plugin.core.analysis.AutoAnalysisManager.startAnalysis(AutoAnalysisManager.java:788)
at ghidra.app.plugin.core.analysis.AutoAnalysisManager.startAnalysis(AutoAnalysisManager.java:667)
at ghidra.app.plugin.core.analysis.AutoAnalysisManager.startAnalysis(AutoAnalysisManager.java:632)
at ghidra.app.plugin.core.analysis.AnalysisBackgroundCommand.applyTo(AnalysisBackgroundCommand.java:58)
at ghidra.framework.plugintool.mgr.BackgroundCommandTask.run(BackgroundCommandTask.java:102)
at ghidra.framework.plugintool.mgr.ToolTaskManager.run(ToolTaskManager.java:315)
at java.base/java.lang.Thread.run(Thread.java:829)
Fix this by only creating data if there is no defined data already.
---
.../dex/analyzer/DexHeaderFormatMarkup.java | 81 +++++++++++--------
1 file changed, 46 insertions(+), 35 deletions(-)
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatMarkup.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatMarkup.java
index ca121da8f3..c34a1d3902 100644
--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatMarkup.java
+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/analyzer/DexHeaderFormatMarkup.java
@@ -675,57 +675,68 @@ public class DexHeaderFormatMarkup {
if (annotationsDirectoryItem.getClassAnnotationsOffset() > 0) {
Address classAddress = baseAddress.add(DexUtil.adjustOffset(
annotationsDirectoryItem.getClassAnnotationsOffset(), header));
- AnnotationSetItem setItem = annotationsDirectoryItem.getClassAnnotations();
- DataType setItemDataType = setItem.toDataType();
- api.createData(classAddress, setItemDataType);
- fragmentManager.classAnnotationsAddressSet.add(classAddress,
- classAddress.add(setItemDataType.getLength() - 1));
- processAnnotationSetItem(setItem, monitor, log);
+ // Only create data if it has not been created already
+ if (api.getDataAt(classAddress) == null) {
+ AnnotationSetItem setItem = annotationsDirectoryItem.getClassAnnotations();
+ DataType setItemDataType = setItem.toDataType();
+ api.createData(classAddress, setItemDataType);
+ fragmentManager.classAnnotationsAddressSet.add(classAddress,
+ classAddress.add(setItemDataType.getLength() - 1));
+ processAnnotationSetItem(setItem, monitor, log);
+ }
}
for (FieldAnnotationsItem field : annotationsDirectoryItem.getFieldAnnotations()) {
monitor.checkCancelled();
Address fieldAddress =
baseAddress.add(DexUtil.adjustOffset(field.getAnnotationsOffset(), header));
- AnnotationSetItem setItem = field.getAnnotationSetItem();
- DataType setItemDataType = setItem.toDataType();
- api.createData(fieldAddress, setItemDataType);
- fragmentManager.annotationFieldsAddressSet.add(fieldAddress,
- fieldAddress.add(setItemDataType.getLength() - 1));
- processAnnotationSetItem(setItem, monitor, log);
+ if (api.getDataAt(fieldAddress) == null) {
+ AnnotationSetItem setItem = field.getAnnotationSetItem();
+ DataType setItemDataType = setItem.toDataType();
+ api.createData(fieldAddress, setItemDataType);
+ fragmentManager.annotationFieldsAddressSet.add(fieldAddress,
+ fieldAddress.add(setItemDataType.getLength() - 1));
+ processAnnotationSetItem(setItem, monitor, log);
+ }
}
for (MethodAnnotationsItem method : annotationsDirectoryItem.getMethodAnnotations()) {
monitor.checkCancelled();
Address methodAddress =
baseAddress.add(DexUtil.adjustOffset(method.getAnnotationsOffset(), header));
- AnnotationSetItem setItem = method.getAnnotationSetItem();
- DataType setItemDataType = setItem.toDataType();
- api.createData(methodAddress, setItemDataType);
- fragmentManager.annotationMethodsAddressSet.add(methodAddress,
- methodAddress.add(setItemDataType.getLength() - 1));
- processAnnotationSetItem(setItem, monitor, log);
+ if (api.getDataAt(methodAddress) == null) {
+ AnnotationSetItem setItem = method.getAnnotationSetItem();
+ DataType setItemDataType = setItem.toDataType();
+ api.createData(methodAddress, setItemDataType);
+ fragmentManager.annotationMethodsAddressSet.add(methodAddress,
+ methodAddress.add(setItemDataType.getLength() - 1));
+ processAnnotationSetItem(setItem, monitor, log);
+ }
}
for (ParameterAnnotationsItem parameter : annotationsDirectoryItem
.getParameterAnnotations()) {
monitor.checkCancelled();
Address parameterAddress =
baseAddress.add(DexUtil.adjustOffset(parameter.getAnnotationsOffset(), header));
- AnnotationSetReferenceList annotationSetReferenceList =
- parameter.getAnnotationSetReferenceList();
- DataType listDataType = annotationSetReferenceList.toDataType();
- api.createData(parameterAddress, listDataType);
- fragmentManager.annotationParametersAddressSet.add(parameterAddress,
- parameterAddress.add(listDataType.getLength() - 1));
-
- for (AnnotationSetReferenceItem refItem : annotationSetReferenceList.getItems()) {
- AnnotationItem annotationItem = refItem.getItem();
- if (annotationItem != null) {
- int annotationsItemOffset = refItem.getAnnotationsOffset();
- Address annotationItemAddress =
- baseAddress.add(DexUtil.adjustOffset(annotationsItemOffset, header));
- DataType annotationItemDataType = annotationItem.toDataType();
- api.createData(annotationItemAddress, annotationItemDataType);
- fragmentManager.annotationItemAddressSet.add(annotationItemAddress,
- annotationItemAddress.add(annotationItemDataType.getLength() - 1));
+ if (api.getDataAt(parameterAddress) == null) {
+ AnnotationSetReferenceList annotationSetReferenceList =
+ parameter.getAnnotationSetReferenceList();
+ DataType listDataType = annotationSetReferenceList.toDataType();
+ api.createData(parameterAddress, listDataType);
+ fragmentManager.annotationParametersAddressSet.add(parameterAddress,
+ parameterAddress.add(listDataType.getLength() - 1));
+
+ for (AnnotationSetReferenceItem refItem : annotationSetReferenceList.getItems()) {
+ AnnotationItem annotationItem = refItem.getItem();
+ if (annotationItem != null) {
+ int annotationsItemOffset = refItem.getAnnotationsOffset();
+ Address annotationItemAddress =
+ baseAddress.add(DexUtil.adjustOffset(annotationsItemOffset, header));
+ if (api.getDataAt(annotationItemAddress) == null) {
+ DataType annotationItemDataType = annotationItem.toDataType();
+ api.createData(annotationItemAddress, annotationItemDataType);
+ fragmentManager.annotationItemAddressSet.add(annotationItemAddress,
+ annotationItemAddress.add(annotationItemDataType.getLength() - 1));
+ }
+ }
}
}
}
--
2.45.1