2

This code generates an API key. I use it in an android app as .so file, but I need to rewrite it to java from c++. How do I translate?

push    rbp
push    r15
push    r14
push    r13
push    r12
push    rbx
sub     rsp, 198h
mov     rbx, rdx
mov     rdx, rsi
mov     r12, rdi
mov     rax, fs:28h
mov     [rsp+1C8h+var_38], rax
lea     rbp, [rsp+1C8h+var_70]
mov     rdi, rbp
mov     rsi, r12
call    __Z12getSignatureP7_JNIEnvP8_jobject ; getSignature(_JNIEnv *,_jobject *)
lea     rdi, [rsp+1C8h+var_88]
mov     edx, 3
mov     ecx, 0Eh
mov     rsi, rbp
mov     r8, rbp
call    __ZNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC2ERKS5_mmRKS4_ ; std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>::basic_string(std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>> const&,ulong,ulong,std::__ndk1::allocator<char> const&)
lea     rdi, [rsp+1C8h+var_A0]
mov     edx, 13h
mov     ecx, 0Bh
mov     rsi, rbp
mov     r8, rbp
call    __ZNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC2ERKS5_mmRKS4_ ; std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>>::basic_string(std::__ndk1::basic_string<char,std::__ndk1::char_traits<char>,std::__ndk1::allocator<char>> const&,ulong,ulong,std::__ndk1::allocator<char> const&)
test    rbx, rbx
jz      loc_21FE3

The full code is here. enter image description here As I understand the key generation occurs here.

To generate a key in Java after importing the library, I call the native method x01 with a string argument.

Please explain how this code works

3
  • 1
    Hi and welcome to RE.SE. So what's your question? Please also be aware that the code isn't complete. Until you provide a more complete piece of code and ask a question, you could read about the SysV ABI to see how the parameters are passed to those calls.
    – 0xC0000022L
    Feb 9, 2023 at 14:34
  • from the code you provided via p*stebin, it seems that the program creates a 128-bit hash represented as a 16-byte string in hexadecimal format. the hash is generated by performing a series of operations on an input string using a custom algorithm. at the beginning, the input string is converted into a byte buffer and padded with zeros. then, the length of the input string in bits is appended to the end of the buffer. after, the algorithm performs a series of operations on the buffer to generate the hash. the resulting hash is then represented as a string of hexadecimal digits and outputted.
    – raheel0x01
    Feb 15, 2023 at 8:19
  • ... the code allows for the creation of a unique hash for any input string using a custom algorithm.
    – raheel0x01
    Feb 15, 2023 at 8:19

0

Browse other questions tagged or ask your own question.