pedump 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/pedump.rb +7 -6
- data/lib/pedump/cli.rb +3 -3
- data/lib/pedump/version.rb +1 -1
- data/pedump.gemspec +9 -2
- data/samples/65535sects.7z +0 -0
- data/samples/imports_badterm.exe +0 -0
- data/samples/imports_vterm.exe +0 -0
- data/spec/65535sects_spec.rb +16 -0
- data/spec/imports_badterm_spec.rb +58 -0
- data/spec/imports_vterm_spec.rb +58 -0
- data/spec/pe_spec.rb +6 -0
- metadata +24 -17
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/pedump.rb
CHANGED
@@ -185,7 +185,7 @@ class PEdump
|
|
185
185
|
|
186
186
|
def initialize *args
|
187
187
|
super
|
188
|
-
self.TimeDateStamp = Time.at(self.TimeDateStamp)
|
188
|
+
self.TimeDateStamp = Time.at(self.TimeDateStamp).utc
|
189
189
|
end
|
190
190
|
def flags
|
191
191
|
FLAGS.find_all{ |k,v| (self.Characteristics & k) != 0 }.map(&:last)
|
@@ -471,12 +471,12 @@ class PEdump
|
|
471
471
|
end
|
472
472
|
end
|
473
473
|
|
474
|
-
if (nToRead=pe.ifh.NumberOfSections) >
|
474
|
+
if (nToRead=pe.ifh.NumberOfSections) > 0xffff
|
475
475
|
if @force.is_a?(Numeric) && @force > 1
|
476
476
|
logger.warn "[!] too many sections (#{pe.ifh.NumberOfSections}). forced. reading all"
|
477
477
|
else
|
478
|
-
logger.warn "[!] too many sections (#{pe.ifh.NumberOfSections}). not forced, reading first
|
479
|
-
nToRead =
|
478
|
+
logger.warn "[!] too many sections (#{pe.ifh.NumberOfSections}). not forced, reading first 65535"
|
479
|
+
nToRead = 65535
|
480
480
|
end
|
481
481
|
end
|
482
482
|
pe.section_table = nToRead.times.map do
|
@@ -543,13 +543,14 @@ class PEdump
|
|
543
543
|
return nil unless file_offset
|
544
544
|
f.seek file_offset
|
545
545
|
r = []
|
546
|
-
until (t=IMAGE_IMPORT_DESCRIPTOR.read(f)).
|
546
|
+
until (t=IMAGE_IMPORT_DESCRIPTOR.read(f)).Name.to_i == 0
|
547
547
|
r << t
|
548
548
|
end
|
549
|
+
logger.warn "[?] non-empty last IMAGE_IMPORT_DESCRIPTOR: #{t.inspect}" unless t.empty?
|
549
550
|
@imports = r.each do |x|
|
550
551
|
if x.Name.to_i != 0 && (va = va2file(x.Name))
|
551
552
|
f.seek va
|
552
|
-
x.module_name = f.gets("\x00").
|
553
|
+
x.module_name = f.gets("\x00").chomp("\x00")
|
553
554
|
end
|
554
555
|
[:original_first_thunk, :first_thunk].each do |tbl|
|
555
556
|
camel = tbl.capitalize.to_s.gsub(/_./){ |char| char[1..-1].upcase}
|
data/lib/pedump/cli.rb
CHANGED
@@ -268,7 +268,7 @@ class PEdump::CLI
|
|
268
268
|
when :pe
|
269
269
|
@pedump.pe.ifh.TimeDateStamp = @pedump.pe.ifh.TimeDateStamp.to_i
|
270
270
|
data = @pedump.pe.signature + (@pedump.pe.ifh.try(:pack)||'') + (@pedump.pe.ioh.try(:pack)||'')
|
271
|
-
@pedump.pe.ifh.TimeDateStamp = Time.at(@pedump.pe.ifh.TimeDateStamp)
|
271
|
+
@pedump.pe.ifh.TimeDateStamp = Time.at(@pedump.pe.ifh.TimeDateStamp).utc
|
272
272
|
when :resources
|
273
273
|
return dump_resources(data)
|
274
274
|
when :strings
|
@@ -352,7 +352,7 @@ class PEdump::CLI
|
|
352
352
|
printf "%30s: %24s\n", k.to_s.sub('Major',''), "#{v}.#{data[k.to_s.sub('Major','Minor')]}"
|
353
353
|
when /\AMinor.*Version\Z/
|
354
354
|
when /TimeDateStamp/
|
355
|
-
printf "%30s: %24s\n", k, Time.at(v).strftime('"%Y-%m-%d %H:%M:%S"')
|
355
|
+
printf "%30s: %24s\n", k, Time.at(v).utc.strftime('"%Y-%m-%d %H:%M:%S"')
|
356
356
|
else
|
357
357
|
comment = ''
|
358
358
|
if COMMENTS[k]
|
@@ -485,7 +485,7 @@ class PEdump::CLI
|
|
485
485
|
printf "# module %s\n# flags=0x%x ts=%s version=%d.%d ord_base=%d\n",
|
486
486
|
data.name.inspect,
|
487
487
|
data.Characteristics.to_i,
|
488
|
-
Time.at(data.TimeDateStamp.to_i).strftime('"%Y-%m-%d %H:%M:%S"'),
|
488
|
+
Time.at(data.TimeDateStamp.to_i).utc.strftime('"%Y-%m-%d %H:%M:%S"'),
|
489
489
|
data.MajorVersion, data.MinorVersion,
|
490
490
|
data.Base
|
491
491
|
|
data/lib/pedump/version.rb
CHANGED
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.
|
8
|
+
s.version = "0.4.1"
|
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 = "2011-12-
|
12
|
+
s.date = "2011-12-19"
|
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"]
|
@@ -40,8 +40,15 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/pedump/version.rb",
|
41
41
|
"lib/pedump/version_info.rb",
|
42
42
|
"pedump.gemspec",
|
43
|
+
"samples/65535sects.7z",
|
43
44
|
"samples/calc.7z",
|
45
|
+
"samples/imports_badterm.exe",
|
46
|
+
"samples/imports_vterm.exe",
|
44
47
|
"samples/zlib.dll",
|
48
|
+
"spec/65535sects_spec.rb",
|
49
|
+
"spec/imports_badterm_spec.rb",
|
50
|
+
"spec/imports_vterm_spec.rb",
|
51
|
+
"spec/pe_spec.rb",
|
45
52
|
"spec/pedump_spec.rb",
|
46
53
|
"spec/resource_spec.rb",
|
47
54
|
"spec/sig_all_packers_spec.rb",
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/pedump')
|
3
|
+
|
4
|
+
describe 'a PE file with 65535 sections' do
|
5
|
+
before :all do
|
6
|
+
fname = File.expand_path(File.dirname(__FILE__) + '/../samples/65535sects.exe')
|
7
|
+
File.open(fname,"rb") do |f|
|
8
|
+
@pedump = PEdump.new(fname)
|
9
|
+
@sections = @pedump.sections(f)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have 65535 sections" do
|
14
|
+
@sections.size.should == 65535
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/pedump')
|
3
|
+
|
4
|
+
describe 'Imports' do
|
5
|
+
# PE with a 'bad' imports terminator, just the dll name is empty
|
6
|
+
# http://code.google.com/p/corkami/source/browse/trunk/asm/PE/imports_badterm.asm
|
7
|
+
describe "imports_badterm.exe" do
|
8
|
+
before :all do
|
9
|
+
fname = File.expand_path(File.dirname(__FILE__) + '/../samples/imports_badterm.exe')
|
10
|
+
File.open(fname,"rb") do |f|
|
11
|
+
@pedump = PEdump.new(fname)
|
12
|
+
@imports = @pedump.imports(f)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have 2 IMAGE_IMPORT_DESCRIPTORs" do
|
17
|
+
@imports.size.should == 2
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have only IMAGE_IMPORT_DESCRIPTORs" do
|
21
|
+
@imports.map(&:class).uniq.should == [PEdump::IMAGE_IMPORT_DESCRIPTOR]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have all entries thunks equal" do
|
25
|
+
@imports.each do |iid|
|
26
|
+
iid.first_thunk.should == iid.original_first_thunk
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "1st image_import_descriptor" do
|
31
|
+
it "should be from kernel32.dll" do
|
32
|
+
@imports[0].module_name.should == "kernel32.dll"
|
33
|
+
end
|
34
|
+
it "should have 1 function" do
|
35
|
+
@imports[0].first_thunk.size.should == 1
|
36
|
+
end
|
37
|
+
it "should have ExitProcess" do
|
38
|
+
@imports[0].first_thunk.first.name.should == "ExitProcess"
|
39
|
+
@imports[0].first_thunk.first.hint.should == 0
|
40
|
+
@imports[0].first_thunk.first.ordinal.should be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "2nd image_import_descriptor" do
|
45
|
+
it "should be from msvcrt.dll" do
|
46
|
+
@imports[1].module_name.should == "msvcrt.dll"
|
47
|
+
end
|
48
|
+
it "should have 1 function" do
|
49
|
+
@imports[1].first_thunk.size.should == 1
|
50
|
+
end
|
51
|
+
it "should have printf" do
|
52
|
+
@imports[1].first_thunk.first.name.should == "printf"
|
53
|
+
@imports[1].first_thunk.first.hint.should == 0
|
54
|
+
@imports[1].first_thunk.first.ordinal.should be_nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/pedump')
|
3
|
+
|
4
|
+
describe 'Imports' do
|
5
|
+
# http://code.google.com/p/corkami/source/browse/trunk/asm/PE/imports_vterm.asm
|
6
|
+
#describe "import terminator in virtual space" do
|
7
|
+
describe "imports_vterm.exe" do
|
8
|
+
before :all do
|
9
|
+
fname = File.expand_path(File.dirname(__FILE__) + '/../samples/imports_vterm.exe')
|
10
|
+
File.open(fname,"rb") do |f|
|
11
|
+
@pedump = PEdump.new(fname)
|
12
|
+
@imports = @pedump.imports(f)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have 2 IMAGE_IMPORT_DESCRIPTORs" do
|
17
|
+
@imports.size.should == 2
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have only IMAGE_IMPORT_DESCRIPTORs" do
|
21
|
+
@imports.map(&:class).uniq.should == [PEdump::IMAGE_IMPORT_DESCRIPTOR]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have all entries thunks equal" do
|
25
|
+
@imports.each do |iid|
|
26
|
+
iid.first_thunk.should == iid.original_first_thunk
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "1st image_import_descriptor" do
|
31
|
+
it "should be from kernel32.dll" do
|
32
|
+
@imports[0].module_name.should == "kernel32.dll"
|
33
|
+
end
|
34
|
+
it "should have 1 function" do
|
35
|
+
@imports[0].first_thunk.size.should == 1
|
36
|
+
end
|
37
|
+
it "should have ExitProcess" do
|
38
|
+
@imports[0].first_thunk.first.name.should == "ExitProcess"
|
39
|
+
@imports[0].first_thunk.first.hint.should == 0
|
40
|
+
@imports[0].first_thunk.first.ordinal.should be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "2nd image_import_descriptor" do
|
45
|
+
it "should be from msvcrt.dll" do
|
46
|
+
@imports[1].module_name.should == "msvcrt.dll"
|
47
|
+
end
|
48
|
+
it "should have 1 function" do
|
49
|
+
@imports[1].first_thunk.size.should == 1
|
50
|
+
end
|
51
|
+
it "should have printf" do
|
52
|
+
@imports[1].first_thunk.first.name.should == "printf"
|
53
|
+
@imports[1].first_thunk.first.hint.should == 0
|
54
|
+
@imports[1].first_thunk.first.ordinal.should be_nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/pe_spec.rb
ADDED
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.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multipart-post
|
16
|
-
requirement: &
|
16
|
+
requirement: &70337431501640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.1.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70337431501640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: progressbar
|
27
|
-
requirement: &
|
27
|
+
requirement: &70337431501120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70337431501120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70337431500620 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.3.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70337431500620
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70337431500120 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70337431500120
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70337431499220 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.6.4
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70337431499220
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rcov
|
71
|
-
requirement: &
|
71
|
+
requirement: &70337431498520 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70337431498520
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: awesome_print
|
82
|
-
requirement: &
|
82
|
+
requirement: &70337431497620 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70337431497620
|
91
91
|
description: dump headers, sections, extract resources of win32 PE exe,dll,etc
|
92
92
|
email: zed.0xff@gmail.com
|
93
93
|
executables:
|
@@ -119,8 +119,15 @@ files:
|
|
119
119
|
- lib/pedump/version.rb
|
120
120
|
- lib/pedump/version_info.rb
|
121
121
|
- pedump.gemspec
|
122
|
+
- samples/65535sects.7z
|
122
123
|
- samples/calc.7z
|
124
|
+
- samples/imports_badterm.exe
|
125
|
+
- samples/imports_vterm.exe
|
123
126
|
- samples/zlib.dll
|
127
|
+
- spec/65535sects_spec.rb
|
128
|
+
- spec/imports_badterm_spec.rb
|
129
|
+
- spec/imports_vterm_spec.rb
|
130
|
+
- spec/pe_spec.rb
|
124
131
|
- spec/pedump_spec.rb
|
125
132
|
- spec/resource_spec.rb
|
126
133
|
- spec/sig_all_packers_spec.rb
|
@@ -141,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
148
|
version: '0'
|
142
149
|
segments:
|
143
150
|
- 0
|
144
|
-
hash:
|
151
|
+
hash: 3050538541444126729
|
145
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
153
|
none: false
|
147
154
|
requirements:
|