service_resolver.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "sandbox/win/src/service_resolver.h"
  5. #include "base/win/pe_image.h"
  6. #include "sandbox/win/src/internal_types.h"
  7. #include "sandbox/win/src/sandbox_nt_util.h"
  8. namespace sandbox {
  9. NTSTATUS ServiceResolverThunk::ResolveInterceptor(
  10. const void* interceptor_module,
  11. const char* interceptor_name,
  12. const void** address) {
  13. // After all, we are using a locally mapped version of the exe, so the
  14. // action is the same as for a target function.
  15. return ResolveTarget(interceptor_module, interceptor_name,
  16. const_cast<void**>(address));
  17. }
  18. // In this case all the work is done from the parent, so resolve is
  19. // just a simple GetProcAddress.
  20. NTSTATUS ServiceResolverThunk::ResolveTarget(const void* module,
  21. const char* function_name,
  22. void** address) {
  23. if (!module)
  24. return STATUS_UNSUCCESSFUL;
  25. base::win::PEImage module_image(module);
  26. *address =
  27. reinterpret_cast<void*>(module_image.GetProcAddress(function_name));
  28. if (!*address) {
  29. NOTREACHED_NT();
  30. return STATUS_UNSUCCESSFUL;
  31. }
  32. return STATUS_SUCCESS;
  33. }
  34. void ServiceResolverThunk::AllowLocalPatches() {
  35. ntdll_base_ = ::GetModuleHandle(kNtdllName);
  36. }
  37. } // namespace sandbox