pedump 0.4.11 → 0.4.12

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ before_install:
3
+ - sudo apt-get update -qq
4
+ - sudo apt-get install -qq upx-ucl p7zip
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "multipart-post", "~> 1.1.4"
6
- gem "progressbar", "~> 0.9.2"
6
+ gem "progressbar"
7
7
  gem "awesome_print"
8
8
 
9
9
  # Add dependencies to develop your gem here.
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GEM
12
12
  json (1.7.5)
13
13
  looksee (1.0.3)
14
14
  multipart-post (1.1.5)
15
- progressbar (0.9.2)
15
+ progressbar (0.12.0)
16
16
  rake (10.0.2)
17
17
  rdoc (3.12)
18
18
  json (~> 1.4)
@@ -35,6 +35,6 @@ DEPENDENCIES
35
35
  jeweler
36
36
  looksee
37
37
  multipart-post (~> 1.1.4)
38
- progressbar (~> 0.9.2)
38
+ progressbar
39
39
  rspec
40
40
  what_methods
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- pedump
1
+ pedump [![Build Status](https://travis-ci.org/zed-0xff/pedump.png?branch=master)](https://travis-ci.org/zed-0xff/pedump) [![Dependency Status](https://gemnasium.com/zed-0xff/pedump.png)](https://gemnasium.com/zed-0xff/pedump)
2
2
  ======
3
3
 
4
4
  Description
@@ -299,7 +299,26 @@ Usage
299
299
  KERNEL32.dll 21f TlsAlloc
300
300
  KERNEL32.dll 220 TlsFree
301
301
  KERNEL32.dll 1fd SetLastError
302
- ...
302
+ KERNEL32.dll 221 TlsGetValue
303
+ KERNEL32.dll 62 ExitProcess
304
+ KERNEL32.dll 1b8 ReadFile
305
+ KERNEL32.dll 16 CloseHandle
306
+ KERNEL32.dll 24f WriteFile
307
+ KERNEL32.dll 83 FlushFileBuffers
308
+ KERNEL32.dll e9 GetModuleFileNameA
309
+ KERNEL32.dll 98 GetCPInfo
310
+ KERNEL32.dll 92 GetACP
311
+ KERNEL32.dll f6 GetOEMCP
312
+ KERNEL32.dll 8b FreeEnvironmentStringsA
313
+ KERNEL32.dll d0 GetEnvironmentStrings
314
+ KERNEL32.dll 8c FreeEnvironmentStringsW
315
+ KERNEL32.dll d2 GetEnvironmentStringsW
316
+ KERNEL32.dll 242 WideCharToMultiByte
317
+ KERNEL32.dll 2b CreateFileA
318
+ KERNEL32.dll 1f8 SetFilePointer
319
+ KERNEL32.dll 206 SetStdHandle
320
+ KERNEL32.dll 178 LoadLibraryA
321
+ KERNEL32.dll 1ef SetEndOfFile
303
322
 
304
323
  ### Exports
305
324
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.11
1
+ 0.4.12
data/lib/pedump.rb CHANGED
@@ -505,23 +505,26 @@ class PEdump
505
505
  tls_aoi = tls_aoi > 0 ? va2file(tls_aoi) : nil
506
506
  end
507
507
 
508
- f.seek file_offset
509
- r = []
510
- while true
511
- if tls_aoi && tls_aoi == file_offset+16
512
- # catched the neat trick! :)
513
- # f.tell + 12 = offset of 'FirstThunk' field from start of IMAGE_IMPORT_DESCRIPTOR structure
514
- logger.warn "[!] catched the 'imports terminator in TLS trick'"
515
- # http://code.google.com/p/corkami/source/browse/trunk/asm/PE/manyimportsW7.asm
516
- break
508
+ r = []; t = nil
509
+ if f.checked_seek(file_offset)
510
+ while true
511
+ if tls_aoi && tls_aoi == file_offset+16
512
+ # catched the neat trick! :)
513
+ # f.tell + 12 = offset of 'FirstThunk' field from start of IMAGE_IMPORT_DESCRIPTOR structure
514
+ logger.warn "[!] catched the 'imports terminator in TLS trick'"
515
+ # http://code.google.com/p/corkami/source/browse/trunk/asm/PE/manyimportsW7.asm
516
+ break
517
+ end
518
+ t=IMAGE_IMPORT_DESCRIPTOR.read(f)
519
+ break if t.Name.to_i == 0 # also catches EOF
520
+ r << t
521
+ file_offset += IMAGE_IMPORT_DESCRIPTOR::SIZE
517
522
  end
518
- t=IMAGE_IMPORT_DESCRIPTOR.read(f)
519
- break if t.Name.to_i == 0 # also catches EOF
520
- r << t
521
- file_offset += IMAGE_IMPORT_DESCRIPTOR::SIZE
523
+ else
524
+ logger.warn "[?] imports info beyond EOF"
522
525
  end
523
526
 
524
- logger.warn "[?] non-empty last IMAGE_IMPORT_DESCRIPTOR: #{t.inspect}" unless t.empty?
527
+ logger.warn "[?] non-empty last IMAGE_IMPORT_DESCRIPTOR: #{t.inspect}" if t && !t.empty?
525
528
  @imports = r.each do |x|
526
529
  if x.Name.to_i != 0 && (ofs = va2file(x.Name))
527
530
  begin
@@ -538,9 +541,9 @@ class PEdump
538
541
  f.seek ofs
539
542
  x[tbl] ||= []
540
543
  if pe.x64?
541
- x[tbl] << t while (t = f.read(8).unpack('Q').first) != 0
544
+ x[tbl] << t while (t = f.read(8).to_s.unpack('Q').first).to_i != 0
542
545
  else
543
- x[tbl] << t while (t = f.read(4).unpack('V').first) != 0
546
+ x[tbl] << t while (t = f.read(4).to_s.unpack('V').first).to_i != 0
544
547
  end
545
548
  end
546
549
  cache = {}
@@ -553,8 +556,7 @@ class PEdump
553
556
  if t & (2**(bits-1)) > 0 # 0x8000_0000(_0000_0000)
554
557
  ImportedFunction.new(nil,nil,t & (2**(bits-1)-1),va) # 0x7fff_ffff(_ffff_ffff)
555
558
  elsif ofs=va2file(t, :quiet => true)
556
- f.seek ofs
557
- if f.eof?
559
+ if !f.checked_seek(ofs) || f.eof?
558
560
  logger.warn "[?] import ofs 0x#{ofs.to_s(16)} beyond EOF"
559
561
  nil
560
562
  else
@@ -597,14 +599,14 @@ class PEdump
597
599
  ##############################################################################
598
600
 
599
601
  #http://msdn.microsoft.com/en-us/library/ms809762.aspx
600
- IMAGE_EXPORT_DIRECTORY = create_struct 'V2v2V2l2V3',
602
+ IMAGE_EXPORT_DIRECTORY = create_struct 'V2v2V7',
601
603
  :Characteristics,
602
604
  :TimeDateStamp,
603
605
  :MajorVersion, # These fields appear to be unused and are set to 0.
604
606
  :MinorVersion, # These fields appear to be unused and are set to 0.
605
607
  :Name,
606
608
  :Base, # The starting ordinal number for exported functions
607
- :NumberOfFunctions,
609
+ :NumberOfFunctions, # UNSIGNED!, perfectly valid when = 0xffff_ffff, see corkami/dllord.dll
608
610
  :NumberOfNames,
609
611
  :AddressOfFunctions,
610
612
  :AddressOfNames,
@@ -631,9 +633,8 @@ class PEdump
631
633
  va = @pe.ioh.DataDirectory[IMAGE_DATA_DIRECTORY::EXPORT].va
632
634
  file_offset = va2file(va)
633
635
  return nil unless file_offset
634
- f.seek file_offset
635
- if f.eof?
636
- logger.info "[?] exports info beyond EOF"
636
+ if !f.checked_seek(file_offset) || f.eof?
637
+ logger.warn "[?] exports info beyond EOF"
637
638
  return nil
638
639
  end
639
640
  @exports = IMAGE_EXPORT_DIRECTORY.read(f).tap do |x|
@@ -715,7 +716,8 @@ class PEdump
715
716
 
716
717
  x.functions = []
717
718
  x.entry_points.each_with_index do |ep,i|
718
- names = ord2name[i+x.Base].try(:join,', ')
719
+ names = ord2name[i+x.Base]
720
+ names = names.join(', ') if names
719
721
  next if ep.to_i == 0 && names.nil?
720
722
  x.functions << ExportedFunction.new(names, i+x.Base, ep)
721
723
  end
@@ -125,7 +125,11 @@ class PEdump::NE
125
125
  cp = PEdump::NE.cp # XXX HACK
126
126
 
127
127
  x.Value = f.read(value_len).to_s.chomp("\x00")
128
- x.Value.force_encoding("CP#{cp}").encode!('UTF-8').sub!(/\u0000$/,'') rescue nil
128
+ begin
129
+ x.Value.force_encoding("CP#{cp}").encode!('UTF-8').sub!(/\u0000$/,'')
130
+ rescue
131
+ x.Value.force_encoding("CP1250").encode!('UTF-8').sub!(/\u0000$/,'') rescue nil
132
+ end
129
133
  if f.tell%4 > 0
130
134
  f.read(4-f.tell%4) # undoc padding?
131
135
  end
data/lib/pedump/pe.rb CHANGED
@@ -38,7 +38,7 @@ class PEdump
38
38
  end
39
39
  PE.new(pe_sig).tap do |pe|
40
40
  pe.image_file_header = IMAGE_FILE_HEADER.read(f)
41
- if pe.ifh.SizeOfOptionalHeader > 0
41
+ if pe.ifh.SizeOfOptionalHeader.to_i > 0
42
42
  if pe.x64?
43
43
  pe.image_optional_header = IMAGE_OPTIONAL_HEADER64.read(f, pe.ifh.SizeOfOptionalHeader)
44
44
  else
@@ -46,7 +46,7 @@ class PEdump
46
46
  end
47
47
  end
48
48
 
49
- if (nToRead=pe.ifh.NumberOfSections) > 0xffff
49
+ if (nToRead=pe.ifh.NumberOfSections.to_i) > 0xffff
50
50
  if force.is_a?(Numeric) && force > 1
51
51
  logger.warn "[!] too many sections (#{pe.ifh.NumberOfSections}). forced. reading all"
52
52
  else
@@ -189,7 +189,7 @@ class PEdump
189
189
  r = []
190
190
  Array(resources(f)).find_all{ |x| x.type == 'STRING'}.each do |res|
191
191
  res.data.each_with_index do |string,idx|
192
- r << STRING.new( ((res.id-1)<<4) + idx, res.lang, string ) unless string.empty?
192
+ r << STRING.new( ((res.id.to_i-1)<<4) + idx, res.lang, string ) unless string.empty?
193
193
  end
194
194
  end
195
195
  r
@@ -2,7 +2,7 @@ class PEdump
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- PATCH = 11
5
+ PATCH = 12
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
data/pedump.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "pedump"
8
- s.version = "0.4.11"
8
+ s.version = "0.4.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrey \"Zed\" Zaikin"]
12
- s.date = "2012-12-11"
12
+ s.date = "2012-12-12"
13
13
  s.description = "dump headers, sections, extract resources of win32 PE exe,dll,etc"
14
14
  s.email = "zed.0xff@gmail.com"
15
15
  s.executables = ["pedump"]
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.files = [
21
21
  ".document",
22
22
  ".rspec",
23
+ ".travis.yml",
23
24
  "Gemfile",
24
25
  "Gemfile.lock",
25
26
  "LICENSE.txt",
@@ -58,8 +59,10 @@ Gem::Specification.new do |s|
58
59
  "misc/aspack/lzxdec.h",
59
60
  "misc/nedump.c",
60
61
  "pedump.gemspec",
62
+ "samples/bad/68.exe",
61
63
  "spec/65535sects_spec.rb",
62
64
  "spec/bad_imports_spec.rb",
65
+ "spec/bad_samples_spec.rb",
63
66
  "spec/composite_io_spec.rb",
64
67
  "spec/dllord_spec.rb",
65
68
  "spec/foldedhdr_spec.rb",
@@ -74,9 +77,11 @@ Gem::Specification.new do |s|
74
77
  "spec/sig_all_packers_spec.rb",
75
78
  "spec/sig_spec.rb",
76
79
  "spec/spec_helper.rb",
80
+ "spec/support/samples.rb",
77
81
  "spec/unpackers/aspack_spec.rb",
78
82
  "spec/unpackers/find_spec.rb",
79
- "spec/virtsectblXP_spec.rb"
83
+ "spec/virtsectblXP_spec.rb",
84
+ "tmp/.keep"
80
85
  ]
81
86
  s.homepage = "http://github.com/zed-0xff/pedump"
82
87
  s.licenses = ["MIT"]
@@ -89,7 +94,7 @@ Gem::Specification.new do |s|
89
94
 
90
95
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
91
96
  s.add_runtime_dependency(%q<multipart-post>, ["~> 1.1.4"])
92
- s.add_runtime_dependency(%q<progressbar>, ["~> 0.9.2"])
97
+ s.add_runtime_dependency(%q<progressbar>, [">= 0"])
93
98
  s.add_runtime_dependency(%q<awesome_print>, [">= 0"])
94
99
  s.add_development_dependency(%q<rspec>, [">= 0"])
95
100
  s.add_development_dependency(%q<bundler>, [">= 0"])
@@ -98,7 +103,7 @@ Gem::Specification.new do |s|
98
103
  s.add_development_dependency(%q<looksee>, [">= 0"])
99
104
  else
100
105
  s.add_dependency(%q<multipart-post>, ["~> 1.1.4"])
101
- s.add_dependency(%q<progressbar>, ["~> 0.9.2"])
106
+ s.add_dependency(%q<progressbar>, [">= 0"])
102
107
  s.add_dependency(%q<awesome_print>, [">= 0"])
103
108
  s.add_dependency(%q<rspec>, [">= 0"])
104
109
  s.add_dependency(%q<bundler>, [">= 0"])
@@ -108,7 +113,7 @@ Gem::Specification.new do |s|
108
113
  end
109
114
  else
110
115
  s.add_dependency(%q<multipart-post>, ["~> 1.1.4"])
111
- s.add_dependency(%q<progressbar>, ["~> 0.9.2"])
116
+ s.add_dependency(%q<progressbar>, [">= 0"])
112
117
  s.add_dependency(%q<awesome_print>, [">= 0"])
113
118
  s.add_dependency(%q<rspec>, [">= 0"])
114
119
  s.add_dependency(%q<bundler>, [">= 0"])
Binary file
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/pedump')
3
+
4
+ PEDUMP_BINARY = File.expand_path(File.dirname(__FILE__) + '/../bin/pedump')
5
+
6
+ Dir[File.join(SAMPLES_DIR,"bad","*.exe")].each do |fname|
7
+ describe fname do
8
+ it "should not cause exception" do
9
+ system "#{PEDUMP_BINARY} -qqq #{fname} > /dev/null"
10
+ $?.should be_success
11
+ end
12
+ end
13
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,26 +8,9 @@ require 'pedump'
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
10
  RSpec.configure do |config|
11
- end
12
-
13
- def sample
14
- @pedump ||=
15
- begin
16
- fname =
17
- if self.example
18
- # called from it(...)
19
- self.example.full_description.split.first
20
- else
21
- # called from before(:all)
22
- self.class.metadata[:example_group][:description_args].first
23
- end
24
- fname = File.expand_path(File.dirname(__FILE__) + '/../samples/' + fname)
25
- File.open(fname,"rb") do |f|
26
- if block_given?
27
- yield PEdump.new(f)
28
- else
29
- PEdump.new(f).dump
30
- end
31
- end
11
+ config.before :suite do
12
+ Dir[File.join(SAMPLES_DIR,"*.7z")].each do |fname|
13
+ system "7zr", "x", "-y", "-o#{SAMPLES_DIR}", fname
32
14
  end
15
+ end
33
16
  end
@@ -0,0 +1,24 @@
1
+ SAMPLES_DIR = File.expand_path(File.dirname(__FILE__) + '/../../samples/')
2
+
3
+ def sample
4
+ @pedump ||=
5
+ begin
6
+ fname =
7
+ if self.example
8
+ # called from it(...)
9
+ self.example.full_description.split.first
10
+ else
11
+ # called from before(:all)
12
+ self.class.metadata[:example_group][:description_args].first
13
+ end
14
+ fname = File.join(SAMPLES_DIR, fname)
15
+ File.open(fname,"rb") do |f|
16
+ if block_given?
17
+ yield PEdump.new(f)
18
+ else
19
+ PEdump.new(f).dump
20
+ end
21
+ end
22
+ end
23
+ end
24
+
data/tmp/.keep ADDED
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pedump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.4.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-11 00:00:00.000000000 Z
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multipart-post
@@ -32,17 +32,17 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ~>
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.9.2
37
+ version: '0'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 0.9.2
45
+ version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: awesome_print
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,7 @@ extra_rdoc_files:
150
150
  files:
151
151
  - .document
152
152
  - .rspec
153
+ - .travis.yml
153
154
  - Gemfile
154
155
  - Gemfile.lock
155
156
  - LICENSE.txt
@@ -188,8 +189,10 @@ files:
188
189
  - misc/aspack/lzxdec.h
189
190
  - misc/nedump.c
190
191
  - pedump.gemspec
192
+ - samples/bad/68.exe
191
193
  - spec/65535sects_spec.rb
192
194
  - spec/bad_imports_spec.rb
195
+ - spec/bad_samples_spec.rb
193
196
  - spec/composite_io_spec.rb
194
197
  - spec/dllord_spec.rb
195
198
  - spec/foldedhdr_spec.rb
@@ -204,9 +207,11 @@ files:
204
207
  - spec/sig_all_packers_spec.rb
205
208
  - spec/sig_spec.rb
206
209
  - spec/spec_helper.rb
210
+ - spec/support/samples.rb
207
211
  - spec/unpackers/aspack_spec.rb
208
212
  - spec/unpackers/find_spec.rb
209
213
  - spec/virtsectblXP_spec.rb
214
+ - tmp/.keep
210
215
  homepage: http://github.com/zed-0xff/pedump
211
216
  licenses:
212
217
  - MIT
@@ -222,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
227
  version: '0'
223
228
  segments:
224
229
  - 0
225
- hash: -1370513960600577087
230
+ hash: -3767964697457459615
226
231
  required_rubygems_version: !ruby/object:Gem::Requirement
227
232
  none: false
228
233
  requirements: