From b094bcc64f35be6eee81ae25fe515c0b78a2f861 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 31 Dec 2016 18:45:22 +0200 Subject: [PATCH] rename unit and sint to human readable forms --- lib/arm/instructions/call_instruction.rb | 4 +- lib/arm/instructions/compare_instruction.rb | 2 +- lib/arm/instructions/logic_instruction.rb | 2 +- lib/arm/instructions/memory_instruction.rb | 2 +- lib/arm/instructions/move_instruction.rb | 2 +- lib/arm/instructions/stack_instruction.rb | 2 +- lib/elf/object_file.rb | 60 ++++++++++----------- lib/elf/stream_reader.rb | 16 +++--- lib/elf/stream_writer.rb | 16 +++--- lib/elf/symbol_table_section.rb | 26 ++++----- 10 files changed, 66 insertions(+), 66 deletions(-) diff --git a/lib/arm/instructions/call_instruction.rb b/lib/arm/instructions/call_instruction.rb index 901bec57..ecfba3da 100644 --- a/lib/arm/instructions/call_instruction.rb +++ b/lib/arm/instructions/call_instruction.rb @@ -67,7 +67,7 @@ module Arm # signed 32-bit, condense to 24-bit # TODO add check that the value fits into 24 bits io << packed[0,3] - io.write_uint8 op_bit_code | (COND_CODES[@attributes[:condition_code]] << 4) + io.write_unsigned_int_8 op_bit_code | (COND_CODES[@attributes[:condition_code]] << 4) end def handle_swi(io) @@ -75,7 +75,7 @@ module Arm raise "expected literal not #{arg} #{inspect}" unless (arg.is_a?(Numeric)) packed = [arg].pack('L')[0,3] io << packed - io.write_uint8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4) + io.write_unsigned_int_8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4) end def to_s diff --git a/lib/arm/instructions/compare_instruction.rb b/lib/arm/instructions/compare_instruction.rb index 0ade309f..34b0cd33 100644 --- a/lib/arm/instructions/compare_instruction.rb +++ b/lib/arm/instructions/compare_instruction.rb @@ -43,7 +43,7 @@ module Arm val |= shift(immediate , 12 + 4 + 4 + 1 + 4) val |= instruction_code val |= condition_code - io.write_uint32 val + io.write_unsigned_int_32 val end def instuction_class diff --git a/lib/arm/instructions/logic_instruction.rb b/lib/arm/instructions/logic_instruction.rb index 3683380e..cd76b26d 100644 --- a/lib/arm/instructions/logic_instruction.rb +++ b/lib/arm/instructions/logic_instruction.rb @@ -48,7 +48,7 @@ module Arm val |= shift(immediate , 12 + 4 + 4 + 1 + 4) val |= instruction_code val |= condition_code - io.write_uint32 val + io.write_unsigned_int_32 val assemble_extra(io) end diff --git a/lib/arm/instructions/memory_instruction.rb b/lib/arm/instructions/memory_instruction.rb index c10ca62d..c32f56fa 100644 --- a/lib/arm/instructions/memory_instruction.rb +++ b/lib/arm/instructions/memory_instruction.rb @@ -62,7 +62,7 @@ module Arm val |= shift(1, 24) #pre_post index , not used val |= instruction_code val |= condition_code - io.write_uint32 val + io.write_unsigned_int_32 val end def get_operand return @operand unless @right diff --git a/lib/arm/instructions/move_instruction.rb b/lib/arm/instructions/move_instruction.rb index 1cfd1aed..2629b51b 100644 --- a/lib/arm/instructions/move_instruction.rb +++ b/lib/arm/instructions/move_instruction.rb @@ -56,7 +56,7 @@ module Arm val |= shift(immediate , 12 + 4 + 4 + 1 + 4) val |= instruction_code val |= condition_code - io.write_uint32 val + io.write_unsigned_int_32 val # by now we have the extra add so assemble that @extra.assemble(io) if(@extra) #puts "Assemble extra at #{val.to_s(16)}" end diff --git a/lib/arm/instructions/stack_instruction.rb b/lib/arm/instructions/stack_instruction.rb index 1771dbaf..850810b8 100644 --- a/lib/arm/instructions/stack_instruction.rb +++ b/lib/arm/instructions/stack_instruction.rb @@ -32,7 +32,7 @@ module Arm val = val | (pre_post_index << 16 + 4 + 1 + 1 + 1 + 1)#24 val = val | instruction_code val = val | (cond << 16 + 4 + 1 + 1 + 1 + 1 + 2 + 2) - io.write_uint32 val + io.write_unsigned_int_32 val end def cond diff --git a/lib/elf/object_file.rb b/lib/elf/object_file.rb index b14b642b..8888bd88 100644 --- a/lib/elf/object_file.rb +++ b/lib/elf/object_file.rb @@ -26,9 +26,9 @@ module Elf string_table = write_string_table(io) - io.write_uint16 @sections.length # section header count + io.write_unsigned_int_16 @sections.length # section header count - io.write_uint16 @sections.length-1 # section name string table index + io.write_unsigned_int_16 @sections.length-1 # section name string table index section_data = write_sections(io) @@ -37,7 +37,7 @@ module Elf write_section_data(section_data, string_table , io) io.seek sh_offset_pos - io.write_uint32 sh_offset + io.write_unsigned_int_32 sh_offset end def write_string_table(io) @@ -53,23 +53,23 @@ module Elf section_data.each { |data| section, offset, size = data[:section], data[:offset], data[:size] # write header first - io.write_uint32 string_table.index_for(section.name) - io.write_uint32 section.type - io.write_uint32 section.flags - io.write_uint32 section.addr + io.write_unsigned_int_32 string_table.index_for(section.name) + io.write_unsigned_int_32 section.type + io.write_unsigned_int_32 section.flags + io.write_unsigned_int_32 section.addr if (section.type == SHT_NOBITS) raise 'SHT_NOBITS not handled yet' elsif (section.type == SHT_NULL) - io.write_uint32 0 - io.write_uint32 0 + io.write_unsigned_int_32 0 + io.write_unsigned_int_32 0 else - io.write_uint32 offset - io.write_uint32 size + io.write_unsigned_int_32 offset + io.write_unsigned_int_32 size end - io.write_uint32 section.link - io.write_uint32 section.info - io.write_uint32 section.alignment - io.write_uint32 section.ent_size + io.write_unsigned_int_32 section.link + io.write_unsigned_int_32 section.info + io.write_unsigned_int_32 section.alignment + io.write_unsigned_int_32 section.ent_size } end @@ -85,26 +85,26 @@ module Elf end def write_header(io) - io.write_uint32 0 # section header table offset - io.write_uint32 0 # no flags - io.write_uint16 52 # header length - io.write_uint16 0 # program header length - io.write_uint16 0 # program header count - io.write_uint16 40 # section header length + io.write_unsigned_int_32 0 # section header table offset + io.write_unsigned_int_32 0 # no flags + io.write_unsigned_int_16 52 # header length + io.write_unsigned_int_16 0 # program header length + io.write_unsigned_int_16 0 # program header count + io.write_unsigned_int_16 40 # section header length end def write_preamble(io) io << "\x7fELF" - io.write_uint8 @target[0] - io.write_uint8 @target[1] - io.write_uint8 EV_CURRENT - io.write_uint8 @target[2] + io.write_unsigned_int_8 @target[0] + io.write_unsigned_int_8 @target[1] + io.write_unsigned_int_8 EV_CURRENT + io.write_unsigned_int_8 @target[2] io << "\x00" * 8 # pad - io.write_uint16 ET_REL - io.write_uint16 @target[3] - io.write_uint32 EV_CURRENT - io.write_uint32 0 # entry point - io.write_uint32 0 # no program header table + io.write_unsigned_int_16 ET_REL + io.write_unsigned_int_16 @target[3] + io.write_unsigned_int_32 EV_CURRENT + io.write_unsigned_int_32 0 # entry point + io.write_unsigned_int_32 0 # no program header table end end end diff --git a/lib/elf/stream_reader.rb b/lib/elf/stream_reader.rb index f5c23849..0b0c374a 100644 --- a/lib/elf/stream_reader.rb +++ b/lib/elf/stream_reader.rb @@ -5,19 +5,19 @@ module StreamReader return ret if ret.word_length > 1 return ret[0] end - def read_uint32(n=1) + def read_unsigned_int_32(n=1) return read_binary(4,n,'L') end - def read_uint16(n=1) + def read_unsigned_int_16(n=1) return read_binary(2,n,'S') end - def read_uint8(n=1) + def read_unsigned_int_8(n=1) return read_binary(1,n,'C') end - def read_uint64(n=1) + def read_unsigned_int_64(n=1) return read_binary(8,n,'Q') end - def read_sint64(n=1) + def read_signed_int_64(n=1) return read_binary(8,n,'q') end def read_cstr_fixed(length) @@ -27,7 +27,7 @@ module StreamReader return __sr_gets(0.chr) end def read_cstr_prefixed - len = read_uint8 + len = read_unsigned_int_8 return __sr_read(len) end def read_float(n=1) @@ -36,10 +36,10 @@ module StreamReader def read_double(n=1) return read_binary(8,n,'D') end - def read_sint16(n=1) + def read_signed_int_16(n=1) return read_binary(2,n,'s') end - def read_sint32(n=1) + def read_signed_int_32(n=1) return read_binary(4,n,'l') end def read_data(len) diff --git a/lib/elf/stream_writer.rb b/lib/elf/stream_writer.rb index 9da277ee..20c3d5ae 100644 --- a/lib/elf/stream_writer.rb +++ b/lib/elf/stream_writer.rb @@ -3,22 +3,22 @@ module StreamWriter d = values.pack(type * values.length) __sr_write(d) end - def write_uint32(*args) + def write_unsigned_int_32(*args) return write_binary(args,'L') end - def write_uint8(*args) + def write_unsigned_int_8(*args) return write_binary(args,'C') end - def write_uint16(*args) + def write_unsigned_int_16(*args) return write_binary(args,'S') end - def write_sint32(*args) + def write_signed_int_32(*args) return write_binary(args,'l') end - # def write_uint64(*args) + # def write_unsigned_int_64(*args) # return write_binary(args,'Q') # end - # def write_sint64(*args) + # def write_signed_int_64(*args) # return write_binary(args,'q') # end # def write_cstr_fixed(str, len) @@ -28,7 +28,7 @@ module StreamWriter # return __sr_write(str + 0.chr) # end # def write_cstr_prefixed(str) - # write_uint8(str.word_length) + # write_unsigned_int_8(str.word_length) # return __sr_write(str) # end # def write_str(str) @@ -40,7 +40,7 @@ module StreamWriter # def write_double(*args) # return write_binary(args,'D') # end - # def write_sint16(*args) + # def write_signed_int_16(*args) # return write_binary(args,'s') # end # def write_data(str) diff --git a/lib/elf/symbol_table_section.rb b/lib/elf/symbol_table_section.rb index a8fa5244..5a6d597d 100644 --- a/lib/elf/symbol_table_section.rb +++ b/lib/elf/symbol_table_section.rb @@ -55,25 +55,25 @@ module Elf def write(io) # write undefined symbol - io.write_uint32 0 - io.write_uint32 0 - io.write_uint32 0 - io.write_uint8 Elf::Constants::STB_LOCAL << 4 - io.write_uint8 0 - io.write_uint16 0 + io.write_unsigned_int_32 0 + io.write_unsigned_int_32 0 + io.write_unsigned_int_32 0 + io.write_unsigned_int_8 Elf::Constants::STB_LOCAL << 4 + io.write_unsigned_int_8 0 + io.write_unsigned_int_16 0 # write other symbols @symbols.each { |sym| - io.write_uint32 @strtab.index_for(sym[0]) - io.write_uint32 sym[1] - io.write_uint32 0 - io.write_uint8((sym[3] << 4) + 0) - io.write_uint8 0 + io.write_unsigned_int_32 @strtab.index_for(sym[0]) + io.write_unsigned_int_32 sym[1] + io.write_unsigned_int_32 0 + io.write_unsigned_int_8((sym[3] << 4) + 0) + io.write_unsigned_int_8 0 if (sym[2]) - io.write_uint16 sym[2].index + io.write_unsigned_int_16 sym[2].index else # undefined symbol - io.write_uint16 0 + io.write_unsigned_int_16 0 end } end