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
2ad73927
Commit
2ad73927
authored
Aug 04, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: handle special values for numbers
parent
caad7888
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
18 deletions
+136
-18
TypeGen.java
jadx-core/src/main/java/jadx/core/codegen/TypeGen.java
+72
-18
TestSpecialValues.java
...est/java/jadx/tests/internal/arith/TestSpecialValues.java
+64
-0
No files found.
jadx-core/src/main/java/jadx/core/codegen/TypeGen.java
View file @
2ad73927
...
...
@@ -66,37 +66,91 @@ public class TypeGen {
}
public
static
String
formatShort
(
short
s
)
{
return
"(short) "
+
wrapNegNum
(
s
<
0
,
Short
.
toString
(
s
));
if
(
s
==
Short
.
MAX_VALUE
)
{
return
"Short.MAX_VALUE"
;
}
if
(
s
==
Short
.
MIN_VALUE
)
{
return
"Short.MIN_VALUE"
;
}
return
"(short) "
+
Short
.
toString
(
s
);
}
public
static
String
formatByte
(
byte
b
)
{
return
"(byte) "
+
wrapNegNum
(
b
<
0
,
Byte
.
toString
(
b
));
if
(
b
==
Byte
.
MAX_VALUE
)
{
return
"Byte.MAX_VALUE"
;
}
if
(
b
==
Byte
.
MIN_VALUE
)
{
return
"Byte.MIN_VALUE"
;
}
return
"(byte) "
+
Byte
.
toString
(
b
);
}
public
static
String
formatInteger
(
int
i
)
{
return
wrapNegNum
(
i
<
0
,
Integer
.
toString
(
i
));
if
(
i
==
Integer
.
MAX_VALUE
)
{
return
"Integer.MAX_VALUE"
;
}
if
(
i
==
Integer
.
MIN_VALUE
)
{
return
"Integer.MIN_VALUE"
;
}
return
Integer
.
toString
(
i
);
}
public
static
String
formatDouble
(
double
d
)
{
return
wrapNegNum
(
d
<
0
,
Double
.
toString
(
d
)
+
"d"
);
public
static
String
formatLong
(
long
l
)
{
if
(
l
==
Long
.
MAX_VALUE
)
{
return
"Long.MAX_VALUE"
;
}
if
(
l
==
Long
.
MIN_VALUE
)
{
return
"Long.MIN_VALUE"
;
}
String
str
=
Long
.
toString
(
l
);
if
(
Math
.
abs
(
l
)
>=
Integer
.
MAX_VALUE
)
{
str
+=
"L"
;
}
return
str
;
}
public
static
String
formatFloat
(
float
f
)
{
return
wrapNegNum
(
f
<
0
,
Float
.
toString
(
f
)
+
"f"
);
public
static
String
formatDouble
(
double
d
)
{
if
(
Double
.
isNaN
(
d
))
{
return
"Double.NaN"
;
}
if
(
d
==
Double
.
NEGATIVE_INFINITY
)
{
return
"Double.NEGATIVE_INFINITY"
;
}
if
(
d
==
Double
.
POSITIVE_INFINITY
)
{
return
"Double.POSITIVE_INFINITY"
;
}
if
(
d
==
Double
.
MIN_VALUE
)
{
return
"Double.MIN_VALUE"
;
}
if
(
d
==
Double
.
MAX_VALUE
)
{
return
"Double.MAX_VALUE"
;
}
if
(
d
==
Double
.
MIN_NORMAL
)
{
return
"Double.MIN_NORMAL"
;
}
return
Double
.
toString
(
d
)
+
"d"
;
}
public
static
String
formatLong
(
long
lit
)
{
String
l
=
Long
.
toString
(
lit
);
if
(
lit
==
Long
.
MIN_VALUE
||
Math
.
abs
(
lit
)
>=
Integer
.
MAX_VALUE
)
{
l
+=
"L"
;
public
static
String
formatFloat
(
float
f
)
{
if
(
Float
.
isNaN
(
f
))
{
return
"Float.NaN"
;
}
if
(
f
==
Float
.
NEGATIVE_INFINITY
)
{
return
"Float.NEGATIVE_INFINITY"
;
}
return
wrapNegNum
(
lit
<
0
,
l
);
if
(
f
==
Float
.
POSITIVE_INFINITY
)
{
return
"Float.POSITIVE_INFINITY"
;
}
if
(
f
==
Float
.
MIN_VALUE
)
{
return
"Float.MIN_VALUE"
;
}
if
(
f
==
Float
.
MAX_VALUE
)
{
return
"Float.MAX_VALUE"
;
}
if
(
f
==
Float
.
MIN_NORMAL
)
{
return
"Float.MIN_NORMAL"
;
}
return
Float
.
toString
(
f
)
+
"f"
;
}
private
static
String
wrapNegNum
(
boolean
lz
,
String
str
)
{
// if (lz)
// return "(" + str + ")";
// else
return
str
;
}
}
jadx-core/src/test/java/jadx/tests/internal/arith/TestSpecialValues.java
0 → 100644
View file @
2ad73927
package
jadx
.
tests
.
internal
.
arith
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestSpecialValues
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
void
test
()
{
shorts
(
Short
.
MIN_VALUE
,
Short
.
MAX_VALUE
);
bytes
(
Byte
.
MIN_VALUE
,
Byte
.
MAX_VALUE
);
ints
(
Integer
.
MIN_VALUE
,
Integer
.
MAX_VALUE
);
longs
(
Long
.
MIN_VALUE
,
Long
.
MAX_VALUE
);
floats
(
Float
.
NaN
,
Float
.
NEGATIVE_INFINITY
,
Float
.
POSITIVE_INFINITY
,
Float
.
MIN_VALUE
,
Float
.
MAX_VALUE
,
Float
.
MIN_NORMAL
);
doubles
(
Double
.
NaN
,
Double
.
NEGATIVE_INFINITY
,
Double
.
POSITIVE_INFINITY
,
Double
.
MIN_VALUE
,
Double
.
MAX_VALUE
,
Double
.
MIN_NORMAL
);
}
private
void
shorts
(
short
...
v
)
{
}
private
void
bytes
(
byte
...
v
)
{
}
private
void
ints
(
int
...
v
)
{
}
private
void
longs
(
long
...
v
)
{
}
private
void
floats
(
float
...
v
)
{
}
private
void
doubles
(
double
...
v
)
{
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsOne
(
"Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, "
+
"Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_NORMAL"
));
assertThat
(
code
,
containsOne
(
"Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, "
+
"Double.MIN_VALUE, Double.MAX_VALUE, Double.MIN_NORMAL"
));
assertThat
(
code
,
containsOne
(
"Short.MIN_VALUE, Short.MAX_VALUE"
));
assertThat
(
code
,
containsOne
(
"Byte.MIN_VALUE, Byte.MAX_VALUE"
));
assertThat
(
code
,
containsOne
(
"Integer.MIN_VALUE, Integer.MAX_VALUE"
));
assertThat
(
code
,
containsOne
(
"Long.MIN_VALUE, Long.MAX_VALUE"
));
}
}
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