Skip to content

Add file offset and size #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Data/Elf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ data ElfSection = ElfSection
, elfSectionAddrAlign :: Word64 -- ^ Contains the required alignment of the section. Must be a power of two.
, elfSectionEntSize :: Word64 -- ^ Size of entries if section has a table.
, elfSectionData :: B.ByteString -- ^ The raw data for the section.
, elfSectionOffset :: Word64 -- ^ Offset of the section in the file image.
} deriving (Eq, Show)

elfMagic :: [Word8]
Expand Down Expand Up @@ -449,6 +450,7 @@ getElf_Shdr ei_class er elf_file string_section =
, elfSectionAddrAlign = fromIntegral sh_addralign
, elfSectionEntSize = fromIntegral sh_entsize
, elfSectionData = B.take (fromIntegral sh_size) $ B.drop (fromIntegral sh_offset) elf_file
, elfSectionOffset = fromIntegral sh_offset
}
ELFCLASS64 -> do
sh_name <- getWord32 er
Expand All @@ -472,6 +474,7 @@ getElf_Shdr ei_class er elf_file string_section =
, elfSectionAddrAlign = sh_addralign
, elfSectionEntSize = sh_entsize
, elfSectionData = B.take (fromIntegral sh_size) $ B.drop (fromIntegral sh_offset) elf_file
, elfSectionOffset = fromIntegral sh_offset
}

data TableInfo = TableInfo { tableOffset :: Int, entrySize :: Int, entryNum :: Int }
Expand Down Expand Up @@ -581,6 +584,8 @@ data ElfSegment = ElfSegment
, elfSegmentAlign :: Word64 -- ^ Segment alignment
, elfSegmentData :: B.ByteString -- ^ Data for the segment
, elfSegmentMemSize :: Word64 -- ^ Size in memory (may be larger then the segment's data)
, elfSegmentFileSize :: Word64 -- ^ Size of the segment in file
, elfSegmentOffset :: Word64 -- ^ Offset of the segment in file
} deriving (Eq,Show)

-- | Segment Types.
Expand Down Expand Up @@ -627,6 +632,8 @@ parseElfSegmentEntry elf_class er elf_file = case elf_class of
, elfSegmentAlign = p_align
, elfSegmentData = B.take (fromIntegral p_filesz) $ B.drop (fromIntegral p_offset) elf_file
, elfSegmentMemSize = p_memsz
, elfSegmentFileSize = fromIntegral p_filesz
, elfSegmentOffset = fromIntegral p_offset
}

ELFCLASS32 -> do
Expand All @@ -646,6 +653,8 @@ parseElfSegmentEntry elf_class er elf_file = case elf_class of
, elfSegmentAlign = p_align
, elfSegmentData = B.take (fromIntegral p_filesz) $ B.drop (fromIntegral p_offset) elf_file
, elfSegmentMemSize = p_memsz
, elfSegmentFileSize = fromIntegral p_filesz
, elfSegmentOffset = fromIntegral p_offset
}

data ElfSegmentFlag
Expand Down