AnsweredAssumed Answered

how to get the root permission in android-4.3(imx6q_sabresd)

Question asked by wang zhigang on Apr 2, 2015

hi everyone,

    I want to execute the command("blkid > filename") in my android-4.3 system ,and the platform is imx6q_sabresd,but I failed to execute the command,because I have not the root permission.so I attempted to root my android-4.3 system as follow:

1.su.c

......

......

int main(int argc, char *argv[])

{

    ALOGI("hello !robin-su begin %d !",getuid());

    printf("hello !robin-su begin");

  int uid=0;

  int gid=0;

  if(setgid(gid) || setuid(uid)) {

  ALOGI("robin su: permission denied\n");

  fprintf(stderr,"su: permission denied\n");

  return 1;

    }

  char command[1024];

 

    ALOGI("hello !robin-su end %d !",getuid());

    printf("hello !robin-su end");

  /* Default exec shell. */

  execlp("/system/bin/sh", "sh", NULL);

  fprintf(stderr, "su: exec failed\n");

    return 1;

}

 

2.su.h

......

......

 

3.Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := su

LOCAL_SRC_FILES := su.c

LOCAL_STATIC_LIBRARIES := \

    liblog \

    libc \

 

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)

LOCAL_MODULE_TAGS := eng debug

LOCAL_FORCE_STATIC_EXECUTABLE := true

include $(BUILD_EXECUTABLE)

 

3.compile the su file

$ mkdir -p packages/experimental/su

$ cp su.c su.h Android.mk  packages/experimental/su

$ mmm packages/experimental/su

 

4.apk (MainActivity.java)

......

......

try{

  process = Runtime.getRuntime().exec("/system/xbin/su");

  os = new DataOutputStream(process.getOutputStream());

  os.writeBytes("blkid > /data/local/tmp/label" + "\n");

  os.writeBytes("exit\n");

  os.flush();

  process.waitFor();

} catch (Exception e){

  Log.e(LOG_TAG, "===unexpected error===");

}finally {

  try {

  if(os != null){

  os.close();

  }

  process.destroy();

  }catch (Exception e){

  }

}

 

5.apk(Android.mk)

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

# Only compile source java files in this apk.

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := usb_label

include $(BUILD_PACKAGE)

 

6.compile apk

$ mkdir -p packages/experimental/usb_label

$ cp su.c su.h Android.mk  packages/experimental/usb_label

$ mmm packages/experimental/usb_label

 

7.compile android-4.3

source build/envsetup.sh

lunch sabresd_6dq-user

make -j8

 

8.write sd card

dd if=system.img of=/dev/mmcblk0p5;sync

 

9.start android system

$ mount -o remount,rw /system

$ chmod 4755 system/xbin/su

reboot system again

 

10.run apk

I failed to execute the the command("blkid > filename"),and get the log:

1)

W/AudioPolicyManagerBase( 2489): getOutput() could not find output for stream 1, samplingRate 0,format 0, channels 3, flags 0

W/AudioPolicyManagerBase( 2489): getOutput() could not find output for stream 1, samplingRate 0,format 0, channels 3, flags 0

W/AudioPolicyManagerBase( 2489): getOutput() could not find output for stream 1, samplingRate 48000,format 1, channels 1, flags 4

2)

robin su: permission denied

 

11.replace the su file

I found that if I compile the android-4.3 in "eng" mode,the is a "su" file in system/xbin/su,so I replace the new su file into my android-4.3(user mode),and test again.I still failed to get the root permission.and get the same log:

W/AudioPolicyManagerBase( 2489): getOutput() could not find output for stream 1, samplingRate 0,format 0, channels 3, flags 0

W/AudioPolicyManagerBase( 2489): getOutput() could not find output for stream 1, samplingRate 0,format 0, channels 3, flags 0

W/AudioPolicyManagerBase( 2489): getOutput() could not find output for stream 1, samplingRate 48000,format 1, channels 1, flags 4

 

Is everyone can help me?

Best wishes!

Outcomes