void load_ext(const char *lib_name) { int (*install_func)(const gawk_api_t *const, awk_ext_id_t); void *dl; int flags = RTLD_LAZY; int *gpl_compat; if (do_sandbox) fatal(_("extensions are not allowed in sandbox mode")); if (do_traditional || do_posix) fatal(_("-l / @load are gawk extensions")); if (lib_name == NULL) fatal(_("load_ext: received NULL lib_name")); if ((dl = dlopen(lib_name, flags)) == NULL) fatal(_("load_ext: cannot open library `%s' (%s)\n"), lib_name, dlerror()); /* Per the GNU Coding standards */ gpl_compat = (int *) dlsym(dl, "plugin_is_GPL_compatible"); if (gpl_compat == NULL) fatal(_("load_ext: library `%s': does not define `plugin_is_GPL_compatible' (%s)\n"), lib_name, dlerror()); install_func = (int (*)(const gawk_api_t *const, awk_ext_id_t)) dlsym(dl, INIT_FUNC); if (install_func == NULL) fatal(_("load_ext: library `%s': cannot call function `%s' (%s)\n"), lib_name, INIT_FUNC, dlerror()); if (install_func(& api_impl, NULL /* ext_id */) == 0) warning(_("load_ext: library `%s' initialization routine `%s' failed\n"), lib_name, INIT_FUNC); }
static LRESULT WINAPI patch_GetMsgProc(int code, WPARAM wparam, LPARAM lparam) { if(code == HC_ACTION) { DWORD error = 0; MSG * msg = reinterpret_cast<MSG *>(lparam); DWORD launching_thread = msg->wParam; // Apply the patch const PatchElement * elem = g_patch.get_elements(); int num_elements = g_patch.get_num_elements(); char Tmp[1024]; wsprintf(Tmp,"num_elements1=%d\n",num_elements); OutputDebugString(Tmp); for(int i = 0; i < num_elements; i++) { DWORD oldProtect; if(VirtualProtect(reinterpret_cast<LPVOID>(elem->m_address), elem->m_length, PAGE_READWRITE, &oldProtect) == 0) { api_error("Failed to patch (page protection)"); error = 1; break; } CopyMemory(reinterpret_cast<unsigned char *>(elem->m_address), elem->m_buffer, elem->m_length); elem++; } // Load Injection DLL (unless disabled) if(error == 0 && g_use_injection) { HINSTANCE hmodule = LoadLibrary("injection.dll"); if(hmodule == NULL) api_error("Failed to load injection.dll in client"); else { // find entry points in injection.dll install_func_t install_func = reinterpret_cast<install_func_t>( GetProcAddress(hmodule, "Install")); geterrortext_func_t geterrortext_func = reinterpret_cast<geterrortext_func_t>( GetProcAddress(hmodule, "GetErrorText")); if(install_func == NULL) { api_error("Failed to find Install function in injection.dll"); error = 1; } else if(geterrortext_func == NULL) { api_error("Failed to find GetErrorText function in injection.dll"); error = 1; } else { // Attempt to install Injection // NOTE: the checksum and length parameters are not needed int err = install_func(0, 0); if(err != 0) { strcpy(g_message, geterrortext_func(err)); error = 1; } } } } // Post a message to the launching thread (param: success/failure) PostThreadMessage(launching_thread, WM_USER, error, GetLastError()); UnhookWindowsHookEx(g_patch_hhook); } return CallNextHookEx(g_patch_hhook, code, wparam, lparam); }