origami 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/COPYING.LESSER +165 -0
  2. data/README +77 -0
  3. data/VERSION +1 -0
  4. data/bin/config/pdfcop.conf.yml +237 -0
  5. data/bin/gui/about.rb +46 -0
  6. data/bin/gui/config.rb +132 -0
  7. data/bin/gui/file.rb +385 -0
  8. data/bin/gui/hexdump.rb +74 -0
  9. data/bin/gui/hexview.rb +91 -0
  10. data/bin/gui/imgview.rb +72 -0
  11. data/bin/gui/menu.rb +392 -0
  12. data/bin/gui/properties.rb +132 -0
  13. data/bin/gui/signing.rb +635 -0
  14. data/bin/gui/textview.rb +107 -0
  15. data/bin/gui/treeview.rb +409 -0
  16. data/bin/gui/walker.rb +282 -0
  17. data/bin/gui/xrefs.rb +79 -0
  18. data/bin/pdf2graph +121 -0
  19. data/bin/pdf2ruby +353 -0
  20. data/bin/pdfcocoon +104 -0
  21. data/bin/pdfcop +455 -0
  22. data/bin/pdfdecompress +104 -0
  23. data/bin/pdfdecrypt +95 -0
  24. data/bin/pdfencrypt +112 -0
  25. data/bin/pdfextract +221 -0
  26. data/bin/pdfmetadata +123 -0
  27. data/bin/pdfsh +13 -0
  28. data/bin/pdfwalker +7 -0
  29. data/bin/shell/.irbrc +104 -0
  30. data/bin/shell/console.rb +136 -0
  31. data/bin/shell/hexdump.rb +83 -0
  32. data/origami.rb +36 -0
  33. data/origami/3d.rb +239 -0
  34. data/origami/acroform.rb +321 -0
  35. data/origami/actions.rb +299 -0
  36. data/origami/adobe/fdf.rb +259 -0
  37. data/origami/adobe/ppklite.rb +489 -0
  38. data/origami/annotations.rb +775 -0
  39. data/origami/array.rb +187 -0
  40. data/origami/boolean.rb +101 -0
  41. data/origami/catalog.rb +486 -0
  42. data/origami/destinations.rb +213 -0
  43. data/origami/dictionary.rb +188 -0
  44. data/origami/docmdp.rb +96 -0
  45. data/origami/encryption.rb +1293 -0
  46. data/origami/export.rb +283 -0
  47. data/origami/file.rb +222 -0
  48. data/origami/filters.rb +250 -0
  49. data/origami/filters/ascii.rb +189 -0
  50. data/origami/filters/ccitt.rb +515 -0
  51. data/origami/filters/crypt.rb +47 -0
  52. data/origami/filters/dct.rb +61 -0
  53. data/origami/filters/flate.rb +112 -0
  54. data/origami/filters/jbig2.rb +63 -0
  55. data/origami/filters/jpx.rb +53 -0
  56. data/origami/filters/lzw.rb +195 -0
  57. data/origami/filters/predictors.rb +276 -0
  58. data/origami/filters/runlength.rb +117 -0
  59. data/origami/font.rb +209 -0
  60. data/origami/functions.rb +93 -0
  61. data/origami/graphics.rb +33 -0
  62. data/origami/graphics/colors.rb +191 -0
  63. data/origami/graphics/instruction.rb +126 -0
  64. data/origami/graphics/path.rb +154 -0
  65. data/origami/graphics/patterns.rb +180 -0
  66. data/origami/graphics/state.rb +164 -0
  67. data/origami/graphics/text.rb +224 -0
  68. data/origami/graphics/xobject.rb +493 -0
  69. data/origami/header.rb +90 -0
  70. data/origami/linearization.rb +318 -0
  71. data/origami/metadata.rb +114 -0
  72. data/origami/name.rb +170 -0
  73. data/origami/null.rb +75 -0
  74. data/origami/numeric.rb +188 -0
  75. data/origami/obfuscation.rb +233 -0
  76. data/origami/object.rb +527 -0
  77. data/origami/outline.rb +59 -0
  78. data/origami/page.rb +559 -0
  79. data/origami/parser.rb +268 -0
  80. data/origami/parsers/fdf.rb +45 -0
  81. data/origami/parsers/pdf.rb +27 -0
  82. data/origami/parsers/pdf/linear.rb +113 -0
  83. data/origami/parsers/ppklite.rb +86 -0
  84. data/origami/pdf.rb +1144 -0
  85. data/origami/reference.rb +113 -0
  86. data/origami/signature.rb +474 -0
  87. data/origami/stream.rb +575 -0
  88. data/origami/string.rb +416 -0
  89. data/origami/trailer.rb +173 -0
  90. data/origami/webcapture.rb +87 -0
  91. data/origami/xfa.rb +3027 -0
  92. data/origami/xreftable.rb +447 -0
  93. data/templates/patterns.rb +66 -0
  94. data/templates/widgets.rb +173 -0
  95. data/templates/xdp.rb +92 -0
  96. data/tests/dataset/test.dummycrt +28 -0
  97. data/tests/dataset/test.dummykey +27 -0
  98. data/tests/tc_actions.rb +32 -0
  99. data/tests/tc_annotations.rb +85 -0
  100. data/tests/tc_pages.rb +37 -0
  101. data/tests/tc_pdfattach.rb +24 -0
  102. data/tests/tc_pdfencrypt.rb +110 -0
  103. data/tests/tc_pdfnew.rb +32 -0
  104. data/tests/tc_pdfparse.rb +98 -0
  105. data/tests/tc_pdfsig.rb +37 -0
  106. data/tests/tc_streams.rb +129 -0
  107. data/tests/ts_pdf.rb +45 -0
  108. metadata +193 -0
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ =begin
4
+
5
+ = Author:
6
+ Guillaume Delugré <guillaume/at/security-labs.org>
7
+
8
+ = Info:
9
+ Prints out the metadata contained in a PDF document.
10
+
11
+ = License:
12
+ Origami is free software: you can redistribute it and/or modify
13
+ it under the terms of the GNU Lesser General Public License as published by
14
+ the Free Software Foundation, either version 3 of the License, or
15
+ (at your option) any later version.
16
+
17
+ Origami is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU Lesser General Public License for more details.
21
+
22
+ You should have received a copy of the GNU Lesser General Public License
23
+ along with Origami. If not, see <http://www.gnu.org/licenses/>.
24
+
25
+ =end
26
+
27
+ begin
28
+ require 'origami'
29
+ rescue LoadError
30
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
31
+ $: << ORIGAMIDIR
32
+ require 'origami'
33
+ end
34
+ include Origami
35
+
36
+ require 'optparse'
37
+
38
+ class OptParser
39
+ BANNER = <<USAGE
40
+ Usage: #{$0} [<PDF-file>] [-i] [-x]
41
+ Prints out the metadata contained in a PDF document.
42
+ Bug reports or feature requests at: http://origami-pdf.googlecode.com/
43
+
44
+ Options:
45
+ USAGE
46
+
47
+ def self.parser(options)
48
+ OptionParser.new do |opts|
49
+ opts.banner = BANNER
50
+
51
+ opts.on("-i", "Extracts document info metadata") do |i|
52
+ options[:doc_info] = true
53
+ end
54
+
55
+ opts.on("-x", "Extracts XMP document metadata stream") do |i|
56
+ options[:doc_stream] = true
57
+ end
58
+
59
+ opts.on_tail("-h", "--help", "Show this message") do
60
+ puts opts
61
+ exit
62
+ end
63
+ end
64
+ end
65
+
66
+ def self.parse(args)
67
+ options =
68
+ {
69
+ :output => STDOUT,
70
+ }
71
+
72
+ self.parser(options).parse!(args)
73
+
74
+ options
75
+ end
76
+ end
77
+
78
+ begin
79
+ @options = OptParser.parse(ARGV)
80
+
81
+ unless @options[:doc_info] or @options[:doc_stream]
82
+ @options[:doc_info] = @options[:doc_stream] = true
83
+ end
84
+
85
+ target = (ARGV.empty?) ? STDIN : ARGV.shift
86
+ params =
87
+ {
88
+ :verbosity => Parser::VERBOSE_QUIET,
89
+ }
90
+
91
+ pdf = PDF.read(target, params)
92
+
93
+ if @options[:doc_info]
94
+ if pdf.has_document_info?
95
+ colorprint "[*] Document information dictionary:\n", Colors::MAGENTA
96
+
97
+ docinfo = pdf.get_document_info
98
+ docinfo.each_pair do |name, item|
99
+ colorprint name.value.to_s.ljust(20, ' '), Colors::GREEN
100
+ puts ": #{item.solve.value}"
101
+ end
102
+ puts
103
+ end
104
+ end
105
+
106
+ if @options[:doc_stream]
107
+ if pdf.has_metadata?
108
+ colorprint "[*] Metadata stream:\n", Colors::MAGENTA
109
+
110
+ metadata = pdf.get_metadata
111
+ metadata.each_pair do |name, item|
112
+ colorprint name.ljust(20, ' '), Colors::GREEN
113
+ puts ": #{item}"
114
+ end
115
+ end
116
+ end
117
+
118
+ rescue SystemExit
119
+ rescue Exception => e
120
+ STDERR.puts "#{e.class}: #{e.message}"
121
+ exit 1
122
+ end
123
+
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'irb'
5
+ rescue LoadError
6
+ abort "Error: you need to install irb to run this application."
7
+ end
8
+
9
+ $:.unshift "#{File.dirname(__FILE__)}/shell"
10
+ ENV["IRBRC"] = "#{File.dirname(__FILE__)}/shell/.irbrc"
11
+
12
+ IRB.start
13
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift "#{File.dirname(__FILE__)}" if RUBY_VERSION >= '1.9'
4
+ require 'gui/walker'
5
+
6
+ PDFWalker::Walker.start
7
+
@@ -0,0 +1,104 @@
1
+ begin
2
+ require 'origami'
3
+ rescue LoadError
4
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../.."
5
+ $: << ORIGAMIDIR
6
+ require 'origami'
7
+ end
8
+ include Origami
9
+
10
+ require 'console.rb'
11
+ require 'readline'
12
+
13
+ DEFAULT_BANNER = "Welcome to the PDF shell (Origami release #{Origami::VERSION})\n\n"
14
+
15
+ def set_completion
16
+
17
+ completionProc = proc { |input|
18
+ bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
19
+
20
+ validClasses = Origami.constants.reject do |name|
21
+ obj = Origami.const_get(name)
22
+ (not obj.is_a?(Module) and not obj.is_a?(Class)) or obj <= Exception
23
+ end
24
+
25
+ case input
26
+
27
+ # # Classes
28
+ # when /^([A-Z][^:\.\(]*)$/
29
+ # classname = $1
30
+ # candidates = validClasses
31
+ # return candidates.grep(/^#{classname}/)
32
+ #
33
+ # # Methods
34
+ # when /^([^:.\(]*)\.([^:.]*)$/
35
+ # classname = $1
36
+ # method = Regexp.quote($2)
37
+ # candidates = []
38
+ # if validClasses.include? $1
39
+ # begin
40
+ # candidates = eval("Origami::#{classname}.methods", bind)
41
+ # rescue Exception
42
+ # candidates = []
43
+ # end
44
+ # return candidates.grep(/^#{method}/).collect{|e| classname + "." + e}
45
+ # else
46
+ # begin
47
+ # var = $1.dup
48
+ # classname = eval("#{classname}.class", bind).to_s
49
+ # if validClasses.include?(classname.split("::").last)
50
+ # candidates = eval("#{classname}.public_instance_methods", bind)
51
+ # end
52
+ # rescue Exception => e
53
+ # candidates = []
54
+ # end
55
+ # return candidates.grep(/^#{method}/).collect{|e| var + "." + e}
56
+ # end
57
+ #
58
+ # Mod/class
59
+ when /^(.*)::$/
60
+ begin
61
+ space = eval("Origami::#{$1}", bind)
62
+ rescue Exception
63
+ return []
64
+ end
65
+
66
+ return space.constants.reject{|const| space.const_get(const) <= Exception}
67
+
68
+ when /^(.*).$/
69
+ begin
70
+ space = eval($1, bind)
71
+ rescue
72
+ return []
73
+ end
74
+
75
+ return space.public_methods
76
+ end
77
+ }
78
+
79
+ if Readline.respond_to?("basic_word_break_characters=")
80
+ Readline.basic_word_break_characters= " \t\n\"\\'`><=;|&{("
81
+ end
82
+ Readline.completion_append_character = nil
83
+ Readline.completion_proc = completionProc
84
+
85
+ end
86
+
87
+ def set_prompt
88
+
89
+ IRB.conf[:PROMPT][:PDFSH] = {
90
+ :PROMPT_C => "?>> ",
91
+ :RETURN => "%s\n",
92
+ :PROMPT_I => ">>> ",
93
+ :PROMPT_N => ">>> ",
94
+ :PROMPT_S => nil
95
+ }
96
+
97
+ IRB.conf[:PROMPT_MODE] = :PDFSH
98
+
99
+ end
100
+
101
+ Origami.colorprint(DEFAULT_BANNER, Origami::Colors::GREEN)
102
+ #set_completion
103
+ set_prompt
104
+
@@ -0,0 +1,136 @@
1
+ =begin
2
+
3
+ = File
4
+ console.rb
5
+
6
+ = Info
7
+ This file is part of Origami, PDF manipulation framework for Ruby
8
+ Copyright (C) 2010 Guillaume Delugré <guillaume@security-labs.org>
9
+ All right reserved.
10
+
11
+ Origami is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU Lesser General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ (at your option) any later version.
15
+
16
+ Origami is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU Lesser General Public License for more details.
20
+
21
+ You should have received a copy of the GNU Lesser General Public License
22
+ along with Origami. If not, see <http://www.gnu.org/licenses/>.
23
+
24
+ =end
25
+
26
+ require 'hexdump'
27
+
28
+ if RUBY_VERSION < '1.9'
29
+ def Kernel.spawn(cmd)
30
+ fork do
31
+ exec(cmd)
32
+ end
33
+ end
34
+ end
35
+
36
+ module Origami
37
+
38
+ module Object
39
+ def inspect
40
+ to_s
41
+ end
42
+ end
43
+
44
+ unless (RUBY_VERSION < '1.9' and RUBY_PLATFORM =~ /win32/)
45
+ require 'tempfile'
46
+
47
+ class Stream
48
+ def edit(editor = 'vim')
49
+ tmpfile = Tempfile.new("origami")
50
+ tmpfile.write(self.data)
51
+ tmpfile.close
52
+
53
+ Process.wait Kernel.spawn "#{editor} #{tmpfile.path}"
54
+
55
+ self.data = File.read(tmpfile.path)
56
+ tmpfile.unlink
57
+
58
+ true
59
+ end
60
+
61
+ def inspect
62
+ self.data.hexdump
63
+ end
64
+ end
65
+
66
+ class Page
67
+ def edit
68
+ self.Contents.edit
69
+ end
70
+ end
71
+ end
72
+
73
+ class PDF
74
+
75
+ class Revision
76
+ def to_s
77
+ colorprint("---------- Body ----------\n", Colors::WHITE, true)
78
+ @body.each_value { |obj|
79
+ colorprint("#{obj.reference.to_s.rjust(8,' ')}".ljust(10), Colors::MAGENTA)
80
+ colorprint("#{obj.type}\n", Colors::YELLOW)
81
+ }
82
+ #colorprint("---------- Xrefs -----------\n", Colors::BRIGHT_WHITE, true)
83
+ #set_fg_color(Colors::BLUE, true) {
84
+ # if not @xreftable
85
+ # puts " [x] No xref table found."
86
+ # else
87
+ # @xreftable.to_s.each_line { |line|
88
+ # puts " " + line
89
+ # }
90
+ # end
91
+ #}
92
+ colorprint("---------- Trailer ---------\n", Colors::WHITE, true)
93
+ if not @trailer.dictionary
94
+ set_fg_color(Colors::BLUE, true) {
95
+ puts " [x] No trailer found."
96
+ }
97
+ else
98
+ @trailer.dictionary.each_pair { |entry, value|
99
+ colorprint(" [*] ", Colors::MAGENTA)
100
+ colorprint("#{entry.to_s}: ", Colors::YELLOW)
101
+ colorprint("#{value.to_s}\n", Colors::RED)
102
+ }
103
+ colorprint(" [+] ", Colors::MAGENTA)
104
+ colorprint("startxref: ", Colors::YELLOW)
105
+ colorprint("#{@trailer.startxref}\n", Colors::RED)
106
+ end
107
+ end
108
+
109
+ def inspect
110
+ to_s
111
+ end
112
+ end
113
+
114
+ def to_s
115
+ puts
116
+
117
+ colorprint("---------- Header ----------\n", Colors::WHITE, true)
118
+ colorprint(" [+] ", Colors::MAGENTA)
119
+ colorprint("Major version: ", Colors::YELLOW)
120
+ colorprint("#{@header.majorversion}\n", Colors::RED)
121
+ colorprint(" [+] ", Colors::MAGENTA)
122
+ colorprint("Minor version: ", Colors::YELLOW)
123
+ colorprint("#{@header.minorversion}\n", Colors::RED)
124
+
125
+ @revisions.each { |revision|
126
+ revision.to_s
127
+ }
128
+ puts
129
+ end
130
+
131
+ def inspect
132
+ to_s
133
+ end
134
+ end
135
+ end
136
+
@@ -0,0 +1,83 @@
1
+ =begin
2
+
3
+ = File
4
+ hexdump.rb
5
+
6
+ = Info
7
+ This file is part of Origami, PDF manipulation framework for Ruby
8
+ Copyright (C) 2009 Guillaume Delugr� <guillaume@security-labs.org>
9
+ All right reserved.
10
+
11
+ Origami is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ (at your option) any later version.
15
+
16
+ Origami is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with Origami. If not, see <http://www.gnu.org/licenses/>.
23
+
24
+ =end
25
+
26
+ if RUBY_VERSION < '1.9'
27
+ class Fixnum
28
+ def ord; self; end
29
+ end
30
+ end
31
+
32
+ class String #:nodoc:
33
+
34
+ def hexdump(bytesperline = 16, upcase = true, offsets = true, delta = 0)
35
+
36
+ dump = ""
37
+ counter = 0
38
+
39
+ while counter < length
40
+
41
+ offset = sprintf("%010X", counter + delta)
42
+
43
+ linelen = (counter < length - bytesperline) ? bytesperline : (length - counter)
44
+ bytes = ""
45
+ linelen.times do |i|
46
+
47
+ byte = self[counter + i].ord.to_s(base=16)
48
+ if byte.size < 2 then byte.insert(0, "0") end
49
+ bytes << byte
50
+ bytes << " " unless i == bytesperline - 1
51
+
52
+ end
53
+
54
+ ascii = self[counter, linelen].ascii_print
55
+
56
+ if upcase
57
+ offset.upcase!
58
+ bytes.upcase!
59
+ end
60
+
61
+ if RUBY_PLATFORM =~ /win32/
62
+ dump << "#{offset if offsets} #{bytes.to_s.ljust(bytesperline * 3 - 1)} #{ascii}\n"
63
+ else
64
+ dump << "#{Origami.colorize(offset, Colors::YELLOW) if offsets} #{Origami.colorize(bytes.to_s.ljust(bytesperline * 3 - 1), Colors::BRIGHT_GREY)} #{ascii}\n"
65
+ end
66
+
67
+ counter += bytesperline
68
+ end
69
+
70
+ dump
71
+ end
72
+
73
+ def ascii_print
74
+
75
+ printable = ""
76
+ self.each_byte { |c|
77
+ if c >= ' '[0].ord && c <= '~'[0].ord then printable << c else printable << '.' end
78
+ }
79
+
80
+ return printable
81
+ end
82
+
83
+ end