pedump 0.6.0 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pedump.rb CHANGED
@@ -30,7 +30,7 @@ class PEdump
30
30
  VERSION = Version::STRING
31
31
  MAX_ERRORS = 100
32
32
  MAX_IMAGE_IMPORT_DESCRIPTORS = 1000
33
- MAX_EXPORT_NUMBER_OF_NAMES = 16384 # got 7977 in http://pedump.me/03ad7400080678c6b1984f995d36fd04
33
+ MAX_EXPORT_NUMBER_OF_NAMES = 16384 # got 7977 in https://pedump.me/03ad7400080678c6b1984f995d36fd04
34
34
  GOOD_FUNCTION_NAME_RE = /\A[\x21-\x7f]+\Z/
35
35
  SUPPORTED_SIGNATURES = ['MZ', 'ZM', 'VZ']
36
36
 
@@ -261,7 +261,7 @@ class PEdump
261
261
 
262
262
  # http://ntcore.com/files/richsign.htm
263
263
  class RichHdr < String
264
- attr_accessor :offset, :key # xor key
264
+ attr_accessor :offset, :skip, :key # xor key
265
265
 
266
266
  class Entry < Struct.new(:version,:id,:times)
267
267
  def inspect
@@ -270,8 +270,21 @@ class PEdump
270
270
  end
271
271
 
272
272
  def self.from_dos_stub stub
273
+ #stub.hexdump
273
274
  key = stub[stub.index('Rich')+4,4]
274
275
  start_idx = stub.index(key.xor('DanS'))
276
+ skip = 0
277
+ if start_idx
278
+ skip = 4
279
+ else
280
+ PEdump.logger.warn "[?] cannot find rich_hdr start_idx, using heuristics"
281
+ start_idx = stub.index("$\x00\x00\x00\x00\x00\x00\x00")
282
+ unless start_idx
283
+ PEdump.logger.warn "[?] heuristics failed :("
284
+ return nil
285
+ end
286
+ start_idx += 8
287
+ end
275
288
  end_idx = stub.index('Rich')+8
276
289
  if stub[end_idx..-1].tr("\x00",'') != ''
277
290
  t = stub[end_idx..-1]
@@ -279,14 +292,16 @@ class PEdump
279
292
  PEdump.logger.error "[!] non-zero dos stub after rich_hdr: #{t.inspect}"
280
293
  return nil
281
294
  end
295
+ #stub[start_idx, end_idx-start_idx].hexdump
282
296
  RichHdr.new(stub[start_idx, end_idx-start_idx]).tap do |x|
283
297
  x.key = key
284
298
  x.offset = stub.offset + start_idx
299
+ x.skip = skip
285
300
  end
286
301
  end
287
302
 
288
303
  def dexor
289
- self[4..-9].sub(/\A(#{Regexp::escape(key)}){3}/,'').xor(key)
304
+ self[skip..-9].sub(/\A(#{Regexp::escape(key)}){3}/,'').xor(key)
290
305
  end
291
306
 
292
307
  def decode
@@ -382,6 +397,13 @@ class PEdump
382
397
  def va2file va, h={}
383
398
  return nil if va.nil?
384
399
 
400
+ va0 = va # save for log output of original addr
401
+ if pe?
402
+ # most common case, do nothing
403
+ elsif te?
404
+ va = va - te_shift()
405
+ end
406
+
385
407
  sections.each do |s|
386
408
  if (s.VirtualAddress...(s.VirtualAddress+s.VirtualSize)).include?(va)
387
409
  offset = va - s.VirtualAddress
@@ -413,9 +435,9 @@ class PEdump
413
435
  # TODO: not all VirtualAdresses == 0 case
414
436
 
415
437
  if h[:quiet]
416
- logger.debug "[?] can't find file_offset of VA 0x#{va.to_i.to_s(16)} (quiet=true)"
438
+ logger.debug "[?] can't find file_offset of VA 0x#{va0.to_i.to_s(16)} (quiet=true)"
417
439
  else
418
- logger.error "[?] can't find file_offset of VA 0x#{va.to_i.to_s(16)}"
440
+ logger.error "[?] can't find file_offset of VA 0x#{va0.to_i.to_s(16)}"
419
441
  end
420
442
  nil
421
443
  end
@@ -546,6 +568,8 @@ class PEdump
546
568
  pe_imports(f)
547
569
  elsif ne(f)
548
570
  ne(f).imports
571
+ else
572
+ []
549
573
  end
550
574
  end
551
575
 
@@ -633,7 +657,7 @@ class PEdump
633
657
  nil
634
658
  else
635
659
  hint = f.read(2).unpack('v').first
636
- name = f.gets("\x00").chomp("\x00")
660
+ name = f.gets("\x00").to_s.chomp("\x00")
637
661
  if !name.empty? && name !~ GOOD_FUNCTION_NAME_RE
638
662
  n_bad_names += 1
639
663
  if n_bad_names > MAX_ERRORS
data/pedump.gemspec CHANGED
@@ -1,17 +1,17 @@
1
- # Generated by jeweler
1
+ # Generated by juwelier
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: pedump 0.6.0 ruby lib
5
+ # stub: pedump 0.6.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "pedump".freeze
9
- s.version = "0.6.0"
9
+ s.version = "0.6.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Andrey \"Zed\" Zaikin".freeze]
14
- s.date = "2020-07-27"
14
+ s.date = "2022-01-29"
15
15
  s.description = "dump headers, sections, extract resources of win32 PE exe,dll,etc".freeze
16
16
  s.email = "zed.0xff@gmail.com".freeze
17
17
  s.executables = ["pedump".freeze]
@@ -20,8 +20,6 @@ Gem::Specification.new do |s|
20
20
  "README.md"
21
21
  ]
22
22
  s.files = [
23
- ".github/FUNDING.yml",
24
- ".github/dependabot.yml",
25
23
  "CODE_OF_CONDUCT.md",
26
24
  "Gemfile",
27
25
  "Gemfile.lock",
@@ -30,6 +28,7 @@ Gem::Specification.new do |s|
30
28
  "Rakefile",
31
29
  "VERSION",
32
30
  "bin/pedump",
31
+ "data/comp_id.txt",
33
32
  "data/fs.txt",
34
33
  "data/jc-userdb.txt",
35
34
  "data/sig.bin",
@@ -50,6 +49,7 @@ Gem::Specification.new do |s|
50
49
  "lib/pedump/packer.rb",
51
50
  "lib/pedump/pe.rb",
52
51
  "lib/pedump/resources.rb",
52
+ "lib/pedump/rich.rb",
53
53
  "lib/pedump/security.rb",
54
54
  "lib/pedump/sig_parser.rb",
55
55
  "lib/pedump/te.rb",
@@ -68,43 +68,33 @@ Gem::Specification.new do |s|
68
68
  ]
69
69
  s.homepage = "http://github.com/zed-0xff/pedump".freeze
70
70
  s.licenses = ["MIT".freeze]
71
- s.rubygems_version = "2.7.10".freeze
71
+ s.rubygems_version = "3.2.32".freeze
72
72
  s.summary = "dump win32 PE executable files with a pure ruby".freeze
73
73
 
74
74
  if s.respond_to? :specification_version then
75
75
  s.specification_version = 4
76
+ end
76
77
 
77
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
78
- s.add_runtime_dependency(%q<rainbow>.freeze, [">= 0"])
79
- s.add_runtime_dependency(%q<awesome_print>.freeze, [">= 0"])
80
- s.add_runtime_dependency(%q<iostruct>.freeze, [">= 0.0.4"])
81
- s.add_runtime_dependency(%q<multipart-post>.freeze, [">= 2.0.0"])
82
- s.add_runtime_dependency(%q<zhexdump>.freeze, [">= 0.0.2"])
83
- s.add_development_dependency(%q<rspec>.freeze, ["~> 3.9.0"])
84
- s.add_development_dependency(%q<rspec-its>.freeze, ["~> 1.3.0"])
85
- s.add_development_dependency(%q<bundler>.freeze, ["~> 2.1.4"])
86
- s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3.9"])
87
- else
88
- s.add_dependency(%q<rainbow>.freeze, [">= 0"])
89
- s.add_dependency(%q<awesome_print>.freeze, [">= 0"])
90
- s.add_dependency(%q<iostruct>.freeze, [">= 0.0.4"])
91
- s.add_dependency(%q<multipart-post>.freeze, [">= 2.0.0"])
92
- s.add_dependency(%q<zhexdump>.freeze, [">= 0.0.2"])
93
- s.add_dependency(%q<rspec>.freeze, ["~> 3.9.0"])
94
- s.add_dependency(%q<rspec-its>.freeze, ["~> 1.3.0"])
95
- s.add_dependency(%q<bundler>.freeze, ["~> 2.1.4"])
96
- s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.9"])
97
- end
78
+ if s.respond_to? :add_runtime_dependency then
79
+ s.add_runtime_dependency(%q<rainbow>.freeze, [">= 0"])
80
+ s.add_runtime_dependency(%q<awesome_print>.freeze, [">= 0"])
81
+ s.add_runtime_dependency(%q<iostruct>.freeze, [">= 0.0.4"])
82
+ s.add_runtime_dependency(%q<multipart-post>.freeze, [">= 2.0.0"])
83
+ s.add_runtime_dependency(%q<zhexdump>.freeze, [">= 0.0.2"])
84
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
85
+ s.add_development_dependency(%q<rspec-its>.freeze, [">= 0"])
86
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
87
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
98
88
  else
99
89
  s.add_dependency(%q<rainbow>.freeze, [">= 0"])
100
90
  s.add_dependency(%q<awesome_print>.freeze, [">= 0"])
101
91
  s.add_dependency(%q<iostruct>.freeze, [">= 0.0.4"])
102
92
  s.add_dependency(%q<multipart-post>.freeze, [">= 2.0.0"])
103
93
  s.add_dependency(%q<zhexdump>.freeze, [">= 0.0.2"])
104
- s.add_dependency(%q<rspec>.freeze, ["~> 3.9.0"])
105
- s.add_dependency(%q<rspec-its>.freeze, ["~> 1.3.0"])
106
- s.add_dependency(%q<bundler>.freeze, ["~> 2.1.4"])
107
- s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.9"])
94
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
95
+ s.add_dependency(%q<rspec-its>.freeze, [">= 0"])
96
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
97
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
108
98
  end
109
99
  end
110
100
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pedump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "Zed" Zaikin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-27 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -84,58 +84,58 @@ dependencies:
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 3.9.0
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 3.9.0
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec-its
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 1.3.0
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 1.3.0
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: bundler
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 2.1.4
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 2.1.4
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: jeweler
126
+ name: juwelier
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 2.3.9
131
+ version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 2.3.9
138
+ version: '0'
139
139
  description: dump headers, sections, extract resources of win32 PE exe,dll,etc
140
140
  email: zed.0xff@gmail.com
141
141
  executables:
@@ -145,8 +145,6 @@ extra_rdoc_files:
145
145
  - LICENSE.txt
146
146
  - README.md
147
147
  files:
148
- - ".github/FUNDING.yml"
149
- - ".github/dependabot.yml"
150
148
  - CODE_OF_CONDUCT.md
151
149
  - Gemfile
152
150
  - Gemfile.lock
@@ -155,6 +153,7 @@ files:
155
153
  - Rakefile
156
154
  - VERSION
157
155
  - bin/pedump
156
+ - data/comp_id.txt
158
157
  - data/fs.txt
159
158
  - data/jc-userdb.txt
160
159
  - data/sig.bin
@@ -175,6 +174,7 @@ files:
175
174
  - lib/pedump/packer.rb
176
175
  - lib/pedump/pe.rb
177
176
  - lib/pedump/resources.rb
177
+ - lib/pedump/rich.rb
178
178
  - lib/pedump/security.rb
179
179
  - lib/pedump/sig_parser.rb
180
180
  - lib/pedump/te.rb
@@ -194,7 +194,7 @@ homepage: http://github.com/zed-0xff/pedump
194
194
  licenses:
195
195
  - MIT
196
196
  metadata: {}
197
- post_install_message:
197
+ post_install_message:
198
198
  rdoc_options: []
199
199
  require_paths:
200
200
  - lib
@@ -209,9 +209,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0'
211
211
  requirements: []
212
- rubyforge_project:
213
- rubygems_version: 2.7.10
214
- signing_key:
212
+ rubygems_version: 3.2.32
213
+ signing_key:
215
214
  specification_version: 4
216
215
  summary: dump win32 PE executable files with a pure ruby
217
216
  test_files: []
data/.github/FUNDING.yml DELETED
@@ -1,2 +0,0 @@
1
- #github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
2
- ko_fi: zed_0xff
@@ -1,8 +0,0 @@
1
- # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2
-
3
- version: 2
4
- updates:
5
- - package-ecosystem: bundler
6
- directory: "/"
7
- schedule:
8
- interval: "weekly"