I want to understand how to write a dynamic library .so for android? This is not the usual linux library, is it? And I want to write my own. For example instead of already lying there. Can anyone help me with this?
You need to use the Android NDK to write native libraries.
Related
I am trying to create an application that uses Android Native Activity in order to avoid explosing my function code in java, but i meet a problem that i also want to use my another written dynamic library which uses JNI.
I want to know whether i can load such a dynamic library in native activity or not. It seems like that dlopen() can not perform well. Can i use reflection to call System.loadlibrary(), or indeed there exist some dramatic way to solve it?
Thank you for any help you can offer.
NativeActivity gives you all you need to use JNI. You should be able to load your library using dlopen:
dlopen("libname.so", RTLD_LAZY | RTLD_LOCAL)
Make sure to call JNI_OnLoad/JNI_OnUnload if your library has any. This will mimic what System.loadLibrary Java function does.
I have used JNI libraries and Java libraries from NativeActivity-based apps. So if you experience any particular problem with dlopen in this environment, feel free to open a separate question with more detail.
I am working on my master thesis, where I am looking at the security for an IoT device, which is controlled by an android application. At this point, I have reverse engineered the application and looked through the code that came out of it. An interesting discovery is that it is using a .so lib to communicate with the IoT device. So, I would like to build a POC android application where I use this same .so lib.
Now, my question is: how do I do this correctly?
From what I have understood so far, I need to put the .so lib into the structure:
app/jniLib/armeabi-v7a/*.so
Then I need to load the library in java with:
static {
System.loadLibrary("something_lib");
}
Now if I wish to call a function I should do this by using the "native" keyword:
But, as shown in the image above, the function is not being found. So, I properly miss something or am doing something completely wrong.
I've looked at a project on GitHub (https://github.com/SandroMachado/openalpr-android), which is also using .so lib. But I'm having the same experience when I open this project.
I have also had a look at the Android NDK guides (https://developer.android.com/ndk/guides/prebuilts.html), but sadly it did not make me a lot smarter. Here it says something about an Android.mk file, is this still something I need in my situation? If so, I would love if something has a link to a page or can explain to me the missing gaps I have in my knowledge about how to do this.
A simple example/guide for how to use a .so file in a project would be the ultimate solution for me at this point.
Maybe this thread help you:
How to include *.so library in Android Studio?
Looks like you should integrate your *.so files into src/main/jniLib/armeabi-v7a/*.so rather than app/jniLib/armeabi-a7/*.so. Verify that your arm-directory is named armeabi-v7a and not armeabi-a7.
Is it possible to alter the code of a library imported through Gradle in Android Studio? I am thinking it isn't possible since the libraries get added in at runtime?
Is there anything equivalent of extensions in Swift in Java? An extension in Swift is basically a way to add more functions/methods to an existing class. Without directly altering the original source code.
Thanks in advance!
Is it possible to alter the code of a library imported through Gradle in Android Studio?
Not as you are defining it, per your Swift extension reference.
An extension in Swift is basically a way to add more functions/methods to an existing class. Without directly altering the original source code.
Java does not have this, sorry.
I am using a jar file which contains an algorithm I have developed. As it is easy to decompile it, in order to prevent it, I want to convert jar into native code and use it with NDK. How to do it ?
Any other way to do it ?
I'm assuming you've written your algorithm in Java. You must have it in C/C++ to use NDK.
I can see only 2 options:
Write it from scratch in C/C++. Looking at your already written Java code it should be easy, but probably boring and time-consuming.
Try some Java to C++ automatic converters, for example j2c. However, sometimes they're not working, they can change the code behavior, so you need to test it all thoroughly.
Java code obfuscation is good to improve the security of your code from reverse engineering. Try any tools like progaurd
I am a beginner on android platform, and I want to build a tracerouting app. So these are my queries:
Is it possible to make such an application in Android? if possible then guide me the way that I follow.
Does Android support low-level programming to capture ICMP packets? or do I need to add some kind of JAR (in java) or some other libraries to support this application?
In Java, there are JPCAP and docjar etc kind of libraries that we can import in our IDE or Eclipse so that Java support for making such kind of API's?
I need valuable suggestions.
It's quite late - but someone might see it.
i found this one and it worked for me:
https://github.com/olivierg13/TraceroutePing
The simplest way I can think of is to just check for the traceroute Linux application, execute it, and parse its output.
Android has full networking support, however, Java doesn't expose an interface to alter the IP header. Hence, manually crafting ICMP packages is out of the question (JPCAP is no help here, since it relies on libpcap, which I suppose you won't find on any vanilla installation).
Another possible solution is to use the NDK and create a small library that handles the low-level number crunching. However, I'm not sure if the NDK would allow you to use setsockopt.
This is working pretty well for me, you may have to filter out the string results.
To add this library, you have to download or clone the git repository and implement the folder "library" just as he does in the other module "app" for it to work properly.