(handle windows.Handle, pattern []byte, todesk bool)
| 27 | return buffer, nil |
| 28 | } |
| 29 | func 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 | } |
| 63 | func MatchPattern(data, pattern []byte) bool { |
| 64 | for i := range pattern { |
| 65 | if data[i] != pattern[i] { |
no test coverage detected