Ejemplo n.º 1
0
Archivo: elf.go Proyecto: eqv/indika
func GetSymbols(e *elf.File) map[ds.Range]*ds.Symbol {
	res := make(map[ds.Range]*ds.Symbol)
	symbols, err := e.Symbols()
	if err != nil {
		log.WithFields(log.Fields{"error": err}).Info("Failed to Parse Symbols")
		return res
	}
	for _, sym := range symbols {
		sym_type := elfSymbolTypeToSymbolType(uint(sym.Info))
		symbol := ds.NewSymbol(sym.Name, sym_type)
		res[ds.NewRange(sym.Value, sym.Value+sym.Size)] = symbol
	}
	return res
}
Ejemplo n.º 2
0
func TestRun(t *testing.T) {
	expected_result := make(map[uint64]ds.BB)
	expected_result[0x1000] = *ds.NewBB(0x1000, 0x1022, []uint64{0x1036, 0x1022})
	expected_result[0x1022] = *ds.NewBB(0x1022, 0x1036, []uint64{0x1056, 0x1036})
	expected_result[0x1036] = *ds.NewBB(0x1036, 0x104f, []uint64{0x1056, 0x104f})
	expected_result[0x104f] = *ds.NewBB(0x104f, 0x1056, []uint64{0x105b, 0x1056})
	expected_result[0x1056] = *ds.NewBB(0x1056, 0x105d, []uint64{})

	blocks := GetBBs(0x1000, []byte(code), ds.NewRange(0x1000, 0x1000+uint64(len(code))))
	if !reflect.DeepEqual(blocks, expected_result) {
		fmt.Printf("Is: %#v\n", blocks)
		fmt.Printf("Sh: %#v\n", expected_result)
		t.Fail()
	}
}
Ejemplo n.º 3
0
Archivo: elf.go Proyecto: eqv/indika
func GetSegments(e *elf.File) map[ds.Range]*ds.MappedRegion {
	res := make(map[ds.Range]*ds.MappedRegion)
	for _, prog_offset := range e.Progs {
		hdr := prog_offset.ProgHeader
		if hdr.Off == 0 && hdr.Filesz == 0 {
			continue
		}
		info := new(ds.MappedRegion)
		info.Range = ds.NewRange(hdr.Vaddr, hdr.Vaddr+hdr.Memsz)
		info.Data = make([]byte, hdr.Filesz, hdr.Filesz)
		info.Flags = elfFlagsToPageFlags(hdr.Flags)
		info.Loaded = (hdr.Type == elf.PT_LOAD)
		res[info.Range] = info
		size_read, err := prog_offset.Open().Read(info.Data)
		check(err)
		if uint64(size_read) != hdr.Filesz {
			panic("size missmatch")
		}
	}
	return res
}