hello,
I want to change the data type returns, Is it possible ?
Can I do this by intercepting a native method ?? if yes please shed some light.
Thanks
Printable View
hello,
I want to change the data type returns, Is it possible ?
Can I do this by intercepting a native method ?? if yes please shed some light.
Thanks
What do you mean by 'change the data type returns'?
You could wrap the existing native calls and do whatever you want.
Why is your native function returning a String if it should be a byte[]?
Has the Java side been mis-translated?
So all you can do is wrap the call in something that'll translate it.
If the 3rd party stuff returns a String and you want a byte[] then:
Code:public byte[] wrappedMethod() {
String result = nativeMethodCall();
return result.getBytes(<whatever character set the String is in>);
}
Thanks for the reply.
The nativeMethodCall() above in first place returns a String which means the byte stream will be incomplete if a 0x00 is met. is that right ? this is the problem i am trying to solve. hints?
I do have access to the binary file and i can tell the bytes returned are incomplete.
Thanks
If the native method returns a String wirth 0x00 in it then that is what you will receive.
Just look at the bytes in Java, as above.
Which is what is contained in the String.
It wouldn't work otherwise.
What is the value you are getting back in the String, when printing out the bytes?
What is happening when you try and get the byte[]?
You haven't said.
Hello,
I did manage to do the bytes by changing the return value of the native method from string to byte[];
But the value is the again the incomplete string e.g. 11 22 33 00 where it should be 11 22 33 00 AA FF.
This means that the native function is returning a string (zero terminated).
Hints?
Thanks
So, complain to whoever wrote that code.
You are calling a native method which is returning the wrong thing, at least according to you.
The only solution we can give to that is to get someone to rewrite that method.
Will this library be beneficial in my case ?
Thanks for your effort
"Pure Java agent to intercept native method calls to handle their implementation in Java code rather than native code."
That says it is for redirecting calls to a native method so that they go to a Java method instead.
So unless you want to rewrite what this 3rd party package does then this is not what you want.
Honestly, you need to talk to whoever wrote this, or see what the documentation says about its interaction with Java.
Hello,
I want to double check what i am doing is correct.
If in a Java package there is a TestImp.java and has the method:
and in the dll files there is an exported function called package_imp_getTestValue.Code:public native String getTestValue()
throws Exception;
So how the java method is mapped to the dll exported function ? is there a wrapper in between ?
Thanks
You can jump around the original native method all you want, but it returns whatever it returns and if it's a zero terminated String then that's what it returns, no matter how you call the type of the returned value. If you want zeros in your String (or char array or whatever) you have to change the original native method. There's no magic involved.
kind regards,
Jos
Ok thanks ;)
could you please answer me thisThanksQuote:
So how the java method is mapped to the dll exported function ? is there a wrapper in between ?
You've definitely got a jumping metaphor going at the moment, Jos.