Android NDK make a program execution

Foreword

Some colleagues realized tracerout in Andrews, Andrews systems because most do not take traceroute command, can only be achieved using ping simulation before.
For example, the ping -t command, you can set ttl, gradually increase the commissioning, by the way of each test.
But the efficiency is very low, c want to write a method
I use to do a ndk so, use rawsocket achieve icmp function inside, but found insufficient permission to create socket.
Access to information that Andrews did not run as root is not rawsocket of.

We found a way to solve
https://blog.csdn.net/Inconsolabl/article/details/50437588
binary file into user space, and then set the permissions 700
-rwx------ (700) -- 只有属主有读、写、执行权限。
successfully tested to find online a cross compiler traceout sealed inside the app , direct calls.

Recently tcpping need to do a feature, but existing cross-compiled binaries not found. In fact tcpping is a handshake detection, using java can also write. But java busy over there, I tried to write a compilation of tcpping cross.

achieve

https://blog.csdn.net/qushaobo/article/details/81089466
reference code written example
but can not perform, display,
"./data/user/0/com.example.myapplication/files/tcpping": error: Android 5.0 and later only support position-independent executables (-fPIE).
find examples of code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char *argv[])
{

    fprintf(stderr, "this is a test...\n");

    return 0;
}

Using stderr, is likely to Andrews authority is very strict, output to the standard error in does not work, change the printf ok.

format

For example code modifications made some compatibility
Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := tcpping
LOCAL_SRC_FILES := tcpping.cpp

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
    LOCAL_CFLAGS += -D__ARMV7__
    LOCAL_ARM_MODE := arm
else
    LOCAL_ARM_MODE := arm
endif

#兼容5.0+
LOCAL_CFLAGS += -fPIE -fPIC
LOCAL_LDFLAGS += -fPIE -pie

include $(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 V=1

Into the libs directory, get tcpping binary implementation of the program in three platforms

Guess you like

Origin blog.51cto.com/xzq2000/2411979