offsetter

package module
v0.0.0-...-9628a76 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2019 License: MIT Imports: 2 Imported by: 0

README

offsetter

Go Report Card

Small package to convert between file offsets and virtual addresses (partialy inspired by some code of pwnlib). For the moment, only ELF files are supported.

Install

Install with go get -u github.com/guitmz/offsetter

Example

$ cat example.go
package main

import (
   "debug/elf"
   "fmt"

   "github.com/guitmz/offsetter"
)

func check(err error) {
   if err != nil {
   	panic(err)
   }
}

func main() {
   targetFile, err := elf.Open("/bin/ls")
   check(err)
   defer targetFile.Close()

   loadAddress, err := offsetter.GetLoadAddress(targetFile)
   check(err)

   hexOffset, uintOffset, err := offsetter.VaddrToOffset(targetFile, loadAddress, targetFile.Entry)
   check(err)
   fmt.Printf("Offset: %s (%d)\n", hexOffset, uintOffset)

   hexVaddr, uintVaddr, err := offsetter.OffsetToVaddr(targetFile, uintOffset)
   check(err)
   fmt.Printf("Vaddr: %s (%d)\n", hexVaddr, uintVaddr)
}
$ go run example.go
Offset: 0x42d4 (17108)
Vaddr: 0x4042d4 (4211412)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLoadAddress

func GetLoadAddress(f *elf.File) (uint64, error)

GetLoadAddress returns input ELF file Load Address (in memory)

func OffsetToVaddr

func OffsetToVaddr(f *elf.File, offset uint64) (string, uint64, error)

OffsetToVaddr converts a file offset to a virtual address (returns string and uint64 representations of the resulting virtual address)

func VaddrToOffset

func VaddrToOffset(f *elf.File, load, addr uint64) (string, uint64, error)

VaddrToOffset converts a virtual address to a file offset (returns string and uint64 representations of the resulting file offset)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL