// PieOffset returns the PIE/ASLR offset for a running instance of this binary
// file. It reads /proc/pid/maps to determine the right location, so the caller
// must have ptrace permissions. If possible, you should cache the result of
// this function instead of calling it multiple times.
PieOffset returns the PIE/ASLR offset for a running instance of this binary
file. It reads /proc/pid/maps to determine the right location, so the caller
must have ptrace permissions. If possible, you should cache the result of
this function instead of calling it multiple times.
// PieOffset returns the PIE / ASLR offset for a running instance of this binary // file . It reads / proc / pid / maps to determine the right location so the caller // must have ptrace permissions . If possible you should cache the result of // this function instead of calling it multiple times .
func (b *BinFile) PieOffset(pid int) (uint64, error) {
	if !b.pie {
		return 0, nil
	}
	maps, err := os.Open(fmt.Sprintf("/proc/%d/maps", pid))
	if err != nil {
		return 0, err
	}
	defer maps.Close()
	scanner := bufio.NewScanner(maps)
	for {
		if !scanner.Scan() {
			if err := scanner.Err(); err != nil {
				return 0, err
			}
			break
		}
		line := scanner.Text()
		if !strings.Contains(line, filepath.Base(b.name)) {
			continue
		}
		parts := strings.Split(line, "-")
		if len(parts) < 1 {
			continue
		}
		off, err := strconv.ParseUint("0x"+parts[0], 0, 64)
		if err != nil {
			return 0, err
		}
		return off, nil
	}
	return 0, errors.New("could not find pie offset")
}
func ( b * BinFile ) PieOffset ( pid int ) ( uint64 , error ) { if ! b . pie { return 0 , nil } maps , err := os . Open ( fmt . Sprintf ( " " , pid ) ) if err != nil { return 0 , err } defer maps . Close ( ) scanner := bufio . NewScanner ( maps ) for { if ! scanner . Scan ( ) { if err := scanner . Err ( ) ; err != nil { return 0 , err } break } line := scanner . Text ( ) if ! strings . Contains ( line , filepath . Base ( b . name ) ) { continue } parts := strings . Split ( line , " " ) if len ( parts ) < 1 { continue } off , err := strconv . ParseUint ( " " + parts [ 0 ] , 0 , 64 ) if err != nil { return 0 , err } return off , nil } return 0 , errors . New ( " " ) }
PieOffset returns the PIE/ASLR offset for a running instance of this binary
file.
PieOffset returns the PIE / ASLR offset for a running instance of this binary file .
// only read the first line of the file (this will show the bottom mapping // for the text segment)