1. Static implementation of jni: first get the declaration of the native method from Java, and then implement the declared method through JNI.
2. Dynamic implementation of jni: first implement the native method through JNI overloading JNI_OnLoad(), and then call the native method directly in Java.
If the static implementation is used, it is easy to search for the exported function in IDA without encryption. If the dynamic
implementation is used, it can also play a certain role in hiding. The exported part does not directly show the function name called by the Java layer, but the bound function name.
Native layer:
register related functions in JNI_OnLoad
JNIEXPORT jstring JNICALL native_hello(JNIEnv *env, jclass clazz) { return (*env)->NewStringUTF(env, "hello load jni."); }
// Binding table for Java and JNI functions
static JNINativeMethod method_table[] = { { "HelloLoad", "()Ljava/lang/String;", (void*)native_hello },//绑定 };
Java layer:
//Methods registered in jni
public native String HelloLoad();
2. Calling Arm assembly code in Android
Android.mk file
# This file is jni/Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_ARM_MODE := arm # Name of the local module LOCAL_MODULE := hello-jni # The files that make up the source code LOCAL_SRC_FILES := hello-jni.c multiple.s include $(BUILD_SHARED_LIBRARY)
multiple.s conforms to GNU syntax
@ This file is jni/multiple.s .text .align 2 .global armFunction .type armFunction, %function armFunction: @ Multiply by 10. Input value and return value in r0 stmfd sp!, {fp,ip,lr} mov r3, r0, asl #3 add r0, r3, r0, asl #1 ldmfd sp!, {fp,ip,lr} bx lr .size armFunction, .-armFunction
Directly call armFunction(input) in c
Previous article:ARM assembly learning (V)
Next article:ARM assembly learning (Part 3)
Recommended ReadingLatest update time:2024-11-23 10:51
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- I downloaded a source code from the Internet. Please help me find out what IDE this project was developed in. Thanks
- X-NUCLEO-IKS01A3 MakeCode Driver (Extension) Collection
- This strange circuit
- EEWORLD University ---- test
- What is ModBus? What are the differences and connections with RS485 protocol?
- Is this speed too fast? I have never experienced it properly.
- Application Differences between HT8691 and HT8691R
- Better
- SimpleLink MCU code migration guide: CC1310 from VQFN48 (7×7) to VQFN32 (5×5) code migration process reference
- Welcome the new moderator of the "201420208012" eSports