Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
06f26ef8
J
jadx
项目概览
Quincy379
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
06f26ef8
编写于
8月 15, 2019
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: use enum for wildcard bounds instead of int
上级
a71bb7a5
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
76 addition
and
45 deletion
+76
-45
jadx-core/src/main/java/jadx/core/clsp/ClsSet.java
jadx-core/src/main/java/jadx/core/clsp/ClsSet.java
+4
-4
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
+3
-4
jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java
...rc/main/java/jadx/core/dex/instructions/args/ArgType.java
+46
-27
jadx-core/src/main/java/jadx/core/dex/nodes/parser/SignatureParser.java
...main/java/jadx/core/dex/nodes/parser/SignatureParser.java
+4
-3
jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/LocalVar.java
.../main/java/jadx/core/dex/visitors/debuginfo/LocalVar.java
+1
-1
jadx-core/src/main/java/jadx/core/dex/visitors/regions/LoopRegionVisitor.java
...ava/jadx/core/dex/visitors/regions/LoopRegionVisitor.java
+1
-1
jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java
...est/java/jadx/core/dex/instructions/args/ArgTypeTest.java
+11
-0
jadx-core/src/test/java/jadx/tests/functional/SignatureParserTest.java
.../test/java/jadx/tests/functional/SignatureParserTest.java
+6
-5
未找到文件。
jadx-core/src/main/java/jadx/core/clsp/ClsSet.java
浏览文件 @
06f26ef8
...
@@ -274,9 +274,9 @@ public class ClsSet {
...
@@ -274,9 +274,9 @@ public class ClsSet {
private
static
void
writeArgType
(
DataOutputStream
out
,
ArgType
argType
,
Map
<
String
,
NClass
>
names
)
throws
IOException
{
private
static
void
writeArgType
(
DataOutputStream
out
,
ArgType
argType
,
Map
<
String
,
NClass
>
names
)
throws
IOException
{
if
(
argType
.
getWildcardType
()
!=
null
)
{
if
(
argType
.
getWildcardType
()
!=
null
)
{
out
.
writeByte
(
TypeEnum
.
WILDCARD
.
ordinal
());
out
.
writeByte
(
TypeEnum
.
WILDCARD
.
ordinal
());
int
bounds
=
argType
.
getWildcardBounds
();
ArgType
.
WildcardBound
bound
=
argType
.
getWildcardBound
();
out
.
writeByte
(
bound
s
);
out
.
writeByte
(
bound
.
getNum
()
);
if
(
bound
s
!=
0
)
{
if
(
bound
!=
ArgType
.
WildcardBound
.
UNBOUND
)
{
writeArgType
(
out
,
argType
.
getWildcardType
(),
names
);
writeArgType
(
out
,
argType
.
getWildcardType
(),
names
);
}
}
}
else
if
(
argType
.
isGeneric
())
{
}
else
if
(
argType
.
isGeneric
())
{
...
@@ -415,7 +415,7 @@ public class ClsSet {
...
@@ -415,7 +415,7 @@ public class ClsSet {
int
bounds
=
in
.
readByte
();
int
bounds
=
in
.
readByte
();
return
bounds
==
0
return
bounds
==
0
?
ArgType
.
wildcard
()
?
ArgType
.
wildcard
()
:
ArgType
.
wildcard
(
readArgType
(
in
),
bounds
);
:
ArgType
.
wildcard
(
readArgType
(
in
),
ArgType
.
WildcardBound
.
getByNum
(
bounds
)
);
case
GENERIC:
case
GENERIC:
String
obj
=
classes
[
in
.
readInt
()].
getName
();
String
obj
=
classes
[
in
.
readInt
()].
getName
();
...
...
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
浏览文件 @
06f26ef8
...
@@ -470,10 +470,9 @@ public class ClassGen {
...
@@ -470,10 +470,9 @@ public class ClassGen {
ArgType
gt
=
generics
[
i
];
ArgType
gt
=
generics
[
i
];
ArgType
wt
=
gt
.
getWildcardType
();
ArgType
wt
=
gt
.
getWildcardType
();
if
(
wt
!=
null
)
{
if
(
wt
!=
null
)
{
code
.
add
(
'?'
);
ArgType
.
WildcardBound
bound
=
gt
.
getWildcardBound
();
int
bounds
=
gt
.
getWildcardBounds
();
code
.
add
(
bound
.
getStr
());
if
(
bounds
!=
0
)
{
if
(
bound
!=
ArgType
.
WildcardBound
.
UNBOUND
)
{
code
.
add
(
bounds
==
-
1
?
" super "
:
" extends "
);
useType
(
code
,
wt
);
useType
(
code
,
wt
);
}
}
}
else
{
}
else
{
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java
浏览文件 @
06f26ef8
...
@@ -74,14 +74,14 @@ public abstract class ArgType {
...
@@ -74,14 +74,14 @@ public abstract class ArgType {
}
}
public
static
ArgType
wildcard
()
{
public
static
ArgType
wildcard
()
{
return
new
WildcardType
(
OBJECT
,
0
);
return
new
WildcardType
(
OBJECT
,
WildcardBound
.
UNBOUND
);
}
}
public
static
ArgType
wildcard
(
ArgType
obj
,
int
bounds
)
{
public
static
ArgType
wildcard
(
ArgType
obj
,
WildcardBound
bound
)
{
return
new
WildcardType
(
obj
,
bound
s
);
return
new
WildcardType
(
obj
,
bound
);
}
}
public
static
ArgType
generic
(
String
sign
)
{
public
static
ArgType
parseGenericSignature
(
String
sign
)
{
return
new
SignatureParser
(
sign
).
consumeType
();
return
new
SignatureParser
(
sign
).
consumeType
();
}
}
...
@@ -212,14 +212,40 @@ public abstract class ArgType {
...
@@ -212,14 +212,40 @@ public abstract class ArgType {
}
}
}
}
public
enum
WildcardBound
{
EXTENDS
(
1
,
"? extends "
),
// upper bound (? extends A)
UNBOUND
(
0
,
"?"
),
// no bounds (?)
SUPER
(-
1
,
"? super "
);
// lower bound (? super A)
private
final
int
num
;
private
final
String
str
;
WildcardBound
(
int
val
,
String
str
)
{
this
.
num
=
val
;
this
.
str
=
str
;
}
public
int
getNum
()
{
return
num
;
}
public
String
getStr
()
{
return
str
;
}
public
static
WildcardBound
getByNum
(
int
num
)
{
return
num
==
0
?
UNBOUND
:
(
num
==
1
?
EXTENDS
:
SUPER
);
}
}
private
static
final
class
WildcardType
extends
ObjectType
{
private
static
final
class
WildcardType
extends
ObjectType
{
private
final
ArgType
type
;
private
final
ArgType
type
;
private
final
int
bounds
;
private
final
WildcardBound
bound
;
public
WildcardType
(
ArgType
obj
,
int
bounds
)
{
public
WildcardType
(
ArgType
obj
,
WildcardBound
bound
)
{
super
(
OBJECT
.
getObject
());
super
(
OBJECT
.
getObject
());
this
.
type
=
obj
;
this
.
type
=
obj
;
this
.
bound
s
=
bounds
;
this
.
bound
=
bound
;
}
}
@Override
@Override
...
@@ -232,32 +258,24 @@ public abstract class ArgType {
...
@@ -232,32 +258,24 @@ public abstract class ArgType {
return
type
;
return
type
;
}
}
/**
* Return wildcard bounds:
* <ul>
* <li>1 for upper bound (? extends A)</li>
* <li>0 no bounds (?)</li>
* <li>-1 for lower bound (? super A)</li>
* </ul>
*/
@Override
@Override
public
int
getWildcardBounds
()
{
public
WildcardBound
getWildcardBound
()
{
return
bound
s
;
return
bound
;
}
}
@Override
@Override
boolean
internalEquals
(
Object
obj
)
{
boolean
internalEquals
(
Object
obj
)
{
return
super
.
internalEquals
(
obj
)
return
super
.
internalEquals
(
obj
)
&&
bound
s
==
((
WildcardType
)
obj
).
bounds
&&
bound
==
((
WildcardType
)
obj
).
bound
&&
type
.
equals
(((
WildcardType
)
obj
).
type
);
&&
type
.
equals
(((
WildcardType
)
obj
).
type
);
}
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
if
(
bound
s
==
0
)
{
if
(
bound
==
WildcardBound
.
UNBOUND
)
{
return
"?"
;
return
bound
.
getStr
()
;
}
}
return
"? "
+
(
bounds
==
-
1
?
"super"
:
"extends"
)
+
' '
+
type
;
return
bound
.
getStr
()
+
type
;
}
}
}
}
...
@@ -468,11 +486,8 @@ public abstract class ArgType {
...
@@ -468,11 +486,8 @@ public abstract class ArgType {
return
null
;
return
null
;
}
}
/**
public
WildcardBound
getWildcardBound
()
{
* @see WildcardType#getWildcardBounds()
return
null
;
*/
public
int
getWildcardBounds
()
{
return
0
;
}
}
public
ArgType
getOuterType
()
{
public
ArgType
getOuterType
()
{
...
@@ -629,6 +644,10 @@ public abstract class ArgType {
...
@@ -629,6 +644,10 @@ public abstract class ArgType {
if
(
isGenericType
())
{
if
(
isGenericType
())
{
return
true
;
return
true
;
}
}
ArgType
wildcardType
=
getWildcardType
();
if
(
wildcardType
!=
null
)
{
return
wildcardType
.
containsGenericType
();
}
if
(
isGeneric
())
{
if
(
isGeneric
())
{
ArgType
[]
genericTypes
=
getGenericTypes
();
ArgType
[]
genericTypes
=
getGenericTypes
();
if
(
genericTypes
!=
null
)
{
if
(
genericTypes
!=
null
)
{
...
@@ -662,7 +681,7 @@ public abstract class ArgType {
...
@@ -662,7 +681,7 @@ public abstract class ArgType {
return
new
GenericObject
(
aliasFullName
,
type
.
getGenericTypes
());
return
new
GenericObject
(
aliasFullName
,
type
.
getGenericTypes
());
}
}
if
(
type
instanceof
WildcardType
)
{
if
(
type
instanceof
WildcardType
)
{
return
new
WildcardType
(
ArgType
.
object
(
aliasFullName
),
type
.
getWildcardBound
s
());
return
new
WildcardType
(
ArgType
.
object
(
aliasFullName
),
type
.
getWildcardBound
());
}
}
}
}
return
ArgType
.
object
(
aliasFullName
);
return
ArgType
.
object
(
aliasFullName
);
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/parser/SignatureParser.java
浏览文件 @
06f26ef8
...
@@ -38,7 +38,8 @@ public class SignatureParser {
...
@@ -38,7 +38,8 @@ public class SignatureParser {
if
(
a
==
null
)
{
if
(
a
==
null
)
{
return
null
;
return
null
;
}
}
return
new
SignatureParser
(
mergeSignature
((
List
<
String
>)
a
.
getDefaultValue
()));
String
signature
=
mergeSignature
((
List
<
String
>)
a
.
getDefaultValue
());
return
new
SignatureParser
(
signature
);
}
}
private
char
next
()
{
private
char
next
()
{
...
@@ -200,10 +201,10 @@ public class SignatureParser {
...
@@ -200,10 +201,10 @@ public class SignatureParser {
type
=
ArgType
.
wildcard
();
type
=
ArgType
.
wildcard
();
}
else
if
(
lookAhead
(
'+'
))
{
}
else
if
(
lookAhead
(
'+'
))
{
next
();
next
();
type
=
ArgType
.
wildcard
(
consumeType
(),
1
);
type
=
ArgType
.
wildcard
(
consumeType
(),
ArgType
.
WildcardBound
.
EXTENDS
);
}
else
if
(
lookAhead
(
'-'
))
{
}
else
if
(
lookAhead
(
'-'
))
{
next
();
next
();
type
=
ArgType
.
wildcard
(
consumeType
(),
-
1
);
type
=
ArgType
.
wildcard
(
consumeType
(),
ArgType
.
WildcardBound
.
SUPER
);
}
else
{
}
else
{
type
=
consumeType
();
type
=
consumeType
();
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/LocalVar.java
浏览文件 @
06f26ef8
...
@@ -31,7 +31,7 @@ public final class LocalVar {
...
@@ -31,7 +31,7 @@ public final class LocalVar {
this
.
name
=
name
;
this
.
name
=
name
;
if
(
sign
!=
null
)
{
if
(
sign
!=
null
)
{
try
{
try
{
ArgType
gType
=
ArgType
.
generic
(
sign
);
ArgType
gType
=
ArgType
.
parseGenericSignature
(
sign
);
if
(
checkSignature
(
type
,
gType
))
{
if
(
checkSignature
(
type
,
gType
))
{
type
=
gType
;
type
=
gType
;
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/LoopRegionVisitor.java
浏览文件 @
06f26ef8
...
@@ -327,7 +327,7 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
...
@@ -327,7 +327,7 @@ public class LoopRegionVisitor extends AbstractVisitor implements IRegionVisitor
}
}
ArgType
wildcardType
=
gType
.
getWildcardType
();
ArgType
wildcardType
=
gType
.
getWildcardType
();
if
(
wildcardType
!=
null
if
(
wildcardType
!=
null
&&
gType
.
getWildcardBound
s
()
==
1
&&
gType
.
getWildcardBound
()
==
ArgType
.
WildcardBound
.
EXTENDS
&&
ArgType
.
isInstanceOf
(
mth
.
root
(),
wildcardType
,
varType
))
{
&&
ArgType
.
isInstanceOf
(
mth
.
root
(),
wildcardType
,
varType
))
{
return
true
;
return
true
;
}
}
...
...
jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java
浏览文件 @
06f26ef8
...
@@ -3,6 +3,7 @@ package jadx.core.dex.instructions.args;
...
@@ -3,6 +3,7 @@ package jadx.core.dex.instructions.args;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
class
ArgTypeTest
{
class
ArgTypeTest
{
...
@@ -13,4 +14,14 @@ class ArgTypeTest {
...
@@ -13,4 +14,14 @@ class ArgTypeTest {
assertEquals
(
first
,
second
);
assertEquals
(
first
,
second
);
}
}
@Test
void
testContainsGenericType
()
{
ArgType
wildcard
=
ArgType
.
wildcard
(
ArgType
.
genericType
(
"T"
),
ArgType
.
WildcardBound
.
SUPER
);
assertTrue
(
wildcard
.
containsGenericType
());
ArgType
type
=
ArgType
.
generic
(
"java.lang.List"
,
wildcard
);
assertTrue
(
type
.
containsGenericType
());
}
}
}
jadx-core/src/test/java/jadx/tests/functional/SignatureParserTest.java
浏览文件 @
06f26ef8
...
@@ -6,6 +6,7 @@ import java.util.List;
...
@@ -6,6 +6,7 @@ import java.util.List;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.ArgType.WildcardBound
;
import
jadx.core.dex.nodes.GenericInfo
;
import
jadx.core.dex.nodes.GenericInfo
;
import
jadx.core.dex.nodes.parser.SignatureParser
;
import
jadx.core.dex.nodes.parser.SignatureParser
;
...
@@ -60,10 +61,10 @@ class SignatureParserTest {
...
@@ -60,10 +61,10 @@ class SignatureParserTest {
@Test
@Test
public
void
testWildcards
()
{
public
void
testWildcards
()
{
checkWildcards
(
"*"
,
wildcard
());
checkWildcards
(
"*"
,
wildcard
());
checkWildcards
(
"+Lb;"
,
wildcard
(
object
(
"b"
),
1
));
checkWildcards
(
"+Lb;"
,
wildcard
(
object
(
"b"
),
WildcardBound
.
EXTENDS
));
checkWildcards
(
"-Lb;"
,
wildcard
(
object
(
"b"
),
-
1
));
checkWildcards
(
"-Lb;"
,
wildcard
(
object
(
"b"
),
WildcardBound
.
SUPER
));
checkWildcards
(
"+TV;"
,
wildcard
(
genericType
(
"V"
),
1
));
checkWildcards
(
"+TV;"
,
wildcard
(
genericType
(
"V"
),
WildcardBound
.
EXTENDS
));
checkWildcards
(
"-TV;"
,
wildcard
(
genericType
(
"V"
),
-
1
));
checkWildcards
(
"-TV;"
,
wildcard
(
genericType
(
"V"
),
WildcardBound
.
SUPER
));
checkWildcards
(
"**"
,
wildcard
(),
wildcard
());
checkWildcards
(
"**"
,
wildcard
(),
wildcard
());
checkWildcards
(
"*Lb;"
,
wildcard
(),
object
(
"b"
));
checkWildcards
(
"*Lb;"
,
wildcard
(),
object
(
"b"
));
...
@@ -116,7 +117,7 @@ class SignatureParserTest {
...
@@ -116,7 +117,7 @@ class SignatureParserTest {
assertThat
(
argTypes
,
hasSize
(
1
));
assertThat
(
argTypes
,
hasSize
(
1
));
ArgType
argType
=
argTypes
.
get
(
0
);
ArgType
argType
=
argTypes
.
get
(
0
);
assertThat
(
argType
.
getObject
().
indexOf
(
'/'
),
is
(-
1
));
assertThat
(
argType
.
getObject
().
indexOf
(
'/'
),
is
(-
1
));
assertThat
(
argType
,
is
(
genericInner
(
generic
(
"La/b/C;"
,
genericType
(
"T"
)),
"d.E"
,
(
ArgType
[])
null
)));
assertThat
(
argType
,
is
(
genericInner
(
generic
(
"La/b/C;"
,
genericType
(
"T"
)),
"d.E"
,
null
)));
}
}
@Test
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录