Skip to content

Commit

Permalink
Modify the memory search method (#1)
Browse files Browse the repository at this point in the history
* Modify the memory search method

---------

Co-authored-by: cuileilei <[email protected]>
  • Loading branch information
bearcat-panda and cuileilei authored Aug 13, 2024
1 parent 453b1f9 commit de265d0
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pkg/pattern/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ func PatternScanModule(gm *memory.Gomem, module resources.MODULEINFO, pattern st
var pageAddress *uintptr = &baseAddress
var found []uintptr

if !returnMultiple {
for *pageAddress < maxAddress {
pageAddress, found, err = scanPatternPage(gm, *pageAddress, pattern, returnMultiple)
if err != nil {
return nil, fmt.Errorf("failed to scan page, err: %w", err)
}
for *pageAddress < maxAddress {
pageAddress, found, err = scanPatternPage(gm, *pageAddress, pattern, returnMultiple)
if err != nil {
return nil, fmt.Errorf("failed to scan page, err: %w", err)
}

if found != nil {
results = append(results, found...)
if !returnMultiple {
break
}
if found != nil {
results = append(results, found...)
if !returnMultiple {
break
}
}
}
Expand All @@ -50,7 +48,7 @@ func scanPatternPage(gm *memory.Gomem, address uintptr, pattern string, returnMu
resources.MEMORY_PROTECTION_PAGE_READONLY,
}

if mbi.State != uint32(resources.MEMORY_STATE_MEM_COMMIT) || slices.Contains(allowedProtections, mbi.Protect) {
if mbi.State != uint32(resources.MEMORY_STATE_MEM_COMMIT) || !slices.Contains(allowedProtections, mbi.Protect) {
return &nextRegion, nil, nil
}

Expand Down

0 comments on commit de265d0

Please sign in to comment.