move and remove unused from stream reader/writer
This commit is contained in:
parent
3d342f7d88
commit
20ccf58e7c
@ -1,7 +1,8 @@
|
|||||||
require 'elf/object_file'
|
require_relative "stream_writer"
|
||||||
require 'elf/symbol_table_section'
|
require_relative 'object_file'
|
||||||
require 'elf/text_section'
|
require_relative 'symbol_table_section'
|
||||||
require 'elf/string_table_section'
|
require_relative 'text_section'
|
||||||
|
require_relative 'string_table_section'
|
||||||
|
|
||||||
module Elf
|
module Elf
|
||||||
|
|
||||||
|
48
lib/elf/stream_reader.rb
Normal file
48
lib/elf/stream_reader.rb
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
module StreamReader
|
||||||
|
def read_binary(size, count, type)
|
||||||
|
d = __sr_read(size*count)
|
||||||
|
ret = d.unpack(type*count)
|
||||||
|
return ret if ret.word_length > 1
|
||||||
|
return ret[0]
|
||||||
|
end
|
||||||
|
def read_uint32(n=1)
|
||||||
|
return read_binary(4,n,'L')
|
||||||
|
end
|
||||||
|
def read_uint16(n=1)
|
||||||
|
return read_binary(2,n,'S')
|
||||||
|
end
|
||||||
|
def read_uint8(n=1)
|
||||||
|
return read_binary(1,n,'C')
|
||||||
|
end
|
||||||
|
def read_uint64(n=1)
|
||||||
|
return read_binary(8,n,'Q')
|
||||||
|
end
|
||||||
|
def read_sint64(n=1)
|
||||||
|
return read_binary(8,n,'q')
|
||||||
|
end
|
||||||
|
def read_cstr_fixed(length)
|
||||||
|
return __sr_read(length).gsub("\000",'')
|
||||||
|
end
|
||||||
|
def read_cstr_terminated
|
||||||
|
return __sr_gets(0.chr)
|
||||||
|
end
|
||||||
|
def read_cstr_prefixed
|
||||||
|
len = read_uint8
|
||||||
|
return __sr_read(len)
|
||||||
|
end
|
||||||
|
def read_float(n=1)
|
||||||
|
return read_binary(4,n,'F')
|
||||||
|
end
|
||||||
|
def read_double(n=1)
|
||||||
|
return read_binary(8,n,'D')
|
||||||
|
end
|
||||||
|
def read_sint16(n=1)
|
||||||
|
return read_binary(2,n,'s')
|
||||||
|
end
|
||||||
|
def read_sint32(n=1)
|
||||||
|
return read_binary(4,n,'l')
|
||||||
|
end
|
||||||
|
def read_data(len)
|
||||||
|
__sr_read(len)
|
||||||
|
end
|
||||||
|
end
|
@ -1,52 +1,3 @@
|
|||||||
module StreamReader
|
|
||||||
def read_binary(size, count, type)
|
|
||||||
d = __sr_read(size*count)
|
|
||||||
ret = d.unpack(type*count)
|
|
||||||
return ret if ret.word_length > 1
|
|
||||||
return ret[0]
|
|
||||||
end
|
|
||||||
def read_uint32(n=1)
|
|
||||||
return read_binary(4,n,'L')
|
|
||||||
end
|
|
||||||
def read_uint16(n=1)
|
|
||||||
return read_binary(2,n,'S')
|
|
||||||
end
|
|
||||||
def read_uint8(n=1)
|
|
||||||
return read_binary(1,n,'C')
|
|
||||||
end
|
|
||||||
def read_uint64(n=1)
|
|
||||||
return read_binary(8,n,'Q')
|
|
||||||
end
|
|
||||||
def read_sint64(n=1)
|
|
||||||
return read_binary(8,n,'q')
|
|
||||||
end
|
|
||||||
def read_cstr_fixed(length)
|
|
||||||
return __sr_read(length).gsub("\000",'')
|
|
||||||
end
|
|
||||||
def read_cstr_terminated
|
|
||||||
return __sr_gets(0.chr)
|
|
||||||
end
|
|
||||||
def read_cstr_prefixed
|
|
||||||
len = read_uint8
|
|
||||||
return __sr_read(len)
|
|
||||||
end
|
|
||||||
def read_float(n=1)
|
|
||||||
return read_binary(4,n,'F')
|
|
||||||
end
|
|
||||||
def read_double(n=1)
|
|
||||||
return read_binary(8,n,'D')
|
|
||||||
end
|
|
||||||
def read_sint16(n=1)
|
|
||||||
return read_binary(2,n,'s')
|
|
||||||
end
|
|
||||||
def read_sint32(n=1)
|
|
||||||
return read_binary(4,n,'l')
|
|
||||||
end
|
|
||||||
def read_data(len)
|
|
||||||
__sr_read(len)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module StreamWriter
|
module StreamWriter
|
||||||
def write_binary(values, type)
|
def write_binary(values, type)
|
||||||
d = values.pack(type * values.length)
|
d = values.pack(type * values.length)
|
||||||
@ -98,7 +49,7 @@ module StreamWriter
|
|||||||
end
|
end
|
||||||
|
|
||||||
class IO
|
class IO
|
||||||
include StreamReader
|
# include StreamReader
|
||||||
include StreamWriter
|
include StreamWriter
|
||||||
|
|
||||||
def __sr_read(len)
|
def __sr_read(len)
|
||||||
@ -111,7 +62,7 @@ end
|
|||||||
|
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
class StringIO
|
class StringIO
|
||||||
include StreamReader
|
# include StreamReader
|
||||||
include StreamWriter
|
include StreamWriter
|
||||||
|
|
||||||
def __sr_read(len)
|
def __sr_read(len)
|
@ -1,6 +1,5 @@
|
|||||||
require 'parslet'
|
require 'parslet'
|
||||||
|
|
||||||
require "stream_reader"
|
|
||||||
require "elf/object_writer"
|
require "elf/object_writer"
|
||||||
require 'salama-reader'
|
require 'salama-reader'
|
||||||
AST::Node.class_eval do
|
AST::Node.class_eval do
|
||||||
|
Loading…
Reference in New Issue
Block a user