Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
98d80150
J
jadx
项目概览
keyescgm
/
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,发现更多精彩内容 >>
提交
98d80150
编写于
11月 16, 2020
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: split field init attribute
上级
42a44f21
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
155 addition
and
21 deletion
+155
-21
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/codegen/RegionGen.java
jadx-core/src/main/java/jadx/core/codegen/RegionGen.java
+4
-4
jadx-core/src/main/java/jadx/core/dex/attributes/AType.java
jadx-core/src/main/java/jadx/core/dex/attributes/AType.java
+1
-0
jadx-core/src/main/java/jadx/core/dex/attributes/fldinit/FieldInitAttr.java
.../java/jadx/core/dex/attributes/fldinit/FieldInitAttr.java
+49
-0
jadx-core/src/main/java/jadx/core/dex/attributes/fldinit/FieldInitConstAttr.java
.../jadx/core/dex/attributes/fldinit/FieldInitConstAttr.java
+30
-0
jadx-core/src/main/java/jadx/core/dex/attributes/fldinit/FieldInitInsnAttr.java
...a/jadx/core/dex/attributes/fldinit/FieldInitInsnAttr.java
+36
-0
jadx-core/src/main/java/jadx/core/dex/info/ConstStorage.java
jadx-core/src/main/java/jadx/core/dex/info/ConstStorage.java
+2
-5
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
+3
-2
jadx-core/src/main/java/jadx/core/dex/visitors/ExtractFieldInit.java
...rc/main/java/jadx/core/dex/visitors/ExtractFieldInit.java
+1
-1
jadx-core/src/main/java/jadx/core/utils/InsnUtils.java
jadx-core/src/main/java/jadx/core/utils/InsnUtils.java
+2
-2
jadx-core/src/main/java/jadx/core/utils/android/AndroidResourcesUtils.java
...n/java/jadx/core/utils/android/AndroidResourcesUtils.java
+1
-1
jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore.java
...ava/jadx/tests/integration/android/TestRFieldRestore.java
+1
-1
jadx-plugins/jadx-plugins-api/src/main/java/jadx/api/plugins/input/data/annotations/EncodedValue.java
...jadx/api/plugins/input/data/annotations/EncodedValue.java
+22
-1
未找到文件。
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
浏览文件 @
98d80150
...
...
@@ -22,8 +22,7 @@ import jadx.core.Consts;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.AttrNode
;
import
jadx.core.dex.attributes.FieldInitAttr
;
import
jadx.core.dex.attributes.FieldInitAttr.InitType
;
import
jadx.core.dex.attributes.fldinit.FieldInitAttr
;
import
jadx.core.dex.attributes.nodes.EnumClassAttr
;
import
jadx.core.dex.attributes.nodes.EnumClassAttr.EnumField
;
import
jadx.core.dex.attributes.nodes.JadxError
;
...
...
@@ -395,14 +394,14 @@ public class ClassGen {
FieldInitAttr
fv
=
f
.
get
(
AType
.
FIELD_INIT
);
if
(
fv
!=
null
)
{
code
.
add
(
" = "
);
if
(
fv
.
getValueType
()
==
InitType
.
CONST
)
{
if
(
fv
.
isConst
()
)
{
EncodedValue
encodedValue
=
fv
.
getEncodedValue
();
if
(
encodedValue
.
getType
()
==
EncodedType
.
ENCODED_NULL
)
{
code
.
add
(
TypeGen
.
literalToString
(
0
,
f
.
getType
(),
cls
,
fallback
));
}
else
{
annotationGen
.
encodeValue
(
cls
.
root
(),
code
,
encodedValue
);
}
}
else
if
(
fv
.
getValueType
()
==
InitType
.
INSN
)
{
}
else
if
(
fv
.
isInsn
()
)
{
InsnGen
insnGen
=
makeInsnGen
(
fv
.
getInsnMth
());
addInsnBody
(
insnGen
,
code
,
fv
.
getInsn
());
}
...
...
jadx-core/src/main/java/jadx/core/codegen/RegionGen.java
浏览文件 @
98d80150
...
...
@@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.FieldInitAttr
;
import
jadx.core.dex.attributes.
fldinit.
FieldInitAttr
;
import
jadx.core.dex.attributes.nodes.DeclareVariablesAttr
;
import
jadx.core.dex.attributes.nodes.ForceReturnAttr
;
import
jadx.core.dex.attributes.nodes.LoopLabelAttr
;
...
...
@@ -287,10 +287,10 @@ public class RegionGen extends InsnGen {
staticField
(
code
,
fn
.
getFieldInfo
());
// print original value, sometimes replaced with incorrect field
FieldInitAttr
valueAttr
=
fn
.
get
(
AType
.
FIELD_INIT
);
if
(
valueAttr
!=
null
&&
valueAttr
.
getValueType
()
==
FieldInitAttr
.
InitType
.
CONST
)
{
Object
value
=
valueAttr
.
getEncodedValue
();
if
(
valueAttr
!=
null
&&
valueAttr
.
isConst
()
)
{
Object
value
=
valueAttr
.
getEncodedValue
()
.
getValue
()
;
if
(
value
!=
null
)
{
code
.
add
(
" /*
"
).
add
(
value
.
toString
()).
add
(
"
*/"
);
code
.
add
(
" /*
"
).
add
(
value
.
toString
()).
add
(
"
*/"
);
}
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/AType.java
浏览文件 @
98d80150
...
...
@@ -6,6 +6,7 @@ import java.util.Set;
import
jadx.core.dex.attributes.annotations.AnnotationsList
;
import
jadx.core.dex.attributes.annotations.MethodParameters
;
import
jadx.core.dex.attributes.fldinit.FieldInitAttr
;
import
jadx.core.dex.attributes.nodes.DeclareVariablesAttr
;
import
jadx.core.dex.attributes.nodes.EdgeInsnAttr
;
import
jadx.core.dex.attributes.nodes.EnumClassAttr
;
...
...
jadx-core/src/main/java/jadx/core/dex/attributes/FieldInitAttr.java
→
jadx-core/src/main/java/jadx/core/dex/attributes/
fldinit/
FieldInitAttr.java
浏览文件 @
98d80150
package
jadx.core.dex.attributes
;
package
jadx.core.dex.attributes.fldinit
;
import
java.util.Objects
;
import
jadx.api.plugins.input.data.annotations.EncodedValue
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.IAttribute
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
public
class
FieldInitAttr
implements
IAttribute
{
public
static
final
FieldInitAttr
NULL_VALUE
=
constValue
(
EncodedValue
.
NULL
);
public
abstract
class
FieldInitAttr
implements
IAttribute
{
public
enum
InitType
{
CONST
,
INSN
public
static
FieldInitAttr
constValue
(
EncodedValue
value
)
{
if
(
Objects
.
equals
(
value
,
EncodedValue
.
NULL
))
{
return
FieldInitConstAttr
.
NULL_VALUE
;
}
return
new
FieldInitConstAttr
(
value
);
}
private
final
Object
value
;
private
final
InitType
valueType
;
private
final
MethodNode
insnMth
;
private
FieldInitAttr
(
InitType
valueType
,
Object
value
,
MethodNode
insnMth
)
{
this
.
value
=
value
;
this
.
valueType
=
valueType
;
this
.
insnMth
=
insnMth
;
public
static
FieldInitAttr
insnValue
(
MethodNode
mth
,
InsnNode
insn
)
{
return
new
FieldInitInsnAttr
(
mth
,
insn
);
}
public
static
FieldInitAttr
constValue
(
EncodedValue
value
)
{
return
new
FieldInitAttr
(
InitType
.
CONST
,
value
,
null
)
;
public
boolean
isConst
(
)
{
return
false
;
}
public
static
FieldInitAttr
insnValue
(
MethodNode
mth
,
InsnNode
insn
)
{
return
new
FieldInitAttr
(
InitType
.
INSN
,
insn
,
mth
)
;
public
boolean
isInsn
(
)
{
return
false
;
}
public
EncodedValue
getEncodedValue
()
{
return
(
EncodedValue
)
value
;
throw
new
JadxRuntimeException
(
"Wrong init type"
)
;
}
public
InsnNode
getInsn
()
{
return
(
InsnNode
)
value
;
}
public
InitType
getValueType
()
{
return
valueType
;
throw
new
JadxRuntimeException
(
"Wrong init type"
);
}
public
MethodNode
getInsnMth
()
{
return
insnMth
;
throw
new
JadxRuntimeException
(
"Wrong init type"
)
;
}
@Override
public
AType
<
FieldInitAttr
>
getType
()
{
return
AType
.
FIELD_INIT
;
}
@Override
public
String
toString
()
{
return
"V="
+
value
;
}
}
jadx-core/src/main/java/jadx/core/dex/attributes/fldinit/FieldInitConstAttr.java
0 → 100644
浏览文件 @
98d80150
package
jadx.core.dex.attributes.fldinit
;
import
jadx.api.plugins.input.data.annotations.EncodedValue
;
import
static
java
.
util
.
Objects
.
requireNonNull
;
public
final
class
FieldInitConstAttr
extends
FieldInitAttr
{
public
static
final
FieldInitAttr
NULL_VALUE
=
new
FieldInitConstAttr
(
EncodedValue
.
NULL
);
private
final
EncodedValue
value
;
FieldInitConstAttr
(
EncodedValue
value
)
{
this
.
value
=
requireNonNull
(
value
);
}
@Override
public
EncodedValue
getEncodedValue
()
{
return
value
;
}
@Override
public
boolean
isConst
()
{
return
true
;
}
@Override
public
String
toString
()
{
return
"INIT{"
+
value
+
'}'
;
}
}
jadx-core/src/main/java/jadx/core/dex/attributes/fldinit/FieldInitInsnAttr.java
0 → 100644
浏览文件 @
98d80150
package
jadx.core.dex.attributes.fldinit
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
static
java
.
util
.
Objects
.
requireNonNull
;
public
final
class
FieldInitInsnAttr
extends
FieldInitAttr
{
private
final
MethodNode
mth
;
private
final
InsnNode
insn
;
FieldInitInsnAttr
(
MethodNode
mth
,
InsnNode
insn
)
{
this
.
mth
=
requireNonNull
(
mth
);
this
.
insn
=
requireNonNull
(
insn
);
}
@Override
public
InsnNode
getInsn
()
{
return
insn
;
}
@Override
public
MethodNode
getInsnMth
()
{
return
mth
;
}
@Override
public
boolean
isInsn
()
{
return
true
;
}
@Override
public
String
toString
()
{
return
"INIT{"
+
insn
+
'}'
;
}
}
jadx-core/src/main/java/jadx/core/dex/info/ConstStorage.java
浏览文件 @
98d80150
...
...
@@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable;
import
jadx.api.JadxArgs
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.FieldInitAttr
;
import
jadx.core.dex.attributes.
fldinit.
FieldInitAttr
;
import
jadx.core.dex.instructions.args.LiteralArg
;
import
jadx.core.dex.instructions.args.PrimitiveType
;
import
jadx.core.dex.nodes.ClassNode
;
...
...
@@ -85,10 +85,7 @@ public class ConstStorage {
AccessInfo
accFlags
=
f
.
getAccessFlags
();
if
(
accFlags
.
isStatic
()
&&
accFlags
.
isFinal
())
{
FieldInitAttr
fv
=
f
.
get
(
AType
.
FIELD_INIT
);
if
(
fv
!=
null
&&
fv
.
getValueType
()
==
FieldInitAttr
.
InitType
.
CONST
&&
fv
!=
FieldInitAttr
.
NULL_VALUE
&&
fv
.
getEncodedValue
()
!=
null
)
{
if
(
fv
!=
null
&&
fv
.
isConst
()
&&
fv
.
getEncodedValue
().
getValue
()
!=
null
)
{
addConstField
(
cls
,
f
,
fv
.
getEncodedValue
().
getValue
(),
accFlags
.
isPublic
());
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
浏览文件 @
98d80150
...
...
@@ -23,8 +23,9 @@ import jadx.api.plugins.input.data.annotations.IAnnotation;
import
jadx.core.Consts
;
import
jadx.core.ProcessClass
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.FieldInitAttr
;
import
jadx.core.dex.attributes.annotations.AnnotationsList
;
import
jadx.core.dex.attributes.fldinit.FieldInitAttr
;
import
jadx.core.dex.attributes.fldinit.FieldInitConstAttr
;
import
jadx.core.dex.attributes.nodes.NotificationAttrNode
;
import
jadx.core.dex.attributes.nodes.SourceFileAttr
;
import
jadx.core.dex.info.AccessInfo
;
...
...
@@ -164,7 +165,7 @@ public class ClassNode extends NotificationAttrNode implements ILoadable, ICodeN
for
(
FieldNode
f
:
staticFields
)
{
if
(
f
.
getAccessFlags
().
isFinal
())
{
// incorrect initialization will be removed if assign found in constructor
f
.
addAttr
(
FieldInitAttr
.
NULL_VALUE
);
f
.
addAttr
(
FieldInit
Const
Attr
.
NULL_VALUE
);
}
}
try
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ExtractFieldInit.java
浏览文件 @
98d80150
...
...
@@ -8,7 +8,7 @@ import java.util.Set;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.FieldInitAttr
;
import
jadx.core.dex.attributes.
fldinit.
FieldInitAttr
;
import
jadx.core.dex.info.AccessInfo
;
import
jadx.core.dex.info.FieldInfo
;
import
jadx.core.dex.instructions.IndexInsnNode
;
...
...
jadx-core/src/main/java/jadx/core/utils/InsnUtils.java
浏览文件 @
98d80150
...
...
@@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.FieldInitAttr
;
import
jadx.core.dex.attributes.
fldinit.
FieldInitAttr
;
import
jadx.core.dex.info.FieldInfo
;
import
jadx.core.dex.instructions.ConstClassNode
;
import
jadx.core.dex.instructions.ConstStringNode
;
...
...
@@ -101,7 +101,7 @@ public class InsnUtils {
return
null
;
}
FieldInitAttr
attr
=
fieldNode
.
get
(
AType
.
FIELD_INIT
);
if
(
attr
!=
null
&&
attr
.
getValueType
()
==
FieldInitAttr
.
InitType
.
CONST
)
{
if
(
attr
!=
null
&&
attr
.
isConst
()
)
{
return
EncodedValueUtils
.
convertToConstValue
(
root
,
attr
.
getEncodedValue
());
}
return
null
;
...
...
jadx-core/src/main/java/jadx/core/utils/android/AndroidResourcesUtils.java
浏览文件 @
98d80150
...
...
@@ -17,7 +17,7 @@ import jadx.core.codegen.CodeWriter;
import
jadx.core.deobf.NameMapper
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.FieldInitAttr
;
import
jadx.core.dex.attributes.
fldinit.
FieldInitAttr
;
import
jadx.core.dex.info.AccessInfo
;
import
jadx.core.dex.info.ClassInfo
;
import
jadx.core.dex.info.ConstStorage
;
...
...
jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore.java
浏览文件 @
98d80150
...
...
@@ -7,7 +7,7 @@ import java.util.Map;
import
org.junit.jupiter.api.Test
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.FieldInitAttr
;
import
jadx.core.dex.attributes.
fldinit.
FieldInitAttr
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.FieldNode
;
import
jadx.tests.api.IntegrationTest
;
...
...
jadx-plugins/jadx-plugins-api/src/main/java/jadx/api/plugins/input/data/annotations/EncodedValue.java
浏览文件 @
98d80150
package
jadx.api.plugins.input.data.annotations
;
import
java.util.Objects
;
public
class
EncodedValue
{
public
static
final
EncodedValue
NULL
=
new
EncodedValue
(
EncodedType
.
ENCODED_NULL
,
n
ew
Object
()
);
public
static
final
EncodedValue
NULL
=
new
EncodedValue
(
EncodedType
.
ENCODED_NULL
,
n
ull
);
private
final
EncodedType
type
;
private
final
Object
value
;
...
...
@@ -19,9 +21,28 @@ public class EncodedValue {
return
value
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
EncodedValue
that
=
(
EncodedValue
)
o
;
return
type
==
that
.
getType
()
&&
Objects
.
equals
(
value
,
that
.
getValue
());
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
getType
(),
getValue
());
}
@Override
public
String
toString
()
{
switch
(
type
)
{
case
ENCODED_NULL:
return
"null"
;
case
ENCODED_STRING:
return
(
String
)
value
;
case
ENCODED_ARRAY:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录