Skip to content
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

BinaryXMLParser generates wrong reference #465

Closed
tRuNKator opened this issue Mar 12, 2019 · 4 comments
Closed

BinaryXMLParser generates wrong reference #465

tRuNKator opened this issue Mar 12, 2019 · 4 comments

Comments

@tRuNKator
Copy link
Contributor

tRuNKator commented Mar 12, 2019

It seems to me (I'm not quite sure) that the jadx.core.xmlgen.BinaryXMLParser.localStyleMap field functionality is not needed. I can not imagine in what situations it can be useful. Most likely it is needless or not implemented correctly. Example apk
one of problem files: res\layout-land-v4\widget4x1.xml
problem with id references in generated code ():

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="center" android:id="@+id/e" android:clipChildren="false" android:clipToPadding="false" android:layout_width="match_parent" android:layout_height="match_parent">
    <include layout="@layout/widget4x1_aa_layout"/>
    <LinearLayout android:gravity="center_vertical" android:orientation="vertical" android:id="@+id/K" android:clipChildren="false" android:clipToPadding="false" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:layout_toLeftOf="@+id/controls" android:layout_toRightOf="@+id/z" android:layout_alignTop="@+id/z" android:layout_alignBottom="@+id/z" android:layout_alignWithParentIfMissing="true">
        <LinearLayout android:orientation="vertical" android:id="@+id/Z" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp"/>
        <LinearLayout android:orientation="horizontal" android:id="@+id/A" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp">
            <FrameLayout android:gravity="center_vertical" android:layout_gravity="center_vertical" android:id="@+id/D" android:paddingLeft="3dp" android:paddingRight="3dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="2dp"/>
            <FrameLayout android:orientation="vertical" android:id="@+id/ll11" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
        </LinearLayout>
    </LinearLayout>
    <LinearLayout android:gravity="center" android:orientation="horizontal" android:id="@+id/controls" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="6dp" android:layout_alignParentRight="true" android:layout_centerVertical="true">
        <include layout="@layout/widget4x1_controls"/>
    </LinearLayout>
    <Button android:id="@+id/d" android:background="@drawable/conf_button_selector" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentTop="true" android:layout_alignParentRight="true"/>
</RelativeLayout>

should be:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="center" android:id="@+id/container" android:clipChildren="false" android:clipToPadding="false" android:layout_width="match_parent" android:layout_height="match_parent">
    <include layout="@layout/widget4x1_aa_layout"/>
    <LinearLayout android:gravity="center_vertical" android:orientation="vertical" android:id="@+id/playing_now" android:clipChildren="false" android:clipToPadding="false" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:layout_toLeftOf="@+id/controls" android:layout_toRightOf="@+id/logo" android:layout_alignTop="@+id/logo" android:layout_alignBottom="@+id/logo" android:layout_alignWithParentIfMissing="true">
        <LinearLayout android:orientation="vertical" android:id="@+id/title_cont" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp"/>
        <LinearLayout android:orientation="horizontal" android:id="@+id/meta_aaa_cont" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp">
            <FrameLayout android:gravity="center_vertical" android:layout_gravity="center_vertical" android:id="@+id/meta_cont" android:paddingLeft="3dp" android:paddingRight="3dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="2dp"/>
            <FrameLayout android:orientation="vertical" android:id="@+id/artist_and_album_cont" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
        </LinearLayout>
    </LinearLayout>
    <LinearLayout android:gravity="center" android:orientation="horizontal" android:id="@+id/controls" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="6dp" android:layout_alignParentRight="true" android:layout_centerVertical="true">
        <include layout="@layout/widget4x1_controls"/>
    </LinearLayout>
    <Button android:id="@+id/configure_button" android:background="@drawable/conf_button_selector" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentTop="true" android:layout_alignParentRight="true"/>
</RelativeLayout>

Isn't it better to use only jadx.core.xmlgen.BinaryXMLParser.resNames? In what situations will jadx.core.xmlgen.BinaryXMLParser.localStyleMap be useful?

PS Sorry for my English

@tRuNKator
Copy link
Contributor Author

Also this (see comment)

...
				FieldNode field = localStyleMap.get(attrValData);
				if (field != null) {
					String cls = field.getParentClass().getShortName().toLowerCase();
					writer.add("@");
//if deobfuscation is enabled, this check fails (сlass "id" renamed to something like "C000id")
					if ("id".equals(cls)) {
						writer.add('+');
					}
					writer.add(cls).add("/").add(field.getName());
				} else {
...

@tRuNKator
Copy link
Contributor Author

Ok, now I found that disabling "Replace constants" generates normal output. But it also affects code, like findViewById(2131558963);

@skylot
Copy link
Owner

skylot commented Mar 12, 2019

@tRuNKator you are right, replacing resources names by field name from R class not needed now because after #308 jadx starts to generate fields from resources. So I will remove this logic.
Also, there is an issue: adding new field not override existing field with the same id, so name not replaced in code.

@skylot
Copy link
Owner

skylot commented Mar 12, 2019

@tRuNKator fixed. Please check latest unstable build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants