逆向工程 --- ai逆向参考
=============== S U B R O U T I N E ======================================= .text:000237F0 .text:000237F0 ; Attributes: bp-based frame .text:000237F0 .text:000237F0 ; int __cdecl Java_com_example_myapplication1_MainActivity_stringFromJNI(_JNIEnv *) .text:000237F0 public Java_com_example_myapplication1_MainActivity_stringFromJNI .text:000237F0 Java_com_example_myapplication1_MainActivity_stringFromJNI proc near .text:000237F0 ; DATA XREF: LOAD:00001420↑o .text:000237F0 .text:000237F0 var_30 = dword ptr -30h .text:000237F0 var_2C = dword ptr -2Ch .text:000237F0 var_28 = dword ptr -28h .text:000237F0 var_24 = dword ptr -24h .text:000237F0 var_20 = dword ptr -20h .text:000237F0 var_1C = dword ptr -1Ch .text:000237F0 var_18 = dword ptr -18h .text:000237F0 var_14 = byte ptr -14h .text:000237F0 var_8 = dword ptr -8 .text:000237F0 arg_0 = dword ptr 8 .text:000237F0 arg_4 = dword ptr 0Ch .text:000237F0 .text:000237F0 ; __unwind { // __gxx_personality_v0 .text:000237F0 push ebp .text:000237F1 mov ebp, esp .text:000237F3 push ebx .text:000237F4 sub esp, 34h .text:000237F7 call $+5 .text:000237FC .text:000237FC loc_237FC: ; DATA XREF: Java_com_example_myapplication1_MainActivity_stringFromJNI+D↓o .text:000237FC pop ebx .text:000237FD add ebx, (offset off_581EC - offset loc_237FC) .text:00023803 mov [ebp+var_28], ebx .text:00023806 mov eax, [ebp+arg_4] .text:00023809 mov eax, [ebp+arg_0] .text:0002380C mov eax, large gs:14h .text:00023812 mov [ebp+var_8], eax .text:00023815 lea ecx, (aHelloFromC - 581ECh)[ebx] ; "Hello from C++" .text:0002381B mov eax, esp .text:0002381D mov [eax+4], ecx .text:00023820 lea ecx, [ebp+var_14] .text:00023823 mov [ebp+var_2C], ecx .text:00023826 mov [eax], ecx .text:00023828 call __ZNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC2B8ne180000ILi0EEEPKc ; std::string::basic_string<0>(char const*) .text:0002382D mov ebx, [ebp+var_28] .text:00023830 mov ecx, [ebp+var_2C] .text:00023833 mov eax, [ebp+arg_0] .text:00023836 mov [ebp+var_24], eax .text:00023839 mov eax, esp .text:0002383B mov [eax], ecx .text:0002383D call sub_239A0 .text:00023842 mov ebx, [ebp+var_28] .text:00023845 mov ecx, [ebp+var_24] .text:00023848 mov edx, eax .text:0002384A ; try { .text:0002384A mov eax, esp .text:0002384C mov [eax+4], edx .text:0002384F mov [eax], ecx .text:00023851 call __ZN7_JNIEnv12NewStringUTFEPKc ; _JNIEnv::NewStringUTF(char const*) .text:00023851 ; } // starts at 2384A .text:00023856 mov [ebp+var_20], eax .text:00023859 jmp $+5 .text:0002385E ; --------------------------------------------------------------------------- .text:0002385E .text:0002385E loc_2385E: ; CODE XREF: Java_com_example_myapplication1_MainActivity_stringFromJNI+69↑j .text:0002385E mov ebx, [ebp+var_28] .text:00023861 mov eax, esp .text:00023863 lea ecx, [ebp+var_14] .text:00023866 mov [eax], ecx .text:00023868 call __ZNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev ; std::string::~string() .text:0002386D mov eax, large gs:14h .text:00023873 mov ecx, [ebp+var_8] .text:00023876 cmp eax, ecx .text:00023878 jnz loc_238C0 .text:0002387E mov eax, [ebp+var_20] .text:00023881 add esp, 34h .text:00023884 pop ebx .text:00023885 pop ebp .text:00023886 retn .text:00023887 ; --------------------------------------------------------------------------- .text:00023887 ; cleanup() // owned by 2384A .text:00023887 mov ebx, [ebp+var_28] .text:0002388A mov [ebp+var_18], eax .text:0002388D mov [ebp+var_1C], edx .text:00023890 lea eax, [ebp+var_14] .text:00023893 mov [esp], eax .text:00023896 call __ZNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev ; std::string::~string() .text:0002389B mov eax, [ebp+var_18] .text:0002389E mov [ebp+var_30], eax .text:000238A1 mov eax, large gs:14h .text:000238A7 mov ecx, [ebp+var_8] .text:000238AA cmp eax, ecx .text:000238AC jnz loc_238C0 .text:000238B2 mov ebx, [ebp+var_28] .text:000238B5 mov eax, [ebp+var_30] .text:000238B8 mov [esp], eax .text:000238BB call sub_50B30 .text:000238C0 ; --------------------------------------------------------------------------- .text:000238C0 .text:000238C0 loc_238C0: ; CODE XREF: Java_com_example_myapplication1_MainActivity_stringFromJNI+88↑j .text:000238C0 ; Java_com_example_myapplication1_MainActivity_stringFromJNI+BC↑j .text:000238C0 mov ebx, [ebp+var_28] .text:000238C3 call ___stack_chk_fail .text:000238C3 ; } // starts at 237F0 .text:000238C3 Java_com_example_myapplication1_MainActivity_stringFromJNI endp .text:000238C3 .text:000238C3 ; --------------------------------------------------------------------------- .text:000238C8 align 10h .text:000238D0 .text:000238D0 ; =============== S U B R O U T I N E =======================================
gemini逆向
#include <jni.h> #include <string> /** * @brief This is the C++ implementation of the native method called from Java. * * This function is called from the Java side of an Android application. It demonstrates * the basic principles of the Java Native Interface (JNI). The function creates a * C++ string, converts it into a Java string, and returns it to the Java virtual machine. * * @param env A pointer to the JNI environment, which provides most of the JNI functions. * @param obj The Java object that this native method is associated with (in this case, an instance of MainActivity). * @return jstring A Java string ("Hello from C++") that can be used in the calling Java code. */ extern "C" JNIEXPORT jstring JNICALL Java_com_example_myapplication1_MainActivity_stringFromJNI( JNIEnv* env, jobject /* this */) { // 1. Define the C++ string to be returned to Java. // In the assembly, the address of the string literal "Hello from C++" is loaded // and used to construct a std::string object on the stack. std::string hello = "Hello from C++"; // 2. Convert the C++ string to a Java String. // The assembly code calls the JNI function `NewStringUTF`. This function takes a // pointer to a modified UTF-8 string (which a standard C-style string from C++ is compatible with) // and returns a `jstring`, which is a handle to a Java String object. jstring result = env->NewStringUTF(hello.c_str()); // 3. Return the Java string. // The handle `result` is returned to the Java code that invoked this native method. return result; }
claude
#include <jni.h> #include <string> extern "C" JNIEXPORT jstring JNICALL Java_com_example_myapplication1_MainActivity_stringFromJNI(JNIEnv *env, jobject /* this */) { try { // 创建C++字符串对象,内容为"Hello from C++" std::string hello = "Hello from C++"; // 获取C风格字符串指针 const char* cStr = hello.c_str(); // 使用JNI创建Java字符串并返回 jstring result = env->NewStringUTF(cStr); return result; } catch (...) { // 异常处理 - 如果发生异常,进行清理 // 汇编中的cleanup代码对应这里的异常处理 return nullptr; } }
deepseek
#include <string> #include <jni.h> extern "C" JNIEXPORT jstring JNICALL Java_com_example_myapplication1_MainActivity_stringFromJNI( JNIEnv* env, // 对应 [ebp+arg_0] jobject thiz // 对应 [ebp+arg_4] (未使用) { // 栈保护机制 (GS) uintptr_t stack_guard = *reinterpret_cast<uintptr_t*>(gs:0x14); try { // 构造 std::string 对象,内容为 "Hello from C++" std::string cppStr("Hello from C++"); // 调用内部函数处理字符串 (可能是 c_str() 或自定义逻辑) const char* processedStr = sub_239A0(&cppStr); // 转换为 Java 字符串 jstring javaStr = env->NewStringUTF(processedStr); // 析构 std::string (编译器自动插入) return javaStr; } catch (...) { // 异常处理 (确保 std::string 正确析构) if (stack_guard != *reinterpret_cast<uintptr_t*>(gs:0x14)) { __stack_chk_fail(); } throw; // 重新抛出异常 } }
chatgpt
#include <jni.h> #include <string> extern "C" JNIEXPORT jstring JNICALL Java_com_example_myapplication1_MainActivity_stringFromJNI(JNIEnv* env, jobject /* this */) { std::string hello = "Hello from C++"; return env->NewStringUTF(hello.c_str()); }
四个差不多,之后由deepseek没有没有猜到函数的定义
浙公网安备 33010602011771号