How to load native library in Android - General Questions and Answers

Can someone give advice in how to load native library and make native function calls in android application? I tried with android 1.0 and my result is below:
Result:
1. I added the following code to android application Lunarlander.java
//native method declaration
native void hello(String name);
static {
System.out.println("libhello.so loaded");
System.load("/data/app/libhello.so");
}
I added my libhellp.so to lunalander.apk and then uploaded the apk to /data/app. The application launches ok.
2. I added the following code to android application Lunarlander.java
//native method declaration
native void hello(String name);
static {
System.out.println("libhello.so loaded");
System.load("/data/app/libhello.so");
}
…
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
…
//test loading hello lib and call hello function
LunarLander myLunarLander = new LunarLander();
myLunarLander.hello("Hi there!");
…
}
I added my libhellp.so to lunalander.apk and then uploaded the apk to /data/app. The application launches was forced to close and the error message is “The application Lunar lander has stopped unexpectedly. Please try again”.
Not sure why it failed to invoke the native function.
Thanks,
SynPad

Please post Questions in the Q&A section. Dev and Hacking Section is for contributers (new programs themes ect)
I'll go ahead and have the thread moved to Q&A for you this time
Thanks for your cooperation,
Joel
Q&A Section Team
EDIT: you may also want to try the g1 section, pm me if you would like it moved there instead.

Check the samples w/ NDK
BTW, do you know how to ship the lib along the apk :
there is a "native library location:" entry on project settings in eclipse plugin
Later

Related

Sl (Steam Locomotive) compiled for Android (arm-none-linux-gnueabi)

** Please notify me if this is off-topic or against rules
I just compiled sl (Steam Locomotive) for Android for fun xD
I linked the ncurses as static library.
It requires /etc/terminfo for sl to run properly since it uses ncurses.
The source code may be found at github, sl project by mtoyoda (Sorry I am a new user so posting link is disallowed..)

[Completed] AT&T Galaxy Alpha g850A US Variant Possible Root Exploit Found

Hi Mods,
I do not have permissions to post in the development forum so I ask that you move this thread accordingly.
I have been researching the AT&T Galaxy Alpha sm-g850a variant in order to gain root access and, as you might know, have found absolutely nothing out there. All other international variants have been rooted Except the A model...which is what I am stuck with. I found a recently released CVE that states it is not patched until Lollipop 5.0 and allows a malicious intent request to take over SYSTEM permissions. I have been able to get the intent code into an app without bricking the phone and am having some NOOB java issues as I'm not a professional programmer. Any interest in helping finish this exploit would be greatly appreciated. A few code snippets below:
import android.accounts.NetworkErrorException;
import android.app.PendingIntent;
import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
android.content.Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.settings","com.android.settings.accounts.AddAccountSettings"));
AccountManager.get(this).addAccount(
accountType,
null, /* authTokenType */
null, /* requiredFeatures */
addAccountOptions,
null,
mCallback,
null /* handler */);
mAddAccountCalled = true;
PendingIntent test = (PendingIntent) options.getParcelable("pendingIntent");
Intent newIntent2 = new Intent("android.intent.action.REBOOT"); <---testing---> somewhere in here I need to drop the SU binary and all of that good stuff.
try {
test.send(mContext, 0, newIntent2, null, null);
} catch (PendingIntent.CanceledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
There is more code obviously. Posting some main parts to see if anyone is interested in helping.
w/respect-PitPin
Can't forget the credit for discovering this vulnerability:
Credits: Wang,Tao(Scloud) - seclist.org
Here is my NOOB showing. Wouldn't this mean I am on the right track and my app took "system root" privileges?
7386-7386/com.pitpindesigns.modpit.pitpin E/dalvikvm﹕ >>>>> com.pitpindesigns.modpit.pitpin [ userId:0 | appId:10248 ]
Nope...1000 would be root.
Sir,
Here isn't the right place for this type of threads so please open a new one here:
xda-developers -> Android Development and Hacking -> Android General
Good luck

[App][6.0+] Package Manager

Please Note: Due to personnel reasons, I'm not updating this thread anymore. For those who wish to stay updated with the development of this project are requested to reach us on GitHub or Telegram. Thank you very much for the understanding.
​
Proudly presenting, Package manager, a highly powerful application to manage apps, both system and user, installed on your android device.
/* DISCLAIMER */
Code:
Please use this app at your own risk.
I am not responsible for any damage to your device.
Everything you are doing on your device is at your own risk.
This app is so powerful to mess up your device/OS if you use it incorrectly.
Requirements
ROOT Access is required for some advanced features.
/* Features */
Package Manager is a simple, yet powerful application to manage the apps installed on an android phone, which currently offer following things
Offer a beautiful list view of System and User Apps, together or separately.
Helps to do basic tasks such as Open app, show App info, visit PlayStore page, uninstall (User apps), etc.
Do advanced tasks such as (need Root access)
Uninstall system apps (de-bloating)
Export (to SDCard) and Share an app (normal APK's)
Export Split APK's into SDCard
Install Split APK's from SDCard
Disable or Enable apps
Back up individual app data
Restore individual app data (Work-in-Progress)
/* Downloads */
/* Please Note */
This app is still in its early stage of development. If you meet any issues, please feel free to leave a comment in this thread, or contact me here. Also, you can report a bug or request a feature by opening an issue.
Help me translating this application! It doesn't take much time as it is ~ 50 lines of strings. The original strings in English can be found here.
/* Note to Developers */
This Application is open sourced and ready to accept the contributions from the development community.
/* Donations */
If you like to appreciate my work, please consider donating to me (by either via PayPal, Ko-fi, or by purchasing the donation app from playstore) as it is helpful to continue my projects more active, although it is not at all necessary.
/* Acknowledgements */
@Grarak for the Kernel Adiutor from where I took a lot of code.
XDA:DevDB Information
Package Manager, App for all devices (see above for details)
Contributors
sunilpaulmathew
Source Code: https://github.com/SmartPack/PackageManager/
Version Information
Status: Beta
Created 2020-02-25
Last Updated 2020-08-14
Change-logs
https://raw.githubusercontent.com/SmartPack/PackageManager/master/change-logs.md
Reserved

[App][Root][6.0+] Kernel Profiler

Please Note: Due to personnel reasons, I'm not updating this thread anymore. For those who wish to stay updated with the development of this project are requested to reach us on GitHub or Telegram. Thank you very much for the understanding.
​/* Introduction */
Kernel Profiler is a free and open-sourced profile based kernel management utility, which helps kernel developers to provide predefined profiles to their users.
/* DISCLAIMER */
Code:
Please use this app at your own risk.
I am not responsible for any damage to your device.
Everything you are doing on your device is at your own risk.
/* Requirements */
ROOT ACCESS
Support from Kernel Developer (if your favorite kernel developer is not willing to support this app, please do not bother to install).
/* Features */
Switch between profiles (no limit) provided by the kernel developer in one click (for users).
Apply default profile, pre-defined by the developer or assigned by the user, on boot.
Completely (almost) customize the interface of app in accordance with the kernel (for developers).
Easily create profiles and necessary configuration file within the app (for developers).
/* Downloads */
/* How to add support in kernel */
Kernel Profiler expects a configuration file (kernelprofiler.json) and one or more profiles (basically shell scripts) in certain specific structure placed inside "/data/kernel_profiler".
/* Structure of kernelprofiler.json */
"kernelprofiler.json" necessarily contains a title string as well as a number of optional strings to properly identify a specific kernel. An example "kernelprofiler.json" can be found here.
"title": "Title of your kernel". The "title" should be a string from your kernel's "uname -a". It will be later matched on your user's devices, and also be displayed as app's main title. Please note that it is the only way of app to distinguish a supported kernel and should be done carefully.
"description": "A short description (in one line) about your kernel". Please note that the "description" string will be also displayed in app along with the main title.
"default": "The exact name of the default profile including ".sh" extension".
"developer": "The identity (name, pet name or anything similar) of the developer". Please note that the "developer" string will be displayed in app along with a © symbol (bottom part of app).
"support": "A link to the discussion page or a support group of your kernel". Please note that the "support" string will be linked to the app's settings menu.
"donations": "A link to send donations to the developer". Please note that the "donations" string will also be linked to the app's settings menu.
/* Structure of profiles */
Kernel Profiler considers any properly formatted shell script as a profile. Optionally, the developer may add a line starting with "# Description=" somewhere in the profile so that the app will recognize and display it as the profile description. An example profile can be found here.
/* How to integrate into an Anykernel zip */
Adding the following lines into anykernel.sh after placing all the support files, such as a properly formatted kernelprofiler.json and one or more profile scripts, into ramdisk/kernel_profiler, allow you to inject Kernel Profiler support upon kernel installation.
Code:
if [ -e $ramdisk/kernel_profiler ]; then
# Inject Kernel Profiler support
if [ -e /data/kernel_profiler ]; then
# Remove old files
rm -rf /data/kernel_profiler/*
mv $ramdisk/kernel_profiler/* /data/kernel_profiler/
else
mv ramdisk/kernel_profiler/ /data/
fi
fi
The following commit shall be used for further reference
AnyKernel: Introduce Kernel Profiler support
/* Translations */
Please help me to translate this app. The original english string of this app is available at
https://github.com/SmartPack/KernelProfiler/blob/master/app/src/main/res/values/strings.xml
/* Support */
/* Feature Requests */
I am generally open to feature requests as long as you provide enough information. Please make sure to provide all the relevant information, either in this thread or in the GitHub page. If you are a developer, please consider contributing to this app by sending pull requests.
/* Note to other developers */
You are allowed to include this app on any of your works. Giving proper credits to the original developers (including me, if you considered me as one among them) are, however, highly appreciated. Feel free to contact me, if you need any assistance from my side.
/* Donations */
If you like to appreciate my work, please consider donating to me (by either via PayPal, Ko-fi, or by purchasing the donation app from playstore) as it is helpful to continue my projects more active, although it is not at all necessary.
XDA:DevDB Information
Kernel Profiler, App for all devices (see above for details)
Contributors
sunilpaulmathew
Source Code: https://github.com/SmartPack/KernelProfiler
Version Information
Status: Beta
Created 2020-06-10
Last Updated 2020-08-14
Change-logs
Latest version
Old versions
v0.5
- Improved developer tools.
- Preparations for play-store release.
beta-v0.4
- Improved developer tools.
- Remove custom banner option.
- Updated build tools to latest.
- Updated change-log view.
- Miscellaneous changes.
beta-v0.3
- Removed a bunch of unnecessary code from the developer tools (improved coding quality).
- Added Portuguese (Brazilian) translations.
- Added a title check button on create config activity.
- Added option to edit the current configuration file.
- Introduced a Developer Mode, which is disabled by default.
- Miscellaneous changes.
beta-v0.2
- Improved kernel support check status before applying custom details.
- Simplified profile structure requirements.
- Fixed title on profile creation menu.
- Overall improvements.
beta-v0.1
- Initial (pre) release for public testing.
Reserved

Profile Owner..

Hello together
since more than 4 Days i stuck on my current app project with the message: "admin componentinfo does not own the profile".
I tried many things - Added an Work Profile programmaticaly - Gave Profile Owner via adb and i dont find the result.
Someone have an Idea, what im doing wrong?
Code to add managed profile:
Java:
private void provisionManagedProfile()
{
Activity activity = this;
if (null == activity) {
return;
}
Intent intent = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
intent.putExtra(
DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
activity.getApplicationContext().getPackageName()
);
} else {
final ComponentName component = new ComponentName(activity,
DeviceAdmin.class.getName());
intent.putExtra(
DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
component
);
}
if (intent.resolveActivity(activity.getPackageManager()) != null) {
startActivityForResult(intent, 1);
Toast.makeText(activity, "Already used!",
Toast.LENGTH_SHORT).show();
activity.finish();
} else {
Toast.makeText(activity, "Device provisioning is not enabled. Stopping.",
Toast.LENGTH_SHORT).show();
}
}
Code to use:
Java:
DevicePolicyManager dpm = (DevicePolicyManager) getApplicationContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
dpm.setProfileEnabled(compName);
compName is:
Java:
compName = new ComponentName(this, DeviceAdmin.class);
#Edit
If i start the manged Profile, its crashed after the end before the "next" button showing.
But if i take an look on my settings its showing that this profile was created.
Greetings
tpoeschl said:
Hello together
since more than 4 Days i stuck on my current app project with the message: "admin componentinfo does not own the profile".
I tried many things - Added an Work Profile programmaticaly - Gave Profile Owner via adb and i dont find the result.
Someone have an Idea, what im doing wrong?
Code to add managed profile:
Java:
private void provisionManagedProfile()
{
Activity activity = this;
if (null == activity) {
return;
}
Intent intent = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
intent.putExtra(
DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
activity.getApplicationContext().getPackageName()
);
} else {
final ComponentName component = new ComponentName(activity,
DeviceAdmin.class.getName());
intent.putExtra(
DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
component
);
}
if (intent.resolveActivity(activity.getPackageManager()) != null) {
startActivityForResult(intent, 1);
Toast.makeText(activity, "Already used!",
Toast.LENGTH_SHORT).show();
activity.finish();
} else {
Toast.makeText(activity, "Device provisioning is not enabled. Stopping.",
Toast.LENGTH_SHORT).show();
}
}
Code to use:
Java:
DevicePolicyManager dpm = (DevicePolicyManager) getApplicationContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
dpm.setProfileEnabled(compName);
compName is:
Java:
compName = new ComponentName(this, DeviceAdmin.class);
#Edit
If i start the manged Profile, its crashed after the end before the "next" button showing.
But if i take an look on my settings its showing that this profile was created.
Greetings
Click to expand...
Click to collapse
Technical discussion of Android development and hacking. No noobs, please. Device-specific releases should go under the appropriate device forum.
Note: Questions go in Q&A Forum
If you are posting a Question Thread post it in the Q&A forum. Technical discussion of Android development and hacking. No noobs, please. Device-specific releases should go under the appropriate device forum...
forum.xda-developers.com

Categories

Resources