Skip to content

[BUG] Bad base address calculation on unpack when base address >= 0x80000000 #13

@S-trace

Description

@S-trace

I have recovery.img, which Android_boot_image_editor can unpack, but can't repack back without manual interaction.

In bootimg.json there is such values:

{
    "bootimg": {
        "args": {
            "base": "0x0",
            "kernel_offset": "0x80008000",
            "ramdisk_offset": "0x81000000",
            "second_offset": "0x80f00000",
            "tags_offset": "0x80000100",
            "pagesize": 2048,
            "board": null,
            "cmdline": "console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 androidboot.bootdevice=7824900.sdhci earlycon=msm_hsl_uart,0x78af000 buildvariant=userdebug",
            "os_version": "7.1.2",
            "os_patch_level": "2017-11-00",
            "id": false
        },
        "img": {
            "kernel_pos": "0x800",
            "kernel_len": "0xa6c647",
            "ramdisk_pos": "0xa6d000",
            "ramdisk_len": "0x4ad065",
            "second_pos": "0xf1a800",
            "second_len": "0x0",
            "hash": "d2309ac6a8538e1b56c6a799c87ee602a9754f19000000000000000000000000"
        }
    }
}

And ./gradlew pack fails with following error:



> Task :abootimg:pack_clear FAILED
Exception in thread "main" java.lang.NumberFormatException: For input string: "80008000"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:583)
        at java.lang.Integer.valueOf(Integer.java:740)
        at java.lang.Integer.decode(Integer.java:1197)
        at java_lang_Integer$decode.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at cfig.bootimg.CImgInfo.fromJson(CImgInfo.groovy:36)
        at cfig.bootimg.CImgInfo$fromJson.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
        at cfig.bootimg.repack_with_cmd.run(repack_with_cmd.groovy:25)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
        at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:923)
        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:906)
        at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:410)
        at org.codehaus.groovy.runtime.InvokerHelper$runScript.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
        at cfig.bootimg.repack_with_cmd.main(repack_with_cmd.groovy)


FAILURE: Build failed with an exception.

If i change bootimg.json as followed, ./gradlew pack finishes successfully:

{
    "bootimg": {
        "args": {
            "base": "0x70000000",
            "kernel_offset": "0x10008000",
            "ramdisk_offset": "0x11000000",
            "second_offset": "0x10f00000",
            "tags_offset": "0x10000100",
            "pagesize": 2048,
            "board": null,
            "cmdline": "console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 androidboot.bootdevice=7824900.sdhci earlycon=msm_hsl_uart,0x78af000 buildvariant=userdebug",
            "os_version": "7.1.2",
            "os_patch_level": "2017-11-00",
            "id": false
        },
        "img": {
            "kernel_pos": "0x800",
            "kernel_len": "0xa6c647",
            "ramdisk_pos": "0xa6d000",
            "ramdisk_len": "0x4ad065",
            "second_pos": "0xf1a800",
            "second_len": "0x0",
            "hash": "d2309ac6a8538e1b56c6a799c87ee602a9754f19000000000000000000000000"
        }
    }
}

Both master and dev branches affected.

recovery.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions