feat(main): 新增 FridaNative、LM 和 RegisterTray 模块
- 添加 FridaNative模块,用于 Frida 相关的 native 代码 - 添加 LM 模块,用于 llama模型相关的 native 代码 - 添加 RegisterTray 模块,用于注册系统托盘图标和相关操作 - 新建对应的头文件、源文件和项目配置文件
This commit is contained in:
164
src/main/Cpp/FridaNative/FridaNative.vcxproj
Normal file
164
src/main/Cpp/FridaNative/FridaNative.vcxproj
Normal file
@@ -0,0 +1,164 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{e7f36e99-a575-47f5-ba40-c4877b08c517}</ProjectGuid>
|
||||
<RootNamespace>FridaNative</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>C:\Users\Administrator\.jdks\corretto-20.0.2.1\include\win32\bridge;C:\Users\Administrator\.jdks\corretto-20.0.2.1\include\win32;C:\Users\Administrator\.jdks\corretto-20.0.2.1\include;C:\Users\Administrator\Desktop\WindowsHook资源\Frida资源包\include;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;FRIDANATIVE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;FRIDANATIVE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;FRIDANATIVE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;FRIDANATIVE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<AdditionalLibraryDirectories>C:\Users\Administrator\Desktop\WindowsHook资源\Frida资源包\lib.x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>frida-core.lib;winmm.lib;setupapi.lib;dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="framework.h" />
|
||||
<ClInclude Include="org_tzd_frida_windows_FridaNative.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp" />
|
||||
<ClCompile Include="org_tzd_frida_windows_FridaNative.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
39
src/main/Cpp/FridaNative/FridaNative.vcxproj.filters
Normal file
39
src/main/Cpp/FridaNative/FridaNative.vcxproj.filters
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="framework.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="org_tzd_frida_windows_FridaNative.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="org_tzd_frida_windows_FridaNative.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
6
src/main/Cpp/FridaNative/FridaNative.vcxproj.user
Normal file
6
src/main/Cpp/FridaNative/FridaNative.vcxproj.user
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>false</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
19
src/main/Cpp/FridaNative/dllmain.cpp
Normal file
19
src/main/Cpp/FridaNative/dllmain.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// dllmain.cpp : 定义 DLL 应用程序的入口点。
|
||||
#include "pch.h"
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
5
src/main/Cpp/FridaNative/framework.h
Normal file
5
src/main/Cpp/FridaNative/framework.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
|
||||
// Windows 头文件
|
||||
#include <windows.h>
|
||||
224
src/main/Cpp/FridaNative/org_tzd_frida_windows_FridaNative.cpp
Normal file
224
src/main/Cpp/FridaNative/org_tzd_frida_windows_FridaNative.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "org_tzd_frida_windows_FridaNative.h"
|
||||
|
||||
|
||||
#include <frida-core.h>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
static void on_message(FridaScript* script, const gchar* message, GBytes* data, gpointer user_data);
|
||||
|
||||
static gboolean stop(gpointer user_data);
|
||||
static GMainLoop* loop = NULL;
|
||||
FridaScript* script;
|
||||
FridaSession* session;
|
||||
JavaVM* jvm;
|
||||
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: injection
|
||||
* Signature: (JLjava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_tzd_frida_windows_FridaNative_injection
|
||||
(JNIEnv* env, jclass clazz, jlong pid, jstring jsCode)
|
||||
{
|
||||
if (jsCode == NULL) {
|
||||
std::cerr << "The injected code is a null pointer " << std::endl;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if (env == NULL)
|
||||
{
|
||||
std::cerr << "JNI environmental issues " << std::endl;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
env->GetJavaVM(&jvm);
|
||||
|
||||
const char* functionName = env->GetStringUTFChars(jsCode, nullptr);
|
||||
frida_init();
|
||||
|
||||
GMainContext* context = g_main_context_new();
|
||||
if (context == nullptr) {
|
||||
std::cerr << "Failed to create a new GMainContext" << std::endl;
|
||||
return JNI_FALSE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
loop = g_main_loop_new(NULL, TRUE);
|
||||
|
||||
FridaDeviceManager* manager = frida_device_manager_new();
|
||||
GError* error = nullptr;
|
||||
FridaDeviceList* devices = frida_device_manager_enumerate_devices_sync(manager, nullptr, &error);
|
||||
|
||||
if (error != nullptr) {
|
||||
std::cerr << "Failed to enumerate devices: " << error->message << std::endl;
|
||||
g_error_free(error);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
FridaDevice* local_device = nullptr;
|
||||
guint num_devices = frida_device_list_size(devices);
|
||||
for (guint i = 0; i < num_devices; i++) {
|
||||
FridaDevice* device = frida_device_list_get(devices, i);
|
||||
if (frida_device_get_dtype(device) == FRIDA_DEVICE_TYPE_LOCAL) {
|
||||
local_device = g_object_ref(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (local_device == nullptr) {
|
||||
std::cerr << "Local device not found" << std::endl;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
session = frida_device_attach_sync(local_device, pid, nullptr, nullptr, &error);
|
||||
if (error != nullptr) {
|
||||
std::cerr << "Failed to attach to process: " << error->message << std::endl;
|
||||
g_error_free(error);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
script = frida_session_create_script_sync(session, functionName, nullptr, nullptr, &error);
|
||||
if (error != nullptr) {
|
||||
jclass jsCodeErrorClass = env->FindClass("org/tzd/frida/windows/JsCodeError");
|
||||
if (jsCodeErrorClass == nullptr) {
|
||||
std::cerr << "Failed to find JsCodeError class" << std::endl;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
jmethodID jsCodeErrorCtor = env->GetMethodID(jsCodeErrorClass, "<init>", "(Ljava/lang/String;)V");
|
||||
if (jsCodeErrorCtor == nullptr) {
|
||||
std::cerr << "Failed to find JsCodeError constructor" << std::endl;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
jstring errorMessage = env->NewStringUTF(error->message);
|
||||
jobject jsCodeErrorObj = env->NewObject(jsCodeErrorClass, jsCodeErrorCtor, errorMessage);
|
||||
env->ThrowNew(jsCodeErrorClass, error->message);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
g_signal_connect(script, "message", G_CALLBACK(on_message), NULL);
|
||||
frida_script_load_sync(script, nullptr, &error);
|
||||
if (error != nullptr) {
|
||||
std::cerr << "Failed to load script: " << error->message << std::endl;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
env->ReleaseStringUTFChars(jsCode, functionName);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: update
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_tzd_frida_windows_FridaNative_update
|
||||
(JNIEnv*, jclass)
|
||||
{
|
||||
g_main_loop_run(loop);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: isRunning
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_tzd_frida_windows_FridaNative_isRunning
|
||||
(JNIEnv*, jclass)
|
||||
{
|
||||
return g_main_loop_is_running(loop);
|
||||
}
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: release
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_tzd_frida_windows_FridaNative_release
|
||||
(JNIEnv*, jclass)
|
||||
{
|
||||
frida_unref(script);
|
||||
frida_unref(session);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: getStringMember
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_org_tzd_frida_windows_FridaNative_getStringMember
|
||||
(JNIEnv* env, jclass, jstring message, jstring member_name)
|
||||
{
|
||||
const char* message_cstr = env->GetStringUTFChars(message, nullptr);
|
||||
const char* member_cstr = env->GetStringUTFChars(member_name, nullptr);
|
||||
|
||||
JsonParser* parser = json_parser_new();
|
||||
GError* error = nullptr;
|
||||
if (!json_parser_load_from_data(parser, message_cstr, -1, &error)) {
|
||||
std::cerr << "Failed to parse JSON: " << error->message << std::endl;
|
||||
g_error_free(error);
|
||||
env->ReleaseStringUTFChars(message, message_cstr);
|
||||
env->ReleaseStringUTFChars(member_name, member_cstr);
|
||||
return nullptr;
|
||||
}
|
||||
JsonObject* root = json_node_get_object(json_parser_get_root(parser));
|
||||
const char* value = json_object_get_string_member(root, member_cstr);
|
||||
|
||||
env->ReleaseStringUTFChars(message, message_cstr);
|
||||
env->ReleaseStringUTFChars(member_name, member_cstr);
|
||||
|
||||
if (value == nullptr) {
|
||||
g_object_unref(parser);
|
||||
return env->NewStringUTF("");
|
||||
}
|
||||
|
||||
jstring result = env->NewStringUTF(value);
|
||||
g_object_unref(parser);
|
||||
return result;
|
||||
}
|
||||
|
||||
void callJavaOnMessage(const gchar* message) {
|
||||
JNIEnv* env = nullptr;
|
||||
jint attachResult = jvm->AttachCurrentThread((void**)&env, nullptr);
|
||||
if (attachResult != JNI_OK) {
|
||||
std::cerr << "Error: Unable to attach current thread to JVM" << std::endl;
|
||||
return;
|
||||
}
|
||||
const char* className = "org/tzd/frida/windows/Frida0";
|
||||
jclass cls = env->FindClass(className);
|
||||
if (cls == nullptr) {
|
||||
std::cerr << "Error: Unable to find class " << className << std::endl;
|
||||
return;
|
||||
}
|
||||
jmethodID methodId = env->GetStaticMethodID(cls, "onMessage", "(Ljava/lang/String;)V");
|
||||
if (methodId == nullptr) {
|
||||
std::cerr << "Error: Unable to find method onMessage" << std::endl;
|
||||
return;
|
||||
}
|
||||
jstring javaMessage = env->NewStringUTF(message);
|
||||
env->CallStaticVoidMethod(cls, methodId, javaMessage);
|
||||
env->DeleteLocalRef(javaMessage);
|
||||
env->DeleteLocalRef(cls);
|
||||
}
|
||||
|
||||
static void
|
||||
on_message(FridaScript* script,
|
||||
const gchar* message,
|
||||
GBytes* data,
|
||||
gpointer user_data)
|
||||
{
|
||||
JsonParser* parser;
|
||||
parser = json_parser_new();
|
||||
json_parser_load_from_data(parser, message, -1, NULL);
|
||||
callJavaOnMessage(message);
|
||||
g_object_unref(parser);
|
||||
}
|
||||
|
||||
static void
|
||||
on_signal(int signo)
|
||||
{
|
||||
g_idle_add(stop, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
stop(gpointer user_data)
|
||||
{
|
||||
g_main_loop_quit(loop);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
53
src/main/Cpp/FridaNative/org_tzd_frida_windows_FridaNative.h
Normal file
53
src/main/Cpp/FridaNative/org_tzd_frida_windows_FridaNative.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_tzd_frida_windows_FridaNative */
|
||||
|
||||
#ifndef _Included_org_tzd_frida_windows_FridaNative
|
||||
#define _Included_org_tzd_frida_windows_FridaNative
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: injection
|
||||
* Signature: (JLjava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_tzd_frida_windows_FridaNative_injection
|
||||
(JNIEnv *, jclass, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: update
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_tzd_frida_windows_FridaNative_update
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: isRunning
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_tzd_frida_windows_FridaNative_isRunning
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: release
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_tzd_frida_windows_FridaNative_release
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_tzd_frida_windows_FridaNative
|
||||
* Method: getStringMember
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_org_tzd_frida_windows_FridaNative_getStringMember
|
||||
(JNIEnv *, jclass, jstring, jstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
5
src/main/Cpp/FridaNative/pch.cpp
Normal file
5
src/main/Cpp/FridaNative/pch.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// pch.cpp: 与预编译标头对应的源文件
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
// 当使用预编译的头时,需要使用此源文件,编译才能成功。
|
||||
13
src/main/Cpp/FridaNative/pch.h
Normal file
13
src/main/Cpp/FridaNative/pch.h
Normal file
@@ -0,0 +1,13 @@
|
||||
// pch.h: 这是预编译标头文件。
|
||||
// 下方列出的文件仅编译一次,提高了将来生成的生成性能。
|
||||
// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
|
||||
// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
|
||||
// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
// 添加要在此处预编译的标头
|
||||
#include "framework.h"
|
||||
|
||||
#endif //PCH_H
|
||||
Reference in New Issue
Block a user