GeneralTraverser.java
5.6 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.util.ArrayListStack
*/
package com.adobe.internal.pdftoolkit.core.traverser;
import com.adobe.internal.pdftoolkit.core.cos.CosContainer;
import com.adobe.internal.pdftoolkit.core.cos.CosContainerValuesIterator;
import com.adobe.internal.pdftoolkit.core.cos.CosList;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFFontException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.traverser.GeneralDispatcher;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.util.ArrayListStack;
import java.util.Set;
public class GeneralTraverser {
private GeneralDispatcher mDispatcher;
private boolean mNeedsProcessing;
public GeneralTraverser(GeneralDispatcher dispatcher) {
this.mDispatcher = dispatcher;
}
/*
* Enabled force condition propagation
* Lifted jumps to return sites
*/
public boolean traverseCosGraph(CosContainer root, Set excludedKeys) throws PDFIOException, PDFSecurityException, PDFFontException, PDFInvalidParameterException {
if (this.mDispatcher == null) {
return true;
}
CosList seenObjects = new CosList();
CosContainerValuesIterator containerIter = root.getValuesIterator();
ArrayListStack traverserStack = new ArrayListStack();
traverserStack.push((Object)null);
seenObjects.add(root.getObjNum(), root);
CosContainerValuesIterator.Entry curEntry = null;
do {
if (containerIter.hasNext()) {
try {
CosObject curObject;
curEntry = containerIter.next();
if (curEntry == null || (curObject = curEntry.getValue()) == null) continue;
ASName curKey = curEntry.getKey();
if (excludedKeys != null && excludedKeys.contains(curKey)) continue;
boolean wasSeen = curObject.isIndirect() && seenObjects.containsIndex(curEntry.getValue().getObjNum());
boolean needsTraversing = true;
this.mNeedsProcessing = this.mDispatcher.isCandidate(curEntry, traverserStack, wasSeen);
if (this.mNeedsProcessing) {
needsTraversing = this.mDispatcher.startDispatch(curEntry, traverserStack, wasSeen);
}
if (needsTraversing) {
if (curObject instanceof CosContainer && !wasSeen) {
if (curObject.isIndirect()) {
seenObjects.add(curObject.getObjNum(), curObject);
}
traverserStack.push((Object)new TraverserStackItem(curEntry, containerIter, this.mNeedsProcessing));
containerIter = ((CosContainer)curEntry.getValue()).getValuesIterator();
continue;
}
if (this.finishEntry(curEntry, traverserStack)) continue;
return this.badReturn();
}
if (this.finishEntry(curEntry, traverserStack)) continue;
return this.badReturn();
}
catch (PDFInvalidDocumentException e) {
if (this.mDispatcher.continueTraversing(e)) continue;
return this.badReturn();
}
}
TraverserStackItem stackItem = (TraverserStackItem)traverserStack.pop();
if (stackItem == null) {
return true;
}
containerIter = stackItem.getIterator();
curEntry = stackItem.get_Entry();
this.mNeedsProcessing = stackItem.needsProcessing();
try {
if (this.finishEntry(curEntry, traverserStack)) continue;
return this.badReturn();
}
catch (PDFInvalidDocumentException e) {
if (!this.mDispatcher.continueTraversing(e)) return this.badReturn();
continue;
}
break;
} while (true);
}
private boolean finishEntry(CosContainerValuesIterator.Entry entry, ArrayListStack visitorStack) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException, PDFFontException {
return this.mNeedsProcessing ? this.mDispatcher.finishDispatch(entry, visitorStack) : true;
}
private boolean badReturn() {
return false;
}
public static class TraverserStackItem {
private CosContainerValuesIterator.Entry mEntry;
private CosContainerValuesIterator mIterator;
private boolean mNeedsProcessing;
TraverserStackItem(CosContainerValuesIterator.Entry entry, CosContainerValuesIterator iterator, boolean needsProcessing) {
this.mEntry = entry;
this.mIterator = iterator;
this.mNeedsProcessing = needsProcessing;
}
public CosContainerValuesIterator.Entry get_Entry() {
return this.mEntry;
}
public CosContainerValuesIterator getIterator() {
return this.mIterator;
}
public boolean needsProcessing() {
return this.mNeedsProcessing;
}
}
}