zoukankan      html  css  js  c++  java
  • Unpack & Repack Android system.img & data.img

    I Get packing software

      1. Download the https://android.googlesource.com/platform/system/core repository:
        cd "$AOSP_ROOT"
        [ ! -d "platform/system" ] && mkdir -p platform/system
        cd platform/system
        git clone https://android.googlesource.com/platform/system/core
      2. Check out a revision of your choice:
        cd core
        git checkout android-4.2.1_r1
      3. Compile simg2img:
        cd libsparse
        gcc -o simg2img -Iinclude simg2img.c sparse_crc32.c backed_block.c output_file.c sparse.c sparse_err.c sparse_read.c -lz

    II Get unpack software

      1. Download the https://android.googlesource.com/platform/system/extras repository:
        cd "$AOSP_ROOT/platform"
        [ ! -d "system" ] && mkdir system
        cd system
        git clone https://android.googlesource.com/platform/system/extras
      2. Check out a revision of your choice:
        cd extras
        git checkout android-4.2.1_r1
      3. Compile make_ext4fs:
        cd ..
        gcc -o make_ext4fs -Icore/libsparse/include extras/ext4_utils/make_ext4fs_main.c extras/ext4_utils/make_ext4fs.c extras/ext4_utils/ext4fixup.c extras/ext4_utils/ext4_utils.c extras/ext4_utils/allocate.c extras/ext4_utils/contents.c extras/ext4_utils/extent.c extras/ext4_utils/indirect.c extras/ext4_utils/uuid.c extras/ext4_utils/sha1.c extras/ext4_utils/wipe.c core/libsparse/backed_block.c core/libsparse/output_file.c core/libsparse/sparse.c core/libsparse/sparse_crc32.c core/libsparse/sparse_err.c core/libsparse/sparse_read.c -lz

    III Problem with Android 4.3

    Compiling make_ext4fs from Android v4.3 sources

    The compilation of simg2img is pretty much the same as for 4.2.*. But the compilation of make_ext4fs got a lot more complicated. First of all, it seems that this cannot be compiled (at least out-of-the-box) on a Mac anymore because of SELinux dependencies.

    If you try to compile it on linux, the following might be sufficient:
    gcc -o make_ext4fs -Isystem/core/libsparse/include -Isystem/core/include -Iexternal/libselinux/include -lz external/libselinux/src/android.c external/libselinux/src/booleans.c external/libselinux/src/callbacks.c external/libselinux/src/check_context.c external/libselinux/src/freecon.c external/libselinux/src/getenforce.c external/libselinux/src/init.c external/libselinux/src/label.c external/libselinux/src/label_android_property.c external/libselinux/src/label_file.c system/extras/ext4_utils/make_ext4fs_main.c system/extras/ext4_utils/make_ext4fs.c system/extras/ext4_utils/ext4fixup.c system/extras/ext4_utils/ext4_utils.c system/extras/ext4_utils/allocate.c system/extras/ext4_utils/contents.c system/extras/ext4_utils/extent.c system/extras/ext4_utils/indirect.c system/extras/ext4_utils/uuid.c system/extras/ext4_utils/sha1.c system/extras/ext4_utils/wipe.c system/extras/ext4_utils/crc16.c system/core/libsparse/backed_block.c system/core/libsparse/output_file.c system/core/libsparse/sparse.c system/core/libsparse/sparse_crc32.c system/core/libsparse/sparse_err.c system/core/libsparse/sparse_read.c

    I didn't have the chance to test it (tried to compile on a Mac, but gave up after hitting the SELinux problem), but it seems to be the complete gcc line for make_ext4fs.
     
    -Icore/include -DANDROID
     

    IV Unpack system.img and mount for modify

    #!/bin/bash
    if [ ! -f system.raw.img ]; then
        ./simg2img system.img system.raw.img
        echo "unpack OK"
    else
        echo "system.raw.img already exist."
    fi
    mount -t ext4 -o loop system.raw.img /mnt/android_system

    V Repack system.img

    #!/bin/bash

    image_size=$(tune2fs -l system.raw.img | awk 'BEGIN{s=1}{if ($1 == "Block") s *= $3;}END{print s}')
    echo "image size ${image_size}"
    PATH="$PATH:$(pwd)" ./make_ext4fs -s -l ${image_size} -a system new_system.img /mnt/android_system/

     
     
  • 相关阅读:
    模板 无源汇上下界可行流 loj115
    ICPC2018JiaozuoE Resistors in Parallel 高精度 数论
    hdu 2255 奔小康赚大钱 最佳匹配 KM算法
    ICPC2018Beijing 现场赛D Frog and Portal 构造
    codeforce 1175E Minimal Segment Cover ST表 倍增思想
    ICPC2018Jiaozuo 现场赛H Can You Solve the Harder Problem? 后缀数组 树上差分 ST表 口胡题解
    luogu P1966 火柴排队 树状数组 逆序对 离散化
    luogu P1970 花匠 贪心
    luogu P1967 货车运输 最大生成树 倍增LCA
    luogu P1315 观光公交 贪心
  • 原文地址:https://www.cnblogs.com/blowing-in-the-wind/p/6022391.html
Copyright © 2011-2022 走看看