-
Notifications
You must be signed in to change notification settings - Fork 2
/
1835-Handle-undefined-directives-in-preprocessor.patch
119 lines (114 loc) · 3.75 KB
/
1835-Handle-undefined-directives-in-preprocessor.patch
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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: mumbel <[email protected]>
Date: Sun, 3 May 2020 19:05:13 -0500
Subject: [PATCH] 1835: Handle undefined directives in preprocessor
Tokenizing undefined directives currently generates an error as
the lookup fails. Using undefined directives should be valid
code as directives are meant to be defined or undefined.
Added input and output for SleighPreprocessorTest
---
.../SoftwareModeling/certification.manifest | 2 ++
.../sleigh/grammar/SleighPreprocessor.java | 3 ++
.../src/test/resources/ifdef.input | 29 +++++++++++++++++++
.../src/test/resources/ifdef.output | 29 +++++++++++++++++++
4 files changed, 63 insertions(+)
create mode 100644 Ghidra/Framework/SoftwareModeling/src/test/resources/ifdef.input
create mode 100644 Ghidra/Framework/SoftwareModeling/src/test/resources/ifdef.output
diff --git a/Ghidra/Framework/SoftwareModeling/certification.manifest b/Ghidra/Framework/SoftwareModeling/certification.manifest
index 565d156f60..1019538da0 100644
--- a/Ghidra/Framework/SoftwareModeling/certification.manifest
+++ b/Ghidra/Framework/SoftwareModeling/certification.manifest
@@ -49,6 +49,8 @@ src/test/resources/empty.input||GHIDRA||reviewed||END|
src/test/resources/empty.output||GHIDRA||reviewed||END|
src/test/resources/expression.input||GHIDRA||reviewed||END|
src/test/resources/expression.output||GHIDRA||reviewed||END|
+src/test/resources/ifdef.input||GHIDRA||||END|
+src/test/resources/ifdef.output||GHIDRA||||END|
src/test/resources/include.input||GHIDRA||reviewed||END|
src/test/resources/include.output||GHIDRA||reviewed||END|
src/test/resources/includes/actual.inc||GHIDRA||||END|
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/sleigh/grammar/SleighPreprocessor.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/sleigh/grammar/SleighPreprocessor.java
index f0ca7bc98f..980d02eb35 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/sleigh/grammar/SleighPreprocessor.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/sleigh/grammar/SleighPreprocessor.java
@@ -411,6 +411,9 @@ public class SleighPreprocessor implements ExpressionEnvironment {
@Override
public void reportError(String msg) {
+ if (isInif()) {
+ return;
+ }
errorCount += 1;
Location location = new Location(file.getName(),lineno);
Msg.error(this, location + ": " + msg);
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/resources/ifdef.input b/Ghidra/Framework/SoftwareModeling/src/test/resources/ifdef.input
new file mode 100644
index 0000000000..921ae750cd
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/test/resources/ifdef.input
@@ -0,0 +1,29 @@
+@ifdef FOO
+@if FOO == "foo"
+true
+@endif
+@endif
+@ifndef FOO
+false
+@else
+@if FOO == "foo"
+true
+@endif
+@endif
+@ifndef FOO
+false
+@elif FOO == "foo"
+true
+@endif
+@if (defined(FOO) && FOO == "foo")
+true
+@endif
+@if FOO == "foo"
+true
+@endif
+@if FOO == "foo" && BAR == "bar"
+true
+@endif
+@if !(FOO == "bar" || BAR != "bar")
+true
+@endif
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/resources/ifdef.output b/Ghidra/Framework/SoftwareModeling/src/test/resources/ifdef.output
new file mode 100644
index 0000000000..d78c712cfd
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/test/resources/ifdef.output
@@ -0,0 +1,29 @@
+ifdef.input###1#@ifdef FOO
+#@if FOO == "foo"
+#true
+#@endif
+#@endif
+#@ifndef FOO
+false
+#@else
+#@if FOO == "foo"
+#true
+#@endif
+#@endif
+#@ifndef FOO
+false
+#@elif FOO == "foo"
+#true
+#@endif
+#@if (defined(FOO) && FOO == "foo")
+#true
+#@endif
+#@if FOO == "foo"
+#true
+#@endif
+#@if FOO == "foo" && BAR == "bar"
+#true
+#@endif
+#@if !(FOO == "bar" || BAR != "bar")
+#true
+#@endif
--
2.45.1