0

I am using JNI to call function from Java. Then, java will return a jstring. I still not know how to convert jstring back to std:string to use in C++

One more thing here is my example code:

std::string valueAttriButeConverted = "\x64\x90\xa0\xe3";

my_cool_Patches.temp= MemoryPatch("il2cpp.so", 0x19E7CD0,
                 &valueAttriButeConverted, 4);

my_cool_Patches.temp.Modify();

I Used LGL Mod menu to make mod menu for game. It used KittyMemory. In MemoryPatch, the 3rd argument must be a void*.

After running that code, memory will be patched with these bytes: "08 64 90 a0", instead of "64 90 a0 e3". I do not know why and where is the byte "08". Please help me correct it.

Here is code which will run perfectly:

my_cool_Patches.temp= MemoryPatch("il2cpp.so", 0x19E7CD0,
                 "\x64\x90\xa0\xe3", 4);

my_cool_Patches.temp.Modify();

But if i change the String to variable, it will be wrong value.

And I want to make the custom value which run in runtime, let user choose the value and then convert to hex and put to MemoryPatch.

For now, JNI call java and return jstring perfectly.

Thanks and Regards,

pptaszni
  • 5,591
  • 5
  • 27
  • 43
  • Use valueAttriButeConverted.c_str(). It's work perfectly. Thanks so much. Please help me with jstring. I need to convert it to std::string to use it. – user2217159 Jul 21 '20 at 16:09

1 Answers1

0

&valueAttriButeConverted gives you a pointer to the std::string itself, not to data inside it. To get a pointer to the data you should use valueAttriButeConverted.c_str()

This question and answer should help you with JNI.

zonk
  • 16
  • 2
  • I found the reason. Here is the memory: https://i.gyazo.com/5f335ee75e4e7052418f45cd4d0bfca1.png In memory there are these bytes: 08 64 90 a0 e3. The pointer point to byte 08. Intead of byte 64 – user2217159 Jul 21 '20 at 15:58
  • and how to cast jstring to std:string? can i use jstring as pointer too? – user2217159 Jul 21 '20 at 16:01
  • @user2217159 Yes that's because you used `&valueAttriButeConverted` instead of `valueAttriButeConverted.c_str()` – user253751 Jul 21 '20 at 16:57