PsToPdfUtils.java
9.24 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
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.pdfg.logging.PDFGLogger
*/
package com.adobe.pdfg.impl.utils;
import com.adobe.pdfg.logging.PDFGLogger;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
public class PsToPdfUtils {
private static PDFGLogger pdfgLogger = PDFGLogger.getPDFGLogger(PsToPdfUtils.class);
private static final byte[] PREVIEW_IMAGE_HEADER = new byte[]{-59, -48, -45, -58};
private static final byte[] END_OF_PREVIEW_IMAGE = new byte[]{37, 33, 80, 83};
private static final byte[] END_OF_FILE = new byte[]{37, 37, 69, 79, 70};
private static byte[] WATERMARK_POSTSCRIPT;
private static final String WATERMARK_RESOURCE_NAME = "/watermark.ps";
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Unable to fully structure code
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
* Converted monitor instructions to comments
* Lifted jumps to return sites
*/
private static void injectWatermark(OutputStream out) throws IOException {
if (PsToPdfUtils.WATERMARK_POSTSCRIPT == null) {
var1_1 = PsToPdfUtils.class;
// MONITORENTER : com.adobe.pdfg.impl.utils.PsToPdfUtils.class
if (PsToPdfUtils.WATERMARK_POSTSCRIPT == null) {
outBytes = new ByteArrayOutputStream();
in = null;
try {
in = PsToPdfUtils.class.getResourceAsStream("/watermark.ps");
buffer = new byte[4096];
nBytesRead = in.read(buffer);
while (nBytesRead != -1) {
outBytes.write(buffer, 0, nBytesRead);
nBytesRead = in.read(buffer);
}
PsToPdfUtils.WATERMARK_POSTSCRIPT = outBytes.toByteArray();
var7_6 = null;
if (in != null) {
try {
in.close();
}
catch (Exception e) {
PsToPdfUtils.pdfgLogger.trace("PsToPdfUtils.injectWatermark exception: " + e.getMessage(), null, (Throwable)e);
}
}
}
catch (Throwable var6_10) {
var7_7 = null;
if (in == null) throw var6_10;
** try [egrp 2[TRYBLOCK] [2 : 105->112)] {
lbl30: // 1 sources:
in.close();
throw var6_10;
lbl32: // 1 sources:
catch (Exception e) {
PsToPdfUtils.pdfgLogger.trace("PsToPdfUtils.injectWatermark exception: " + e.getMessage(), null, (Throwable)e);
}
throw var6_10;
}
}
// MONITOREXIT : var1_1
}
out.write(PsToPdfUtils.WATERMARK_POSTSCRIPT);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public static String preProcessEPS(String dataFileName, File modifiedFile) throws Exception {
String string;
Exception e2;
OutputStream out;
block13 : {
BufferedInputStream in = null;
out = null;
try {
in = new BufferedInputStream(new FileInputStream(dataFileName));
out = new BufferedOutputStream(new FileOutputStream(modifiedFile));
byte[] header = new byte[4];
int headerLength = in.read(header);
if (headerLength == 4 && Arrays.equals(header, PREVIEW_IMAGE_HEADER)) {
PsToPdfUtils.copyBytesBetween(in, out, END_OF_PREVIEW_IMAGE, END_OF_FILE);
} else {
out.write(header, 0, headerLength);
PsToPdfUtils.copyStreams(in, out);
}
string = modifiedFile.getCanonicalPath();
Object var8_7 = null;
if (in == null) break block13;
}
catch (Throwable var7_11) {
Exception e2;
Object var8_8 = null;
if (in != null) {
try {
in.close();
}
catch (Exception e2) {
pdfgLogger.trace("PsToPdfUtils.preProcessEPS exception: " + e2.getMessage(), null, (Throwable)e2);
}
}
if (out != null) {
try {
out.close();
}
catch (Exception e2) {
pdfgLogger.trace("PsToPdfUtils.preProcessEPS exception: " + e2.getMessage(), null, (Throwable)e2);
}
}
throw var7_11;
}
try {
in.close();
}
catch (Exception e2) {
pdfgLogger.trace("PsToPdfUtils.preProcessEPS exception: " + e2.getMessage(), null, (Throwable)e2);
}
}
if (out != null) {
try {
out.close();
}
catch (Exception e2) {
pdfgLogger.trace("PsToPdfUtils.preProcessEPS exception: " + e2.getMessage(), null, (Throwable)e2);
}
}
return string;
}
private static void copyBytesBetween(InputStream in, OutputStream out, byte[] begin, byte[] end) throws IOException {
boolean STAGE_SKIPPING = false;
boolean STAGE_COPYING = true;
int STAGE_DONE = 2;
int stage = 0;
int posBegin = 0;
int posEnd = 0;
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
while (stage != 2) {
int byteRead = in.read();
if (byteRead == -1) {
stage = 2;
break;
}
if (stage == 0) {
if (byteRead == begin[posBegin]) {
outBytes.write(byteRead);
if (++posBegin != begin.length) continue;
out.write(outBytes.toByteArray());
outBytes.reset();
stage = 1;
continue;
}
posBegin = 0;
outBytes.reset();
continue;
}
if (stage != 1) continue;
out.write(byteRead);
if (byteRead != end[posEnd]) {
posEnd = 0;
}
if (byteRead != end[posEnd] || ++posEnd != end.length) continue;
stage = 2;
break;
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public static String preProcessPS(String dataFileName, File modifiedFile) throws Exception {
String string;
Exception e2;
OutputStream out;
block11 : {
BufferedInputStream in = null;
out = null;
try {
in = new BufferedInputStream(new FileInputStream(dataFileName));
out = new BufferedOutputStream(new FileOutputStream(modifiedFile));
PsToPdfUtils.injectWatermark(out);
PsToPdfUtils.copyStreams(in, out);
string = modifiedFile.getCanonicalPath();
Object var6_5 = null;
if (in == null) break block11;
}
catch (Throwable var5_9) {
Exception e2;
Object var6_6 = null;
if (in != null) {
try {
in.close();
}
catch (Exception e2) {
pdfgLogger.trace("PsToPdfUtils.preProcessPS exception: " + e2.getMessage(), null, (Throwable)e2);
}
}
if (out != null) {
try {
out.close();
}
catch (Exception e2) {
pdfgLogger.trace("PsToPdfUtils.preProcessPS exception: " + e2.getMessage(), null, (Throwable)e2);
}
}
throw var5_9;
}
try {
in.close();
}
catch (Exception e2) {
pdfgLogger.trace("PsToPdfUtils.preProcessPS exception: " + e2.getMessage(), null, (Throwable)e2);
}
}
if (out != null) {
try {
out.close();
}
catch (Exception e2) {
pdfgLogger.trace("PsToPdfUtils.preProcessPS exception: " + e2.getMessage(), null, (Throwable)e2);
}
}
return string;
}
private static void copyStreams(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[32678];
int nBytesRead = in.read(buffer);
while (nBytesRead != -1) {
out.write(buffer, 0, nBytesRead);
nBytesRead = in.read(buffer);
}
}
}