PokeGOAPI-Java icon indicating copy to clipboard operation
PokeGOAPI-Java copied to clipboard

JNA quick example

Open Paul776 opened this issue 10 years ago • 20 comments

I started writing the fix for that signature stuff. It requires java (JNA easier than JNI) to read some bloody c code. If you guys want to get started here is how

  1. Grap the encrypt.c and .h (somewhere on the subreddit)
  2. make
  3. grap the .so (or dll if you are on windows)
public class Test {

  public interface CTest extends Library {
    public int encrypt(byte[] input, long size, byte[] iv, long size2, byte[] output, int[] output size)
  }
  public static void main(String ... args) {
    CTest ctest = (CTest) Native.loadLibrary("encrypt", CTest.class);
    System.out.println(ctest.encrypt(new byte[3], 3, iv, 32, null, new int[50000]));
    //System.out.println(new Encrypt().encrypt(new byte[3], 3, iv, 32, null, 32));
  }  
}
```;

It should output 0

the real input are
(raw_signature_proto_buf, size, iv, 32, output, output size pointer)

I'm off to bed hope I see a PR tomorrow morning 👍 

Paul776 avatar Aug 07 '16 04:08 Paul776

I am working on re-scripting the encryption to java to a jar. Probably you could skip the jnit part at this moment and let me see if the java implementation of the encryption works.

DanippDm5vzDS8HWnc9fap avatar Aug 07 '16 05:08 DanippDm5vzDS8HWnc9fap

Ideally you would rewrite the encryption code in java. Using their library isn't very optimal. JNA/JNI is messy IMO

PS: do you happen to have encrypt.c and encrypt.h?

illusion12 avatar Aug 07 '16 05:08 illusion12

Why not?

illusion12 avatar Aug 07 '16 05:08 illusion12

Here you go http://pgoapi.com/

avelizmu avatar Aug 07 '16 05:08 avelizmu

I have a working JNA code (and actually the all flow working) but it is mess indeed hmm good luck to rewrite the encrypt.c into java! it's impossible so much code :/

Paul776 avatar Aug 07 '16 06:08 Paul776

Paul776 If you need any help I'm good with Java and would be willing to help out.

DrBrad avatar Aug 07 '16 06:08 DrBrad

@Paul776 semi-automated. almost done. testing.

DanippDm5vzDS8HWnc9fap avatar Aug 07 '16 07:08 DanippDm5vzDS8HWnc9fap

Is this all that needs to be done for the api to actually work again?

DrBrad avatar Aug 07 '16 07:08 DrBrad

@DrBrad nope. compile proto. generate signature for every message envelope. encripted. put it into unknown6.

DanippDm5vzDS8HWnc9fap avatar Aug 07 '16 07:08 DanippDm5vzDS8HWnc9fap

i don't think will be added to this api anytime soon unfortunately :(

ramarro123 avatar Aug 07 '16 07:08 ramarro123

@Paul776 it is not impossible. Plus using JNA is slow. I have been able to implement most of the Signature proto (minus the final hash using the encryption) but I am too tired to finish it tonight. I will probably have this all implemented tomorrow at some point.

Assuming this xxhash library I found functions correctly. I may have to do some testing on it. If it fails, I will write my own version.

illusion12 avatar Aug 07 '16 07:08 illusion12

@ramarro123 Do you know of any other Java PokemonGo-API's out currently? As you could use another api to help with this one.

DrBrad avatar Aug 07 '16 07:08 DrBrad

@illusion12 Just curious. Is it possible to import C library using jni? I read jni is faster than jna?

jsl303 avatar Aug 07 '16 09:08 jsl303

@Paul776 completed. tested with varying random input of size 200, 256, 500 and seems to be correct. but i dont have dump to fully verify

DanippDm5vzDS8HWnc9fap avatar Aug 07 '16 12:08 DanippDm5vzDS8HWnc9fap

Actually I fail at the make-step (ld -lencrpyt missing) and using a windows dll I found in chat I get -1 as result.

clangdev avatar Aug 07 '16 12:08 clangdev

For JNA, see https://github.com/Grover-c13/PokeGOAPI-Java/pull/494

feel free to make that thing actually work as right now either the encryption thing or the xxhash'ing is not working correctly.

jabbink avatar Aug 07 '16 12:08 jabbink

@DanippDm5vzDS8HWnc9fap http://imgur.com/a/338XO

It is working perfectly (meaning I have a valid final output) but the making the request I get 0 pokemons back

I will gave up with JNA it's not the right solution. Could you share your converted java code? I can give it a try right now with a valid request

Paul776 avatar Aug 07 '16 12:08 Paul776

https://github.com/Grover-c13/PokeGOAPI-Java/pull/494

Has Java code

jabbink avatar Aug 07 '16 12:08 jabbink

@jabbink I have hooked my JNA imp with your code, and it return 0 pokemons as well might be something wrong in the way we build the requests

Paul776 avatar Aug 07 '16 12:08 Paul776

merged #494 so i close this issue ;)

vmarchaud avatar Aug 07 '16 15:08 vmarchaud