Add symbol entry header structure
This commit is contained in:
parent
7979c0cd23
commit
a66365eef4
@ -19,6 +19,7 @@ common warnings
|
||||
base ^>=4.19.1.0,
|
||||
bytestring ^>= 0.12.1,
|
||||
megaparsec ^>= 9.6,
|
||||
vector ^>= 0.13.1,
|
||||
text ^>= 2.0
|
||||
ghc-options: -Wall
|
||||
default-extensions:
|
||||
@ -37,7 +38,6 @@ library elna-internal
|
||||
hashable ^>= 1.4.3,
|
||||
parser-combinators ^>= 1.3,
|
||||
transformers ^>= 0.6.1,
|
||||
vector ^>= 0.13.1,
|
||||
unordered-containers ^>= 0.2.20
|
||||
hs-source-dirs: lib
|
||||
|
||||
|
@ -6,6 +6,7 @@ module Language.Elna.Object.Elf
|
||||
, Elf32_Sword
|
||||
, Elf32_Ehdr(..)
|
||||
, Elf32_Shdr(..)
|
||||
, Elf32_Sym(..)
|
||||
, ElfIdentification(..)
|
||||
, ElfMachine(..)
|
||||
, ElfVersion(..)
|
||||
@ -19,12 +20,13 @@ module Language.Elna.Object.Elf
|
||||
, elf32Sword
|
||||
, elf32Word
|
||||
, elf32Ehdr
|
||||
, elf32Sym
|
||||
, elfIdentification
|
||||
) where
|
||||
|
||||
import qualified Data.ByteString.Builder as ByteString.Builder
|
||||
import Data.Int (Int32)
|
||||
import Data.Word (Word16, Word32)
|
||||
import Data.Word (Word8, Word16, Word32)
|
||||
import qualified Data.ByteString as ByteString
|
||||
|
||||
-- * Data types.
|
||||
@ -190,6 +192,17 @@ instance Enum ElfType
|
||||
fromEnum ET_LOPROC = 0xff00
|
||||
fromEnum ET_HIPROC = 0xffff
|
||||
|
||||
data Elf32_Sym = Elf32_Sym
|
||||
{ st_name :: Elf32_Word
|
||||
, st_value :: Elf32_Addr
|
||||
, st_size :: Elf32_Word
|
||||
, st_info :: Word8
|
||||
, st_other :: Word8
|
||||
, st_shndx :: Elf32_Half
|
||||
} deriving Eq
|
||||
|
||||
-- * Help types.
|
||||
|
||||
data ByteOrder = LSB | MSB
|
||||
deriving Eq
|
||||
|
||||
@ -272,3 +285,12 @@ elf32Shdr byteOrder Elf32_Shdr{..}
|
||||
<> elf32Word byteOrder sh_info
|
||||
<> elf32Word byteOrder sh_addralign
|
||||
<> elf32Word byteOrder sh_entsize
|
||||
|
||||
elf32Sym :: ByteOrder -> Elf32_Sym -> ByteString.Builder.Builder
|
||||
elf32Sym byteOrder Elf32_Sym{..}
|
||||
= elf32Word byteOrder st_name
|
||||
<> elf32Addr byteOrder st_value
|
||||
<> elf32Word byteOrder st_size
|
||||
<> ByteString.Builder.word8 st_info
|
||||
<> ByteString.Builder.word8 st_other
|
||||
<> elf32Half byteOrder st_shndx
|
||||
|
22
src/Main.hs
22
src/Main.hs
@ -2,9 +2,11 @@ module Main
|
||||
( main
|
||||
) where
|
||||
|
||||
import Language.Elna.Object.Elf ()
|
||||
import Language.Elna.Object.Elf (Elf32_Sym(..))
|
||||
import Data.ByteString (ByteString)
|
||||
import qualified Data.ByteString as ByteString
|
||||
import Data.Vector (Vector)
|
||||
import qualified Data.Vector as Vector
|
||||
import Data.Bits (Bits(..))
|
||||
|
||||
data Chunk
|
||||
@ -20,7 +22,7 @@ instance Show Chunk
|
||||
show (SymbolDefinitionChunk label chunk)
|
||||
= "SymbolDefinitionChunk "
|
||||
<> show label
|
||||
<> "(Size: "
|
||||
<> " (Size: "
|
||||
<> show (ByteString.length chunk)
|
||||
<> ")"
|
||||
|
||||
@ -39,6 +41,22 @@ splitContents accumulator remaining
|
||||
in splitContents (SymbolDefinitionChunk label chunk : accumulator) remaining'
|
||||
_ -> ExternSymbolChunk label : accumulator
|
||||
|
||||
go
|
||||
:: Chunk
|
||||
-> (Vector Elf32_Sym, Vector ByteString)
|
||||
-> (Vector Elf32_Sym, Vector ByteString)
|
||||
go (ExternSymbolChunk symbolName) (symbolEntries, stringTable) =
|
||||
let symbolEntry = Elf32_Sym
|
||||
{ st_name = fromIntegral $ Vector.foldr ((+) . ByteString.length) 0 stringTable
|
||||
, st_value = 0
|
||||
, st_size = 0
|
||||
, st_info = shiftL 1 4 -- STB_GLOBAL and STT_NOTYPE
|
||||
, st_other = 0
|
||||
, st_shndx = 0 -- SHN_UNDEF
|
||||
}
|
||||
in (Vector.snoc symbolEntries symbolEntry, Vector.snoc stringTable symbolName)
|
||||
go (SymbolDefinitionChunk _ _) _acc = undefined
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
contents <- ByteString.getContents
|
||||
|
Loading…
x
Reference in New Issue
Block a user