root@zerofltektt:/sdcard/test # ./hijack                                       

error: only position independent executables (PIE) are supported.


안드로이드에서(아마도 롤리팝 이상인 경우 ELF로더가 PIE를 확인하는 듯) 위와 같이 PIE로 컴파일 되지 않으면 실행되지 않는다는 에러 메시지가 발생한 경우


Android.mk 파일에 아래와 같이 두줄을 간단히 추가해주면 해결된다.


LOCAL_CFLAGS += -fPIE

LOCAL_LDFLAGS += -fPIE -pie


# vi Android.mk

=============================================

  1 # Copyright (C) 2009 The Android Open Source Project

  2 #

  3 # Licensed under the Apache License, Version 2.0 (the "License");

  4 # you may not use this file except in compliance with the License.

  5 # You may obtain a copy of the License at

  6 #

  7 #      http://www.apache.org/licenses/LICENSE-2.0

  8 #

  9 # Unless required by applicable law or agreed to in writing, software

 10 # distributed under the License is distributed on an "AS IS" BASIS,

 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 12 # See the License for the specific language governing permissions and

 13 # limitations under the License.

 14 #

 15 LOCAL_PATH := $(call my-dir)

 16 

 17 include $(CLEAR_VARS)

 18 LOCAL_MODULE := base

 19 LOCAL_SRC_FILES := ../../base/obj/local/armeabi/libbase.a

 20 LOCAL_EXPORT_C_INCLUDES := ../../base

 21 include $(PREBUILT_STATIC_LIBRARY)

 22 

 23 

 24 include $(CLEAR_VARS)

 25 LOCAL_MODULE    := libexample

 26 LOCAL_SRC_FILES := ../epoll.c  ../epoll_arm.c.arm

 27 LOCAL_CFLAGS := -g

 28 LOCAL_SHARED_LIBRARIES := dl

 29 LOCAL_STATIC_LIBRARIES := base

 30 LOCAL_CFLAGS += -fPIE

 31 LOCAL_LDFLAGS += -fPIE -pie

 32 

 33 include $(BUILD_SHARED_LIBRARY)


# make


해결~

+ Recent posts