Class: Exerb::Executable
- Inherits:
-
Object
- Object
- Exerb::Executable
- Defined in:
- lib/exerb/executable.rb
Overview
#
Instance Attribute Summary collapse
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#rsrc ⇒ Object
Returns the value of attribute rsrc.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(core) ⇒ Executable
constructor
A new instance of Executable.
- #pack ⇒ Object
- #write(output) ⇒ Object
Constructor Details
#initialize(core) ⇒ Executable
Returns a new instance of Executable.
23 24 25 26 |
# File 'lib/exerb/executable.rb', line 23 def initialize(core) @core = core @rsrc = Exerb::Resource.new_from_pe_binary(@core) end |
Instance Attribute Details
#core ⇒ Object (readonly)
Returns the value of attribute core.
28 29 30 |
# File 'lib/exerb/executable.rb', line 28 def core @core end |
#rsrc ⇒ Object
Returns the value of attribute rsrc.
29 30 31 |
# File 'lib/exerb/executable.rb', line 29 def rsrc @rsrc end |
Class Method Details
Instance Method Details
#pack ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/exerb/executable.rb', line 35 def pack pe = Exerb::Win32::PeFile.new_from_binary(@core) fh = pe.nt_headers.file_header oh = pe.nt_headers.optional_header rsh = pe.sections.last raise(Exerb::ExerbError, "the last section must be resource section") unless rsh.name == '.rsrc' packed_rsrc = @rsrc.pack(rsh.virtual_address) aligned_rsrc = Exerb::Utility.alignment(packed_rsrc, oh.file_alignment) old_resource_size = Exerb::Utility.align_value(rsh.virtual_size, oh.section_alignment) new_resource_size = Exerb::Utility.align_value(packed_rsrc.size, oh.section_alignment) @core[rsh.pointer_to_raw_data, rsh.size_of_raw_data] = aligned_rsrc fh.time_date_stamp = Time.now.to_i oh.size_of_initialized_data = oh.size_of_initialized_data - rsh.size_of_raw_data + aligned_rsrc.size oh.size_of_image = oh.size_of_image - old_resource_size + new_resource_size oh.resource_directory_virtual_size = packed_rsrc.size rsh.virtual_size = packed_rsrc.size rsh.size_of_raw_data = aligned_rsrc.size fh.update(@core) oh.update(@core) rsh.update(@core) return Exerb::Utility.alignment16(@core) end |