bool hook_d3d8(void) { HMODULE d3d8_module = get_system_module("d3d8.dll"); void *present_addr; void *reset_addr; if (!d3d8_module) { return false; } present_addr = get_offset_addr(d3d8_module, global_hook_info->offsets.d3d8.present); reset_addr = get_offset_addr(d3d8_module, global_hook_info->offsets.d3d8.reset); hook_init(&present, present_addr, (void*)hook_present, "IDirect3DDevice8::Present"); hook_init(&reset, reset_addr, (void*)hook_reset, "IDirect3DDevice8::Reset"); rehook(&present); rehook(&reset); hlog("Hooked D3D8"); return true; }
void weechat_init (int argc, char *argv[], void (*gui_init_cb)()) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); /* catch signals */ util_catch_signal (SIGINT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGPIPE, SIG_IGN); /* signal ignored */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump */ util_catch_signal (SIGHUP, &weechat_sighup); /* exit WeeChat */ util_catch_signal (SIGQUIT, &weechat_sigquit); /* exit WeeChat */ util_catch_signal (SIGTERM, &weechat_sigterm); /* exit WeeChat */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_color_init (); /* initialize colors */ gui_chat_init (); /* initialize chat */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ weechat_shutdown (EXIT_FAILURE, 0); weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dir (); /* create WeeChat home directory */ log_init (); /* init log file */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ if (gui_init_cb) (*gui_init_cb) (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_startup_message (); /* display WeeChat startup message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ weechat_term_check (); /* warning about wrong $TERM */ weechat_locale_check (); /* warning about wrong locale */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_force_plugin_autoload, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ }
bool hook_gl(void) { void *wgl_dc_proc; void *wgl_slb_proc; void *wgl_sb_proc; gl = get_system_module("opengl32.dll"); if (!gl) { return false; } if (!gl_register_window()) { return true; } wgl_dc_proc = base_get_proc("wglDeleteContext"); wgl_slb_proc = base_get_proc("wglSwapLayerBuffers"); wgl_sb_proc = base_get_proc("wglSwapBuffers"); hook_init(&swap_buffers, SwapBuffers, hook_swap_buffers, "SwapBuffers"); if (wgl_dc_proc) { hook_init(&wgl_delete_context, wgl_dc_proc, hook_wgl_delete_context, "wglDeleteContext"); rehook(&wgl_delete_context); } if (wgl_slb_proc) { hook_init(&wgl_swap_layer_buffers, wgl_slb_proc, hook_wgl_swap_layer_buffers, "wglSwapLayerBuffers"); rehook(&wgl_swap_layer_buffers); } if (wgl_sb_proc) { hook_init(&wgl_swap_buffers, wgl_sb_proc, hook_wgl_swap_buffers, "wglSwapBuffers"); rehook(&wgl_swap_buffers); } rehook(&swap_buffers); return true; }
static void setup_reset_hooks(IDirect3DDevice9 *device) { IDirect3DDevice9Ex *d3d9ex = nullptr; uintptr_t *vtable = *(uintptr_t**)device; HRESULT hr; hook_init(&reset, (void*)vtable[16], (void*)hook_reset, "IDirect3DDevice9::Reset"); rehook(&reset); hr = device->QueryInterface(__uuidof(IDirect3DDevice9Ex), (void**)&d3d9ex); if (SUCCEEDED(hr)) { hook_init(&reset_ex, (void*)vtable[132], (void*)hook_reset_ex, "IDirect3DDevice9Ex::ResetEx"); rehook(&reset_ex); d3d9ex->Release(); } hooked_reset = true; }
/** * Register hook * * @param __proc - hook procedure name * @param __callback - handler's callback * @param __user_data - user's data * @param __priority - handler's priority * @return nzero on success, non-zero otherwise */ int hook_register (char *__proc, hook_callback_proc __callback, void *__user_data, int __priority) { hook_node_t node; if (__priority < 0 || __priority >= HOOK_MAX_PRIORITY) { return -1; } hook_init (); node = hook_spawn_node (__proc, __callback, __user_data); dyna_append (hooks[__priority], node, 0); return 0; }
int main(int argc, char *argv[]) { errno = 0; assert(argc == 2); hook_init(); double num = strtod(argv[1], NULL); fprintf(stderr,"%x\n", sqrt); orig = (double (*)())hook_attach((uintptr_t)_sqrt, (hook_t)my_sqrt, 0); printf("%p,errno=%i\n", orig, hook_error(NULL, 0)); perror(""); if (orig == NULL) assert(orig != NULL); printf("\n\n%f => %f\n", num, _sqrt(num)); printf("%d", hook_detach((uintptr_t)_sqrt, (hook_t)orig)); }
void monitor_init(HMODULE module_handle) { // Sends crashes to the process rather than showing error popup boxes etc. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); config_t cfg; config_read(&cfg); // Required to be initialized before any logging starts. mem_init(); // Initialize capstone without our custom allocator as it is // not available yet. hook_init(module_handle); pipe_init(cfg.pipe_name); native_init(); // Re-initialize capstone with our custom allocator which is now // accessible after native_init(). hook_init2(); misc_init(module_handle, cfg.shutdown_mutex); misc_set_hook_library(&monitor_hook); diffing_init(cfg.hashes_path, cfg.diffing_enable); log_init(cfg.logpipe); ignore_init(); sleep_init(cfg.first_process, cfg.force_sleep_skip, cfg.startup_time); unhook_init_detection(cfg.first_process); hide_module_from_peb(module_handle); symbol_init(module_handle); // Should be the last as some of the other initialization routines extract // the image size, EAT pointers, etc while the PE header is still intact. destroy_pe_header(module_handle); misc_set_monitor_options(cfg.track, cfg.mode); }
int main() { pipe_init("\\\\.\\PIPE\\cuckoo", 0); hook_init(GetModuleHandle(NULL)); mem_init(); assert(native_init() == 0); uint8_t buf[16]; uint16_t val[2]; assert(utf8_encode(0x00000001, buf) == 1 && memcmp(buf, "\x01", 1) == 0); assert(utf8_encode(0x0000007f, buf) == 1 && memcmp(buf, "\x7f", 1) == 0); assert(utf8_encode(0x00000080, buf) == 2 && memcmp(buf, "\xc2\x80", 2) == 0); assert(utf8_encode(0x000007ff, buf) == 2 && memcmp(buf, "\xdf\xbf", 2) == 0); assert(utf8_encode(0x00000800, buf) == 3 && memcmp(buf, "\xe0\xa0\x80", 3) == 0); assert(utf8_encode(0x0000ffff, buf) == 3 && memcmp(buf, "\xef\xbf\xbf", 3) == 0); assert(utf8_encode(0x00010000, buf) == 4 && memcmp(buf, "\xf0\x90\x80\x80", 4) == 0); assert(utf8_encode(0x001fffff, buf) == 4 && memcmp(buf, "\xf7\xbf\xbf\xbf", 4) == 0); assert(utf8_encode(0x00200000, buf) == 5 && memcmp(buf, "\xf8\x88\x80\x80\x80", 5) == 0); assert(utf8_encode(0x03ffffff, buf) == 5 && memcmp(buf, "\xfb\xbf\xbf\xbf\xbf", 5) == 0); assert(utf8_encode(0x04000000, buf) == 6 && memcmp(buf, "\xfc\x84\x80\x80\x80\x80", 6) == 0); assert(utf8_encode(0x7fffffff, buf) == 6 && memcmp(buf, "\xfd\xbf\xbf\xbf\xbf\xbf", 6) == 0); // It's kind of a hassle to get utf8_wstring() to work here, so we'll just // do similar work with the byte count, which calculates the required // amount of bytes for a sequence. The following sequences represent the // various utf8 boundaries, i.e., their maximum values before needing an // extra byte etc. assert(utf8_bytecnt_unicode((val[0] = 0xd800, val[1] = 0xdc00, val), 2) == 1); assert(utf8_bytecnt_unicode((val[0] = 0xd801, val[1] = 0xdc00, val), 2) == 2); assert(utf8_bytecnt_unicode((val[0] = 0xd802, val[1] = 0xdc00, val), 2) == 3); assert(utf8_bytecnt_unicode((val[0] = 0xd840, val[1] = 0xdc00, val), 2) == 4); // We used to have some issues with signed chars and the MSB being set as // we wouldn't cast these as unsigned characters. This would result in // utf8_length(0xffffff81) returning -1, rather than utf8_length(0x81) // returning 2. Similarly to incorrect return values of utf8_length() we'd // also experience out-of-bounds writes as our buffer would be indexed by // -1, resulting in undefined behavior. assert(utf8_bytecnt_ascii("\x81", 1) == 2); assert(utf8_bytecnt_unicode(L"\u8081", 1) == 3); assert(memcmp(utf8_string("\x81", 1), "\x02\x00\x00\x00\xc2\x81", 6) == 0); assert(memcmp(utf8_wstring(L"\u8081", 1), "\x03\x00\x00\x00\xe8\x82\x81", 7) == 0); }
static int __init logcap_init(void) { struct proc_dir_entry *proc_entry; printk(KERN_DEBUG TAG": allocate storage for %d registers, %d bytes\n", MAX_REGS, sizeof(ar_logcap_regs)); store = vmalloc(sizeof(ar_logcap_regs)); memset(store, 0, sizeof(ar_logcap_regs)); proc_root = proc_mkdir(TAG, NULL); create_proc_read_entry("rd_count", 0444, proc_root, proc_rd_count_read, NULL); create_proc_read_entry("wr_count", 0444, proc_root, proc_wr_count_read, NULL); create_proc_read_entry("map", 0444, proc_root, proc_map_read, NULL); proc_entry = create_proc_read_entry("log_enable", 0666, proc_root, proc_log_enable_read, NULL); proc_entry->write_proc = proc_log_enable_write; if (log_enable & L_DMESG) capcap_dumpnames(); hook_init(); hooked = true; return 0; }
int main (int argc, char *argv[]) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); setlocale (LC_ALL, ""); /* initialize gettext */ #ifdef ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif #ifdef HAVE_LANGINFO_CODESET weechat_local_charset = strdup (nl_langinfo (CODESET)); #else weechat_local_charset = strdup (""); #endif utf8_init (); util_catch_signal (SIGINT, SIG_IGN); /* ignore SIGINT signal */ util_catch_signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal */ util_catch_signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump for SIGSEGV signal */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_main_pre_init (&argc, &argv); /* pre-initialize interface */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ weechat_shutdown (EXIT_FAILURE, 0); weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dir (); /* create WeeChat home directory */ log_init (); /* init log file */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ gui_main_init (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_welcome_message (); /* display WeeChat welcome message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_auto_load_plugins, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ gui_main_loop (); /* WeeChat main loop */ gui_layout_store_on_exit (); /* store layout */ plugin_end (); /* end plugin interface(s) */ if (CONFIG_BOOLEAN(config_look_save_config_on_exit)) (void) config_weechat_write (); /* save WeeChat config file */ (void) secure_write (); /* save secured data */ gui_main_end (1); /* shut down WeeChat GUI */ proxy_free_all (); /* free all proxies */ config_weechat_free (); /* free WeeChat options */ secure_free (); /* free secured data options */ config_file_free_all (); /* free all configuration files */ gui_key_end (); /* remove all keys */ unhook_all (); /* remove all hooks */ hdata_end (); /* end hdata */ secure_end (); /* end secured data */ string_end (); /* end string */ weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */ return EXIT_SUCCESS; /* make C compiler happy */ }
void init_netsukuku(char **argv) { xsrand(); if (geteuid()) fatal("Need root privileges"); destroy_netsukuku_mutex = pid_saved = 0; sigterm_timestamp = sighup_timestamp = sigalrm_timestamp = 0; setzero(&me, sizeof(struct current_globals)); if (is_ntkd_already_running()) fatal("ntkd is already running. If it is not, remove \"%s\"", server_opt.pid_file); else save_pid(); my_family = server_opt.family; restricted_mode = server_opt.restricted; restricted_class = server_opt.restricted_class ? RESTRICTED_172 : RESTRICTED_10; /* Check if the DATA_DIR exists, if not create it */ if (check_and_create_dir(DATA_DIR)) fatal("Cannot access to the %s directory. Exiting.", DATA_DIR); /* * Device initialization */ if (if_init_all(server_opt.ifs, server_opt.ifs_n, me.cur_ifs, &me.cur_ifs_n) < 0) fatal("Cannot initialize any network interfaces"); /* * ANDNA init */ if (!server_opt.disable_andna) andna_init(); /* * Initialize the Internet gateway stuff */ if (server_opt.my_upload_bw && server_opt.my_dnload_bw) me.my_bandwidth = bandwidth_in_8bit((server_opt.my_upload_bw + server_opt.my_dnload_bw) / 2); init_internet_gateway_search(); pkts_init(me.cur_ifs, me.cur_ifs_n, 0); qspn_init(FAMILY_LVLS); me.cur_erc = e_rnode_init(&me.cur_erc_counter); /* Radar init */ rq_wait_idx_init(rq_wait_idx); first_init_radar(); total_radars = 0; ntk_load_maps(); #if 0 /* TODO: activate and test it !! */ debug(DBG_NORMAL, "ACPT: Initializing the accept_tbl: \n" " max_connections: %d,\n" " max_accepts_per_host: %d,\n" " max_accept_per_host_time: %d", server_opt.max_connections, server_opt.max_accepts_per_host, server_opt.max_accepts_per_host_time); init_accept_tbl(server_opt.max_connections, server_opt.max_accepts_per_host, server_opt.max_accepts_per_host_time); #endif if (restricted_mode) loginfo("NetsukukuD is in restricted mode. " "Restricted class: %s", server_opt. restricted_class ? RESTRICTED_172_STR : RESTRICTED_10_STR); hook_init(); rehook_init(); me.uptime = time(0); }
static int __init mmcfix_init(void) { printk(KERN_INFO "MMC-fix init\n"); hook_init(); return 0; }
int main() { pipe_init("\\\\.\\PIPE\\cuckoo", 0); hook_init(GetModuleHandle(NULL)); mem_init(); assert(native_init() == 0); dnq_t d1, d2, d3; uint32_t val1[] = { 1, 6, 4, 8, 13337, 42, 89, 9001, 90, }; uint32_t val1_sorted[] = { 1, 4, 6, 8, 42, 89, 90, 9001, 13337, }; dnq_init(&d1, val1, sizeof(uint32_t), sizeof(val1) / sizeof(uint32_t)); assert(memcmp(d1.list, val1_sorted, sizeof(val1_sorted)) == 0); assert(dnq_has32(&d1, 4) == 1); assert(dnq_has32(&d1, 0) == 0); assert(dnq_has32(&d1, 1) == 1); assert(dnq_has32(&d1, 2) == 0); assert(dnq_has32(&d1, 43) == 0); assert(dnq_has32(&d1, 91) == 0); assert(dnq_has32(&d1, 90) == 1); assert(dnq_has32(&d1, 9002) == 0); assert(dnq_has32(&d1, 9000) == 0); assert(dnq_has32(&d1, 13337) == 1); assert(dnq_has32(&d1, 13338) == 0); assert(dnq_has32(&d1, 13336) == 0); assert(dnq_has32(&d1, 88) == 0); assert(dnq_has32(&d1, 41) == 0); assert(dnq_has32(&d1, 42) == 1); uint64_t val2[] = { 1, 6, 4, 8, 13337, 42, 89, 9001, 90, }; uint64_t val2_sorted[] = { 1, 4, 6, 8, 42, 89, 90, 9001, 13337, }; dnq_init(&d2, val2, sizeof(uint64_t), sizeof(val2) / sizeof(uint64_t)); assert(memcmp(d2.list, val2_sorted, sizeof(val2_sorted)) == 0); assert(dnq_has64(&d2, 4) == 1); assert(dnq_has64(&d2, 0) == 0); assert(dnq_has64(&d2, 1) == 1); assert(dnq_has64(&d2, 2) == 0); assert(dnq_has64(&d2, 43) == 0); assert(dnq_has64(&d2, 91) == 0); assert(dnq_has64(&d2, 90) == 1); assert(dnq_has64(&d2, 9002) == 0); assert(dnq_has64(&d2, 9000) == 0); assert(dnq_has64(&d2, 13337) == 1); assert(dnq_has64(&d2, 13338) == 0); assert(dnq_has64(&d2, 13336) == 0); assert(dnq_has64(&d2, 88) == 0); assert(dnq_has64(&d2, 41) == 0); assert(dnq_has64(&d2, 42) == 1); uintptr_t val3[] = { 1, 6, 4, 8, 13337, 42, 89, 9001, 90, }; uintptr_t val3_sorted[] = { 1, 4, 6, 8, 42, 89, 90, 9001, 13337, }; dnq_init(&d3, val3, sizeof(uintptr_t), sizeof(val3) / sizeof(uintptr_t)); assert(memcmp(d3.list, val3_sorted, sizeof(val3_sorted)) == 0); assert(dnq_hasptr(&d3, 4) == 1); assert(dnq_hasptr(&d3, 0) == 0); assert(dnq_hasptr(&d3, 1) == 1); assert(dnq_hasptr(&d3, 2) == 0); assert(dnq_hasptr(&d3, 43) == 0); assert(dnq_hasptr(&d3, 91) == 0); assert(dnq_hasptr(&d3, 90) == 1); assert(dnq_hasptr(&d3, 9002) == 0); assert(dnq_hasptr(&d3, 9000) == 0); assert(dnq_hasptr(&d3, 13337) == 1); assert(dnq_hasptr(&d3, 13338) == 0); assert(dnq_hasptr(&d3, 13336) == 0); assert(dnq_hasptr(&d3, 88) == 0); assert(dnq_hasptr(&d3, 41) == 0); assert(dnq_hasptr(&d3, 42) == 1); assert(dnq_iter32(&d1)[4] == 42); assert(dnq_iter64(&d2)[4] == 42); assert(dnq_iterptr(&d3)[4] == 42); pipe("INFO:Test finished!"); return 0; }
test_mockable int main(void) { /* * Pre-initialization (pre-verified boot) stage. Initialization at * this level should do as little as possible, because verified boot * may need to jump to another image, which will repeat this * initialization. In particular, modules should NOT enable * interrupts. */ #ifdef CONFIG_BOARD_PRE_INIT board_config_pre_init(); #endif #ifdef CONFIG_MPU mpu_pre_init(); #endif /* Configure the pin multiplexers and GPIOs */ jtag_pre_init(); gpio_pre_init(); #ifdef CONFIG_BOARD_POST_GPIO_INIT board_config_post_gpio_init(); #endif /* * Initialize interrupts, but don't enable any of them. Note that * task scheduling is not enabled until task_start() below. */ task_pre_init(); /* * Initialize the system module. This enables the hibernate clock * source we need to calibrate the internal oscillator. */ system_pre_init(); system_common_pre_init(); #ifdef CONFIG_FLASH /* * Initialize flash and apply write protect if necessary. Requires * the reset flags calculated by system initialization. */ flash_pre_init(); #endif /* Set the CPU clocks / PLLs. System is now running at full speed. */ clock_init(); /* * Initialize timer. Everything after this can be benchmarked. * get_time() and udelay() may now be used. usleep() requires task * scheduling, so cannot be used yet. Note that interrupts declared * via DECLARE_IRQ() call timer routines when profiling is enabled, so * timer init() must be before uart_init(). */ timer_init(); /* Main initialization stage. Modules may enable interrupts here. */ cpu_init(); #ifdef CONFIG_DMA /* Initialize DMA. Must be before UART. */ dma_init(); #endif /* Initialize UART. Console output functions may now be used. */ uart_init(); if (system_jumped_to_this_image()) { CPRINTS("UART initialized after sysjump"); } else { CPUTS("\n\n--- UART initialized after reboot ---\n"); CPUTS("[Reset cause: "); system_print_reset_flags(); CPUTS("]\n"); } CPRINTF("[Image: %s, %s]\n", system_get_image_copy_string(), system_get_build_info()); #ifdef CONFIG_WATCHDOG /* * Intialize watchdog timer. All lengthy operations between now and * task_start() must periodically call watchdog_reload() to avoid * triggering a watchdog reboot. (This pretty much applies only to * verified boot, because all *other* lengthy operations should be done * by tasks.) */ watchdog_init(); #endif /* * Verified boot needs to read the initial keyboard state and EEPROM * contents. EEPROM must be up first, so keyboard_scan can toggle * debugging settings via keys held at boot. */ #ifdef CONFIG_EEPROM eeprom_init(); #endif #ifdef CONFIG_EOPTION eoption_init(); #endif #ifdef HAS_TASK_KEYSCAN keyboard_scan_init(); #endif /* Initialize the hook library. This calls HOOK_INIT hooks. */ hook_init(); /* * Print the init time. Not completely accurate because it can't take * into account the time before timer_init(), but it'll at least catch * the majority of the time. */ CPRINTS("Inits done"); /* Launch task scheduling (never returns) */ return task_start(); }
static int __init fix_init(void) { hook_init(); return 0; }
void weechat_init (int argc, char *argv[], void (*gui_init_cb)()) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); weechat_locale_ok = (setlocale (LC_ALL, "") != NULL); /* init gettext */ #ifdef ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif #ifdef HAVE_LANGINFO_CODESET weechat_local_charset = strdup (nl_langinfo (CODESET)); #else weechat_local_charset = strdup (""); #endif utf8_init (); /* catch signals */ util_catch_signal (SIGINT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGQUIT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGPIPE, SIG_IGN); /* signal ignored */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump */ util_catch_signal (SIGHUP, &weechat_sighup); /* exit WeeChat */ util_catch_signal (SIGQUIT, &weechat_sigquit); /* exit WeeChat */ util_catch_signal (SIGTERM, &weechat_sigterm); /* exit WeeChat */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_color_init (); /* initialize colors */ gui_chat_init (); /* initialize chat */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ weechat_shutdown (EXIT_FAILURE, 0); weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dir (); /* create WeeChat home directory */ log_init (); /* init log file */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ if (gui_init_cb) (*gui_init_cb) (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_welcome_message (); /* display WeeChat welcome message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ weechat_term_check (); /* warnings about $TERM (if wrong) */ weechat_locale_check (); /* warning about wrong locale */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_auto_load_plugins, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ }
bool hook_d3d9(void) { HMODULE d3d9_module = get_system_module("d3d9.dll"); uint32_t d3d9_size; void *present_addr = nullptr; void *present_ex_addr = nullptr; void *present_swap_addr = nullptr; if (!d3d9_module) { return false; } d3d9_size = module_size(d3d9_module); if (global_hook_info->offsets.d3d9.present < d3d9_size && global_hook_info->offsets.d3d9.present_ex < d3d9_size && global_hook_info->offsets.d3d9.present_swap < d3d9_size) { present_addr = get_offset_addr(d3d9_module, global_hook_info->offsets.d3d9.present); present_ex_addr = get_offset_addr(d3d9_module, global_hook_info->offsets.d3d9.present_ex); present_swap_addr = get_offset_addr(d3d9_module, global_hook_info->offsets.d3d9.present_swap); } else { if (!dummy_window) { return false; } if (!manually_get_d3d9_addrs(d3d9_module, &present_addr, &present_ex_addr, &present_swap_addr)) { hlog("Failed to get D3D9 values"); return true; } } if (!present_addr && !present_ex_addr && !present_swap_addr) { hlog("Invalid D3D9 values"); return true; } if (present_swap_addr) { hook_init(&present_swap, present_swap_addr, (void*)hook_present_swap, "IDirect3DSwapChain9::Present"); rehook(&present_swap); } if (present_ex_addr) { hook_init(&present_ex, present_ex_addr, (void*)hook_present_ex, "IDirect3DDevice9Ex::PresentEx"); rehook(&present_ex); } if (present_addr) { hook_init(&present, present_addr, (void*)hook_present, "IDirect3DDevice9::Present"); rehook(&present); } hlog("Hooked D3D9"); return true; }
bool hook_dxgi(void) { pD3DCompile compile; ID3D10Blob *blob; HMODULE dxgi_module = get_system_module("dxgi.dll"); HRESULT hr; void *present_addr; void *resize_addr; if (!dxgi_module) { return false; } compile = get_compiler(); if (!compile) { hlog("hook_dxgi: failed to find d3d compiler library"); return true; } /* ---------------------- */ hr = compile(vertex_shader_string, sizeof(vertex_shader_string), "vertex_shader_string", nullptr, nullptr, "main", "vs_4_0", D3D10_SHADER_OPTIMIZATION_LEVEL1, 0, &blob, nullptr); if (FAILED(hr)) { hlog_hr("hook_dxgi: failed to compile vertex shader", hr); return true; } vertex_shader_size = (size_t)blob->GetBufferSize(); memcpy(vertex_shader_data, blob->GetBufferPointer(), blob->GetBufferSize()); blob->Release(); /* ---------------------- */ hr = compile(pixel_shader_string, sizeof(pixel_shader_string), "pixel_shader_string", nullptr, nullptr, "main", "ps_4_0", D3D10_SHADER_OPTIMIZATION_LEVEL1, 0, &blob, nullptr); if (FAILED(hr)) { hlog_hr("hook_dxgi: failed to compile pixel shader", hr); return true; } pixel_shader_size = (size_t)blob->GetBufferSize(); memcpy(pixel_shader_data, blob->GetBufferPointer(), blob->GetBufferSize()); blob->Release(); /* ---------------------- */ present_addr = get_offset_addr(dxgi_module, global_hook_info->offsets.dxgi.present); resize_addr = get_offset_addr(dxgi_module, global_hook_info->offsets.dxgi.resize); hook_init(&present, present_addr, (void*)hook_present, "IDXGISwapChain::Present"); hook_init(&resize_buffers, resize_addr, (void*)hook_resize_buffers, "IDXGISwapChain::ResizeBuffers"); rehook(&resize_buffers); rehook(&present); hlog("Hooked DXGI"); return true; }
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID lpReserved) { static bool bDllInited = false; BOOL IsUnload = false, bEnableDW = true; switch(reason) { case DLL_PROCESS_ATTACH: #ifdef DEBUG //MessageBox(0, L"Load", NULL, MB_OK); #endif if (bDllInited) return true; bDllInited = true; g_dllInstance = instance; { LPWSTR dllPath = new WCHAR[MAX_PATH + 1]; int nSize = GetModuleFileName(g_dllInstance, dllPath, MAX_PATH + 1); WCHAR* p = &dllPath[nSize]; while (*--p != L'\\'); *p = L'\0'; #ifdef _WIN64 wcscat(dllPath, L"\\EasyHk64.dll"); #else wcscat(dllPath, L"\\EasyHk32.dll"); #endif HMODULE hEasyhk = LoadLibrary(dllPath); delete[]dllPath; if (!hEasyhk) return false; } //弶婜壔弴彉 //DLL_PROCESS_DETACH偱偼偙傟偺媡弴偵偡傞 //1. CRT娭悢偺弶婜壔 //2. 僋儕僥傿僇儖僙僋僔儑儞偺弶婜壔 //3. TLS偺弨旛 //4. CGdippSettings偺僀儞僗僞儞僗惗惉丄INI撉傒崬傒 //5. ExcludeModule僠僃僢僋 // 6. FreeType儔僀僽儔儕偺弶婜壔 // 7. FreeTypeFontEngine偺僀儞僗僞儞僗惗惉 // 8. API傪僼僢僋 // 9. Manager偺GetProcAddress傪僼僢僋 //1 _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_WNDW); //_CrtSetBreakAlloc(100); //Opera傛巭傑傟乣 //Assert(GetModuleHandleA("opera.exe") == NULL); setlocale(LC_ALL, ""); g_hinstDLL = instance; //APITracer::Start(instance, APITracer::OutputFile); //2, 3 CCriticalSectionLock::Init(); COwnedCriticalSectionLock::Init(); CThreadCounter::Init(); if (!g_TLInfo.ProcessInit()) { return FALSE; } //4 { CGdippSettings* pSettings = CGdippSettings::CreateInstance(); if (!pSettings || !pSettings->LoadSettings(instance)) { CGdippSettings::DestroyInstance(); return FALSE; } IsUnload = IsProcessUnload(); bEnableDW = pSettings->DirectWrite(); } if (!IsUnload) hook_initinternal(); //不加载的模块就不做任何事情 //5 if (!IsProcessExcluded() && !IsUnload) { #ifndef _WIN64 InitWow64ext(); #endif if (!FontLInit()) { return FALSE; } g_pFTEngine = new FreeTypeFontEngine; if (!g_pFTEngine) { return FALSE; } //if (!AddEasyHookEnv()) return FALSE; //fail to load easyhook InterlockedExchange(&g_bHookEnabled, TRUE); if (hook_init()!=NOERROR) return FALSE; //hook d2d if already loaded /* DWORD dwSessionID = 0; if (ProcessIdToSessionIdProc) ProcessIdToSessionIdProc(GetCurrentThreadId(), &dwSessionID); else dwSessionID = 1;*/ if (IsRunAsUser() && bEnableDW && IsWindowsVistaOrGreater()) //vista or later { //ORIG_LdrLoadDll = LdrLoadDll; //MessageBox(0, L"Test", NULL, MB_OK); HookD2DDll(); //hook_demand_LdrLoadDll(); } /*if (IsWindows8OrGreater()) { *(DWORD_PTR*)&(ORIG_MySetProcessMitigationPolicy) = *(DWORD_PTR*)&(MySetProcessMitigationPolicy); //hook_demand_MySetProcessMitigationPolicy(); }*/ // InstallManagerHook(); } //获得当前加载模式 if (IsUnload) { HANDLE mutex_offical = OpenMutex(MUTEX_ALL_ACCESS, false, _T("{46AD3688-30D0-411e-B2AA-CB177818F428}")); HANDLE mutex_gditray2 = OpenMutex(MUTEX_ALL_ACCESS, false, _T("Global\\MacType")); if (!mutex_gditray2) mutex_gditray2 = OpenMutex(MUTEX_ALL_ACCESS, false, _T("MacType")); HANDLE mutex_CompMode = OpenMutex(MUTEX_ALL_ACCESS, false, _T("Global\\MacTypeCompMode")); if (!mutex_CompMode) mutex_CompMode = OpenMutex(MUTEX_ALL_ACCESS, false, _T("MacTypeCompMode")); BOOL HookMode = (mutex_offical || (mutex_gditray2 && mutex_CompMode)) || (!mutex_offical && !mutex_gditray2); //是否在兼容模式下 CloseHandle(mutex_CompMode); CloseHandle(mutex_gditray2); CloseHandle(mutex_offical); if (!HookMode) //非兼容模式下,拒绝加载 return false; } //APITracer::Finish(); break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: g_TLInfo.ThreadTerm(); break; case DLL_PROCESS_DETACH: // RemoveManagerHook(); if (!bDllInited) return true; bDllInited = false; if (InterlockedExchange(&g_bHookEnabled, FALSE) && lpReserved == NULL) { //如果是进程终止,则不需要释放 hook_term(); //delete AACacheFull; //delete AACache; // for (int i=0;i<CACHE_SIZE;i++) // delete g_AACache2[i]; //清除缓存 //free(g_charmapCache); } #ifndef DEBUG if (lpReserved != NULL) return true; #endif if (g_pFTEngine) { delete g_pFTEngine; } //if (g_alterGUIFont) // DeleteObject(g_alterGUIFont); FontLFree(); /* #ifndef _WIN64 __FUnloadDelayLoadedDLL2("easyhk32.dll"); #else __FUnloadDelayLoadedDLL2("easyhk64.dll"); #endif*/ CGdippSettings::DestroyInstance(); g_TLInfo.ProcessTerm(); CCriticalSectionLock::Term(); COwnedCriticalSectionLock::Term(); break; } return TRUE; }