#include "services/test/echo/echo_service.h"
#include <optional>
#include <string>
#include "base/immediate_crash.h"
#include "base/memory/shared_memory_mapping.h"
#include "build/build_config.h"
#include "components/os_crypt/sync/os_crypt.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include <winevt.h>
#include "base/native_library.h"
#endif
#include <string>
namespace echo {
EchoService::EchoService(mojo::PendingReceiver<mojom::EchoService> receiver)
: … { … }
EchoService::~EchoService() = default;
void EchoService::EchoString(const std::string& input,
EchoStringCallback callback) { … }
void EchoService::EchoStringToSharedMemory(
const std::string& input,
base::UnsafeSharedMemoryRegion region) { … }
void EchoService::Quit() { … }
void EchoService::Crash() { … }
#if BUILDFLAG(IS_WIN)
void EchoService::DelayLoad() {
EVT_HANDLE handle = ::EvtCreateRenderContext(0, nullptr, 0);
::EvtClose(handle);
}
void EchoService::LoadNativeLibrary(const ::base::FilePath& library,
bool call_sec32_delayload,
LoadNativeLibraryCallback callback) {
base::NativeLibraryLoadError error;
HMODULE hmod = base::LoadNativeLibrary(library, &error);
if (!hmod) {
std::move(callback).Run(LoadStatus::kFailedLoadLibrary, error.code);
return;
}
if (call_sec32_delayload) {
BOOL(WINAPI * fn)() = nullptr;
fn = reinterpret_cast<decltype(fn)>(
GetProcAddress(hmod, "FnCallsDelayloadFn"));
if (!fn) {
std::move(callback).Run(LoadStatus::kFailedGetProcAddress,
GetLastError());
return;
}
BOOL ret = fn();
if (!ret) {
std::move(callback).Run(LoadStatus::kFailedCallingDelayLoad,
GetLastError());
return;
}
}
std::move(callback).Run(LoadStatus::kSuccess, ERROR_SUCCESS);
}
#endif
void EchoService::DecryptEncrypt(os_crypt_async::Encryptor encryptor,
const std::vector<uint8_t>& input,
DecryptEncryptCallback callback) { … }
}