Repository: nevermoe/EHook
Branch: master
Commit: 58c1acea7727
Files: 18
Total size: 63.0 KB
Directory structure:
gitextract_6plxykad/
├── .gitignore
├── LICENSE
├── README.md
├── jni/
│ ├── Android.mk
│ ├── Application.mk
│ ├── hook.c
│ ├── hook.h
│ ├── inject.c
│ ├── realinject.c
│ ├── relocate.c
│ ├── relocate.h
│ ├── stalker.c
│ └── target.c
├── libs/
│ ├── armeabi-v7a/
│ │ ├── stalker
│ │ └── target
│ └── x86/
│ ├── stalker
│ └── target
└── push.cmd
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.swp
*.id0
*.id1
*.id2
*.idb
*.nam
*.til
*.un~
obj/
================================================
FILE: LICENSE
================================================
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
================================================
FILE: README.md
================================================
# EHook
A hooking framework for commercial Android emulators ([雷电模拟器](http://www.ldmnq.com/), [NOX](https://jp.bignox.com/), [BlueStacks](https://www.bluestacks.com/ja/index.html#gref)).
As you may know, these commercail emulators use x86 (kernel) and arm (user land) mixed-mode method to accelerate the emulation and this makes it difficult to hook the native arm libraries. This emulator hooking framework is intented to solve this problem.
# Usage
1. Modify the jni/realinject.c file. You can hook functions both by address or by the function's symbol name:
```
static struct hook_t eph1;
static struct hook_t eph_sendto;
...
...
/*On BlueStacks*/
//hook_by_addr(&eph1, "arm/libc.so", target_addr, hook_func1);
/*Other emulators*/
hook_by_name(&eph_sendto, "nb/libc.so", "sendto", hook_sendto);
```
**Notice:** If you are hooking system libraries like "libc.so", please make sure you are giving the right path of the arm version binary.
2. Run `ndk-build`
3. Push the following 3 binary to android /data/local/tmp directory:
`libs/x86/stalker`
`libs/x86/libinject.so`
`libs/armeabi/librealinject.so`
Or just run `push.cmd`.
4. On android, type `./stalker [pid]`.
# Notice
1. For NOX emulator, you should use the Android 5.1.1 instead of the default 4.4.2.
2. Also see this repo: [XEHook](https://github.com/nevermoe/XEHook).
# acknowledgement
Thanks to these 大神s' work. They made my life much easier.
https://github.com/zhengmin1989/TheSevenWeapons/tree/master/LiBieGou
https://github.com/ele7enxxh/Android-Inline-Hook
================================================
FILE: jni/Android.mk
================================================
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -fPIE
LOCAL_LDFLAGS += -fPIE -pie
LOCAL_MODULE := target
LOCAL_SRC_FILES := target.c
cmd-strip :=
include $(BUILD_EXECUTABLE)
###########################################################
include $(CLEAR_VARS)
LOCAL_MODULE := hook
#LOCAL_SRC_FILES := hook.c.arm
LOCAL_SRC_FILES := hook.c
include $(BUILD_STATIC_LIBRARY)
###########################################################
include $(CLEAR_VARS)
LOCAL_MODULE := relocate
LOCAL_SRC_FILES := relocate.c
include $(BUILD_STATIC_LIBRARY)
###########################################################
include $(CLEAR_VARS)
LOCAL_CFLAGS += -fPIE
LOCAL_LDFLAGS += -fPIE -pie
LOCAL_MODULE := stalker
LOCAL_SRC_FILES := stalker.c
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := hook
include $(BUILD_EXECUTABLE)
###########################################################
include $(CLEAR_VARS)
LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true
LOCAL_MODULE := inject
LOCAL_SRC_FILES := inject.c
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := hook relocate
include $(BUILD_SHARED_LIBRARY)
###########################################################
include $(CLEAR_VARS)
LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true
LOCAL_MODULE := realinject
LOCAL_SRC_FILES := realinject.c
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := hook relocate
include $(BUILD_SHARED_LIBRARY)
================================================
FILE: jni/Application.mk
================================================
APP_ABI := x86 armeabi-v7a
# APP_OPTIM := debug
================================================
FILE: jni/hook.c
================================================
#include "hook.h"
#include "relocate.h"
void get_module_range(pid_t pid, const char* module_name, uint32_t* start_addr, uint32_t* end_addr)
{
FILE *fp;
char *pch;
char filename[32];
char line[1024];
*start_addr = 0;
if (end_addr) {
*end_addr = 0;
}
if (pid == 0) {
snprintf(filename, sizeof(filename), "/proc/self/maps");
} else {
snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
}
fp = fopen(filename, "r");
if (fp != NULL) {
while (fgets(line, sizeof(line), fp)) {
//LOGD("line: %s", line);
if (strstr(line, module_name)) {
pch = strtok(line, "-");
*start_addr = strtoul(pch, NULL, 16);
//LOGD("pch start: %s start_addr: %x\n", pch, *start_addr);
pch = strtok(NULL, " ");
if (end_addr) {
*end_addr = strtoul(pch, NULL, 16);
//LOGD("pch end: %s end_addr: %x\n", pch, *end_addr);
}
/*
if (*start_addr == 0x8000) {
*start_addr -= 0x8000;
if (end_addr)
*end_addr -= 0x8000;
}
*/
break;
}
}
fclose(fp) ;
}
}
int hook_by_name(struct hook_t *h, char* module_name, const char* func_name, void *hook_func)
{
int ret = 0;
void *handle = dlopen(module_name, RTLD_NOW);
void *func_addr = dlsym(handle, func_name);
//get module range for self process
uint32_t module_start_addr = 0, module_end_addr = 0;
get_module_range(0, module_name, &module_start_addr, &module_end_addr);
if(module_start_addr == 0 || module_end_addr == 0) {
LOGD("HOOK_ERROR_SO_NOT_FOUND: %s\n", module_name);
return HOOK_ERROR_SO_NOT_FOUND;
}
//mprotect
ret = mprotect((void*)module_start_addr, module_end_addr - module_start_addr,
PROT_READ|PROT_WRITE|PROT_EXEC);
if (ret) {
LOGD("mprotect failed\n");
return HOOK_ERROR_MPROTECT_FAILED;
}
h->module_base = module_start_addr;
return _hook(h, (unsigned int)func_addr, hook_func);
}
int hook_by_addr(struct hook_t *h, char* module_name, unsigned int addr, void *hook_func)
{
int i;
uint32_t module_start_addr = 0, module_end_addr = 0;
get_module_range(0, module_name, &module_start_addr, &module_end_addr);
if(module_start_addr == 0 || module_end_addr == 0) {
LOGD("HOOK_ERROR_SO_NOT_FOUND: %s\n", module_name);
return HOOK_ERROR_SO_NOT_FOUND;
}
unsigned int func_addr = module_start_addr + addr;
//mprotect
int ret = mprotect((void*)module_start_addr, module_end_addr - module_start_addr,
PROT_READ|PROT_WRITE|PROT_EXEC);
if (ret) {
LOGD("mprotect failed\n");
return HOOK_ERROR_MPROTECT_FAILED;
}
h->module_base = module_start_addr;
return _hook(h, (unsigned int)func_addr, hook_func);
}
static int _hook(struct hook_t *h, unsigned int addr, void *hook_func)
{
LOGD("[%d] hooking: 0x%x\n", getpid(), addr - h->module_base);
h->new_addr = (unsigned int)hook_func;
h->target_addr = addr;
h->length = TEST_BIT0(h->target_addr) ? 12 : 8;
memcpy(h->orig_instructions, (void *) CLEAR_BIT0(h->target_addr), h->length);
//modify function entry point
if (!TEST_BIT0(h->target_addr)) {
//ARM mode
LOGD("using ARM mode 0x%lx\n", (unsigned long)hook_func);
h->thumb = 0;
h->proto = h->trampoline_instructions;
((uint32_t *)h->target_addr)[0] = 0xe51ff004; // LDR pc, [pc, #-4]
((uint32_t *)h->target_addr)[1] = h->new_addr;
}
else {
//thumb mode
LOGD("using thumb mode 0x%lx\n", (unsigned long)hook_func);
int i = 0;
if (CLEAR_BIT0(h->target_addr) % 4 != 0) {
((uint16_t *) CLEAR_BIT0(h->target_addr))[i++] = 0xBF00; // NOP
}
h->thumb = 1;
h->proto = (uint32_t *)SET_BIT0((uint32_t)h->trampoline_instructions);
((uint16_t *) CLEAR_BIT0(h->target_addr))[i++] = 0xF8DF;
((uint16_t *) CLEAR_BIT0(h->target_addr))[i++] = 0xF000; // LDR.W PC, [PC]
((uint16_t *) CLEAR_BIT0(h->target_addr))[i++] = h->new_addr & 0xFFFF;
((uint16_t *) CLEAR_BIT0(h->target_addr))[i++] = h->new_addr >> 16;
}
hook_cacheflush(CLEAR_BIT0(h->target_addr), CLEAR_BIT0(h->target_addr)+h->length);
relocateInstruction(h->target_addr, h->orig_instructions, h->length, h->trampoline_instructions, h->orig_boundaries, h->trampoline_boundaries, &h->count);
//addr must align to page (4kb)
int ret = mprotect((void*)((int)h->trampoline_instructions & 0xFFFFF000), 0x1000,
PROT_READ|PROT_WRITE|PROT_EXEC);
if (ret != 0) {
LOGD("mprotect failed: %d\ttrampoline_addr: 0x%x\n", ret, (uint32_t)h->trampoline_instructions);
ret = HOOK_ERROR_MPROTECT_FAILED;
}
return ret;
}
void inline hook_cacheflush(unsigned int begin, unsigned int end)
{
#if 0
#if defined(__arm__)
const int syscall = 0xf0002;
__asm __volatile (
"mov r0, %0\n"
"mov r1, %1\n"
"mov r7, %2\n"
"mov r2, #0x0\n"
"svc 0x00000000\n"
:
: "r" (begin), "r" (end), "r" (syscall)
: "r0", "r1", "r7"
);
#endif
#endif
}
/*
void hook_unset_jump(struct hook_t *h)
{
int i;
if (h->thumb) {
unsigned int orig = h->orig - 1;
for (i = 0; i < sizeof(h->storet); i++) {
((unsigned char*)orig)[i] = h->storet[i];
}
}
else {
for (i = 0; i < sizeof(h->store)/4; i++)
((unsigned int*)h->orig)[i] = h->store[i];
}
hook_cacheflush((unsigned int)h->orig, (unsigned int)h->orig+sizeof(h->jumpt));
}
*/
/*
void hook_set_jump(struct hook_t *h)
{
int i;
if (h->thumb) {
unsigned int orig = h->orig - 1;
for (i = 0; i < sizeof(h->jumpt); i++)
((unsigned char*)orig)[i] = h->jumpt[i];
}
else {
for (i = 0; i < sizeof(h->jump)/sizeof(unsigned int); i++)
((int*)h->orig)[i] = h->jump[i];
}
hook_cacheflush((unsigned int)h->orig, (unsigned int)h->orig+sizeof(h->jumpt));
}
*/
================================================
FILE: jni/hook.h
================================================
#ifndef __HOOK_H__
#define __HOOK_H__
#include <stdio.h>
#include <stdlib.h>
//#include <asm/user.h>
#include <sys/user.h>
#include <asm/ptrace.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <dlfcn.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include <elf.h>
#include <android/log.h>
#if defined(__i386__)
#define pt_regs user_regs_struct
#endif
#define LOG_TAG "MY_HOOK"
#define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args)
#define LOGF(...) \
{FILE *fp = fopen("/data/local/tmp/hook.log", "a+"); if (fp) {\
fprintf(fp, __VA_ARGS__);\
fclose(fp);}}
#define SET_BIT0(addr) (addr | 1)
#define CLEAR_BIT0(addr) (addr & 0xFFFFFFFE)
#define TEST_BIT0(addr) (addr & 1)
#define ORIG_INS_SIZE 3
#define TRAMPOLINE_INS_SIZE 10
#define ORIG_BOUND_SIZE 4
#define TRAMPOLINE_BOUND_SIZE 20
struct hook_t {
uint32_t target_addr;
uint32_t new_addr;
uint32_t orig_instructions[ORIG_INS_SIZE];
uint32_t trampoline_instructions[TRAMPOLINE_INS_SIZE];
int orig_boundaries[ORIG_BOUND_SIZE];
int trampoline_boundaries[TRAMPOLINE_BOUND_SIZE];
uint32_t *proto;
int count;
int length;
unsigned int thumb;
unsigned int module_base;
};
enum hook_status {
HOOK_OK = 0,
//HOOK_ERROR_NOT_EXECUTABLE,
HOOK_ERROR_SO_NOT_FOUND,
HOOK_ERROR_MPROTECT_FAILED,
HOOK_ERROR_UNKNOWN
};
void get_module_range(pid_t pid, const char* module_name, uint32_t* start_addr, uint32_t* end_addr);
int hook_by_addr(struct hook_t *h, char* module_name, unsigned int addr, void *hook_func);
int hook_by_name(struct hook_t *h, char* module_name, const char* func_name, void *hook_func);
static int _hook(struct hook_t *h, unsigned int addr, void *hook_func);
void inline hook_cacheflush(unsigned int begin, unsigned int end);
void hook_unset_jump(struct hook_t *h);
void hook_set_jump(struct hook_t *h);
#endif
================================================
FILE: jni/inject.c
================================================
#include "hook.h"
#include <android/log.h>
typedef void *native_load_library(void *handle, const char *symbol);
typedef void *native_bridge_get_trampoline(void *handle, const char *symbol_name, const char* shorty, uint32_t length);
typedef void* dvm2_hd_dlopen(const char* filename, int flag);
typedef int real_init_func(char * str);
void load_real_lib_bluestacks()
{
void* dvm2hdDlopen = 0, *librealinject = 0, *lib3btrans = 0;
lib3btrans = dlopen("/system/lib/lib3btrans.so", RTLD_NOW);
LOGD("lib3btrans.so handler addr is %p\n", lib3btrans);
dvm2hdDlopen = dlsym(lib3btrans, "dvm2hdDlopen");
LOGD("dvm2hdDlopen addr is %p\n", dvm2hdDlopen);
librealinject = ((dvm2_hd_dlopen*)dvm2hdDlopen)("/data/local/tmp/librealinject.so", RTLD_NOW);
LOGD("librealinject.so handler addr is %p\n", librealinject);
}
void load_real_lib_4_4_2()
{
void* dvm2hdDlopen = 0, *librealinject = 0, *libhoudini = 0;
libhoudini = dlopen("/system/lib/libhoudini.so", RTLD_NOW);
LOGD("libhoudini.so handler addr is %p\n", libhoudini);
dvm2hdDlopen = dlsym(libhoudini, "dvm2hdDlopen");
LOGD("dvm2hdDlopen addr is %p\n", dvm2hdDlopen);
librealinject = ((dvm2_hd_dlopen*)dvm2hdDlopen)("/data/local/tmp/librealinject.so", RTLD_NOW);
LOGD("librealinject.so handler addr is %p\n", librealinject);
}
void load_real_lib_5_5_1()
{
void* libnativebridge = 0, *NativeBridgeLoadLibrary = 0,
*librealinject = 0;
libnativebridge = dlopen("/system/lib/libnativebridge.so", RTLD_NOW);
LOGD("libnativebridge.so handler addr is %p\n", libnativebridge);
NativeBridgeLoadLibrary = dlsym(libnativebridge, "_ZN7android23NativeBridgeLoadLibraryEPKci");
LOGD("NativeBridgeLoadLibrary addr is %p\n", NativeBridgeLoadLibrary);
librealinject = ((native_load_library*)NativeBridgeLoadLibrary)("/data/local/tmp/librealinject.so", RTLD_NOW);
LOGD("librealinject.so handler addr is %p\n", librealinject);
#if 0
void *NativeBridgeGetTrampoline = 0, *RealInitFunc = 0;
NativeBridgeGetTrampoline = dlsym(libnativebridge, "_ZN7android25NativeBridgeGetTrampolineEPvPKcS2_j");
LOGD("NativeBridgeGetTrampoline addr is %p\n", NativeBridgeGetTrampoline);
RealInitFunc = ((native_bridge_get_trampoline*)NativeBridgeGetTrampoline)(librealinject, "real_init_func", 0, 0);
LOGD("RealInitFunc addr is %p\n", RealInitFunc);
((real_init_func*)RealInitFunc)("HelloWorld");
#endif
}
int init_func(char * str){
LOGD("%s, hook in pid = %d\n", str, getpid());
char* nb_file = "/system/lib/libnativebridge.so";
char* dvm_file = "/system/lib/libdvm.so";
char* btrans_file = "/system/lib/lib3btrans.so";
if( access(nb_file, F_OK) != -1 ) {
// native bridge exists, Android 5.5.1
load_real_lib_5_5_1();
} else if ( access(btrans_file, F_OK) != -1){
// BlueStacks
load_real_lib_bluestacks();
} else { //dvm_file exsits
//Android 4.4.2, maybe NOX
load_real_lib_4_4_2();
}
LOGD("init_func ended");
return 0;
}
================================================
FILE: jni/realinject.c
================================================
#include "hook.h"
#include <android/log.h>
static struct hook_t eph;
int hook_battleEnd(int p1, int p2)
{
int (*orig_func)(int p1, int p2);
orig_func = (void*)eph.proto;
LOGD("hooking: 0x%x\n", (unsigned int)(eph.target_addr-eph.module_base));
p2 = 1;
int ret = orig_func(p1, p2);
return ret;
}
static void real_init_func() __attribute__((constructor));
void real_init_func()
{
#if 0
LOGD("real_init_func called\n");
long target_addr = 0;
target_addr = 0x590f0;//sendto
/*Bluestacks*/
//hook_by_addr(&eph_sendto, "arm/libc.so", target_addr, hook_sendto);
//hook_by_name(&eph_recvfrom, "arm/libc.so", "recvfrom", hook_recvfrom);
/*Other emulators*/
hook_by_addr(&eph_sendto, "nb/libc.so", target_addr, hook_sendto);
hook_by_name(&eph_recvfrom, "nb/libc.so", "recvfrom", hook_recvfrom);
LOGD("real_init_func ended\n");
#endif
LOGD("real_init_func called\n");
long target_addr = 0;
target_addr = 0x177335;
hook_by_addr(&eph, "libcocos2dcpp.so", target_addr, hook_battleEnd);
LOGD("real_init_func ended\n");
}
================================================
FILE: jni/relocate.c
================================================
/*
relocate instruction
author: ele7enxxh
mail: ele7enxxh@qq.com
website: ele7enxxh.com
modified time: 2016-10-17
created time: 2015-01-17
*/
#include "relocate.h"
#include <android/log.h>
#define ALIGN_PC(pc) (pc & 0xFFFFFFFC)
#define LOG_TAG "MY_HOOK"
#define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args)
enum INSTRUCTION_TYPE {
// B <label>
B1_THUMB16,
// B <label>
B2_THUMB16,
// BX PC
BX_THUMB16,
// ADD <Rdn>, PC (Rd != PC, Rn != PC) 在对ADD进行修正时,采用了替换PC为Rr的方法,当Rd也为PC时,由于之前更改了Rr的值,可能会影响跳转后的正常功能。
ADD_THUMB16,
// MOV Rd, PC
MOV_THUMB16,
// ADR Rd, <label>
ADR_THUMB16,
// LDR Rt, <label>
LDR_THUMB16,
// CB{N}Z <Rn>, <label>
CB_THUMB16,
//if-then
IT_THUMB16,
//dmb sy?
DMB_THUMB32,
// BLX <label>
BLX_THUMB32,
// BL <label>
BL_THUMB32,
// B.W <label>
B1_THUMB32,
// B.W <label>
B2_THUMB32,
// ADR.W Rd, <label>
ADR1_THUMB32,
// ADR.W Rd, <label>
ADR2_THUMB32,
// LDR.W Rt, <label>
LDR_THUMB32,
// TBB [PC, Rm]
TBB_THUMB32,
// TBH [PC, Rm, LSL #1]
TBH_THUMB32,
// BLX <label>
BLX_ARM,
// BL <label>
BL_ARM,
// B <label>
B_ARM,
// BX PC
BX_ARM,
// ADD Rd, PC, Rm (Rd != PC, Rm != PC) 在对ADD进行修正时,采用了替换PC为Rr的方法,当Rd也为PC时,由于之前更改了Rr的值,可能会影响跳转后的正常功能;实际汇编中没有发现Rm也为PC的情况,故未做处理。
ADD_ARM,
// ADR Rd, <label>
ADR1_ARM,
// ADR Rd, <label>
ADR2_ARM,
// MOV Rd, PC
MOV_ARM,
// LDR Rt, <label>
LDR_ARM,
UNDEFINE,
};
static int getTypeInThumb16(uint16_t instruction)
{
if ((instruction & 0xF000) == 0xD000) {
return B1_THUMB16;
}
if ((instruction & 0xF800) == 0xE000) {
return B2_THUMB16;
}
if ((instruction & 0xFFF8) == 0x4778) {
return BX_THUMB16;
}
if ((instruction & 0xFF78) == 0x4478) {
return ADD_THUMB16;
}
if ((instruction & 0xFF78) == 0x4678) {
return MOV_THUMB16;
}
if ((instruction & 0xF800) == 0xA000) {
return ADR_THUMB16;
}
if ((instruction & 0xF800) == 0x4800) {
return LDR_THUMB16;
}
if ((instruction & 0xF500) == 0xB100) {
return CB_THUMB16;
}
if ((instruction & 0xFF00) == 0xBF00) {
return IT_THUMB16;
}
return UNDEFINE;
}
static int getTypeInThumb32(uint32_t instruction)
{
if ((instruction & 0xF800D000) == 0xF000C000) {
return BLX_THUMB32;
}
if ((instruction & 0xF800D000) == 0xF000D000) {
return BL_THUMB32;
}
if ((instruction & 0xF3B08050) == 0xF3B08050) {
//FIXME
return DMB_THUMB32;
}
if ((instruction & 0xF800D000) == 0xF0008000) {
return B1_THUMB32;
}
if ((instruction & 0xF800D000) == 0xF0009000) {
return B2_THUMB32;
}
if ((instruction & 0xFBFF8000) == 0xF2AF0000) {
return ADR1_THUMB32;
}
if ((instruction & 0xFBFF8000) == 0xF20F0000) {
return ADR2_THUMB32;
}
if ((instruction & 0xFF7F0000) == 0xF85F0000) {
return LDR_THUMB32;
}
if ((instruction & 0xFFFF00F0) == 0xE8DF0000) {
return TBB_THUMB32;
}
if ((instruction & 0xFFFF00F0) == 0xE8DF0010) {
return TBH_THUMB32;
}
return UNDEFINE;
}
static int getTypeInArm(uint32_t instruction)
{
if ((instruction & 0xFE000000) == 0xFA000000) {
return BLX_ARM;
}
if ((instruction & 0xF000000) == 0xB000000) {
return BL_ARM;
}
if ((instruction & 0xF000000) == 0xA000000) {
return B_ARM;
}
if ((instruction & 0xFF000FF) == 0x120001F) {
return BX_ARM;
}
if ((instruction & 0xFEF0010) == 0x8F0000) {
return ADD_ARM;
}
if ((instruction & 0xFFF0000) == 0x28F0000) {
return ADR1_ARM;
}
if ((instruction & 0xFFF0000) == 0x24F0000) {
return ADR2_ARM;
}
if ((instruction & 0xE5F0000) == 0x41F0000) {
return LDR_ARM;
}
if ((instruction & 0xFE00FFF) == 0x1A0000F) {
return MOV_ARM;
}
return UNDEFINE;
}
static int relocateInstructionInThumb16(uint32_t pc, uint16_t instruction, uint16_t *trampoline_instructions)
{
int type;
int offset;
type = getTypeInThumb16(instruction);
if (type == B1_THUMB16 || type == B2_THUMB16 || type == BX_THUMB16) {
uint32_t x;
int top_bit;
uint32_t imm32;
uint32_t value;
int idx;
idx = 0;
if (type == B1_THUMB16) {
x = (instruction & 0xFF) << 1;
top_bit = x >> 8;
imm32 = top_bit ? (x | (0xFFFFFFFF << 8)) : x;
//value = pc + imm32;//FIXME
value = (pc + imm32) | 0x1;
trampoline_instructions[idx++] = instruction & 0xFF00;
trampoline_instructions[idx++] = 0xE003; // B PC, #6
}
else if (type == B2_THUMB16) {
x = (instruction & 0x7FF) << 1;
top_bit = x >> 11;
imm32 = top_bit ? (x | (0xFFFFFFFF << 11)) : x;
//value = pc + imm32;//FIXME
value = (pc + imm32) | 0x1;
}
else if (type == BX_THUMB16) {
value = pc;
}
trampoline_instructions[idx++] = 0xF8DF;
trampoline_instructions[idx++] = 0xF000; // LDR.W PC, [PC]
trampoline_instructions[idx++] = value & 0xFFFF;
trampoline_instructions[idx++] = value >> 16;
offset = idx;
}
else if (type == ADD_THUMB16) {
int rdn;
int rm;
int r;
rdn = ((instruction & 0x80) >> 4) | (instruction & 0x7);
for (r = 7; ; --r) {
if (r != rdn) {
break;
}
}
trampoline_instructions[0] = 0xB400 | (1 << r); // PUSH {Rr}
trampoline_instructions[1] = 0x4802 | (r << 8); // LDR Rr, [PC, #8]
trampoline_instructions[2] = (instruction & 0xFF87) | (r << 3);
trampoline_instructions[3] = 0xBC00 | (1 << r); // POP {Rr}
trampoline_instructions[4] = 0xE002; // B PC, #4
trampoline_instructions[5] = 0xBF00;
trampoline_instructions[6] = pc & 0xFFFF;
trampoline_instructions[7] = pc >> 16;
offset = 8;
}
else if (type == MOV_THUMB16 || type == ADR_THUMB16 || type == LDR_THUMB16) {
int r;
uint32_t value;
if (type == MOV_THUMB16) {
r = instruction & 0x7;
value = pc;
}
else if (type == ADR_THUMB16) {
r = (instruction & 0x700) >> 8;
value = ALIGN_PC(pc) + (instruction & 0xFF) << 2;
}
else {
r = (instruction & 0x700) >> 8;
value = ((uint32_t *) (ALIGN_PC(pc) + ((instruction & 0xFF) << 2)))[0];
}
trampoline_instructions[0] = 0x4800 | (r << 8); // LDR Rd, [PC]
trampoline_instructions[1] = 0xE001; // B PC, #2
trampoline_instructions[2] = value & 0xFFFF;
trampoline_instructions[3] = value >> 16;
offset = 4;
}
else if (type == CB_THUMB16) {
int nonzero;
uint32_t imm32;
uint32_t value;
nonzero = (instruction & 0x800) >> 11;
imm32 = ((instruction & 0x200) >> 3) | ((instruction & 0xF8) >> 2);
//value = pc + imm32 + 1;
value = (pc + imm32) | 0x1;
trampoline_instructions[0] = instruction & 0xFD07;
trampoline_instructions[1] = 0xE003; // B PC, #6
trampoline_instructions[2] = 0xF8DF;
trampoline_instructions[3] = 0xF000; // LDR.W PC, [PC]
trampoline_instructions[4] = value & 0xFFFF;
trampoline_instructions[5] = value >> 16;
offset = 6;
}
else if (type == IT_THUMB16) {
//FIXME: only considered IT XX.
//TODO: consider general situation like ITT, ITTT, ITE etc.
trampoline_instructions[0] = 0xBF00; // NOP
trampoline_instructions[1] = instruction;
offset = 2;
}
else {
trampoline_instructions[0] = instruction;
trampoline_instructions[1] = 0xBF00; // NOP
offset = 2;
}
return offset;
}
static int relocateInstructionInThumb32(uint32_t pc, uint16_t high_instruction, uint16_t low_instruction, uint16_t *trampoline_instructions)
{
uint32_t instruction;
int type;
int idx;
int offset;
instruction = (high_instruction << 16) | low_instruction;
type = getTypeInThumb32(instruction);
idx = 0;
if (type == BLX_THUMB32 || type == BL_THUMB32 || type == B1_THUMB32 || type == B2_THUMB32) {
uint32_t j1;
uint32_t j2;
uint32_t s;
uint32_t i1;
uint32_t i2;
uint32_t x;
uint32_t imm32;
uint32_t value;
j1 = (low_instruction & 0x2000) >> 13;
j2 = (low_instruction & 0x800) >> 11;
s = (high_instruction & 0x400) >> 10;
i1 = !(j1 ^ s);
i2 = !(j2 ^ s);
if (type == BLX_THUMB32 || type == BL_THUMB32) {
trampoline_instructions[idx++] = 0xF20F;
trampoline_instructions[idx++] = 0x0E09; // ADD.W LR, PC, #9
}
else if (type == B1_THUMB32) {
trampoline_instructions[idx++] = 0xD000 | ((high_instruction & 0x3C0) << 2);
trampoline_instructions[idx++] = 0xE003; // B PC, #6
}
trampoline_instructions[idx++] = 0xF8DF;
trampoline_instructions[idx++] = 0xF000; // LDR.W PC, [PC]
if (type == BLX_THUMB32) {
x = (s << 24) | (i1 << 23) | (i2 << 22) | ((high_instruction & 0x3FF) << 12) | ((low_instruction & 0x7FE) << 1);
imm32 = s ? (x | (0xFFFFFFFF << 25)) : x;
value = pc + imm32;
}
else if (type == BL_THUMB32) {
x = (s << 24) | (i1 << 23) | (i2 << 22) | ((high_instruction & 0x3FF) << 12) | ((low_instruction & 0x7FF) << 1);
imm32 = s ? (x | (0xFFFFFFFF << 25)) : x;
value = pc + imm32 + 1;
}
else if (type == B1_THUMB32) {
x = (s << 20) | (j2 << 19) | (j1 << 18) | ((high_instruction & 0x3F) << 12) | ((low_instruction & 0x7FF) << 1);
imm32 = s ? (x | (0xFFFFFFFF << 21)) : x;
value = pc + imm32 + 1;
}
else if (type == B2_THUMB32) {
x = (s << 24) | (i1 << 23) | (i2 << 22) | ((high_instruction & 0x3FF) << 12) | ((low_instruction & 0x7FF) << 1);
imm32 = s ? (x | (0xFFFFFFFF << 25)) : x;
value = pc + imm32 + 1;
}
trampoline_instructions[idx++] = value & 0xFFFF;
trampoline_instructions[idx++] = value >> 16;
offset = idx;
}
else if (type == ADR1_THUMB32 || type == ADR2_THUMB32 || type == LDR_THUMB32) {
int r;
uint32_t imm32;
uint32_t value;
if (type == ADR1_THUMB32 || type == ADR2_THUMB32) {
uint32_t i;
uint32_t imm3;
uint32_t imm8;
r = (low_instruction & 0xF00) >> 8;
i = (high_instruction & 0x400) >> 10;
imm3 = (low_instruction & 0x7000) >> 12;
imm8 = instruction & 0xFF;
imm32 = (i << 31) | (imm3 << 30) | (imm8 << 27);
if (type == ADR1_THUMB32) {
value = ALIGN_PC(pc) + imm32;
}
else {
value = ALIGN_PC(pc) - imm32;
}
}
else {
int is_add;
uint32_t *addr;
is_add = (high_instruction & 0x80) >> 7;
r = low_instruction >> 12;
imm32 = low_instruction & 0xFFF;
if (is_add) {
addr = (uint32_t *) (ALIGN_PC(pc) + imm32);
}
else {
addr = (uint32_t *) (ALIGN_PC(pc) - imm32);
}
value = addr[0];
}
trampoline_instructions[0] = 0x4800 | (r << 8); // LDR Rr, [PC]
trampoline_instructions[1] = 0xE001; // B PC, #2
trampoline_instructions[2] = value & 0xFFFF;
trampoline_instructions[3] = value >> 16;
offset = 4;
}
else if (type == TBB_THUMB32 || type == TBH_THUMB32) {
int rm;
int r;
int rx;
rm = low_instruction & 0xF;
for (r = 7;; --r) {
if (r != rm) {
break;
}
}
for (rx = 7; ; --rx) {
if (rx != rm && rx != r) {
break;
}
}
trampoline_instructions[0] = 0xB400 | (1 << rx); // PUSH {Rx}
trampoline_instructions[1] = 0x4805 | (r << 8); // LDR Rr, [PC, #20]
trampoline_instructions[2] = 0x4600 | (rm << 3) | rx; // MOV Rx, Rm
if (type == TBB_THUMB32) {
trampoline_instructions[3] = 0xEB00 | r;
trampoline_instructions[4] = 0x0000 | (rx << 8) | rx; // ADD.W Rx, Rr, Rx
trampoline_instructions[5] = 0x7800 | (rx << 3) | rx; // LDRB Rx, [Rx]
}
else if (type == TBH_THUMB32) {
trampoline_instructions[3] = 0xEB00 | r;
trampoline_instructions[4] = 0x0040 | (rx << 8) | rx; // ADD.W Rx, Rr, Rx, LSL #1
trampoline_instructions[5] = 0x8800 | (rx << 3) | rx; // LDRH Rx, [Rx]
}
trampoline_instructions[6] = 0xEB00 | r;
trampoline_instructions[7] = 0x0040 | (r << 8) | rx; // ADD Rr, Rr, Rx, LSL #1
trampoline_instructions[8] = 0x3001 | (r << 8); // ADD Rr, #1
trampoline_instructions[9] = 0xBC00 | (1 << rx); // POP {Rx}
trampoline_instructions[10] = 0x4700 | (r << 3); // BX Rr
trampoline_instructions[11] = 0xBF00;
trampoline_instructions[12] = pc & 0xFFFF;
trampoline_instructions[13] = pc >> 16;
offset = 14;
}
else {
trampoline_instructions[0] = high_instruction;
trampoline_instructions[1] = low_instruction;
offset = 2;
}
return offset;
}
static void relocateInstructionInThumb(uint32_t target_addr, uint16_t *orig_instructions, int length, uint16_t *trampoline_instructions, int *orig_boundaries, int *trampoline_boundaries, int *count)
{
int orig_pos;
int trampoline_pos;
uint32_t pc;
uint32_t lr;
orig_pos = 0;
trampoline_pos = 0;
pc = target_addr + 4;
while (1) {
int offset;
orig_boundaries[*count] = orig_pos * sizeof(uint16_t);
trampoline_boundaries[*count] = trampoline_pos * sizeof(uint16_t);
++(*count);
if ((orig_instructions[orig_pos] >> 11) >= 0x1D && (orig_instructions[orig_pos] >> 11) <= 0x1F) {
if (orig_pos + 2 > length / sizeof(uint16_t)) {
break;
}
offset = relocateInstructionInThumb32(pc, orig_instructions[orig_pos], orig_instructions[orig_pos + 1], &trampoline_instructions[trampoline_pos]);
pc += sizeof(uint32_t);
trampoline_pos += offset;
orig_pos += 2;
}
else {
offset = relocateInstructionInThumb16(pc, orig_instructions[orig_pos], &trampoline_instructions[trampoline_pos]);
pc += sizeof(uint16_t);
trampoline_pos += offset;
++orig_pos;
}
if (orig_pos >= length / sizeof(uint16_t)) {
break;
}
}
lr = target_addr + orig_pos * sizeof(uint16_t) + 1;
trampoline_instructions[trampoline_pos] = 0xF8DF;
trampoline_instructions[trampoline_pos + 1] = 0xF000; // LDR.W PC, [PC]
trampoline_instructions[trampoline_pos + 2] = lr & 0xFFFF;
trampoline_instructions[trampoline_pos + 3] = lr >> 16;
}
static void relocateInstructionInArm(uint32_t target_addr, uint32_t *orig_instructions, int length, uint32_t *trampoline_instructions, int *orig_boundaries, int *trampoline_boundaries, int *count)
{
uint32_t pc;
uint32_t lr;
int orig_pos;
int trampoline_pos;
pc = target_addr + 8;
lr = target_addr + length;
trampoline_pos = 0;
for (orig_pos = 0; orig_pos < length / sizeof(uint32_t); ++orig_pos) {
uint32_t instruction;
int type;
orig_boundaries[*count] = orig_pos * sizeof(uint32_t);
trampoline_boundaries[*count] = trampoline_pos * sizeof(uint32_t);
++(*count);
instruction = orig_instructions[orig_pos];
type = getTypeInArm(instruction);
if (type == BLX_ARM || type == BL_ARM || type == B_ARM || type == BX_ARM) {
uint32_t x;
int top_bit;
uint32_t imm32;
uint32_t value;
if (type == BLX_ARM || type == BL_ARM) {
trampoline_instructions[trampoline_pos++] = 0xE28FE004; // ADD LR, PC, #4
}
trampoline_instructions[trampoline_pos++] = 0xE51FF004; // LDR PC, [PC, #-4]
if (type == BLX_ARM) {
x = ((instruction & 0xFFFFFF) << 2) | ((instruction & 0x1000000) >> 23);
}
else if (type == BL_ARM || type == B_ARM) {
x = (instruction & 0xFFFFFF) << 2;
}
else {
x = 0;
}
top_bit = x >> 25;
imm32 = top_bit ? (x | (0xFFFFFFFF << 26)) : x;
if (type == BLX_ARM) {
value = pc + imm32 + 1;
}
else {
value = pc + imm32;
}
trampoline_instructions[trampoline_pos++] = value;
}
else if (type == ADD_ARM) {
int rd;
int rm;
int r;
rd = (instruction & 0xF000) >> 12;
rm = instruction & 0xF;
for (r = 12; ; --r) {
if (r != rd && r != rm) {
break;
}
}
//ADD Rd, PC, Rm
trampoline_instructions[trampoline_pos++] = 0xE52D0004 | (r << 12); // PUSH {Rr}
trampoline_instructions[trampoline_pos++] = 0xE59F0008 | (r << 12); // LDR Rr, [PC, #8]
trampoline_instructions[trampoline_pos++] = (instruction & 0xFFF0FFFF) | (r << 16);
trampoline_instructions[trampoline_pos++] = 0xE49D0004 | (r << 12); // POP {Rr}
trampoline_instructions[trampoline_pos++] = 0xE28FF000; // ADD PC, PC
trampoline_instructions[trampoline_pos++] = pc;
//ADD PC, R12, PC
//ADD
}
else if (type == ADR1_ARM || type == ADR2_ARM || type == LDR_ARM || type == MOV_ARM) {
int r;
uint32_t value;
r = (instruction & 0xF000) >> 12;
if (type == ADR1_ARM || type == ADR2_ARM || type == LDR_ARM) {
uint32_t imm32;
imm32 = instruction & 0xFFF;
if (type == ADR1_ARM) {
value = pc + imm32;
}
else if (type == ADR2_ARM) {
value = pc - imm32;
}
else if (type == LDR_ARM) {
int is_add;
is_add = (instruction & 0x800000) >> 23;
if (is_add) {
value = ((uint32_t *) (pc + imm32))[0];
}
else {
value = ((uint32_t *) (pc - imm32))[0];
}
}
}
else {
value = pc;
}
trampoline_instructions[trampoline_pos++] = 0xE51F0000 | (r << 12); // LDR Rr, [PC]
trampoline_instructions[trampoline_pos++] = 0xE28FF000; // ADD PC, PC
trampoline_instructions[trampoline_pos++] = value;
}
else {
trampoline_instructions[trampoline_pos++] = instruction;
}
pc += sizeof(uint32_t);
}
trampoline_instructions[trampoline_pos++] = 0xe51ff004; // LDR PC, [PC, #-4]
trampoline_instructions[trampoline_pos++] = lr;
}
void relocateInstruction(uint32_t target_addr, void *orig_instructions, int length, void *trampoline_instructions, int *orig_boundaries, int *trampoline_boundaries, int *count)
{
if (target_addr & 1 == 1) {
relocateInstructionInThumb(target_addr - 1, (uint16_t *) orig_instructions, length, (uint16_t *) trampoline_instructions, orig_boundaries, trampoline_boundaries, count);
}
else {
relocateInstructionInArm(target_addr, (uint32_t *) orig_instructions, length, (uint32_t *) trampoline_instructions, orig_boundaries, trampoline_boundaries, count);
}
}
================================================
FILE: jni/relocate.h
================================================
#ifndef __RELOCATE_H__
#define __RELOCATE_H__
#include <stdio.h>
void relocateInstruction(uint32_t target_addr, void *orig_instructions, int length, void *trampoline_instructions, int *orig_boundaries, int *trampoline_boundaries, int *count);
#endif
================================================
FILE: jni/stalker.c
================================================
#include "hook.h"
//#include <stdio.h>
//#include <stdlib.h>
////#include <asm/user.h>
//#include <sys/user.h>
//#include <asm/ptrace.h>
//#include <sys/ptrace.h>
//#include <sys/wait.h>
//#include <sys/mman.h>
//#include <dlfcn.h>
//#include <dirent.h>
//#include <unistd.h>
//#include <string.h>
//#include <elf.h>
//#include <android/log.h>
//#define LOG_TAG "MY_HOOK"
//#define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##args)
//#define LOGF(...) \
// {FILE *fp = fopen("/data/local/tmp/hook.log", "a+"); if (fp) {\
// fprintf(fp, __VA_ARGS__);\
// fclose(fp);}}
#define CPSR_T_MASK ( 1u << 5 )
const char *libc_path = "/system/lib/libc.so";
const char *linker_path = "/system/bin/linker";
const char *libdl_path = "/system/lib/libdl.so";
const int long_size = sizeof(long);
uint32_t get_remote_addr(pid_t target_pid, const char* module_name, void* local_addr)
{
uint32_t local_handle, remote_handle;
get_module_range(0, module_name, &local_handle, 0);
get_module_range(target_pid, module_name, &remote_handle, 0);
printf("remote %s handle = 0x%x\n", module_name, (unsigned int)remote_handle);
long ret_addr = (long)((uint32_t)local_addr + (uint32_t)remote_handle - (uint32_t)local_handle);
return ret_addr;
}
int ptrace_attach(pid_t pid)
{
if (ptrace(PTRACE_ATTACH, pid, NULL, 0) < 0) {
perror("ptrace_attach");
return -1;
}
int status = 0;
waitpid(pid, &status , WUNTRACED);
return 0;
}
long ptrace_retval(struct pt_regs * regs)
{
#if defined(__arm__)
return regs->ARM_r0;
#elif defined(__i386__)
return regs->eax;
#else
#error "Not supported"
#endif
}
long ptrace_ip(struct pt_regs * regs)
{
#if defined(__arm__)
return regs->ARM_pc;
#elif defined(__i386__)
return regs->eip;
#else
#error "Not supported"
#endif
}
int ptrace_setregs(pid_t pid, struct pt_regs * regs)
{
if (ptrace(PTRACE_SETREGS, pid, NULL, regs) < 0) {
perror("ptrace_setregs: Can not set register values");
return -1;
}
return 0;
}
int ptrace_getregs(pid_t pid, struct pt_regs * regs)
{
if (ptrace(PTRACE_GETREGS, pid, NULL, regs) < 0) {
perror("ptrace_getregs: Can not get register values");
return -1;
}
return 0;
}
int ptrace_continue(pid_t pid)
{
if (ptrace(PTRACE_CONT, pid, NULL, 0) < 0) {
perror("ptrace_cont");
return -1;
}
return 0;
}
int ptrace_detach(pid_t pid)
{
if (ptrace(PTRACE_DETACH, pid, NULL, 0) < 0) {
perror("ptrace_detach");
return -1;
}
return 0;
}
int ptrace_readdata(pid_t pid, uint8_t *src, uint8_t *buf, size_t size)
{
uint32_t i, j, remain;
uint8_t *laddr;
union u {
long val;
char chars[sizeof(long)];
} d;
j = size / 4;
remain = size % 4;
laddr = buf;
for (i = 0; i < j; i ++) {
d.val = ptrace(PTRACE_PEEKTEXT, pid, src, 0);
memcpy(laddr, d.chars, 4);
src += 4;
laddr += 4;
}
if (remain > 0) {
d.val = ptrace(PTRACE_PEEKTEXT, pid, src, 0);
memcpy(laddr, d.chars, remain);
}
return 0;
}
int ptrace_writedata(pid_t pid, uint8_t *dest, uint8_t *data, size_t size)
{
uint32_t i, j, remain;
uint8_t *laddr;
union u {
long val;
char chars[sizeof(long)];
} d;
j = size / 4;
remain = size % 4;
laddr = data;
for (i = 0; i < j; i ++) {
memcpy(d.chars, laddr, 4);
ptrace(PTRACE_POKETEXT, pid, dest, d.val);
dest += 4;
laddr += 4;
}
if (remain > 0) {
d.val = ptrace(PTRACE_PEEKTEXT, pid, dest, 0);
for (i = 0; i < remain; i ++) {
d.chars[i] = *laddr ++;
}
ptrace(PTRACE_POKETEXT, pid, dest, d.val);
}
return 0;
}
long ptrace_call(pid_t pid, uint32_t addr, uint32_t *params, uint32_t num_params, struct pt_regs * regs)
{
#if defined(__i386__)
regs->esp -= (num_params) * sizeof(uint32_t) ;
ptrace_writedata(pid, (void *)regs->esp, (uint8_t *)params, (num_params) * sizeof(uint32_t));
long tmp_addr = 0x00;
regs->esp -= sizeof(long);
ptrace_writedata(pid, (void *)regs->esp, (uint8_t *)&tmp_addr, sizeof(tmp_addr));
regs->eip = addr;
if (ptrace_setregs(pid, regs) == -1
|| ptrace_continue( pid) == -1) {
printf("error\n");
return -1;
}
int stat = 0;
waitpid(pid, &stat, WUNTRACED);
#if 0
LOGD("stat: %x", stat);
int i = 0;
for (i = 0; i < 10 ; i++) {
ptrace(PTRACE_SINGLESTEP, pid, 0, 0);
waitpid(pid, &stat, WUNTRACED);
if (ptrace_getregs(pid, regs) == -1)
return -1;
LOGD("[+] Target process single stepped, return value=%lx, pc=%lx \n",
ptrace_retval(regs), ptrace_ip(regs));
LOGD("stat: %x", stat);
}
#endif
while (stat != 0xb7f) {
if (ptrace_continue(pid) == -1) {
printf("error\n");
return -1;
}
waitpid(pid, &stat, WUNTRACED);
}
#endif
return 0;
}
int ptrace_call_wrapper(pid_t target_pid, const char * func_name, void * func_addr, uint32_t* parameters, int param_num, struct pt_regs * regs)
{
LOGD("[+] Calling %s in target process.\n", func_name);
if (ptrace_call(target_pid, (uint32_t)func_addr, parameters, param_num, regs) == -1)
return -1;
if (ptrace_getregs(target_pid, regs) == -1)
return -1;
LOGD("[+] Target process returned from %s, return value=%lx, pc=%lx \n",
func_name, ptrace_retval(regs), ptrace_ip(regs));
return 0;
}
int inject_remote_process(pid_t target_pid, const char *library_path, const char *function_name, const char *param, size_t param_size)
{
int ret = -1;
void *mmap_addr, *dlopen_addr, *dlsym_addr, *dlclose_addr, *dlerror_addr;
void *local_handle, *remote_handle, *dlhandle;
uint32_t map_base = 0;
struct pt_regs regs, original_regs;
uint32_t parameters[10];
LOGD("[+] Injecting process: %d\n", target_pid);
if (ptrace_attach(target_pid) == -1)
goto exit;
if (ptrace_getregs(target_pid, ®s) == -1)
goto exit;
/* save original registers */
memcpy(&original_regs, ®s, sizeof(regs));
mmap_addr = (void*)get_remote_addr(target_pid, libc_path, (void *)mmap);
LOGD("[+] Remote mmap address: %x\n", (uint32_t)mmap_addr);
/* call mmap */
parameters[0] = 0; // addr
parameters[1] = 0x4000; // size
parameters[2] = PROT_READ | PROT_WRITE | PROT_EXEC; // prot
parameters[3] = MAP_ANONYMOUS | MAP_PRIVATE; // flags
parameters[4] = 0; //fd
parameters[5] = 0; //offset
if (ptrace_call_wrapper(target_pid, "mmap", mmap_addr, parameters, 6, ®s) == -1)
goto exit;
map_base = ptrace_retval(®s);
LOGD("[+] map_base %p\n", (void *)map_base);
dlopen_addr = (void*)get_remote_addr( target_pid, linker_path, (void *)dlopen );
dlsym_addr = (void*)get_remote_addr( target_pid, linker_path, (void *)dlsym );
dlclose_addr = (void*)get_remote_addr( target_pid, linker_path, (void *)dlclose );
dlerror_addr = (void*)get_remote_addr( target_pid, linker_path, (void *)dlerror );
LOGD("[+] Get imports: dlopen: %p, dlsym: %p, dlclose: %p, dlerror: %p\n",
dlopen_addr, dlsym_addr, dlclose_addr, dlerror_addr);
printf("library path = %s\n", library_path);
ptrace_writedata(target_pid, (uint8_t *)map_base, (uint8_t *)library_path, strlen(library_path) + 1);
parameters[0] = map_base;
parameters[1] = RTLD_NOW| RTLD_GLOBAL;
if (ptrace_call_wrapper(target_pid, "dlopen", dlopen_addr, parameters, 2, ®s) == -1)
goto exit;
uint32_t sohandle = (uint32_t)ptrace_retval(®s);
#define FUNCTION_NAME_ADDR_OFFSET 0x100
ptrace_writedata(target_pid, (uint8_t *)(map_base + FUNCTION_NAME_ADDR_OFFSET), (uint8_t *)function_name, strlen(function_name) + 1);
parameters[0] = sohandle;
parameters[1] = map_base + FUNCTION_NAME_ADDR_OFFSET;
if (ptrace_call_wrapper(target_pid, "dlsym", dlsym_addr, parameters, 2, ®s) == -1)
goto exit;
void * hook_init_addr = (void *)ptrace_retval(®s);
LOGD("hook_init_addr = %p\n", hook_init_addr);
#define FUNCTION_PARAM_ADDR_OFFSET 0x200
ptrace_writedata(target_pid, (uint8_t *)(map_base + FUNCTION_PARAM_ADDR_OFFSET), (uint8_t *)param, strlen(param) + 1);
parameters[0] = map_base + FUNCTION_PARAM_ADDR_OFFSET;
if (ptrace_call_wrapper(target_pid, "init_func", hook_init_addr, parameters, 1, ®s) == -1)
goto exit;
#if 0
printf("Press enter to dlclose and detach\n");
getchar();
parameters[0] = sohandle;
if (ptrace_call_wrapper(target_pid, "dlclose", dlclose, parameters, 1, ®s) == -1)
goto exit;
#endif
/* restore */
printf("detach\n");
ptrace_setregs(target_pid, &original_regs);
ptrace_detach(target_pid);
ret = 0;
exit:
return ret;
}
static int get_all_tids(pid_t pid, pid_t *tids)
{
char dir_path[32];
DIR *dir;
int i;
struct dirent *entry;
pid_t tid;
if (pid < 0) {
snprintf(dir_path, sizeof(dir_path), "/proc/self/task");
}
else {
snprintf(dir_path, sizeof(dir_path), "/proc/%d/task", pid);
}
dir = opendir(dir_path);
if (dir == NULL) {
return 0;
}
i = 0;
while((entry = readdir(dir)) != NULL) {
tid = atoi(entry->d_name);
if (tid != 0 && tid != getpid()) {
tids[i++] = tid;
}
}
closedir(dir);
return i;
}
int main(int argc, char *argv[])
{
if(argc != 2) {
printf("Usage: %s <pid to be traced>\n", argv[0]);
return 1;
}
pid_t pid;
pid_t tids[1024];
int status;
pid = atoi(argv[1]);
int i = 0;
char* so_path = "/data/local/tmp/libinject.so";
char* init_func = "init_func";
char* parameter = "init_func called, initializing";
#if 0
if(0 != ptrace(PTRACE_ATTACH, pid, NULL, NULL)) {
printf("Trace process failed:%d.\n", errno);
return 1;
}
waitpid(pid, &status, WUNTRACED);
#endif
#if 0
int count = get_all_tids(pid, tids);
for (i = 0; i < count; ++i) {
if (tids[i] == pid)
continue;
if (ptrace(PTRACE_ATTACH, tids[i], NULL, NULL) == 0) {
waitpid(tids[i], &status, WUNTRACED);
struct pt_regs regs;
ptrace(PTRACE_GETREGS, tids[i], NULL, ®s);
}
}
#endif
#if 0
uint32_t entry_addr = get_entry_addr("libc.so", 0x11640);
uint32_t hook_func = get_hook_func();
_hook(&eph1, entry_addr, (void*)hook_func);
#endif
#if 0
struct pt_regs regs;
if (ptrace(PTRACE_GETREGS, pid, NULL, ®s) < 0) {
perror("ptrace_getregs: Can not get register values");
}
#ifdef __i386__
regs.eip = 0x00;
printf("regs.eax = %x\n", regs.eax);
printf("regs.eip = %x\n", regs.eip);
#elif defined __arm__
//regs.ARM_pc = 0x00;
printf("regs.ARM_r0 = %x\n", regs.ARM_r0);
printf("regs.ARM_pc = %x\n", regs.ARM_pc);
#endif
ptrace_setregs(pid, ®s);
#endif
#if 1
inject_remote_process(pid, so_path, init_func, parameter, strlen(parameter));
#endif
#if 0
for (i = 0; i < count; ++i) {
printf("releasing [%d]\n", tids[i]);
ptrace(PTRACE_CONT, tids[i], NULL, 0);
ptrace(PTRACE_DETACH, tids[i], NULL, 0);
}
#endif
return 0;
}
================================================
FILE: jni/target.c
================================================
#include <stdio.h>
#include <time.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(){
srand(time(NULL));
int j = 0;
scanf("%d", &j);
j = 0;
//dlopen("/data/local/tmp/libinject.so", RTLD_NOW);
while(1) {
j++;
sleep(1);
printf("hello world: %d\n",rand()%100);
if (j == 5) {
void* p = malloc(100);
int i = 0;
for (i = 0 ; i < 100 ; i++) {
((int*)p)[i] = i*i;
//printf("p[i]: %d\n", ((int*)p)[i]);
}
}
}
return 0;
}
================================================
FILE: push.cmd
================================================
adb push libs/armeabi-v7a/librealinject.so /data/local/tmp
adb push libs/x86/stalker /data/local/tmp
adb push libs/x86/libinject.so /data/local/tmp
gitextract_6plxykad/ ├── .gitignore ├── LICENSE ├── README.md ├── jni/ │ ├── Android.mk │ ├── Application.mk │ ├── hook.c │ ├── hook.h │ ├── inject.c │ ├── realinject.c │ ├── relocate.c │ ├── relocate.h │ ├── stalker.c │ └── target.c ├── libs/ │ ├── armeabi-v7a/ │ │ ├── stalker │ │ └── target │ └── x86/ │ ├── stalker │ └── target └── push.cmd
SYMBOL INDEX (44 symbols across 7 files)
FILE: jni/hook.c
function get_module_range (line 5) | void get_module_range(pid_t pid, const char* module_name, uint32_t* star...
function hook_by_name (line 53) | int hook_by_name(struct hook_t *h, char* module_name, const char* func_n...
function hook_by_addr (line 80) | int hook_by_addr(struct hook_t *h, char* module_name, unsigned int addr,...
function _hook (line 105) | static int _hook(struct hook_t *h, unsigned int addr, void *hook_func)
function hook_cacheflush (line 160) | void inline hook_cacheflush(unsigned int begin, unsigned int end)
FILE: jni/hook.h
type hook_t (line 41) | struct hook_t {
type hook_status (line 55) | enum hook_status {
type hook_t (line 65) | struct hook_t
type hook_t (line 66) | struct hook_t
type hook_t (line 68) | struct hook_t
type hook_t (line 72) | struct hook_t
type hook_t (line 73) | struct hook_t
FILE: jni/inject.c
function load_real_lib_bluestacks (line 12) | void load_real_lib_bluestacks()
function load_real_lib_4_4_2 (line 27) | void load_real_lib_4_4_2()
function load_real_lib_5_5_1 (line 41) | void load_real_lib_5_5_1()
function init_func (line 67) | int init_func(char * str){
FILE: jni/realinject.c
type hook_t (line 4) | struct hook_t
function hook_battleEnd (line 6) | int hook_battleEnd(int p1, int p2)
function real_init_func (line 21) | void real_init_func()
FILE: jni/relocate.c
type INSTRUCTION_TYPE (line 18) | enum INSTRUCTION_TYPE {
function getTypeInThumb16 (line 84) | static int getTypeInThumb16(uint16_t instruction)
function getTypeInThumb32 (line 116) | static int getTypeInThumb32(uint32_t instruction)
function getTypeInArm (line 153) | static int getTypeInArm(uint32_t instruction)
function relocateInstructionInThumb16 (line 185) | static int relocateInstructionInThumb16(uint32_t pc, uint16_t instructio...
function relocateInstructionInThumb32 (line 305) | static int relocateInstructionInThumb32(uint32_t pc, uint16_t high_instr...
function relocateInstructionInThumb (line 465) | static void relocateInstructionInThumb(uint32_t target_addr, uint16_t *o...
function relocateInstructionInArm (line 512) | static void relocateInstructionInArm(uint32_t target_addr, uint32_t *ori...
function relocateInstruction (line 634) | void relocateInstruction(uint32_t target_addr, void *orig_instructions, ...
FILE: jni/stalker.c
function get_remote_addr (line 33) | uint32_t get_remote_addr(pid_t target_pid, const char* module_name, void...
function ptrace_attach (line 46) | int ptrace_attach(pid_t pid)
function ptrace_retval (line 59) | long ptrace_retval(struct pt_regs * regs)
function ptrace_ip (line 70) | long ptrace_ip(struct pt_regs * regs)
function ptrace_setregs (line 81) | int ptrace_setregs(pid_t pid, struct pt_regs * regs)
function ptrace_getregs (line 91) | int ptrace_getregs(pid_t pid, struct pt_regs * regs)
function ptrace_continue (line 101) | int ptrace_continue(pid_t pid)
function ptrace_detach (line 111) | int ptrace_detach(pid_t pid)
function ptrace_readdata (line 122) | int ptrace_readdata(pid_t pid, uint8_t *src, uint8_t *buf, size_t size)
function ptrace_writedata (line 152) | int ptrace_writedata(pid_t pid, uint8_t *dest, uint8_t *data, size_t size)
function ptrace_call (line 187) | long ptrace_call(pid_t pid, uint32_t addr, uint32_t *params, uint32_t nu...
function ptrace_call_wrapper (line 236) | int ptrace_call_wrapper(pid_t target_pid, const char * func_name, void *...
function inject_remote_process (line 249) | int inject_remote_process(pid_t target_pid, const char *library_path, co...
function get_all_tids (line 344) | static int get_all_tids(pid_t pid, pid_t *tids)
function main (line 377) | int main(int argc, char *argv[])
FILE: jni/target.c
function main (line 9) | int main(){
Condensed preview — 18 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (69K chars).
[
{
"path": ".gitignore",
"chars": 53,
"preview": "*.swp\n*.id0\n*.id1\n*.id2\n*.idb\n*.nam\n*.til\n*.un~\nobj/\n"
},
{
"path": "LICENSE",
"chars": 18092,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 2, June 1991\n\n Copyright (C) 1989, 1991 Fr"
},
{
"path": "README.md",
"chars": 1596,
"preview": "# EHook\n\nA hooking framework for commercial Android emulators ([雷电模拟器](http://www.ldmnq.com/), [NOX](https://jp.bignox.c"
},
{
"path": "jni/Android.mk",
"chars": 1412,
"preview": "LOCAL_PATH := $(call my-dir)\n\ninclude $(CLEAR_VARS)\nLOCAL_CFLAGS += -fPIE\nLOCAL_LDFLAGS += -fPIE -pie\nLOCAL_MODULE :="
},
{
"path": "jni/Application.mk",
"chars": 50,
"preview": "APP_ABI := x86 armeabi-v7a\n# APP_OPTIM := debug\n\n\n"
},
{
"path": "jni/hook.c",
"chars": 6274,
"preview": "#include \"hook.h\"\n#include \"relocate.h\"\n\n\nvoid get_module_range(pid_t pid, const char* module_name, uint32_t* start_addr"
},
{
"path": "jni/hook.h",
"chars": 2003,
"preview": "#ifndef __HOOK_H__\n#define __HOOK_H__\n\n#include <stdio.h>\n#include <stdlib.h>\n//#include <asm/user.h>\n#include <sys/user"
},
{
"path": "jni/inject.c",
"chars": 3054,
"preview": "#include \"hook.h\"\n#include <android/log.h>\n\ntypedef void *native_load_library(void *handle, const char *symbol);\ntypedef"
},
{
"path": "jni/realinject.c",
"chars": 1103,
"preview": "#include \"hook.h\"\n#include <android/log.h>\n\nstatic struct hook_t eph;\n\nint hook_battleEnd(int p1, int p2)\n{\n\tint (*orig_"
},
{
"path": "jni/relocate.c",
"chars": 17212,
"preview": "/*\nrelocate instruction\nauthor: ele7enxxh\nmail: ele7enxxh@qq.com\nwebsite: ele7enxxh.com\nmodified time: 2016-10-17\ncreate"
},
{
"path": "jni/relocate.h",
"chars": 253,
"preview": "#ifndef __RELOCATE_H__\n#define __RELOCATE_H__\n\n#include <stdio.h>\n\nvoid relocateInstruction(uint32_t target_addr, void *"
},
{
"path": "jni/stalker.c",
"chars": 12597,
"preview": "#include \"hook.h\"\n//#include <stdio.h>\n//#include <stdlib.h>\n////#include <asm/user.h>\n//#include <sys/user.h>\n//#includ"
},
{
"path": "jni/target.c",
"chars": 633,
"preview": "#include <stdio.h>\n#include <time.h>\n#include <dlfcn.h>\n#include <stdlib.h>\n#include <string.h>\n#include <sys/types.h>\n#"
},
{
"path": "push.cmd",
"chars": 148,
"preview": "adb push libs/armeabi-v7a/librealinject.so /data/local/tmp\nadb push libs/x86/stalker /data/local/tmp\nadb push libs/x86/l"
}
]
// ... and 4 more files (download for full content)
About this extraction
This page contains the full source code of the nevermoe/EHook GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 18 files (63.0 KB), approximately 19.3k tokens, and a symbol index with 44 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.