@@ -655,11 +655,16 @@ def self.replace_msi_buffer(pe, opts)
655
655
}
656
656
657
657
section_size = 2 **( msi [ 30 ..31 ] . unpack ( 'v' ) [ 0 ] )
658
- sector_allocation_table = msi [ section_size ..section_size *2 ] . unpack ( 'V*' )
658
+
659
+ # This table is one of the few cases where signed values are needed
660
+ sector_allocation_table = msi [ section_size ..section_size *2 ] . unpack ( 'l<*' )
659
661
660
662
buffer_chain = [ ]
661
- current_secid = 5 # This is closely coupled with the template provided and ideally
662
- # would be calculated from the dir stream?
663
+
664
+ # This is closely coupled with the template provided and ideally
665
+ # would be calculated from the dir stream?
666
+ current_secid = 5
667
+
663
668
664
669
until current_secid == -2
665
670
buffer_chain << current_secid
@@ -827,16 +832,16 @@ def self.to_exe_elf(framework, opts, template, code, big_endian=false)
827
832
828
833
# Check EI_CLASS to determine if the header is 32 or 64 bit
829
834
# Use the proper offsets and pack size
830
- case elf [ 4 ]
831
- when 1 , " \x01 " # ELFCLASS32 - 32 bit (ruby 1.8 and 1.9 )
835
+ case elf [ 4 , 1 ] . unpack ( "C" ) . first
836
+ when 1 # ELFCLASS32 - 32 bit (ruby 1.9+ )
832
837
if big_endian
833
838
elf [ 0x44 , 4 ] = [ elf . length ] . pack ( 'N' ) #p_filesz
834
839
elf [ 0x48 , 4 ] = [ elf . length + code . length ] . pack ( 'N' ) #p_memsz
835
840
else # little endian
836
841
elf [ 0x44 , 4 ] = [ elf . length ] . pack ( 'V' ) #p_filesz
837
842
elf [ 0x48 , 4 ] = [ elf . length + code . length ] . pack ( 'V' ) #p_memsz
838
843
end
839
- when 2 , " \x02 " # ELFCLASS64 - 64 bit (ruby 1.8 and 1.9 )
844
+ when 2 # ELFCLASS64 - 64 bit (ruby 1.9+ )
840
845
if big_endian
841
846
elf [ 0x60 , 8 ] = [ elf . length ] . pack ( 'Q>' ) #p_filesz
842
847
elf [ 0x68 , 8 ] = [ elf . length + code . length ] . pack ( 'Q>' ) #p_memsz
0 commit comments