Files
2024-01-31 20:17:11 +08:00

53 lines
1.4 KiB
C++

#include <Windows.h>
#include "pch.h"
#include "detours.h"
#include <string>
typedef cef_v8context_t* (*get_context)();
PVOID v8getcontext_source = NULL;
std::string script;
cef_v8context_t* v8getcontext_hooked() {
cef_v8context_t* context = ((get_context)v8getcontext_source)();
cef_browser_t* browser = context->get_browser(context);
_cef_frame_t* frame = browser->get_main_frame(browser);
CefString exec_script = "if(!window.__easyCefInject__){window.__easyCefInject__=true;" + script + "}";
CefString url = "libeasycef/inject.js";
frame->execute_java_script(frame, exec_script.GetStruct(), url.GetStruct(), 0);
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
//CefRefPtr<CefBrowser> browser = context->GetBrowser();
//CefString jsCode = "alert('Hello, World!');";
//browser->GetMainFrame()->ExecuteJavaScript(jsCode, browser->GetMainFrame()->GetURL(), 0);
return context;
}
void StartHook()
{
long err;
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
v8getcontext_source = DetourFindFunction("libcef.dll", "cef_v8context_get_current_context");
if (v8getcontext_source) {
DetourAttach(&v8getcontext_source, v8getcontext_hooked);
}
LONG err = DetourTransactionCommit();
}
void EndHook()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&v8getcontext_source, v8getcontext_hooked);
DetourTransactionCommit();
}