-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct type and data merge for filled-array instruction
- Loading branch information
Showing
5 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
jadx-core/src/main/java/jadx/core/utils/EncodedValueUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package jadx.core.utils; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import jadx.api.plugins.input.data.annotations.EncodedValue; | ||
import jadx.core.dex.instructions.args.ArgType; | ||
import jadx.core.dex.instructions.args.InsnArg; | ||
import jadx.core.dex.instructions.args.LiteralArg; | ||
import jadx.core.dex.nodes.RootNode; | ||
|
||
public class EncodedValueUtils { | ||
|
||
/** | ||
* Return constant literal from {@code jadx.api.plugins.input.data.annotations.EncodedValue} | ||
* | ||
* @return LiteralArg, String, ArgType or null | ||
*/ | ||
@Nullable | ||
public static Object convertToConstValue(RootNode root, EncodedValue encodedValue) { | ||
if (encodedValue == null) { | ||
return null; | ||
} | ||
Object value = encodedValue.getValue(); | ||
switch (encodedValue.getType()) { | ||
case ENCODED_NULL: | ||
return InsnArg.lit(0, ArgType.OBJECT); | ||
case ENCODED_BOOLEAN: | ||
return Boolean.TRUE.equals(value) ? LiteralArg.TRUE : LiteralArg.FALSE; | ||
case ENCODED_BYTE: | ||
return InsnArg.lit((Byte) value, ArgType.BYTE); | ||
case ENCODED_SHORT: | ||
return InsnArg.lit((Short) value, ArgType.SHORT); | ||
case ENCODED_CHAR: | ||
return InsnArg.lit((Character) value, ArgType.CHAR); | ||
case ENCODED_INT: | ||
return InsnArg.lit((Integer) value, ArgType.INT); | ||
case ENCODED_LONG: | ||
return InsnArg.lit((Long) value, ArgType.LONG); | ||
case ENCODED_FLOAT: | ||
return InsnArg.lit(Float.floatToIntBits((Float) value), ArgType.FLOAT); | ||
case ENCODED_DOUBLE: | ||
return InsnArg.lit(Double.doubleToLongBits((Double) value), ArgType.DOUBLE); | ||
case ENCODED_STRING: | ||
return (String) value; | ||
|
||
case ENCODED_TYPE: | ||
return ArgType.parse((String) value); | ||
|
||
default: | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package jadx.tests.integration.arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestArrayFill4 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
|
||
// replaced constant break filled array creation | ||
private static final int ARRAY_SIZE = 4; | ||
|
||
public long[] test() { | ||
return new long[] { 0, 1, Long.MAX_VALUE, Long.MIN_VALUE + 1 }; | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
noDebugInfo(); | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.doesNotContain("new long[ARRAY_SIZE];") | ||
.containsOne("return new long[]{0, 1, "); | ||
} | ||
} |