loader_windows.go 858 B

123456789101112131415161718192021222324252627282930313233
  1. package winloader
  2. import (
  3. "github.com/jchv/go-winloader/internal/memloader"
  4. "github.com/jchv/go-winloader/internal/winloader"
  5. )
  6. var native = winloader.Loader{}
  7. var cache = memloader.NewCache(native)
  8. var ldr = memloader.New(memloader.Options{
  9. Next: cache,
  10. Machine: winloader.NativeMachine{},
  11. })
  12. // LoadFromFile loads a Windows module from file using the native Windows
  13. // loader.
  14. func LoadFromFile(name string) (Module, error) {
  15. return native.Load(name)
  16. }
  17. // LoadFromMemory loads a Windows module from memory.
  18. func LoadFromMemory(data []byte) (Module, error) {
  19. return ldr.LoadMem(data)
  20. }
  21. // AddToCache adds a module to the loader cache, allowing in-memory libraries
  22. // to link to it. Note that modules in the cache must exist in the same
  23. // address space.
  24. func AddToCache(name string, module Module) error {
  25. return cache.Add(name, module)
  26. }