Skip to content

Commit

Permalink
add test for null section symtab
Browse files Browse the repository at this point in the history
  • Loading branch information
katsyoshi committed Mar 11, 2024
1 parent ce320e5 commit ea9d844
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/vaporware/compiler/assembler/elf/section/symtab.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
class Vaporware::Compiler::Assembler::ELF::Section::Symtab
include Vaporware::Compiler::Assembler::ELF::Utils
def initialize(name: 0, info: 0, other: 0, shndx: 0, value: 0, size: 0)
@name = num2bytes(name, 4)
@info = num2bytes(info, 1)
@other = num2bytes(other, 1)
@shndx = num2bytes(shndx, 4)
@value = num2bytes(value, 8)
@size = num2bytes(size, 8)
def initialize
@name = num2bytes(0, 4)
@info = num2bytes(0, 1)
@other = num2bytes(0, 1)
@shndx = num2bytes(0, 2)
@value = num2bytes(0, 8)
@size = num2bytes(0, 8)
end

def build = bytes.flatten.pack("C*")

def set!(name: nil, info: nil, other: nil, shndx: nil, value: nil, size: nil)
@name = num2bytes(name, 4) if check(name, 4)
@info = num2bytes(info, 1) if check(info, 4)
Expand All @@ -19,4 +17,7 @@ def set!(name: nil, info: nil, other: nil, shndx: nil, value: nil, size: nil)
@value = num2bytes(value, 8) if check(value, 8)
@size = num2bytes(size, 8) if check(size, 8)
end

private
def bytes = [@name, @info, @other, @shndx, @value, @size]
end
10 changes: 10 additions & 0 deletions test/vaporware/compiler/assembler/elf/section/test_symtab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "vaporware"
require "test/unit"

class Vaporware::Compiler::Assembler::ELF::Section::TestSymtab < Test::Unit::TestCase
def setup = @symtab = Vaporware::Compiler::Assembler::ELF::Section::Symtab.new
def test_set_values
binary = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x10\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".force_encoding("ASCII-8BIT")
assert_equal(@symtab.build.size, binary.size)
end
end

0 comments on commit ea9d844

Please sign in to comment.