Skip to content

Commit

Permalink
Add Readable and ReadableN functions so callers can avoid panics
Browse files Browse the repository at this point in the history
from Read* methods if the address is questionable.
  • Loading branch information
randall77 committed Oct 23, 2017
1 parent 49d52fe commit 3b81b64
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,28 @@ func (p *Process) Mappings() []*Mapping {
return p.maps
}

// Writeable reports whether the address is writeable (by the inferior at the time of the core dump).
// Readable reports whether the address a is readable.
func (p *Process) Readable(a Address) bool {
return p.findMapping(a) != nil
}

// ReadableN reports whether the n bytes starting at address a are readable.
func (p *Process) ReadableN(a Address, n int64) bool {
for {
m := p.findMapping(a)
if m == nil || m.perm&Read == 0 {
return false
}
c := m.max.Sub(a)
if n <= c {
return true
}
n -= c
a = a.Add(c)
}
}

// Writeable reports whether the address a was writeable (by the inferior at the time of the core dump).
func (p *Process) Writeable(a Address) bool {
m := p.findMapping(a)
if m == nil {
Expand Down

0 comments on commit 3b81b64

Please sign in to comment.