In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares with you is about how NDK makes an Android executive program. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Preface
How to implement tracerout in Android, because most Android systems do not have the traceroute command, so they can only use ping to simulate.
For example, the-t command of ping can set up ttl, gradually increase debugging, and test each route.
But the efficiency is very low, I want to write a method with c
I used ndk to make a so, in which I used rawsocket to implement the icmp function, but found that there were insufficient permissions to establish a socket.
Access to the data found that Android can not run rawsocket without root permission.
Found a way to solve it.
Https://blog.csdn.net/Inconsolabl/article/details/50437588
Put the binaries into user space, and then set permissions 700
-rwx- (700)-- only owners have read, write, and execute permissions.
The experiment is successful, find a cross-compiled traceout on the Internet and seal it in app and call it directly.
Recently, I need to do another tcpping function, but I can't find a ready-made cross-compiled binary. In fact, tcpping is just a handshake probe, which can also be written with java. But java was busy, so I tried to write a cross-compiled tcpping.
Realize
Https://blog.csdn.net/qushaobo/article/details/81089466
An example is written with reference to the code.
But cannot be executed, display
". / data/user/0/com.example.myapplication/files/tcpping": error: Android 5.0and later only support position-independent executables (- fPIE).
It is found that the example code is
# include # include # include int main (int argc, char * argv []) {fprintf (stderr, "this is a test...\ n"); return 0;}
Using stderr, it is possible that Android's permissions are very strict, and it is not possible to output to standard error, so change it to printf and ok.
Format
Some compatibility changes have been made to the example code
Android.mk:
LOCAL_PATH: = $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE: = tcppingLOCAL_SRC_FILES: = tcpping.cppifeq ($(TARGET_ARCH_ABI), armeabi-v7a) LOCAL_CFLAGS + =-LOCAL_CFLAGS: = armelse LOCAL_ARM_MODE: = armendif# compatible 5.0+LOCAL_CFLAGS + =-fPIE-fPICLOCAL_LDFLAGS + =-fPIE-pieinclude $(BUILD_EXECUTABLE)
Application.mk
APP_STL: = gnustl_static
APP_CPPFLAGS: =-frtti-fexceptions
APP_ABI: = armeabi armeabi-v7a x86
APP_PLATFORM: = android-14
Compile
$NDK/ndk-build DK_DEBUG=1-B Vista 1
Go to the libs directory and get the execution program of tcpping binary on three platforms
This is how NDK makes an Android executive program. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.