New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't convert to ComplexColor: type=0x1 #1382

Closed
xpirt opened this Issue Dec 16, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@xpirt
Contributor

xpirt commented Dec 16, 2016

Information

  1. Apktool Version (apktool -version) - 2.2.1
  2. Operating System (Mac, Linux, Windows) - Windows
  3. APK From? (Playstore, ROM, Other) - ROM

Stacktrace/Logcat

http://pastebin.com/raw/ZF5VxH3F

Steps to Reproduce

Application crashes with no modifications done to it, after decompilation/compilation.

  1. apktool d LGSystemUI.apk
  2. apktool b LGSystemUI

Frameworks

lge-res.apk: https://mega.nz/#!6UtWhDjA!iw6MjIan1GY9bzf9tXeV5zMZJ6w1zvEgMuI1kOuezdU
framework-res.apk: https://mega.nz/#!TM9DlYqY!YuGlJICKx7SpOswEsT4Ax4uR9EmElu2qiApsQZero1I

APK

LGSystemUI.apk: https://mega.nz/#!PA9BmCoa!roycqSEpcvU-H1dEH8X6a1zy4iBi3er1BeO8I9RHk-o

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? Yes
  2. If you are trying to install a modified apk, did you resign it? Yes
  3. Are you using the latest apktool version? Yes
@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Dec 19, 2016

Owner

I need to refresh myself on colors for Android. This application is huge so going to run some localized tests so I can pinpoint the problem.

We have

    <color name="fake_shadow_start_color">#44000000</color>
    <color name="notification_guts_disabled_slider_color">@android:color/material_grey_300</color>
    <color name="qs_vector_btn">?qs_panel_highlight</color>
    <color name="pin_color">?android:colorAccent</color>
    <color name="accent_material_dark">@color/material_deep_teal_200</color>

So about every syntax format possible for colors. Apktool may be decoding incorrectly or building incorrectly. Will need to investigate at smaller size.

Owner

iBotPeaches commented Dec 19, 2016

I need to refresh myself on colors for Android. This application is huge so going to run some localized tests so I can pinpoint the problem.

We have

    <color name="fake_shadow_start_color">#44000000</color>
    <color name="notification_guts_disabled_slider_color">@android:color/material_grey_300</color>
    <color name="qs_vector_btn">?qs_panel_highlight</color>
    <color name="pin_color">?android:colorAccent</color>
    <color name="accent_material_dark">@color/material_deep_teal_200</color>

So about every syntax format possible for colors. Apktool may be decoding incorrectly or building incorrectly. Will need to investigate at smaller size.

@xpirt

This comment has been minimized.

Show comment
Hide comment
@xpirt

xpirt Dec 19, 2016

Contributor

Today I investigated about this issue and I found out the cause.
The good thing is that all the colors you mentioned are decoded properly, the bad thing is that what is not encoded properly is a reference to a framework attribute.

More specifically:

android:textColor="@com.lge:attr/textColorPrimaryType3"

in res/layout/qs_paged_tile_layout.xml, then:

< color name="qs_detail_transition">@com.lge:attr/textColorPrimaryType4< /color>

in res/values/colors.xml, and:

< item name="qs_edit_panel_drag_highlight">@com.lge:attr/colorAccentType3< /item>

in res/values/colors.xml.

So, basically all (and the only ones) references to color attrs in lge-res.apk in this format: @com.lge:attr/xxxxxxx, which in the framework's attrs.xml are reference|color.

Example, from attrs.xml:

< attr name="textColorPrimaryType3" format="reference|color" />

Finally, replacing those references with standard color types (eg. #ffffffff) fixed the issue.

Contributor

xpirt commented Dec 19, 2016

Today I investigated about this issue and I found out the cause.
The good thing is that all the colors you mentioned are decoded properly, the bad thing is that what is not encoded properly is a reference to a framework attribute.

More specifically:

android:textColor="@com.lge:attr/textColorPrimaryType3"

in res/layout/qs_paged_tile_layout.xml, then:

< color name="qs_detail_transition">@com.lge:attr/textColorPrimaryType4< /color>

in res/values/colors.xml, and:

< item name="qs_edit_panel_drag_highlight">@com.lge:attr/colorAccentType3< /item>

in res/values/colors.xml.

So, basically all (and the only ones) references to color attrs in lge-res.apk in this format: @com.lge:attr/xxxxxxx, which in the framework's attrs.xml are reference|color.

Example, from attrs.xml:

< attr name="textColorPrimaryType3" format="reference|color" />

Finally, replacing those references with standard color types (eg. #ffffffff) fixed the issue.

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Dec 20, 2016

Owner

Okay, so let me follow this to get things straight.

  1. We find in res/layout/qs_paged_tile_layout.xml
android:textColor="@com.lge:attr/textColorPrimaryType3" 
  1. So we follow that to the attribute based on the pkg name to lge-res.apk and res/value/attrs.xml
    <attr name="textColorPrimaryType3" format="reference|color" />
  1. Its either a reference or a color, so lets check out res/value/styles.xml in lge-res.apk.
    <style name="Theme.LGE.Default" parent="@android:style/Theme.Material.Light">
        <item name="textColorPrimaryType1">@color/primary_text_default_material_light_80</item>
        <item name="textColorPrimaryType2">@color/primary_text_default_material_light_70</item>
        <item name="textColorPrimaryType3">@color/primary_text_default_material_light_60</item>
    </style>
  1. So lets go checkout res/values/colors.xml in lge-res.apk.
    <color name="primary_text_default_material_light_80">#cc000000</color>
    <color name="primary_text_default_material_light_70">#b2000000</color>
    <color name="primary_text_default_material_light_60">#99000000</color>
  1. So going to rebuild LGSystemUI and decode it again.

Clean

        A: android:textColor(0x01010098)=(type 0x8)0x201000d

Dirty

        A: android:textColor(0x01010098)=(type 0x7)0x201000d

So we improperly converted the resource from type 8 to type 7.

    /**
     * The <var>data</var> holds a dynamic res table reference, which needs to be
     * resolved before it can be used like TYPE_REFERENCE
     */
    public static final int TYPE_DYNAMIC_REFERENCE = 0x07;
    /**
     * The <var>data</var> an attribute resource identifier, which needs to be resolved
     * before it can be used like a TYPE_ATTRIBUTE.
     */
    public static final int TYPE_DYNAMIC_ATTRIBUTE = 0x08;

So the correct type was TYPE_DYNAMIC_ATTRIBUTE, but then it became TYPE_DYNAMIC_REFERENCE which probably led to the errors.

I improperly patched the newly added TYPE_DYNAMIC_ATTRIBUTE as

            case TypedValue.TYPE_DYNAMIC_REFERENCE:
            case TypedValue.TYPE_DYNAMIC_ATTRIBUTE:
                return newReference(value, rawValue);

so I need to take another look at it.

Owner

iBotPeaches commented Dec 20, 2016

Okay, so let me follow this to get things straight.

  1. We find in res/layout/qs_paged_tile_layout.xml
android:textColor="@com.lge:attr/textColorPrimaryType3" 
  1. So we follow that to the attribute based on the pkg name to lge-res.apk and res/value/attrs.xml
    <attr name="textColorPrimaryType3" format="reference|color" />
  1. Its either a reference or a color, so lets check out res/value/styles.xml in lge-res.apk.
    <style name="Theme.LGE.Default" parent="@android:style/Theme.Material.Light">
        <item name="textColorPrimaryType1">@color/primary_text_default_material_light_80</item>
        <item name="textColorPrimaryType2">@color/primary_text_default_material_light_70</item>
        <item name="textColorPrimaryType3">@color/primary_text_default_material_light_60</item>
    </style>
  1. So lets go checkout res/values/colors.xml in lge-res.apk.
    <color name="primary_text_default_material_light_80">#cc000000</color>
    <color name="primary_text_default_material_light_70">#b2000000</color>
    <color name="primary_text_default_material_light_60">#99000000</color>
  1. So going to rebuild LGSystemUI and decode it again.

Clean

        A: android:textColor(0x01010098)=(type 0x8)0x201000d

Dirty

        A: android:textColor(0x01010098)=(type 0x7)0x201000d

So we improperly converted the resource from type 8 to type 7.

    /**
     * The <var>data</var> holds a dynamic res table reference, which needs to be
     * resolved before it can be used like TYPE_REFERENCE
     */
    public static final int TYPE_DYNAMIC_REFERENCE = 0x07;
    /**
     * The <var>data</var> an attribute resource identifier, which needs to be resolved
     * before it can be used like a TYPE_ATTRIBUTE.
     */
    public static final int TYPE_DYNAMIC_ATTRIBUTE = 0x08;

So the correct type was TYPE_DYNAMIC_ATTRIBUTE, but then it became TYPE_DYNAMIC_REFERENCE which probably led to the errors.

I improperly patched the newly added TYPE_DYNAMIC_ATTRIBUTE as

            case TypedValue.TYPE_DYNAMIC_REFERENCE:
            case TypedValue.TYPE_DYNAMIC_ATTRIBUTE:
                return newReference(value, rawValue);

so I need to take another look at it.

@xpirt

This comment has been minimized.

Show comment
Hide comment
@xpirt

xpirt Dec 20, 2016

Contributor

You're right, treating TYPE_DYNAMIC_ATTRIBUTE as TYPE_ATTRIBUTE fixes the issue.

Sent also a pull request, 983e0ad.

Tested and working just fine, thank you!

Contributor

xpirt commented Dec 20, 2016

You're right, treating TYPE_DYNAMIC_ATTRIBUTE as TYPE_ATTRIBUTE fixes the issue.

Sent also a pull request, 983e0ad.

Tested and working just fine, thank you!

@iBotPeaches iBotPeaches closed this in #1385 Dec 20, 2016

iBotPeaches added a commit that referenced this issue Dec 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment