pedump 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c167f3c637d0eb649e1ff15a7d18a58682ed89b318d2425c8f6713e5c203409e
4
- data.tar.gz: f362fd8c83ad8697439b212751c7c8b5c4514a92fd5becaf4769bde5566f752a
3
+ metadata.gz: 73c28547719cedc77a48cbcd0b519283d09d061c358c24fd14fcff8e130072bf
4
+ data.tar.gz: 4444e01ee15c6920856ed30e63d118bc027758de0e696ea02d1c1bd3a6486bee
5
5
  SHA512:
6
- metadata.gz: 8997606d9577b1e43e47681151017edfde52b32da1125ee67fab26c9649a9f6d03a9fdb3e5259a790c1519def75e536c124fefe59608af861e17d86e7e201a63
7
- data.tar.gz: 62ad9a8fef0aaea4cc0b637f033705ee02e1623320bf043ad4e08c8834d95ce92f1b04639ec5e7e46c5212ba23d132181a664d41dd84d454cd72ed55ac19f6a7
6
+ metadata.gz: d35bdf91d6081245a723b569837b7332baf0b61962747d6595a0afed6625fba3f15fa1e7ae5db9734ed7e08f03008031037254fc2df60f655c10b0e95db5d005
7
+ data.tar.gz: e9ac50ac19c5814f6364dde31dd0a16c0e263015e752c4a82b04e707c08a3e999255572c643da990ce9fabb4d3e624e85bdab53697e702044f941772fc96974e
@@ -0,0 +1,2 @@
1
+ #github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
2
+ ko_fi: zed_0xff
@@ -0,0 +1,8 @@
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"
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at zed.0xff@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/Gemfile CHANGED
@@ -5,7 +5,6 @@ gem 'rainbow'
5
5
  gem "awesome_print"
6
6
  gem "iostruct", ">= 0.0.4"
7
7
  gem "multipart-post", ">= 2.0.0"
8
- gem "progressbar"
9
8
  gem "zhexdump", ">= 0.0.2"
10
9
 
11
10
  group :development do
@@ -36,8 +36,8 @@ GEM
36
36
  mini_portile2 (2.4.0)
37
37
  multi_json (1.14.1)
38
38
  multi_xml (0.6.0)
39
- multipart-post (2.0.0)
40
- nokogiri (1.10.7)
39
+ multipart-post (2.1.1)
40
+ nokogiri (1.10.8)
41
41
  mini_portile2 (~> 2.4.0)
42
42
  oauth2 (1.4.2)
43
43
  faraday (>= 0.8, < 2.0)
@@ -45,9 +45,8 @@ GEM
45
45
  multi_json (~> 1.3)
46
46
  multi_xml (~> 0.5)
47
47
  rack (>= 1.2, < 3)
48
- progressbar (1.10.1)
49
48
  psych (3.1.0)
50
- rack (2.1.1)
49
+ rack (2.2.3)
51
50
  rainbow (3.0.0)
52
51
  rake (13.0.1)
53
52
  rdoc (6.2.1)
@@ -80,7 +79,6 @@ DEPENDENCIES
80
79
  iostruct (>= 0.0.4)
81
80
  jeweler (~> 2.3.9)
82
81
  multipart-post (>= 2.0.0)
83
- progressbar
84
82
  rainbow
85
83
  rspec (~> 3.9.0)
86
84
  rspec-its (~> 1.3.0)
data/README.md CHANGED
@@ -1,6 +1,11 @@
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)
1
+ pedump [![Build Status](https://travis-ci.org/zed-0xff/pedump.png?branch=master)](https://travis-ci.org/zed-0xff/pedump) [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/K3K81Z3W5)
2
2
  ======
3
3
 
4
+ News
5
+ ----
6
+ 2020.07.26 - now travis autotests run on ARM and OSX too!
7
+ 2020.07.25 - added EFI TE parsing; removed 'progressbar' gem dependency
8
+
4
9
  Description
5
10
  -----------
6
11
  A pure ruby implementation of win32 PE binary files dumper.
@@ -11,6 +16,7 @@ Supported formats:
11
16
  * win16 NE
12
17
  * win32 PE
13
18
  * win64 PE
19
+ * EFI TE
14
20
 
15
21
  Can dump:
16
22
 
@@ -50,6 +56,7 @@ Usage
50
56
  --rich
51
57
  --pe
52
58
  --ne
59
+ --te
53
60
  --data-directory
54
61
  -S, --sections
55
62
  --tls
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.6.0
@@ -17,6 +17,7 @@ require 'pedump/security'
17
17
  require 'pedump/packer'
18
18
  require 'pedump/ne'
19
19
  require 'pedump/ne/version_info'
20
+ require 'pedump/te'
20
21
 
21
22
  # pedump.rb by zed_0xff
22
23
  #
@@ -31,6 +32,7 @@ class PEdump
31
32
  MAX_IMAGE_IMPORT_DESCRIPTORS = 1000
32
33
  MAX_EXPORT_NUMBER_OF_NAMES = 16384 # got 7977 in http://pedump.me/03ad7400080678c6b1984f995d36fd04
33
34
  GOOD_FUNCTION_NAME_RE = /\A[\x21-\x7f]+\Z/
35
+ SUPPORTED_SIGNATURES = ['MZ', 'ZM', 'VZ']
34
36
 
35
37
  @@logger = nil
36
38
 
@@ -322,9 +324,9 @@ class PEdump
322
324
  @mz ||= f && MZ.read(f).tap do |mz|
323
325
  if mz.signature != 'MZ' && mz.signature != 'ZM'
324
326
  if @force
325
- logger.warn "[?] no MZ signature. want: 'MZ' or 'ZM', got: #{mz.signature.inspect}"
327
+ #logger.warn "[?] no MZ signature. want: 'MZ' or 'ZM', got: #{mz.signature.inspect}"
326
328
  else
327
- logger.error "[!] no MZ signature. want: 'MZ' or 'ZM', got: #{mz.signature.inspect}. (not forced)"
329
+ #logger.error "[!] no MZ signature. want: 'MZ' or 'ZM', got: #{mz.signature.inspect}. (not forced)"
328
330
  return nil
329
331
  end
330
332
  end
@@ -431,16 +433,22 @@ class PEdump
431
433
  end
432
434
 
433
435
  def _dump_handle h
434
- return unless pe(h) # also calls mz(h)
435
- rich_hdr h
436
- resources h
437
- imports h # also calls tls(h)
438
- exports h
439
- packer h
436
+ if pe(h) # also calls mz(h)
437
+ rich_hdr h
438
+ resources h
439
+ imports h # also calls tls(h)
440
+ exports h
441
+ packer h
442
+ elsif te(h)
443
+ end
440
444
  end
441
445
 
442
446
  def data_directory f=@io
443
- pe(f) && pe.ioh && pe.ioh.DataDirectory
447
+ if pe(f)
448
+ pe.ioh && pe.ioh.DataDirectory
449
+ elsif te(f)
450
+ te.DataDirectory
451
+ end
444
452
  end
445
453
 
446
454
  def sections f=@io
@@ -448,16 +456,52 @@ class PEdump
448
456
  pe.section_table
449
457
  elsif ne(f)
450
458
  ne.segments
459
+ elsif te(f)
460
+ te.sections
451
461
  end
452
462
  end
453
463
  alias :section_table :sections
454
464
 
455
- def ne?
456
- @pe ? false : (@ne ? true : (pe ? false : (ne ? true : false)))
465
+ def supported_file? f=@io
466
+ pos = f.tell
467
+ sig = f.read(2)
468
+ f.seek(pos)
469
+ if SUPPORTED_SIGNATURES.include?(sig)
470
+ true
471
+ else
472
+ unless @not_supported_sig_warned
473
+ msg = "no supported signature. want: #{SUPPORTED_SIGNATURES.join("/")}, got: #{sig.inspect}"
474
+ if @force
475
+ logger.warn "[?] #{msg}"
476
+ else
477
+ logger.error "[!] #{msg}. (not forced)"
478
+ end
479
+ @not_supported_sig_warned = true
480
+ end
481
+ false
482
+ end
483
+ end
484
+
485
+ def _detect_format
486
+ return :pe if @pe
487
+ return :ne if @ne
488
+ return :te if @te
489
+ return :pe if pe()
490
+ return :ne if ne()
491
+ return :te if te()
492
+ nil
457
493
  end
458
494
 
459
495
  def pe?
460
- @pe ? true : (@ne ? false : (pe ? true : false ))
496
+ _detect_format() == :pe
497
+ end
498
+
499
+ def ne?
500
+ _detect_format() == :ne
501
+ end
502
+
503
+ def te?
504
+ _detect_format() == :te
461
505
  end
462
506
 
463
507
  ##############################################################################
@@ -33,7 +33,7 @@ class PEdump::CLI
33
33
  attr_accessor :data, :argv
34
34
 
35
35
  KNOWN_ACTIONS = (
36
- %w'mz dos_stub rich pe ne data_directory sections tls security' +
36
+ %w'mz dos_stub rich pe ne te data_directory sections tls security' +
37
37
  %w'strings resources resource_directory imports exports version_info packer web console packer_only'
38
38
  ).map(&:to_sym)
39
39
 
@@ -135,7 +135,7 @@ class PEdump::CLI
135
135
  File.open(fname,'rb') do |f|
136
136
  @pedump = create_pedump fname
137
137
 
138
- next if !@options[:force] && !@pedump.mz(f)
138
+ next if !@options[:force] && !@pedump.supported_file?(f)
139
139
 
140
140
  @actions.each do |action|
141
141
  case action
@@ -194,16 +194,14 @@ class PEdump::CLI
194
194
  end
195
195
 
196
196
  class ProgressProxy
197
- attr_reader :pbar
198
-
199
- def initialize file
200
- @file = file
201
- @pbar = ProgressBar.new("[.] uploading", file.size, STDOUT)
202
- @pbar.try(:file_transfer_mode)
203
- @pbar.bar_mark = '='
197
+ def initialize file, prefix = "[.] uploading: ", io = STDOUT
198
+ @file = file
199
+ @io = io
200
+ @prefix = prefix
204
201
  end
205
202
  def read *args
206
- @pbar.inc args.first
203
+ @io.write("\r#{@prefix}#{@file.tell}/#{@file.size} ")
204
+ @io.flush
207
205
  @file.read *args
208
206
  end
209
207
  def method_missing *args
@@ -212,6 +210,10 @@ class PEdump::CLI
212
210
  def respond_to? *args
213
211
  @file.respond_to?(args.first) || super(*args)
214
212
  end
213
+
214
+ def finish!
215
+ @io.write("\r#{@prefix}#{@file.size}/#{@file.size} \n")
216
+ end
215
217
  end
216
218
 
217
219
  def upload f
@@ -224,7 +226,6 @@ class PEdump::CLI
224
226
  require 'open-uri'
225
227
  require 'net/http'
226
228
  require 'net/http/post/multipart'
227
- require 'progressbar'
228
229
 
229
230
  stdout_sync = STDOUT.sync
230
231
  STDOUT.sync = true
@@ -250,15 +251,15 @@ class PEdump::CLI
250
251
 
251
252
  f.rewind
252
253
 
253
- # upload with progressbar
254
+ # upload with progress
254
255
  post_url = URI.parse(URL_BASE+'/')
256
+ # UploadIO is from multipart-post
255
257
  uio = UploadIO.new(f, "application/octet-stream", File.basename(f.path))
256
258
  ppx = ProgressProxy.new(uio)
257
259
  req = Net::HTTP::Post::Multipart.new post_url.path, "file" => ppx
258
260
  res = Net::HTTP.start(post_url.host, post_url.port){ |http| http.request(req) }
259
- ppx.pbar.finish
261
+ ppx.finish!
260
262
 
261
- puts
262
263
  puts "[.] analyzing..."
263
264
 
264
265
  if (r=open(File.join(URL_BASE,md5,'analyze')).read) != "OK"
@@ -457,6 +458,8 @@ class PEdump::CLI
457
458
  case data.first
458
459
  when PEdump::IMAGE_DATA_DIRECTORY
459
460
  dump_data_dir data
461
+ when PEdump::EFI_IMAGE_DATA_DIRECTORY
462
+ dump_efi_data_dir data
460
463
  when PEdump::IMAGE_SECTION_HEADER
461
464
  dump_sections data
462
465
  when PEdump::Resource
@@ -781,13 +784,18 @@ class PEdump::CLI
781
784
  end
782
785
  end
783
786
 
784
-
785
787
  def dump_data_dir data
786
788
  data.each do |row|
787
789
  printf " %-12s rva:0x%8x size:0x %8x\n", row.type, row.va.to_i, row.size.to_i
788
790
  end
789
791
  end
790
792
 
793
+ def dump_efi_data_dir data
794
+ data.each_with_index do |row, idx|
795
+ printf " %-12s rva:0x%8x size:0x %8x\n", PEdump::EFI_IMAGE_DATA_DIRECTORY::TYPES[idx], row.va.to_i, row.size.to_i
796
+ end
797
+ end
798
+
791
799
  def dump_rich_hdr data
792
800
  if decoded = data.decode
793
801
  puts " LIB_ID VERSION TIMES_USED "
@@ -405,7 +405,7 @@ class PEdump
405
405
  begin
406
406
  ne_offset = mz(f) && mz(f).lfanew
407
407
  if ne_offset.nil?
408
- logger.fatal "[!] NULL NE offset (e_lfanew)."
408
+ logger.debug "[!] NULL NE offset (e_lfanew)."
409
409
  nil
410
410
  elsif ne_offset > f.size
411
411
  logger.fatal "[!] NE offset beyond EOF."
@@ -24,78 +24,87 @@ class PEdump
24
24
  signature + ifh.pack + ioh.pack
25
25
  end
26
26
 
27
- def self.read f, args = {}
27
+ def self.read_sections f, nToRead, args = {}
28
28
  force = args[:force]
29
29
 
30
+ if nToRead > 0xffff
31
+ if force.is_a?(Numeric) && force > 1
32
+ PEdump.logger.warn "[!] too many sections (#{nToRead}). forced. reading all"
33
+ else
34
+ PEdump.logger.warn "[!] too many sections (#{nToRead}). not forced, reading first 65535"
35
+ nToRead = 65535
36
+ end
37
+ end
38
+
39
+ sections = []
40
+ nToRead.times do
41
+ break if f.eof?
42
+ sections << IMAGE_SECTION_HEADER.read(f)
43
+ end
44
+
45
+ if sections.any?
46
+ # zero all missing values of last section
47
+ sections.last.tap do |last_section|
48
+ last_section.each_pair do |k,v|
49
+ last_section[k] = 0 if v.nil?
50
+ end
51
+ end
52
+ end
53
+
54
+ sections
55
+ end
56
+
57
+ def self.read f, args = {}
30
58
  pe_offset = f.tell
31
59
  pe_sig = f.read 4
32
60
  #logger.error "[!] 'NE' format is not supported!" if pe_sig == "NE\x00\x00"
33
61
  if pe_sig != "PE\x00\x00"
34
- if force
62
+ if args[:force]
35
63
  logger.warn "[?] no PE signature (want: 'PE\\x00\\x00', got: #{pe_sig.inspect})"
36
64
  else
37
65
  logger.debug "[?] no PE signature (want: 'PE\\x00\\x00', got: #{pe_sig.inspect}). (not forced)"
38
66
  return nil
39
67
  end
40
68
  end
41
- PE.new(pe_sig).tap do |pe|
42
- pe.image_file_header = IMAGE_FILE_HEADER.read(f)
43
- ioh_offset = f.tell # offset to IMAGE_OPTIONAL_HEADER
44
- if pe.ifh.SizeOfOptionalHeader.to_i > 0
45
- if pe.x64?
46
- pe.image_optional_header = IMAGE_OPTIONAL_HEADER64.read(f, pe.ifh.SizeOfOptionalHeader)
47
- else
48
- pe.image_optional_header = IMAGE_OPTIONAL_HEADER32.read(f, pe.ifh.SizeOfOptionalHeader)
49
- end
69
+ pe = PE.new(pe_sig)
70
+ pe.image_file_header = IMAGE_FILE_HEADER.read(f)
71
+ ioh_offset = f.tell # offset to IMAGE_OPTIONAL_HEADER
72
+ if pe.ifh.SizeOfOptionalHeader.to_i > 0
73
+ if pe.x64?
74
+ pe.image_optional_header = IMAGE_OPTIONAL_HEADER64.read(f, pe.ifh.SizeOfOptionalHeader)
75
+ else
76
+ pe.image_optional_header = IMAGE_OPTIONAL_HEADER32.read(f, pe.ifh.SizeOfOptionalHeader)
50
77
  end
78
+ end
51
79
 
52
- if (nToRead=pe.ifh.NumberOfSections.to_i) > 0xffff
53
- if force.is_a?(Numeric) && force > 1
54
- logger.warn "[!] too many sections (#{pe.ifh.NumberOfSections}). forced. reading all"
55
- else
56
- logger.warn "[!] too many sections (#{pe.ifh.NumberOfSections}). not forced, reading first 65535"
57
- nToRead = 65535
58
- end
59
- end
80
+ nToRead=pe.ifh.NumberOfSections.to_i
60
81
 
61
- # The Windows loader expects to find the PE section headers after the optional header. It calculates the address of the first section header by adding SizeOfOptionalHeader to the beginning of the optional header.
62
- # // http://www.phreedom.org/research/tinype/
63
- f.seek( ioh_offset + pe.ifh.SizeOfOptionalHeader.to_i )
64
- pe.sections = []
65
- nToRead.times do
66
- break if f.eof?
67
- pe.sections << IMAGE_SECTION_HEADER.read(f)
68
- end
82
+ # The Windows loader expects to find the PE section headers after the optional header. It calculates the address of the first section header by adding SizeOfOptionalHeader to the beginning of the optional header.
83
+ # // http://www.phreedom.org/research/tinype/
84
+ f.seek( ioh_offset + pe.ifh.SizeOfOptionalHeader.to_i )
85
+ pe.sections = read_sections(f, nToRead, args)
69
86
 
70
- if pe.sections.any?
71
- # zero all missing values of last section
72
- pe.sections.last.tap do |last_section|
73
- last_section.each_pair do |k,v|
74
- last_section[k] = 0 if v.nil?
75
- end
76
- end
77
- end
87
+ pe_end = f.tell
88
+ if s=pe.sections.find{ |s| (pe_offset...pe_end).include?(s.va) }
89
+ if args[:pass2]
90
+ # already called with CompositeIO ?
91
+ PEdump.logger.error "[!] section with va=0x#{s.va.to_s(16)} overwrites PE header! 2nd time?!"
78
92
 
79
- pe_end = f.tell
80
- if s=pe.sections.find{ |s| (pe_offset...pe_end).include?(s.va) }
81
- if args[:pass2]
82
- # already called with CompositeIO ?
83
- logger.error "[!] section with va=0x#{s.va.to_s(16)} overwrites PE header! 2nd time?!"
84
-
85
- elsif pe_end-pe_offset < 0x100_000
86
- logger.warn "[!] section with va=0x#{s.va.to_s(16)} overwrites PE header! trying to rebuild..."
87
- f.seek pe_offset
88
- data = f.read(s.va-pe_offset)
89
- f.seek s.PointerToRawData
90
- io = CompositeIO.new(StringIO.new(data), f)
91
- args1 = args.dup
92
- args1[:pass2] = true
93
- return PE.read(io, args1)
94
- else
95
- logger.error "[!] section with va=0x#{s.va.to_s(16)} overwrites PE header! too big to rebuild!"
96
- end
93
+ elsif pe_end-pe_offset < 0x100_000
94
+ PEdump.logger.warn "[!] section with va=0x#{s.va.to_s(16)} overwrites PE header! trying to rebuild..."
95
+ f.seek pe_offset
96
+ data = f.read(s.va-pe_offset)
97
+ f.seek s.PointerToRawData
98
+ io = CompositeIO.new(StringIO.new(data), f)
99
+ args1 = args.dup
100
+ args1[:pass2] = true
101
+ return PE.read(io, args1)
102
+ else
103
+ PEdump.logger.error "[!] section with va=0x#{s.va.to_s(16)} overwrites PE header! too big to rebuild!"
97
104
  end
98
105
  end
106
+
107
+ pe
99
108
  end
100
109
 
101
110
  def self.logger; PEdump.logger; end
@@ -106,7 +115,7 @@ class PEdump
106
115
  begin
107
116
  pe_offset = mz(f) && mz(f).lfanew
108
117
  if pe_offset.nil?
109
- logger.fatal "[!] NULL PE offset (e_lfanew). cannot continue."
118
+ logger.debug "[!] NULL PE offset (e_lfanew). cannot continue."
110
119
  nil
111
120
  elsif pe_offset > f.size
112
121
  logger.fatal "[!] PE offset beyond EOF. cannot continue."
@@ -0,0 +1,51 @@
1
+ class PEdump
2
+ # https://www.intel.com/content/www/us/en/architecture-and-technology/unified-extensible-firmware-interface/efi-specifications-general-technology.html
3
+ # http://wiki.phoenix.com/wiki/index.php/EFI_TE_IMAGE_HEADER
4
+ # https://formats.kaitai.io/uefi_te/index.html
5
+ # http://ho.ax/tag/efi/
6
+
7
+ class EFI_TE_IMAGE_HEADER < IOStruct.new 'vvCCvVVQ',
8
+ :Signature,
9
+ :Machine,
10
+ :NumberOfSections,
11
+ :Subsystem,
12
+ :StrippedSize,
13
+ :AddressOfEntryPoint,
14
+ :BaseOfCode,
15
+ :ImageBase,
16
+ :DataDirectory # readed manually: EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]
17
+
18
+ attr_accessor :sections
19
+
20
+ def self.read io, args = {}
21
+ super(io).tap do |te|
22
+ te.DataDirectory = 2.times.map do
23
+ EFI_IMAGE_DATA_DIRECTORY.read(io)
24
+ end
25
+ te.sections = PE.read_sections(io, te.NumberOfSections, args)
26
+ end
27
+ end
28
+ end
29
+ TE = EFI_TE_IMAGE_HEADER
30
+
31
+ EFI_IMAGE_DATA_DIRECTORY = IOStruct.new( "VV", :va, :size )
32
+ EFI_IMAGE_DATA_DIRECTORY::TYPES = %w'BASERELOC DEBUG'
33
+ EFI_IMAGE_DATA_DIRECTORY::TYPES.each_with_index do |type,idx|
34
+ EFI_IMAGE_DATA_DIRECTORY.const_set(type,idx)
35
+ end
36
+
37
+ def te f=@io
38
+ return @te if defined?(@te)
39
+ @te ||=
40
+ begin
41
+ te_offset = 0
42
+ f.seek te_offset
43
+ if f.read(2) == 'VZ'
44
+ f.seek te_offset
45
+ EFI_TE_IMAGE_HEADER.read f, :force => @force
46
+ else
47
+ nil
48
+ end
49
+ end
50
+ end
51
+ end
@@ -30,6 +30,7 @@ int unpack(BYTE*packed_data, size_t packed_size, size_t unpacked_size){
30
30
  LZX_CONTEXT LZX;
31
31
  BYTE* unpacked_data = NULL;
32
32
  size_t decoded_size;
33
+ int r;
33
34
 
34
35
  bzero(&LZX, sizeof(LZX));
35
36
 
@@ -38,8 +39,9 @@ int unpack(BYTE*packed_data, size_t packed_size, size_t unpacked_size){
38
39
  return(ERR_NO_MEM);
39
40
  }
40
41
 
41
- decoded_size = DecodeLZX(&LZX, packed_data, unpacked_data, packed_size, unpacked_size);
42
- if ( decoded_size < 0 || decoded_size < unpacked_size ) {
42
+ r = DecodeLZX(&LZX, packed_data, unpacked_data, packed_size, unpacked_size);
43
+ decoded_size = (size_t)r;
44
+ if ( r < 0 || decoded_size < unpacked_size ) {
43
45
  free(unpacked_data);
44
46
  fprintf(stderr,"ERR_UNPACK\n");
45
47
  return(ERR_UNPACK);
@@ -58,7 +60,7 @@ int main(int argc, char*argv[]){
58
60
  if(argc != 3){
59
61
  fprintf(stderr, "ASPack unLZX\n");
60
62
  fprintf(stderr, "usage: %s <packed_size> <unpacked_size>\n", argv[0]);
61
- fprintf(stderr, "(data is read from stdin and written to stdout)\n", argv[0]);
63
+ fprintf(stderr, "(data is read from stdin and written to stdout)\n");
62
64
  return 1;
63
65
  }
64
66
 
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: pedump 0.5.4 ruby lib
5
+ # stub: pedump 0.6.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "pedump".freeze
9
- s.version = "0.5.4"
9
+ s.version = "0.6.0"
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-01-25"
14
+ s.date = "2020-07-27"
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,6 +20,9 @@ Gem::Specification.new do |s|
20
20
  "README.md"
21
21
  ]
22
22
  s.files = [
23
+ ".github/FUNDING.yml",
24
+ ".github/dependabot.yml",
25
+ "CODE_OF_CONDUCT.md",
23
26
  "Gemfile",
24
27
  "Gemfile.lock",
25
28
  "LICENSE.txt",
@@ -49,6 +52,7 @@ Gem::Specification.new do |s|
49
52
  "lib/pedump/resources.rb",
50
53
  "lib/pedump/security.rb",
51
54
  "lib/pedump/sig_parser.rb",
55
+ "lib/pedump/te.rb",
52
56
  "lib/pedump/tls.rb",
53
57
  "lib/pedump/unpacker.rb",
54
58
  "lib/pedump/unpacker/aspack.rb",
@@ -75,7 +79,6 @@ Gem::Specification.new do |s|
75
79
  s.add_runtime_dependency(%q<awesome_print>.freeze, [">= 0"])
76
80
  s.add_runtime_dependency(%q<iostruct>.freeze, [">= 0.0.4"])
77
81
  s.add_runtime_dependency(%q<multipart-post>.freeze, [">= 2.0.0"])
78
- s.add_runtime_dependency(%q<progressbar>.freeze, [">= 0"])
79
82
  s.add_runtime_dependency(%q<zhexdump>.freeze, [">= 0.0.2"])
80
83
  s.add_development_dependency(%q<rspec>.freeze, ["~> 3.9.0"])
81
84
  s.add_development_dependency(%q<rspec-its>.freeze, ["~> 1.3.0"])
@@ -86,7 +89,6 @@ Gem::Specification.new do |s|
86
89
  s.add_dependency(%q<awesome_print>.freeze, [">= 0"])
87
90
  s.add_dependency(%q<iostruct>.freeze, [">= 0.0.4"])
88
91
  s.add_dependency(%q<multipart-post>.freeze, [">= 2.0.0"])
89
- s.add_dependency(%q<progressbar>.freeze, [">= 0"])
90
92
  s.add_dependency(%q<zhexdump>.freeze, [">= 0.0.2"])
91
93
  s.add_dependency(%q<rspec>.freeze, ["~> 3.9.0"])
92
94
  s.add_dependency(%q<rspec-its>.freeze, ["~> 1.3.0"])
@@ -98,7 +100,6 @@ Gem::Specification.new do |s|
98
100
  s.add_dependency(%q<awesome_print>.freeze, [">= 0"])
99
101
  s.add_dependency(%q<iostruct>.freeze, [">= 0.0.4"])
100
102
  s.add_dependency(%q<multipart-post>.freeze, [">= 2.0.0"])
101
- s.add_dependency(%q<progressbar>.freeze, [">= 0"])
102
103
  s.add_dependency(%q<zhexdump>.freeze, [">= 0.0.2"])
103
104
  s.add_dependency(%q<rspec>.freeze, ["~> 3.9.0"])
104
105
  s.add_dependency(%q<rspec-its>.freeze, ["~> 1.3.0"])
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.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "Zed" Zaikin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-25 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.0.0
69
- - !ruby/object:Gem::Dependency
70
- name: progressbar
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: zhexdump
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +145,9 @@ extra_rdoc_files:
159
145
  - LICENSE.txt
160
146
  - README.md
161
147
  files:
148
+ - ".github/FUNDING.yml"
149
+ - ".github/dependabot.yml"
150
+ - CODE_OF_CONDUCT.md
162
151
  - Gemfile
163
152
  - Gemfile.lock
164
153
  - LICENSE.txt
@@ -188,6 +177,7 @@ files:
188
177
  - lib/pedump/resources.rb
189
178
  - lib/pedump/security.rb
190
179
  - lib/pedump/sig_parser.rb
180
+ - lib/pedump/te.rb
191
181
  - lib/pedump/tls.rb
192
182
  - lib/pedump/unpacker.rb
193
183
  - lib/pedump/unpacker/aspack.rb