pedump 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.travis.yml +4 -0
  2. data/Gemfile +10 -6
  3. data/Gemfile.lock +27 -19
  4. data/README.md +37 -25
  5. data/Rakefile +45 -6
  6. data/VERSION +1 -1
  7. data/data/fs.txt +37 -1408
  8. data/data/jc-userdb.txt +14371 -0
  9. data/data/sig.bin +0 -0
  10. data/lib/pedump.rb +355 -618
  11. data/lib/pedump/cli.rb +214 -113
  12. data/lib/pedump/comparer.rb +147 -0
  13. data/lib/pedump/composite_io.rb +56 -0
  14. data/lib/pedump/core.rb +38 -0
  15. data/lib/pedump/core_ext/try.rb +57 -0
  16. data/lib/pedump/loader.rb +393 -0
  17. data/lib/pedump/loader/minidump.rb +187 -0
  18. data/lib/pedump/loader/section.rb +57 -0
  19. data/lib/pedump/logger.rb +67 -0
  20. data/lib/pedump/ne.rb +425 -0
  21. data/lib/pedump/ne/version_info.rb +171 -0
  22. data/lib/pedump/packer.rb +50 -2
  23. data/lib/pedump/pe.rb +121 -0
  24. data/lib/pedump/resources.rb +436 -0
  25. data/lib/pedump/security.rb +58 -0
  26. data/lib/pedump/sig_parser.rb +145 -24
  27. data/lib/pedump/tls.rb +17 -0
  28. data/lib/pedump/unpacker.rb +26 -0
  29. data/lib/pedump/unpacker/aspack.rb +858 -0
  30. data/lib/pedump/unpacker/upx.rb +13 -0
  31. data/lib/pedump/version.rb +1 -1
  32. data/lib/pedump/version_info.rb +15 -10
  33. data/misc/aspack/Makefile +3 -0
  34. data/misc/aspack/aspack_unlzx.c +92 -0
  35. data/misc/aspack/lzxdec.c +479 -0
  36. data/misc/aspack/lzxdec.h +56 -0
  37. data/misc/nedump.c +751 -0
  38. data/pedump.gemspec +75 -25
  39. data/samples/bad/68.exe +0 -0
  40. data/samples/bad/data_dir_15_entries.exe +0 -0
  41. data/spec/65535sects_spec.rb +8 -0
  42. data/spec/bad_imports_spec.rb +20 -0
  43. data/spec/bad_samples_spec.rb +13 -0
  44. data/spec/composite_io_spec.rb +122 -0
  45. data/spec/data/calc.exe_sections.yml +49 -0
  46. data/spec/data/data_dir_15_entries.exe_sections.yml +95 -0
  47. data/spec/dllord_spec.rb +21 -0
  48. data/spec/foldedhdr_spec.rb +28 -0
  49. data/spec/imports_badterm_spec.rb +52 -0
  50. data/spec/imports_vterm_spec.rb +52 -0
  51. data/spec/loader/names_spec.rb +24 -0
  52. data/spec/loader/va_spec.rb +44 -0
  53. data/spec/manyimportsW7_spec.rb +22 -0
  54. data/spec/ne_spec.rb +125 -0
  55. data/spec/packer_spec.rb +17 -0
  56. data/spec/pe_spec.rb +67 -0
  57. data/spec/pedump_spec.rb +16 -4
  58. data/spec/sections_spec.rb +11 -0
  59. data/spec/sig_all_packers_spec.rb +15 -5
  60. data/spec/sig_spec.rb +6 -1
  61. data/spec/spec_helper.rb +15 -3
  62. data/spec/support/samples.rb +24 -0
  63. data/spec/unpackers/aspack_spec.rb +69 -0
  64. data/spec/unpackers/find_spec.rb +21 -0
  65. data/spec/virtsectblXP_spec.rb +12 -0
  66. data/tmp/.keep +0 -0
  67. metadata +146 -35
  68. data/README.md.tpl +0 -90
  69. data/samples/calc.7z +0 -0
  70. data/samples/zlib.dll +0 -0
@@ -5,53 +5,97 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "pedump"
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
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-17"
12
+ s.date = "2013-04-20"
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"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE.txt",
18
- "README.md",
19
- "README.md.tpl"
18
+ "README.md"
20
19
  ]
21
20
  s.files = [
22
21
  ".document",
23
22
  ".rspec",
23
+ ".travis.yml",
24
24
  "Gemfile",
25
25
  "Gemfile.lock",
26
26
  "LICENSE.txt",
27
27
  "README.md",
28
- "README.md.tpl",
29
28
  "Rakefile",
30
29
  "VERSION",
31
30
  "bin/pedump",
32
31
  "data/fs.txt",
32
+ "data/jc-userdb.txt",
33
33
  "data/sig.bin",
34
34
  "data/signatures.txt",
35
35
  "data/userdb.txt",
36
36
  "lib/pedump.rb",
37
37
  "lib/pedump/cli.rb",
38
+ "lib/pedump/comparer.rb",
39
+ "lib/pedump/composite_io.rb",
40
+ "lib/pedump/core.rb",
41
+ "lib/pedump/core_ext/try.rb",
42
+ "lib/pedump/loader.rb",
43
+ "lib/pedump/loader/minidump.rb",
44
+ "lib/pedump/loader/section.rb",
45
+ "lib/pedump/logger.rb",
46
+ "lib/pedump/ne.rb",
47
+ "lib/pedump/ne/version_info.rb",
38
48
  "lib/pedump/packer.rb",
49
+ "lib/pedump/pe.rb",
50
+ "lib/pedump/resources.rb",
51
+ "lib/pedump/security.rb",
39
52
  "lib/pedump/sig_parser.rb",
53
+ "lib/pedump/tls.rb",
54
+ "lib/pedump/unpacker.rb",
55
+ "lib/pedump/unpacker/aspack.rb",
56
+ "lib/pedump/unpacker/upx.rb",
40
57
  "lib/pedump/version.rb",
41
58
  "lib/pedump/version_info.rb",
59
+ "misc/aspack/Makefile",
60
+ "misc/aspack/aspack_unlzx.c",
61
+ "misc/aspack/lzxdec.c",
62
+ "misc/aspack/lzxdec.h",
63
+ "misc/nedump.c",
42
64
  "pedump.gemspec",
43
- "samples/calc.7z",
44
- "samples/zlib.dll",
65
+ "samples/bad/68.exe",
66
+ "samples/bad/data_dir_15_entries.exe",
67
+ "spec/65535sects_spec.rb",
68
+ "spec/bad_imports_spec.rb",
69
+ "spec/bad_samples_spec.rb",
70
+ "spec/composite_io_spec.rb",
71
+ "spec/data/calc.exe_sections.yml",
72
+ "spec/data/data_dir_15_entries.exe_sections.yml",
73
+ "spec/dllord_spec.rb",
74
+ "spec/foldedhdr_spec.rb",
75
+ "spec/imports_badterm_spec.rb",
76
+ "spec/imports_vterm_spec.rb",
77
+ "spec/loader/names_spec.rb",
78
+ "spec/loader/va_spec.rb",
79
+ "spec/manyimportsW7_spec.rb",
80
+ "spec/ne_spec.rb",
81
+ "spec/packer_spec.rb",
82
+ "spec/pe_spec.rb",
45
83
  "spec/pedump_spec.rb",
46
84
  "spec/resource_spec.rb",
85
+ "spec/sections_spec.rb",
47
86
  "spec/sig_all_packers_spec.rb",
48
87
  "spec/sig_spec.rb",
49
- "spec/spec_helper.rb"
88
+ "spec/spec_helper.rb",
89
+ "spec/support/samples.rb",
90
+ "spec/unpackers/aspack_spec.rb",
91
+ "spec/unpackers/find_spec.rb",
92
+ "spec/virtsectblXP_spec.rb",
93
+ "tmp/.keep"
50
94
  ]
51
95
  s.homepage = "http://github.com/zed-0xff/pedump"
52
96
  s.licenses = ["MIT"]
53
97
  s.require_paths = ["lib"]
54
- s.rubygems_version = "1.8.10"
98
+ s.rubygems_version = "1.8.24"
55
99
  s.summary = "dump win32 PE executable files with a pure ruby"
56
100
 
57
101
  if s.respond_to? :specification_version then
@@ -59,29 +103,35 @@ Gem::Specification.new do |s|
59
103
 
60
104
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
105
  s.add_runtime_dependency(%q<multipart-post>, ["~> 1.1.4"])
62
- s.add_runtime_dependency(%q<progressbar>, ["~> 0.9.2"])
63
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
64
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
65
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
66
- s.add_development_dependency(%q<rcov>, [">= 0"])
67
- s.add_development_dependency(%q<awesome_print>, [">= 0"])
106
+ s.add_runtime_dependency(%q<progressbar>, [">= 0"])
107
+ s.add_runtime_dependency(%q<awesome_print>, [">= 0"])
108
+ s.add_runtime_dependency(%q<iostruct>, [">= 0.0.4"])
109
+ s.add_runtime_dependency(%q<zhexdump>, [">= 0.0.2"])
110
+ s.add_development_dependency(%q<rspec>, [">= 0"])
111
+ s.add_development_dependency(%q<bundler>, [">= 0"])
112
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
113
+ s.add_development_dependency(%q<what_methods>, [">= 0"])
68
114
  else
69
115
  s.add_dependency(%q<multipart-post>, ["~> 1.1.4"])
70
- s.add_dependency(%q<progressbar>, ["~> 0.9.2"])
71
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
72
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
73
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
74
- s.add_dependency(%q<rcov>, [">= 0"])
116
+ s.add_dependency(%q<progressbar>, [">= 0"])
75
117
  s.add_dependency(%q<awesome_print>, [">= 0"])
118
+ s.add_dependency(%q<iostruct>, [">= 0.0.4"])
119
+ s.add_dependency(%q<zhexdump>, [">= 0.0.2"])
120
+ s.add_dependency(%q<rspec>, [">= 0"])
121
+ s.add_dependency(%q<bundler>, [">= 0"])
122
+ s.add_dependency(%q<jeweler>, [">= 0"])
123
+ s.add_dependency(%q<what_methods>, [">= 0"])
76
124
  end
77
125
  else
78
126
  s.add_dependency(%q<multipart-post>, ["~> 1.1.4"])
79
- s.add_dependency(%q<progressbar>, ["~> 0.9.2"])
80
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
81
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
82
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
83
- s.add_dependency(%q<rcov>, [">= 0"])
127
+ s.add_dependency(%q<progressbar>, [">= 0"])
84
128
  s.add_dependency(%q<awesome_print>, [">= 0"])
129
+ s.add_dependency(%q<iostruct>, [">= 0.0.4"])
130
+ s.add_dependency(%q<zhexdump>, [">= 0.0.2"])
131
+ s.add_dependency(%q<rspec>, [">= 0"])
132
+ s.add_dependency(%q<bundler>, [">= 0"])
133
+ s.add_dependency(%q<jeweler>, [">= 0"])
134
+ s.add_dependency(%q<what_methods>, [">= 0"])
85
135
  end
86
136
  end
87
137
 
Binary file
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/pedump')
3
+
4
+ describe 'corkami/65535sects.exe' do
5
+ it "should have 65535 sections" do
6
+ sample.sections.size.should == 65535
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/pedump')
3
+
4
+ describe 'bad_imports.exe' do
5
+ before :all do
6
+ @imports = sample.imports
7
+ end
8
+
9
+ it "should have IMAGE_IMPORT_DESCRIPTOR" do
10
+ @imports.size.should == 1
11
+ end
12
+
13
+ it "should have only IMAGE_IMPORT_DESCRIPTORs" do
14
+ @imports.map(&:class).uniq.should == [PEdump::IMAGE_IMPORT_DESCRIPTOR]
15
+ end
16
+
17
+ it "should not detect packer" do
18
+ sample.packer.should be_nil
19
+ end
20
+ end
@@ -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
@@ -0,0 +1,122 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/pedump/composite_io')
3
+
4
+ describe PEdump::CompositeIO do
5
+ it "concatenates" do
6
+ io = PEdump::CompositeIO.new(
7
+ StringIO.new('foo'),
8
+ StringIO.new('bar'),
9
+ StringIO.new('baz')
10
+ )
11
+ io.read.should == 'foobarbaz'
12
+ end
13
+
14
+ it "reads sequentally" do
15
+ io = PEdump::CompositeIO.new(
16
+ StringIO.new('foo1'),
17
+ StringIO.new('bar2'),
18
+ StringIO.new('baz')
19
+ )
20
+ io.read(3).should == 'foo'
21
+ io.read(3).should == '1ba'
22
+ io.read(3).should == 'r2b'
23
+ io.read(3).should == 'az'
24
+ end
25
+
26
+ it "behaves like StringIO" do
27
+ io1 = StringIO.new('foo')
28
+ io2 = PEdump::CompositeIO.new(StringIO.new('foo'))
29
+
30
+ io1.read.should == io2.read # 'foo'
31
+ io1.read.should == io2.read # ''
32
+ io1.read(3).should == io2.read(3) # nil
33
+ end
34
+
35
+ it "tracks number of bytes read" do
36
+ io = PEdump::CompositeIO.new(
37
+ StringIO.new('foo1'),
38
+ StringIO.new('bar2'),
39
+ StringIO.new('baz')
40
+ )
41
+ io.tell.should == 0
42
+ io.read(3)
43
+ io.tell.should == 3
44
+ io.read(4)
45
+ io.tell.should == 7
46
+ io.read
47
+ io.tell.should == 11
48
+ io.read
49
+ io.tell.should == 11
50
+ io.read 10
51
+ io.tell.should == 11
52
+ end
53
+
54
+ it "chains eof? call" do
55
+ io = PEdump::CompositeIO.new(
56
+ StringIO.new('foo1'),
57
+ StringIO.new('bar2'),
58
+ StringIO.new('baz')
59
+ )
60
+ io.eof?.should be_false
61
+ io.read(3)
62
+ io.eof?.should be_false
63
+ io.read(4)
64
+ io.eof?.should be_false
65
+ io.read
66
+ io.eof?.should be_true
67
+ io.read
68
+ io.eof?.should be_true
69
+ io.read 10
70
+ io.eof?.should be_true
71
+ end
72
+
73
+ it "seeks" do
74
+ io = PEdump::CompositeIO.new(
75
+ StringIO.new('foo1'),
76
+ StringIO.new('bar2'),
77
+ StringIO.new('baz')
78
+ )
79
+
80
+ io.seek(5)
81
+ io.tell.should == 5
82
+ io.read(4).should == "ar2b"
83
+
84
+ io.seek(0)
85
+ io.tell.should == 0
86
+ io.read.should == "foo1bar2baz"
87
+
88
+ io.seek(1)
89
+ io.tell.should == 1
90
+ io.read.should == "oo1bar2baz"
91
+ end
92
+
93
+ it "respects start positions" do
94
+ ios = [
95
+ StringIO.new('foo1'),
96
+ StringIO.new('bar2'),
97
+ StringIO.new('baz3')
98
+ ]
99
+ ios.each_with_index{ |io,idx| io.seek(idx+1) }
100
+
101
+ s = "oo1r23"
102
+
103
+ io = PEdump::CompositeIO.new(*ios)
104
+ io.tell.should == 0
105
+ io.read.should == s
106
+
107
+ s.size.times do |pos|
108
+ io.seek(pos)
109
+ io.tell.should == pos
110
+ io.read.should == s[pos..-1]
111
+ end
112
+ end
113
+
114
+ it "summarizes size" do
115
+ io = PEdump::CompositeIO.new(
116
+ StringIO.new('foo1'),
117
+ StringIO.new('bar2'),
118
+ StringIO.new('baz')
119
+ )
120
+ io.size.should == 11
121
+ end
122
+ end
@@ -0,0 +1,49 @@
1
+ ---
2
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
3
+ Name: !binary |-
4
+ LnRleHQ=
5
+ VirtualSize: 305562
6
+ VirtualAddress: 4096
7
+ SizeOfRawData: 305664
8
+ PointerToRawData: 1024
9
+ PointerToRelocations: 0
10
+ PointerToLinenumbers: 0
11
+ NumberOfRelocations: 0
12
+ NumberOfLinenumbers: 0
13
+ Characteristics: 1610612768
14
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
15
+ Name: !binary |-
16
+ LmRhdGE=
17
+ VirtualSize: 17180
18
+ VirtualAddress: 311296
19
+ SizeOfRawData: 12288
20
+ PointerToRawData: 306688
21
+ PointerToRelocations: 0
22
+ PointerToLinenumbers: 0
23
+ NumberOfRelocations: 0
24
+ NumberOfLinenumbers: 0
25
+ Characteristics: 3221225536
26
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
27
+ Name: !binary |-
28
+ LnJzcmM=
29
+ VirtualSize: 305927
30
+ VirtualAddress: 331776
31
+ SizeOfRawData: 306176
32
+ PointerToRawData: 318976
33
+ PointerToRelocations: 0
34
+ PointerToLinenumbers: 0
35
+ NumberOfRelocations: 0
36
+ NumberOfLinenumbers: 0
37
+ Characteristics: 1073741888
38
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
39
+ Name: !binary |-
40
+ LnJlbG9j
41
+ VirtualSize: 16886
42
+ VirtualAddress: 638976
43
+ SizeOfRawData: 16896
44
+ PointerToRawData: 625152
45
+ PointerToRelocations: 0
46
+ PointerToLinenumbers: 0
47
+ NumberOfRelocations: 0
48
+ NumberOfLinenumbers: 0
49
+ Characteristics: 1107296320
@@ -0,0 +1,95 @@
1
+ ---
2
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
3
+ Name: !binary ""
4
+ VirtualSize: 245760
5
+ VirtualAddress: 8192
6
+ SizeOfRawData: 103936
7
+ PointerToRawData: 8192
8
+ PointerToRelocations: 0
9
+ PointerToLinenumbers: 0
10
+ NumberOfRelocations: 0
11
+ NumberOfLinenumbers: 0
12
+ Characteristics: 3758096448
13
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
14
+ Name: !binary |-
15
+ LnJzcmM=
16
+ VirtualSize: 2624
17
+ VirtualAddress: 253952
18
+ SizeOfRawData: 1536
19
+ PointerToRawData: 112128
20
+ PointerToRelocations: 0
21
+ PointerToLinenumbers: 0
22
+ NumberOfRelocations: 0
23
+ NumberOfLinenumbers: 0
24
+ Characteristics: 3221225536
25
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
26
+ Name: !binary |-
27
+ LmlkYXRh
28
+ VirtualSize: 8192
29
+ VirtualAddress: 262144
30
+ SizeOfRawData: 1024
31
+ PointerToRawData: 113664
32
+ PointerToRelocations: 0
33
+ PointerToLinenumbers: 0
34
+ NumberOfRelocations: 0
35
+ NumberOfLinenumbers: 0
36
+ Characteristics: 3221225536
37
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
38
+ Name: !binary ""
39
+ VirtualSize: 1679360
40
+ VirtualAddress: 270336
41
+ SizeOfRawData: 512
42
+ PointerToRawData: 114688
43
+ PointerToRelocations: 0
44
+ PointerToLinenumbers: 0
45
+ NumberOfRelocations: 0
46
+ NumberOfLinenumbers: 0
47
+ Characteristics: 3758096448
48
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
49
+ Name: !binary |-
50
+ cnVsbm1kdnE=
51
+ VirtualSize: 1613824
52
+ VirtualAddress: 1949696
53
+ SizeOfRawData: 1607680
54
+ PointerToRawData: 115200
55
+ PointerToRelocations: 0
56
+ PointerToLinenumbers: 0
57
+ NumberOfRelocations: 0
58
+ NumberOfLinenumbers: 0
59
+ Characteristics: 3758096448
60
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
61
+ Name: !binary |-
62
+ Ym5uYm1jcWY=
63
+ VirtualSize: 8192
64
+ VirtualAddress: 3563520
65
+ SizeOfRawData: 512
66
+ PointerToRawData: 1722880
67
+ PointerToRelocations: 0
68
+ PointerToLinenumbers: 0
69
+ NumberOfRelocations: 0
70
+ NumberOfLinenumbers: 0
71
+ Characteristics: 3758096448
72
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
73
+ Name: !binary |-
74
+ Ym5uYm1jcWY=
75
+ VirtualSize: 8192
76
+ VirtualAddress: 3571712
77
+ SizeOfRawData: 3072
78
+ PointerToRawData: 1723392
79
+ PointerToRelocations: 0
80
+ PointerToLinenumbers: 0
81
+ NumberOfRelocations: 0
82
+ NumberOfLinenumbers: 0
83
+ Characteristics: 3758096448
84
+ - !ruby/struct:PEdump::IMAGE_SECTION_HEADER
85
+ Name: !binary |-
86
+ LmRhdGEAQXA=
87
+ VirtualSize: 8192
88
+ VirtualAddress: 3579904
89
+ SizeOfRawData: 0
90
+ PointerToRawData: 1726464
91
+ PointerToRelocations: 0
92
+ PointerToLinenumbers: 0
93
+ NumberOfRelocations: 0
94
+ NumberOfLinenumbers: 0
95
+ Characteristics: 3758096448