machine.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package loader
  2. import "io"
  3. // Proc represents a procedure in memory.
  4. type Proc interface {
  5. // Call calls the procedure. r1 and r2 contain the return value. lastErr
  6. // contains the Windows error value after calling.
  7. Call(a ...uint64) (r1, r2 uint64, lastErr error)
  8. // Returns the raw address of this function.
  9. Addr() uint64
  10. }
  11. // Memory is an interface for a block of allocated virtual memory.
  12. type Memory interface {
  13. io.ReadWriteSeeker
  14. io.ReaderAt
  15. io.WriterAt
  16. // Free frees the virtual memory region.
  17. Free()
  18. // Addr returns the address of the region of memory in the virtual address
  19. // space.
  20. Addr() uint64
  21. // Clear zeros the entire region of memory.
  22. Clear()
  23. // Protect changes the memory protection for a subregion of this allocated
  24. // block. It should match the semantics of the VirtualProtect function on
  25. // Windows.
  26. Protect(addr, size uint64, protect int) error
  27. }
  28. // Machine is an abstract machine interface.
  29. type Machine interface {
  30. // IsArchitectureSupported returns whether or not an architecture is
  31. // supported by this abstract machine. Machine is a PE machine ID.
  32. IsArchitectureSupported(machine int) bool
  33. // GetPageSize returns the size of a memory page on this abstract machine.
  34. GetPageSize() uint64
  35. // Alloc performs virtual memory allocation. It should match the semantics
  36. // of VirtualAlloc/VirtualFree on Windows.
  37. Alloc(addr, size uint64, allocType, protect int) Memory
  38. // MemProc returns an object for interfacing with a procedure at addr in
  39. // the abstract machine's virtual memory space.
  40. MemProc(addr uint64) Proc
  41. }