Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
b5344f45
Commit
b5344f45
authored
Mar 29, 2019
by
Ahmed Ashour
Committed by
skylot
Mar 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: redundant byte and short cast (#538) (PR #539)
parent
0fa3842a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
3 deletions
+80
-3
TypeGen.java
jadx-core/src/main/java/jadx/core/codegen/TypeGen.java
+2
-2
TestRedundantType.java
...java/jadx/tests/integration/arrays/TestRedundantType.java
+77
-0
TestTypeResolver4.java
.../java/jadx/tests/integration/types/TestTypeResolver4.java
+1
-1
No files found.
jadx-core/src/main/java/jadx/core/codegen/TypeGen.java
View file @
b5344f45
...
...
@@ -97,7 +97,7 @@ public class TypeGen {
if
(
s
==
Short
.
MIN_VALUE
)
{
return
"Short.MIN_VALUE"
;
}
return
"(short) "
+
s
;
return
Short
.
toString
(
s
)
;
}
public
static
String
formatByte
(
byte
b
)
{
...
...
@@ -107,7 +107,7 @@ public class TypeGen {
if
(
b
==
Byte
.
MIN_VALUE
)
{
return
"Byte.MIN_VALUE"
;
}
return
"(byte) "
+
b
;
return
Byte
.
toString
(
b
)
;
}
public
static
String
formatInteger
(
int
i
)
{
...
...
jadx-core/src/test/java/jadx/tests/integration/arrays/TestRedundantType.java
0 → 100644
View file @
b5344f45
package
jadx
.
tests
.
integration
.
arrays
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
public
class
TestRedundantType
extends
IntegrationTest
{
public
static
class
TestCls
{
public
byte
[]
method
()
{
return
new
byte
[]{
10
,
11
,
12
};
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"return new byte[]{10, 11, 12};"
));
}
public
static
class
TestByte
{
public
byte
[]
method
()
{
byte
[]
arr
=
new
byte
[
50
];
arr
[
10
]
=
126
;
arr
[
20
]
=
127
;
arr
[
30
]
=
(
byte
)
128
;
arr
[
40
]
=
(
byte
)
129
;
return
arr
;
}
}
@Test
public
void
testByte
()
{
ClassNode
cls
=
getClassNode
(
TestByte
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"arr[10] = 126"
));
assertThat
(
code
,
containsString
(
"arr[20] = Byte.MAX_VALUE"
));
assertThat
(
code
,
containsString
(
"arr[30] = Byte.MIN_VALUE"
));
assertThat
(
code
,
containsString
(
"arr[40] = -127"
));
assertEquals
(-
127
,
new
TestByte
().
method
()[
40
]);
}
public
static
class
TestShort
{
public
short
[]
method
()
{
short
[]
arr
=
new
short
[
50
];
arr
[
10
]
=
32766
;
arr
[
20
]
=
32767
;
arr
[
30
]
=
(
short
)
32768
;
arr
[
40
]
=
(
short
)
32769
;
return
arr
;
}
}
@Test
public
void
testShort
()
{
ClassNode
cls
=
getClassNode
(
TestShort
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"arr[10] = 32766"
));
assertThat
(
code
,
containsString
(
"arr[20] = Short.MAX_VALUE"
));
assertThat
(
code
,
containsString
(
"arr[30] = Short.MIN_VALUE"
));
assertThat
(
code
,
containsString
(
"arr[40] = -32767"
));
assertEquals
(-
32767
,
new
TestShort
().
method
()[
40
]);
}
}
jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver4.java
View file @
b5344f45
...
...
@@ -41,7 +41,7 @@ public class TestTypeResolver4 extends IntegrationTest {
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"(strArray[end] !=
(byte) 0 || strArray[end + 1] != (byte)
0)"
));
assertThat
(
code
,
containsOne
(
"(strArray[end] !=
0 || strArray[end + 1] !=
0)"
));
}
@Test
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment