origami 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/bin/gui/hexview.rb +1 -1
- data/bin/gui/menu.rb +4 -4
- data/bin/gui/textview.rb +6 -4
- data/bin/gui/treeview.rb +4 -4
- data/bin/gui/walker.rb +1 -1
- data/bin/pdf2graph +1 -1
- data/bin/pdf2pdfa +1 -1
- data/bin/pdf2ruby +1 -1
- data/bin/pdfcocoon +1 -1
- data/bin/pdfcop +1 -1
- data/bin/pdfdecompress +1 -1
- data/bin/pdfdecrypt +1 -1
- data/bin/pdfencrypt +1 -1
- data/bin/pdfextract +75 -14
- data/bin/pdfmetadata +1 -1
- data/bin/shell/.irbrc +1 -1
- data/{origami.rb → lib/origami.rb} +3 -3
- data/{origami → lib/origami}/3d.rb +0 -0
- data/{origami → lib/origami}/acroform.rb +2 -2
- data/{origami → lib/origami}/actions.rb +0 -0
- data/{origami → lib/origami}/annotations.rb +0 -0
- data/{origami → lib/origami}/array.rb +0 -0
- data/{origami → lib/origami}/boolean.rb +0 -0
- data/{origami → lib/origami}/catalog.rb +0 -0
- data/{origami → lib/origami}/destinations.rb +0 -0
- data/{origami → lib/origami}/dictionary.rb +0 -0
- data/{origami → lib/origami}/docmdp.rb +0 -0
- data/{origami → lib/origami}/encryption.rb +9 -7
- data/{origami → lib/origami}/export.rb +0 -0
- data/lib/origami/extensions/fdf.rb +257 -0
- data/{origami/adobe → lib/origami/extensions}/ppklite.rb +3 -1
- data/{origami → lib/origami}/file.rb +0 -0
- data/{origami → lib/origami}/filters.rb +0 -0
- data/{origami → lib/origami}/filters/ascii.rb +0 -0
- data/{origami → lib/origami}/filters/ccitt.rb +0 -1
- data/{origami → lib/origami}/filters/crypt.rb +0 -0
- data/{origami → lib/origami}/filters/dct.rb +0 -0
- data/{origami → lib/origami}/filters/flate.rb +0 -0
- data/{origami → lib/origami}/filters/jbig2.rb +0 -0
- data/{origami → lib/origami}/filters/jpx.rb +0 -0
- data/{origami → lib/origami}/filters/lzw.rb +0 -0
- data/{origami → lib/origami}/filters/predictors.rb +0 -0
- data/{origami → lib/origami}/filters/runlength.rb +0 -0
- data/{origami → lib/origami}/font.rb +0 -0
- data/{origami → lib/origami}/functions.rb +0 -0
- data/{origami → lib/origami}/graphics.rb +0 -0
- data/{origami → lib/origami}/graphics/colors.rb +45 -23
- data/{origami → lib/origami}/graphics/instruction.rb +0 -0
- data/{origami → lib/origami}/graphics/path.rb +0 -0
- data/{origami → lib/origami}/graphics/patterns.rb +0 -0
- data/{origami → lib/origami}/graphics/render.rb +0 -0
- data/{origami → lib/origami}/graphics/state.rb +2 -2
- data/{origami → lib/origami}/graphics/text.rb +0 -0
- data/{origami → lib/origami}/graphics/xobject.rb +219 -0
- data/{origami → lib/origami}/header.rb +0 -0
- data/{origami → lib/origami}/javascript.rb +0 -0
- data/{origami → lib/origami}/linearization.rb +0 -0
- data/{origami → lib/origami}/metadata.rb +0 -0
- data/{origami → lib/origami}/name.rb +0 -0
- data/{origami → lib/origami}/null.rb +0 -0
- data/{origami → lib/origami}/numeric.rb +0 -0
- data/{origami → lib/origami}/obfuscation.rb +0 -0
- data/{origami → lib/origami}/object.rb +7 -2
- data/{origami → lib/origami}/outline.rb +0 -0
- data/{origami → lib/origami}/outputintents.rb +0 -0
- data/{origami → lib/origami}/page.rb +0 -0
- data/{origami → lib/origami}/parser.rb +76 -51
- data/{origami → lib/origami}/parsers/fdf.rb +9 -6
- data/{origami/parsers/pdf/linear.rb → lib/origami/parsers/pdf.rb} +31 -39
- data/lib/origami/parsers/pdf/linear.rb +84 -0
- data/lib/origami/parsers/ppklite.rb +93 -0
- data/{origami → lib/origami}/pdf.rb +6 -3
- data/{origami → lib/origami}/reference.rb +0 -0
- data/{origami → lib/origami}/signature.rb +170 -19
- data/{origami → lib/origami}/stream.rb +9 -0
- data/{origami → lib/origami}/string.rb +0 -0
- data/{origami → lib/origami}/trailer.rb +0 -0
- data/{origami → lib/origami}/webcapture.rb +0 -0
- data/{origami → lib/origami}/xfa.rb +0 -0
- data/{origami → lib/origami}/xreftable.rb +3 -7
- data/samples/README.txt +45 -0
- data/samples/actions/launch/calc.rb +87 -0
- data/samples/actions/launch/winparams.rb +22 -0
- data/samples/actions/loop/loopgoto.rb +24 -0
- data/samples/actions/loop/loopnamed.rb +21 -0
- data/samples/actions/named/named.rb +31 -0
- data/samples/actions/samba/smbrelay.rb +26 -0
- data/samples/actions/triggerevents/trigger.rb +75 -0
- data/samples/actions/webbug/submitform.js +26 -0
- data/samples/actions/webbug/webbug-browser.rb +68 -0
- data/samples/actions/webbug/webbug-js.rb +67 -0
- data/samples/actions/webbug/webbug-reader.rb +90 -0
- data/samples/attachments/attach.rb +40 -0
- data/samples/attachments/attached.txt +1 -0
- data/samples/crypto/crypto.rb +28 -0
- data/samples/digsig/signed.rb +46 -0
- data/samples/exploits/cve-2008-2992-utilprintf.rb +87 -0
- data/samples/exploits/cve-2009-0927-geticon.rb +65 -0
- data/samples/exploits/exploit_customdictopen.rb +55 -0
- data/samples/exploits/getannots.rb +69 -0
- data/samples/flash/flash.rb +31 -0
- data/samples/flash/helloworld.swf +0 -0
- data/samples/javascript/attached.txt +1 -0
- data/samples/javascript/js.rb +52 -0
- data/{tests → test}/ts_pdf.rb +1 -1
- metadata +109 -95
- data/origami/adobe/fdf.rb +0 -259
- data/origami/parsers/pdf.rb +0 -27
- data/origami/parsers/ppklite.rb +0 -86
- data/tests/dataset/test.dummycrt +0 -28
- data/tests/dataset/test.dummykey +0 -27
- data/tests/tc_actions.rb +0 -32
- data/tests/tc_annotations.rb +0 -85
- data/tests/tc_pages.rb +0 -37
- data/tests/tc_pdfattach.rb +0 -24
- data/tests/tc_pdfencrypt.rb +0 -110
- data/tests/tc_pdfnew.rb +0 -32
- data/tests/tc_pdfparse.rb +0 -98
- data/tests/tc_pdfsig.rb +0 -37
- data/tests/tc_streams.rb +0 -129
data/README
CHANGED
data/bin/gui/hexview.rb
CHANGED
data/bin/gui/menu.rb
CHANGED
@@ -152,14 +152,14 @@ module PDFWalker
|
|
152
152
|
:Sensitive => true,
|
153
153
|
:Callback => lambda { |widget, viewer, path|
|
154
154
|
stm = viewer.model.get_value(viewer.model.get_iter(path), viewer.class::OBJCOL)
|
155
|
-
w,h = stm
|
156
|
-
|
157
|
-
bpr = (
|
155
|
+
w,h = stm.Width, stm.Height
|
156
|
+
bpc = stm.BitsPerComponent || 8
|
157
|
+
bpr = (bpc >> 3) * 3 * w
|
158
158
|
data = stm.data
|
159
159
|
|
160
160
|
begin
|
161
161
|
imgview = ImgViewer.new
|
162
|
-
if stm
|
162
|
+
if stm.Filter == :DCTDecode or (stm.Filter.is_a?(Array) and stm.Filter[0] == :DCTDecode)
|
163
163
|
imgview.show_compressed_img data
|
164
164
|
else
|
165
165
|
imgview.show_raw_img data, w, h, bpp, bpr
|
data/bin/gui/textview.rb
CHANGED
@@ -33,9 +33,7 @@ module PDFWalker
|
|
33
33
|
private
|
34
34
|
|
35
35
|
def create_objectview
|
36
|
-
|
37
36
|
@objectview = ObjectView.new(self)
|
38
|
-
|
39
37
|
end
|
40
38
|
|
41
39
|
class ObjectView < Notebook
|
@@ -56,14 +54,18 @@ module PDFWalker
|
|
56
54
|
@pdfpanel.add_with_viewport @pdfview
|
57
55
|
append_page(@pdfpanel, Label.new("PDF Code"))
|
58
56
|
|
59
|
-
@pdfbuffer.create_tag("Object",
|
57
|
+
@pdfbuffer.create_tag("Object",
|
58
|
+
:weight => Pango::WEIGHT_BOLD,
|
59
|
+
:foreground => "darkblue",
|
60
|
+
:family => "Courier",
|
61
|
+
:scale => Pango::AttrScale::LARGE
|
62
|
+
)
|
60
63
|
|
61
64
|
end
|
62
65
|
|
63
66
|
def load(object)
|
64
67
|
|
65
68
|
begin
|
66
|
-
|
67
69
|
self.clear
|
68
70
|
|
69
71
|
pdftag = "Object"
|
data/bin/gui/treeview.rb
CHANGED
@@ -59,7 +59,7 @@ module PDFWalker
|
|
59
59
|
FGCOL = 4
|
60
60
|
BGCOL = 5
|
61
61
|
|
62
|
-
@@appearance = Hash.new(
|
62
|
+
@@appearance = Hash.new(:Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_NORMAL)
|
63
63
|
|
64
64
|
attr_reader :parent
|
65
65
|
|
@@ -368,7 +368,7 @@ module PDFWalker
|
|
368
368
|
|
369
369
|
def reset_appearance
|
370
370
|
|
371
|
-
@@appearance[:Filename] = {:
|
371
|
+
@@appearance[:Filename] = {:Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
372
372
|
@@appearance[:Header] = {:Color => "darkgreen", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
373
373
|
@@appearance[:Revision] = {:Color => "blue", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
374
374
|
@@appearance[:Body] = {:Color => "purple", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
@@ -376,7 +376,7 @@ module PDFWalker
|
|
376
376
|
@@appearance[:XRefSubSection] = {:Color => "brown", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
377
377
|
@@appearance[:XRef] = {:Color => "gray20", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
378
378
|
@@appearance[:Trailer] = {:Color => "purple", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
379
|
-
@@appearance[:StartXref] = {:
|
379
|
+
@@appearance[:StartXref] = {:Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
380
380
|
@@appearance[:String] = {:Color => "red", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_ITALIC}
|
381
381
|
@@appearance[:Name] = {:Color => "gray", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_ITALIC}
|
382
382
|
@@appearance[:Number] = {:Color => "orange", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_NORMAL}
|
@@ -384,7 +384,7 @@ module PDFWalker
|
|
384
384
|
@@appearance[:Stream] = {:Color => "darkcyan", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
385
385
|
@@appearance[:StreamData] = {:Color => "darkcyan", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_OBLIQUE}
|
386
386
|
@@appearance[:Array] = {:Color => "darkgreen", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
|
387
|
-
@@appearance[:Reference] = {:
|
387
|
+
@@appearance[:Reference] = {:Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_OBLIQUE}
|
388
388
|
@@appearance[:Boolean] = {:Color => "deeppink", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_NORMAL}
|
389
389
|
|
390
390
|
end
|
data/bin/gui/walker.rb
CHANGED
data/bin/pdf2graph
CHANGED
data/bin/pdf2pdfa
CHANGED
data/bin/pdf2ruby
CHANGED
data/bin/pdfcocoon
CHANGED
data/bin/pdfcop
CHANGED
data/bin/pdfdecompress
CHANGED
data/bin/pdfdecrypt
CHANGED
data/bin/pdfencrypt
CHANGED
data/bin/pdfextract
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
begin
|
31
31
|
require 'origami'
|
32
32
|
rescue LoadError
|
33
|
-
ORIGAMIDIR = "#{File.dirname(__FILE__)}
|
33
|
+
ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
|
34
34
|
$: << ORIGAMIDIR
|
35
35
|
require 'origami'
|
36
36
|
end
|
@@ -42,7 +42,7 @@ require 'rexml/document'
|
|
42
42
|
class OptParser
|
43
43
|
BANNER = <<USAGE
|
44
44
|
Usage: #{$0} <PDF-file> [-afjms] [-d <output-directory>]
|
45
|
-
Extracts various data out of a document (streams, scripts, fonts, metadata, attachments).
|
45
|
+
Extracts various data out of a document (streams, scripts, images, fonts, metadata, attachments).
|
46
46
|
Bug reports or feature requests at: http://origami-pdf.googlecode.com/
|
47
47
|
|
48
48
|
Options:
|
@@ -76,6 +76,10 @@ USAGE
|
|
76
76
|
options[:metadata] = true
|
77
77
|
end
|
78
78
|
|
79
|
+
opts.on("-i", "--images", "Extracts embedded images") do
|
80
|
+
options[:images] = true
|
81
|
+
end
|
82
|
+
|
79
83
|
opts.on_tail("-h", "--help", "Show this message") do
|
80
84
|
puts opts
|
81
85
|
exit
|
@@ -104,11 +108,12 @@ begin
|
|
104
108
|
target = ARGV.shift
|
105
109
|
end
|
106
110
|
|
107
|
-
unless [:streams,:javascript,:attachments,:fonts,:metadata].any? {|opt| @options[opt]}
|
111
|
+
unless [:streams,:javascript,:attachments,:fonts,:metadata,:images].any? {|opt| @options[opt]}
|
108
112
|
@options[:streams] =
|
109
113
|
@options[:javascript] =
|
110
114
|
@options[:fonts] =
|
111
|
-
@options[:attachments] =
|
115
|
+
@options[:attachments] =
|
116
|
+
@options[:images] = true
|
112
117
|
end
|
113
118
|
|
114
119
|
if @options[:output_dir].nil?
|
@@ -125,17 +130,26 @@ begin
|
|
125
130
|
pdf = PDF.read(target, params)
|
126
131
|
|
127
132
|
if @options[:streams]
|
133
|
+
nstreams = 0
|
134
|
+
Dir::mkdir("#{OUTPUT_DIR}/streams") unless File.directory?("#{OUTPUT_DIR}/streams")
|
135
|
+
|
128
136
|
pdf.root_objects.find_all{|obj| obj.is_a?(Stream)}.each do |stream|
|
129
|
-
stream_file = "#{OUTPUT_DIR}/stream_#{stream.reference.refno}.dmp"
|
137
|
+
stream_file = "#{OUTPUT_DIR}/streams/stream_#{stream.reference.refno}.dmp"
|
130
138
|
File.open(stream_file, "w") do |fd|
|
131
139
|
fd.write(stream.data)
|
132
140
|
end
|
141
|
+
nstreams += 1
|
133
142
|
end
|
143
|
+
|
144
|
+
puts "Extracted #{nstreams} PDF streams to '#{OUTPUT_DIR}/streams'."
|
134
145
|
end
|
135
146
|
|
136
147
|
if @options[:javascript]
|
148
|
+
nscripts = 0
|
149
|
+
Dir::mkdir("#{OUTPUT_DIR}/scripts") unless File.directory?("#{OUTPUT_DIR}/scripts")
|
150
|
+
|
137
151
|
pdf.ls(/^JS$/).each do |script|
|
138
|
-
script_file = "#{OUTPUT_DIR}/script_#{script.hash}.js"
|
152
|
+
script_file = "#{OUTPUT_DIR}/scripts/script_#{script.hash}.js"
|
139
153
|
File.open(script_file, "w") do |fd|
|
140
154
|
fd.write(
|
141
155
|
case script
|
@@ -146,6 +160,7 @@ begin
|
|
146
160
|
end
|
147
161
|
)
|
148
162
|
end
|
163
|
+
nscripts += 1
|
149
164
|
end
|
150
165
|
|
151
166
|
# Also checking for presence of JavaScript in XML forms.
|
@@ -175,42 +190,88 @@ begin
|
|
175
190
|
File.open(script_file, 'w') do |fd|
|
176
191
|
fd.write(script.text)
|
177
192
|
end
|
193
|
+
nscripts += 1
|
178
194
|
end
|
179
195
|
end
|
196
|
+
|
197
|
+
puts "Extracted #{nscripts} scripts to '#{OUTPUT_DIR}/scripts'."
|
180
198
|
end
|
181
199
|
|
182
200
|
if @options[:attachments]
|
201
|
+
nattach = 0
|
202
|
+
Dir::mkdir("#{OUTPUT_DIR}/attachments") unless File.directory?("#{OUTPUT_DIR}/attachments")
|
203
|
+
|
183
204
|
pdf.ls_names(Names::Root::EMBEDDEDFILES).each do |name, attachment|
|
184
|
-
attached_file = "#{OUTPUT_DIR}/attached_#{File.basename(name)}"
|
205
|
+
attached_file = "#{OUTPUT_DIR}/attachments/attached_#{File.basename(name)}"
|
185
206
|
spec = attachment.solve
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
207
|
+
if spec and spec.EF and f = spec.EF.F and f.is_a?(Stream)
|
208
|
+
File.open(attached_file, "w") do |fd|
|
209
|
+
fd.write(f.data)
|
210
|
+
end
|
211
|
+
nattach += 1
|
191
212
|
end
|
192
213
|
end
|
214
|
+
|
215
|
+
puts "Extracted #{nattach} attachments to '#{OUTPUT_DIR}/attachments'."
|
193
216
|
end
|
194
217
|
|
195
218
|
if @options[:fonts]
|
219
|
+
nfonts = 0
|
220
|
+
Dir::mkdir("#{OUTPUT_DIR}/fonts") unless File.directory?("#{OUTPUT_DIR}/fonts")
|
221
|
+
|
196
222
|
pdf.root_objects.find_all{|obj| obj.is_a?(Stream)}.each do |stream|
|
197
223
|
font = stream.xrefs.find{|obj| obj.is_a?(FontDescriptor)}
|
198
224
|
if font
|
199
|
-
font_file = "#{OUTPUT_DIR}/font_#{File.basename(font.FontName.value.to_s)}"
|
225
|
+
font_file = "#{OUTPUT_DIR}/fonts/font_#{File.basename(font.FontName.value.to_s)}"
|
200
226
|
File.open(font_file, "w") do |fd|
|
201
227
|
fd.write(stream.data)
|
202
228
|
end
|
229
|
+
nfonts += 1
|
203
230
|
end
|
204
231
|
end
|
232
|
+
|
233
|
+
puts "Extracted #{nfonts} fonts to '#{OUTPUT_DIR}/fonts'."
|
205
234
|
end
|
206
235
|
|
207
236
|
if @options[:metadata]
|
237
|
+
nmeta = 0
|
238
|
+
Dir::mkdir("#{OUTPUT_DIR}/metadata") unless File.directory?("#{OUTPUT_DIR}/metadata")
|
239
|
+
|
208
240
|
pdf.root_objects.find_all{|obj| obj.is_a?(MetadataStream)}.each do |stream|
|
209
|
-
metadata_file = "#{OUTPUT_DIR}/metadata_#{stream.reference.refno}.xml"
|
241
|
+
metadata_file = "#{OUTPUT_DIR}/metadata/metadata_#{stream.reference.refno}.xml"
|
210
242
|
File.open(metadata_file, "w") do |fd|
|
211
243
|
fd.write(stream.data)
|
212
244
|
end
|
245
|
+
nmeta += 1
|
246
|
+
end
|
247
|
+
|
248
|
+
puts "Extracted #{nmeta} metadata streams to '#{OUTPUT_DIR}/metadata'."
|
249
|
+
end
|
250
|
+
|
251
|
+
if @options[:images]
|
252
|
+
nimages = 0
|
253
|
+
Dir::mkdir("#{OUTPUT_DIR}/images") unless File.directory?("#{OUTPUT_DIR}/images")
|
254
|
+
|
255
|
+
pdf.root_objects.find_all{|obj| obj.is_a?(Graphics::ImageXObject)}.each do |stream|
|
256
|
+
begin
|
257
|
+
ext, image_data = stream.to_image_file
|
258
|
+
image_file = "#{OUTPUT_DIR}/images/image_#{stream.reference.refno}.#{ext}"
|
259
|
+
|
260
|
+
if ext != 'png' and stream.ColorSpace == Graphics::Color::Space::DEVICE_CMYK
|
261
|
+
STDERR.puts "Warning: file '#{image_file}' is intended to be viewed in CMYK color space."
|
262
|
+
end
|
263
|
+
|
264
|
+
File.open(image_file, "w") do |fd|
|
265
|
+
fd.write(image_data)
|
266
|
+
end
|
267
|
+
nimages += 1
|
268
|
+
|
269
|
+
rescue Exception => e
|
270
|
+
STDERR.puts "Unable to decode image (stream #{stream.reference.refno}). #{e.message}"
|
271
|
+
end
|
213
272
|
end
|
273
|
+
|
274
|
+
puts "Extracted #{nimages} images to '#{OUTPUT_DIR}/images'."
|
214
275
|
end
|
215
276
|
|
216
277
|
rescue SystemExit
|
data/bin/pdfmetadata
CHANGED
data/bin/shell/.irbrc
CHANGED
File without changes
|
@@ -145,7 +145,7 @@ module Origami
|
|
145
145
|
RIGHT = 2
|
146
146
|
end
|
147
147
|
|
148
|
-
def self.included(receiver)
|
148
|
+
def self.included(receiver) #:nodoc:
|
149
149
|
|
150
150
|
receiver.field :FT, :Type => Name, :Default => Type::TEXT, :Required => true
|
151
151
|
receiver.field :Parent, :Type => Dictionary
|
@@ -166,7 +166,7 @@ module Origami
|
|
166
166
|
|
167
167
|
end
|
168
168
|
|
169
|
-
def pre_build
|
169
|
+
def pre_build #:nodoc:
|
170
170
|
|
171
171
|
if not self.T
|
172
172
|
self.T = "undef#{::Array.new(5) {(0x30 + rand(10)).chr}.join}"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|