Skip to content

Commit

Permalink
Used PwnMethodBitmap functionality rather than duplicating it
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed May 30, 2022
1 parent c1aeb3d commit aa2ca58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
18 changes: 5 additions & 13 deletions modules/engine/analyzeobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,11 @@ func AnalyzeObjects(opts AnalyzeObjectsOptions) (pg PwnGraph) {
}
}

maxprobability := Probability(-128)
for i := 0; i < len(pwnnums); i++ {
if detectedmethods.IsSet(PwnMethod(i)) {
var probability Probability
if forward {
probability = CalculateProbability(pwntarget, object, PwnMethod(i))
} else {
probability = CalculateProbability(object, pwntarget, PwnMethod(i))
}
if probability > maxprobability {
maxprobability = probability
}
}
var maxprobability Probability
if forward {
maxprobability = detectedmethods.MaxProbability(pwntarget, object)
} else {
maxprobability = detectedmethods.MaxProbability(object, pwntarget)
}
if maxprobability < Probability(opts.MinProbability) {
// Too unlikeliy, so we skip it
Expand Down
11 changes: 8 additions & 3 deletions modules/engine/pwn.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const MAXPWNMETHODPOSSIBLE = PMBSIZE * 64
type PwnMethodBitmap [PMBSIZE]uint64
type Probability int8

const (
MINPROBABILITY Probability = -1
MAXPROBABILITY Probability = 100
)

type PwnInfo struct {
Target *Object
Method PwnMethod
Expand Down Expand Up @@ -220,12 +225,12 @@ func (m PwnMethodBitmap) IsSet(method PwnMethod) bool {
return (m[method/64] & (1 << (method % 64))) != 0 // Uuuuh, nasty and unreadable
}

func (m PwnMethodBitmap) MaxProbabiltity(source, target *Object) Probability {
func (m PwnMethodBitmap) MaxProbability(source, target *Object) Probability {
var max Probability
for i := 0; i < len(pwnnums); i++ {
if m.IsSet(PwnMethod(i)) {
prob := CalculateProbability(source, target, PwnMethod(i))
if prob == 100 {
prob := PwnMethod(i).Probability(source, target)
if prob == MAXPROBABILITY {
return prob
}
if prob > max {
Expand Down

0 comments on commit aa2ca58

Please sign in to comment.