int main(int argc, char *argv[]) { int pid; struct link_map *map; struct elf_info einfo; extern dl_fl_t ldl; void *handle = NULL; long proc = 0; long hooker_fopen = 0; (void)argc; pid = atoi(argv[1]); ptrace_attach(pid); ptrace_find_dlinfo(pid); handle = ptrace_dlopen(pid, "/system/lib/libmynet.so",1); printf("ptrace_dlopen handle %p\n",handle); proc = (long)ptrace_dlsym(pid, handle, "my_connect"); printf("my_connect = %lx\n",proc); replace_all_rels(pid, "connect", proc, sos); ptrace_detach(pid); exit(0); }
int main(int argc, char* argv[]) { int pid; struct link_map *map; struct elf_info einfo; extern dl_fl_t ldl; void *handle = NULL; long proc = 0; long hooker_fopen = 0; char pathfile[100]; if (argc != 4) { LOGE("illegal arguments, injection reject"); return -1; } LOGD("inject begin"); pid = find_pid_of(argv[1]); ptrace_attach(pid); ptrace_find_dlinfo(pid); handle = ptrace_dlopen(pid, str_contact(argv[2], HOOK_LIB), 1); printf("ptrace_dlopen handle %p\n", handle); proc = (long) ptrace_dlsym(pid, handle, "hook"); printf("main = %lx\n", proc); ptrace_arg arg; arg.s = argv[3]; arg.type = PAT_STR; static char buffer[0x1000]; strcpy(buffer, argv[1]); strcat(buffer, "#"); strcat(buffer, argv[3]); arg.s = buffer; printf("arg.s=%s\n", arg.s); ptrace_call(pid, proc, 1, &arg); ptrace_detach(pid); LOGD("inject end"); exit(0); return 0; }