0x00 jni目錄
構建一個新jni目錄,包含以下文件:
hook.cpp
SubstrateHook.h
nativelog.h
Android.mk
libsubstrate.a
0x01 編寫hook.cpp
#include <netinet/in.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <dlfcn.h>
#include <unistd.h>
#include <jni.h>
#include <stdio.h>
#include <dirent.h>
#include "nativelog.h"
#include "SubstrateHook.h"
unsigned long get_module_base( pid_t pid, const char* module_name)
{
FILE *fp;
unsigned long addr = 0;
char *pch;
char filename[32];
char line[1024];
if ( pid < 0 )
{
/* self process */
snprintf( filename, sizeof(filename), "/proc/self/maps", pid );
}
else
{
snprintf( filename, sizeof(filename), "/proc/%d/maps", pid );
}
fp = fopen( filename, "r" );
if ( fp != NULL )
{
while ( fgets( line, sizeof(line), fp ) )
{
if ( strstr( line, module_name ) )
{