Skip to content

Commit

Permalink
Improve ELF parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Apr 26, 2023
1 parent 3b7b5e3 commit 0bdf097
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions lib/sass/embedded/elf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,32 +223,35 @@ def read_phdr
end
end

def read1(type)
def explicit_endian
case data_encoding
when ELFDATA2LSB
case type
when :__u16
@buffer.read(2).unpack1('v*')
when :__u32
@buffer.read(4).unpack1('V*')
when :__u64
buffer = @buffer.read(8).unpack('V*')
(buffer[1] << 32) | buffer[0]
else
raise ArgumentError
end
'<'
when ELFDATA2MSB
case type
when :__u16
@buffer.read(2).unpack1('n*')
when :__u32
@buffer.read(4).unpack1('N*')
when :__u64
buffer = @buffer.read(8).unpack('N*')
(buffer[0] << 32) | buffer[1]
else
raise ArgumentError
end
'>'
else
raise ArgumentError
end
end

def read1(type)
case type
when :__u8
@buffer.read(1).unpack1('C')
when :__u16
@buffer.read(2).unpack1("S#{explicit_endian}")
when :__u32
@buffer.read(4).unpack1("L#{explicit_endian}")
when :__u64
@buffer.read(8).unpack1("Q#{explicit_endian}")
when :__s8
@buffer.read(1).unpack1('c')
when :__s16
@buffer.read(2).unpack1("s#{explicit_endian}")
when :__s32
@buffer.read(4).unpack1("l#{explicit_endian}")
when :__s64
@buffer.read(8).unpack1("q#{explicit_endian}")
else
raise ArgumentError
end
Expand Down

0 comments on commit 0bdf097

Please sign in to comment.