Skip to content

Commit

Permalink
Add ReadUint func
Browse files Browse the repository at this point in the history
  • Loading branch information
ramory-l committed Mar 25, 2024
1 parent b96365a commit 925fb10
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,23 @@ func ReadBytes(handle windows.Handle, address uintptr, size uintptr) ([]byte, er
func ReadInt(handle windows.Handle, address uintptr) (int32, error) {
bytes, err := ReadBytes(handle, address, 4)
if err != nil {
return 0, err
return 0, fmt.Errorf("memory read error at address %x: %w", address, err)
}
if len(bytes) < 4 {
return 0, fmt.Errorf("expected to read 4 bytes, got %d", len(bytes))
}
val := int32(binary.LittleEndian.Uint32(bytes))
return val, nil
}

func ReadUint(handle windows.Handle, address uintptr) (uint32, error) {
bytes, err := ReadBytes(handle, address, 4)
if err != nil {
return 0, fmt.Errorf("memory read error at address %x: %w", address, err)
}
if len(bytes) < 4 {
return 0, fmt.Errorf("expected to read 4 bytes, got %d", len(bytes))
}
val := binary.LittleEndian.Uint32(bytes)
return val, nil
}

0 comments on commit 925fb10

Please sign in to comment.