Changelog History
-
v0.30 Changes
December 26, 2018parseSymbolTables
now parsesSHT_DYNSYM
in addition toSHT_SYMTAB
-
v0.29 Changes
June 19, 2018- โ Add few more test cases
- โ remove call to deprecated functions in
binary
-
v0.28 Changes
February 23, 2017Hi list,
โ with below test program:
๐ โ/* test1.c: build with -g -O0 */
include <stdio.h>static const char appmsg[] = "hello, world";
int main(int argc, char* argv[])
{
fputs(appmsg, stdout);return 0;
}
--- โ elf-test1.hs
module Main whereโ import qualified Data.ByteString as B
โ import qualified Data.ByteString.Char8 as Cimport Control.Monad
import Data.Elf
โ testelf = "/tmp/test1"
โ testelfsym = C.pack "appmsg"lookupSymbol1 _ [] = Nothing
lookupSymbol1 sym (t:ts) =
case (snd (steName t)) of
Nothing -> lookupSymbol1 sym ts
Just sname -> if sname == sym then Just t
else lookupSymbol1 sym tslookupSymbol _ [] = Nothing
lookupSymbol sym (t:ts) =
case (lookupSymbol1 sym t) of
Nothing -> lookupSymbol sym ts
t1 -> t1โ test1 elf symtab symbol = mapM_ (print) (elfSections elf)
โ test2 elf symtab symbol =
lookupSymbol symbol symtabโ test3 elf symtab symbol =
lookupSymbol symbol symtab >>= \et ->
findSymbolDefinition etmainloop elf symtab symbol =
-- โ (test1 elf symtab symbol) >>
โ print (test2 elf symtab symbol) >>
โ print (test3 elf symtab symbol) >>
return ()main = do
โ contents <- B.readFile testelf
๐ let elf = parseElf contents
๐ symtab = parseSymbolTables elfโ mainloop elf symtab testelfsym
โ the latest Data.Elf doesn't geive correct output as expected:
output will be:
Just (EST {steName = (9,Just "appmsg"), steEnclosingSection = Just (ElfSection {elfSectionName = ".fini", elfSectionType = SHT_PROGBITS, elfSectionFlags = [SHF_EXECINSTR,SHF_ALLOC], elfSectionAddr = 4195908, elfSectionSize = 9, elfSectionLink = 0, elfSectionInfo = 0, elfSectionAddrAlign = 4, elfSectionEntSize = 0, elfSectionData = "H\131\236\bH\131\196\b\195"}), steType = STTObject, steBind = STBLocal, steOther = 0, steIndex = SHNIndex 14, steValue = 4195924, steSize = 13})
๐ From above, you can see the steEnclosingSection is wrong and offset by 1.
The correct output should be:
Just (EST {steName = (9,Just "appmsg"), steEnclosingSection = Just (ElfSection {elfSectionName = ".rodata", elfSectionType = SHT_PROGBITS, elfSectionFlags = [SHF_ALLOC], elfSectionAddr = 4195920, elfSectionSize = 17, elfSectionLink = 0, elfSectionInfo = 0, elfSectionAddrAlign = 4, elfSectionEntSize = 0, elfSectionData = "\SOH\NUL\STX\NULhello, world\NUL"}), steType = STTObject, steBind = STBLocal, steOther = 0, steIndex = SHNIndex 14, steValue = 4195924, steSize = 13})
Just "hello, world\NUL"After check Elf.hs, I found there could be two issues:
- in sectionByIndex, (SHNIndex) should start from 0, not 1; this cause the steEnclosingSection from my exmaple offset by 1;
- in findSymbolDefinition, start should substract the sectionAddr (base address).
-
v0.27 Changes
February 23, 2017๐ This release is exactly the same as v0.27 from hackage (https://hackage.haskell.org/package/elf).
๐ฆ The package is no longer exist in github (by Erik Charlebois), thus (re-)creating this repo for maintaining purpose.