Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
2b300341
J
jadx
项目概览
2301_76393173
/
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,发现更多精彩内容 >>
提交
2b300341
编写于
2月 25, 2014
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: improve error reporting for inconsistent code
上级
01fabca3
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
60 addition
and
53 deletion
+60
-53
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
+42
-37
jadx-core/src/main/java/jadx/core/codegen/MethodGen.java
jadx-core/src/main/java/jadx/core/codegen/MethodGen.java
+17
-15
jadx-core/src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java
...src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java
+1
-1
未找到文件。
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
浏览文件 @
2b300341
...
@@ -6,7 +6,6 @@ import jadx.core.dex.attributes.AttributeFlag;
...
@@ -6,7 +6,6 @@ import jadx.core.dex.attributes.AttributeFlag;
import
jadx.core.dex.attributes.AttributeType
;
import
jadx.core.dex.attributes.AttributeType
;
import
jadx.core.dex.attributes.EnumClassAttr
;
import
jadx.core.dex.attributes.EnumClassAttr
;
import
jadx.core.dex.attributes.EnumClassAttr.EnumField
;
import
jadx.core.dex.attributes.EnumClassAttr.EnumField
;
import
jadx.core.dex.attributes.IAttribute
;
import
jadx.core.dex.attributes.SourceFileAttr
;
import
jadx.core.dex.attributes.SourceFileAttr
;
import
jadx.core.dex.info.AccessInfo
;
import
jadx.core.dex.info.AccessInfo
;
import
jadx.core.dex.info.ClassInfo
;
import
jadx.core.dex.info.ClassInfo
;
...
@@ -236,17 +235,20 @@ public class ClassGen {
...
@@ -236,17 +235,20 @@ public class ClassGen {
code
.
add
(
';'
);
code
.
add
(
';'
);
}
else
{
}
else
{
MethodGen
mthGen
=
new
MethodGen
(
this
,
mth
);
MethodGen
mthGen
=
new
MethodGen
(
this
,
mth
);
if
(
mth
.
getAttributes
().
contains
(
AttributeFlag
.
INCONSISTENT_CODE
))
{
boolean
badCode
=
mth
.
getAttributes
().
contains
(
AttributeFlag
.
INCONSISTENT_CODE
);
code
.
startLine
(
"/* JADX WARNING: inconsistent code */"
);
if
(
badCode
)
{
code
.
startLine
(
"/* JADX WARNING: inconsistent code. */"
);
code
.
startLine
(
"/* Code decompiled incorrectly, please refer to instructions dump. */"
);
LOG
.
error
(
ErrorsCounter
.
formatErrorMsg
(
mth
,
" Inconsistent code"
));
LOG
.
error
(
ErrorsCounter
.
formatErrorMsg
(
mth
,
" Inconsistent code"
));
mthGen
.
makeMethodDump
(
code
);
}
}
if
(
mthGen
.
addDefinition
(
code
))
{
if
(
mthGen
.
addDefinition
(
code
))
{
code
.
add
(
' '
);
code
.
add
(
' '
);
}
}
code
.
add
(
'{'
);
code
.
add
(
'{'
);
code
.
incIndent
();
insertSourceFileInfo
(
code
,
mth
);
insertSourceFileInfo
(
code
,
mth
);
code
.
add
(
mthGen
.
makeInstructions
(
code
.
getIndent
()));
mthGen
.
addInstructions
(
code
);
code
.
decIndent
();
code
.
startLine
(
'}'
);
code
.
startLine
(
'}'
);
}
}
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
...
@@ -263,6 +265,33 @@ public class ClassGen {
...
@@ -263,6 +265,33 @@ public class ClassGen {
private
CodeWriter
makeFields
(
CodeWriter
clsCode
,
ClassNode
cls
,
List
<
FieldNode
>
fields
)
throws
CodegenException
{
private
CodeWriter
makeFields
(
CodeWriter
clsCode
,
ClassNode
cls
,
List
<
FieldNode
>
fields
)
throws
CodegenException
{
CodeWriter
code
=
new
CodeWriter
(
clsCode
.
getIndent
()
+
1
);
CodeWriter
code
=
new
CodeWriter
(
clsCode
.
getIndent
()
+
1
);
addEnumFields
(
cls
,
code
);
for
(
FieldNode
f
:
fields
)
{
if
(
f
.
getAttributes
().
contains
(
AttributeFlag
.
DONT_GENERATE
))
{
continue
;
}
annotationGen
.
addForField
(
code
,
f
);
code
.
startLine
(
f
.
getAccessFlags
().
makeString
());
code
.
add
(
TypeGen
.
translate
(
this
,
f
.
getType
()));
code
.
add
(
' '
);
code
.
add
(
f
.
getName
());
FieldValueAttr
fv
=
(
FieldValueAttr
)
f
.
getAttributes
().
get
(
AttributeType
.
FIELD_VALUE
);
if
(
fv
!=
null
)
{
code
.
add
(
" = "
);
if
(
fv
.
getValue
()
==
null
)
{
code
.
add
(
TypeGen
.
literalToString
(
0
,
f
.
getType
()));
}
else
{
code
.
add
(
annotationGen
.
encValueToString
(
fv
.
getValue
()));
}
}
code
.
add
(
';'
);
code
.
attachAnnotation
(
f
);
}
return
code
;
}
private
void
addEnumFields
(
ClassNode
cls
,
CodeWriter
code
)
throws
CodegenException
{
EnumClassAttr
enumFields
=
(
EnumClassAttr
)
cls
.
getAttributes
().
get
(
AttributeType
.
ENUM_CLASS
);
EnumClassAttr
enumFields
=
(
EnumClassAttr
)
cls
.
getAttributes
().
get
(
AttributeType
.
ENUM_CLASS
);
if
(
enumFields
!=
null
)
{
if
(
enumFields
!=
null
)
{
InsnGen
igen
=
null
;
InsnGen
igen
=
null
;
...
@@ -278,7 +307,7 @@ public class ClassGen {
...
@@ -278,7 +307,7 @@ public class ClassGen {
MethodGen
mthGen
=
new
MethodGen
(
this
,
enumFields
.
getStaticMethod
());
MethodGen
mthGen
=
new
MethodGen
(
this
,
enumFields
.
getStaticMethod
());
igen
=
new
InsnGen
(
mthGen
,
enumFields
.
getStaticMethod
(),
false
);
igen
=
new
InsnGen
(
mthGen
,
enumFields
.
getStaticMethod
(),
false
);
}
}
code
.
add
(
igen
.
arg
(
arg
)
);
igen
.
addArg
(
code
,
arg
);
if
(
aIt
.
hasNext
())
{
if
(
aIt
.
hasNext
())
{
code
.
add
(
", "
);
code
.
add
(
", "
);
}
}
...
@@ -298,29 +327,6 @@ public class ClassGen {
...
@@ -298,29 +327,6 @@ public class ClassGen {
code
.
add
(
';'
);
code
.
add
(
';'
);
code
.
newLine
();
code
.
newLine
();
}
}
for
(
FieldNode
f
:
fields
)
{
if
(
f
.
getAttributes
().
contains
(
AttributeFlag
.
DONT_GENERATE
))
{
continue
;
}
annotationGen
.
addForField
(
code
,
f
);
code
.
startLine
(
f
.
getAccessFlags
().
makeString
());
code
.
add
(
TypeGen
.
translate
(
this
,
f
.
getType
()));
code
.
add
(
' '
);
code
.
add
(
f
.
getName
());
FieldValueAttr
fv
=
(
FieldValueAttr
)
f
.
getAttributes
().
get
(
AttributeType
.
FIELD_VALUE
);
if
(
fv
!=
null
)
{
code
.
add
(
" = "
);
if
(
fv
.
getValue
()
==
null
)
{
code
.
add
(
TypeGen
.
literalToString
(
0
,
f
.
getType
()));
}
else
{
code
.
add
(
annotationGen
.
encValueToString
(
fv
.
getValue
()));
}
}
code
.
add
(
';'
);
code
.
attachAnnotation
(
f
);
}
return
code
;
}
}
public
String
useClass
(
ArgType
clsType
)
{
public
String
useClass
(
ArgType
clsType
)
{
...
@@ -357,9 +363,9 @@ public class ClassGen {
...
@@ -357,9 +363,9 @@ public class ClassGen {
}
}
private
String
useClassInternal
(
ClassInfo
useCls
,
ClassInfo
classInfo
)
{
private
String
useClassInternal
(
ClassInfo
useCls
,
ClassInfo
classInfo
)
{
String
clsStr
=
classInfo
.
getFullName
();
String
fullName
=
classInfo
.
getFullName
();
if
(
fallback
)
{
if
(
fallback
)
{
return
clsStr
;
return
fullName
;
}
}
String
shortName
=
classInfo
.
getShortName
();
String
shortName
=
classInfo
.
getShortName
();
if
(
classInfo
.
getPackage
().
equals
(
"java.lang"
)
&&
classInfo
.
getParentClass
()
==
null
)
{
if
(
classInfo
.
getPackage
().
equals
(
"java.lang"
)
&&
classInfo
.
getParentClass
()
==
null
)
{
...
@@ -374,15 +380,15 @@ public class ClassGen {
...
@@ -374,15 +380,15 @@ public class ClassGen {
return
shortName
;
return
shortName
;
}
}
if
(
classInfo
.
getPackage
().
equals
(
useCls
.
getPackage
()))
{
if
(
classInfo
.
getPackage
().
equals
(
useCls
.
getPackage
()))
{
clsStr
=
classInfo
.
getNameWithoutPackage
();
fullName
=
classInfo
.
getNameWithoutPackage
();
}
}
if
(
searchCollision
(
cls
.
dex
(),
useCls
,
shortName
))
{
if
(
searchCollision
(
cls
.
dex
(),
useCls
,
shortName
))
{
return
clsStr
;
return
fullName
;
}
}
for
(
ClassInfo
importCls
:
imports
)
{
for
(
ClassInfo
importCls
:
imports
)
{
if
(!
importCls
.
equals
(
classInfo
)
if
(!
importCls
.
equals
(
classInfo
)
&&
importCls
.
getShortName
().
equals
(
shortName
))
{
&&
importCls
.
getShortName
().
equals
(
shortName
))
{
return
clsStr
;
return
fullName
;
}
}
}
}
addImport
(
classInfo
);
addImport
(
classInfo
);
...
@@ -425,10 +431,9 @@ public class ClassGen {
...
@@ -425,10 +431,9 @@ public class ClassGen {
}
}
private
void
insertSourceFileInfo
(
CodeWriter
code
,
AttrNode
node
)
{
private
void
insertSourceFileInfo
(
CodeWriter
code
,
AttrNode
node
)
{
IAttribute
sourceFileAttr
=
node
.
getAttributes
().
get
(
AttributeType
.
SOURCE_FILE
);
SourceFileAttr
sourceFileAttr
=
(
SourceFileAttr
)
node
.
getAttributes
().
get
(
AttributeType
.
SOURCE_FILE
);
if
(
sourceFileAttr
!=
null
)
{
if
(
sourceFileAttr
!=
null
)
{
code
.
startLine
(
"// compiled from: "
);
code
.
startLine
(
"// compiled from: "
).
add
(
sourceFileAttr
.
getFileName
());
code
.
add
(((
SourceFileAttr
)
sourceFileAttr
).
getFileName
());
}
}
}
}
...
...
jadx-core/src/main/java/jadx/core/codegen/MethodGen.java
浏览文件 @
2b300341
...
@@ -12,6 +12,7 @@ import jadx.core.dex.instructions.args.NamedArg;
...
@@ -12,6 +12,7 @@ import jadx.core.dex.instructions.args.NamedArg;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.regions.Region
;
import
jadx.core.dex.trycatch.CatchAttr
;
import
jadx.core.dex.trycatch.CatchAttr
;
import
jadx.core.dex.visitors.DepthTraverser
;
import
jadx.core.dex.visitors.DepthTraverser
;
import
jadx.core.dex.visitors.FallbackModeVisitor
;
import
jadx.core.dex.visitors.FallbackModeVisitor
;
...
@@ -227,16 +228,14 @@ public class MethodGen {
...
@@ -227,16 +228,14 @@ public class MethodGen {
return
r
;
return
r
;
}
}
public
CodeWriter
makeInstructions
(
int
mthIndent
)
throws
CodegenException
{
public
void
addInstructions
(
CodeWriter
code
)
throws
CodegenException
{
CodeWriter
code
=
new
CodeWriter
(
mthIndent
+
1
);
if
(
mth
.
getAttributes
().
contains
(
AttributeType
.
JADX_ERROR
))
{
if
(
mth
.
getAttributes
().
contains
(
AttributeType
.
JADX_ERROR
))
{
code
.
startLine
(
"throw new UnsupportedOperationException(\"Method not decompiled: "
);
code
.
startLine
(
"throw new UnsupportedOperationException(\"Method not decompiled: "
);
code
.
add
(
mth
.
toString
());
code
.
add
(
mth
.
toString
());
code
.
add
(
"\");"
);
code
.
add
(
"\");"
);
JadxErrorAttr
err
=
(
JadxErrorAttr
)
mth
.
getAttributes
().
get
(
AttributeType
.
JADX_ERROR
);
JadxErrorAttr
err
=
(
JadxErrorAttr
)
mth
.
getAttributes
().
get
(
AttributeType
.
JADX_ERROR
);
code
.
startLine
(
"/
/ jadx: method processing error
"
);
code
.
startLine
(
"/
* JADX: method processing error */
"
);
Throwable
cause
=
err
.
getCause
();
Throwable
cause
=
err
.
getCause
();
if
(
cause
!=
null
)
{
if
(
cause
!=
null
)
{
code
.
newLine
();
code
.
newLine
();
...
@@ -245,32 +244,35 @@ public class MethodGen {
...
@@ -245,32 +244,35 @@ public class MethodGen {
code
.
add
(
"*/"
);
code
.
add
(
"*/"
);
}
}
makeMethodDump
(
code
);
makeMethodDump
(
code
);
}
else
if
(
mth
.
getAttributes
().
contains
(
AttributeFlag
.
INCONSISTENT_CODE
))
{
code
.
startLine
(
"/*"
);
addFallbackMethodCode
(
code
);
code
.
startLine
(
"*/"
);
code
.
newLine
();
}
else
{
}
else
{
if
(
mth
.
getRegion
()
!=
null
)
{
Region
startRegion
=
mth
.
getRegion
();
CodeWriter
insns
=
new
CodeWriter
(
mthIndent
+
1
);
if
(
startRegion
!=
null
)
{
(
new
RegionGen
(
this
,
mth
)).
makeRegion
(
insns
,
mth
.
getRegion
());
(
new
RegionGen
(
this
,
mth
)).
makeRegion
(
code
,
startRegion
);
code
.
add
(
insns
);
}
else
{
}
else
{
makeFallbackMethod
(
code
,
mth
);
addFallbackMethodCode
(
code
);
}
}
}
}
return
code
;
}
}
p
ublic
void
makeMethodDump
(
CodeWriter
code
)
{
p
rivate
void
makeMethodDump
(
CodeWriter
code
)
{
code
.
startLine
(
"/*"
);
code
.
startLine
(
"/*"
);
getFallbackMethodGen
(
mth
).
addDefinition
(
code
);
getFallbackMethodGen
(
mth
).
addDefinition
(
code
);
code
.
add
(
" {"
);
code
.
add
(
" {"
);
code
.
incIndent
();
code
.
incIndent
();
makeFallbackMethod
(
code
,
mth
);
addFallbackMethodCode
(
code
);
code
.
decIndent
();
code
.
decIndent
();
code
.
startLine
(
'}'
);
code
.
startLine
(
'}'
);
code
.
startLine
(
"*/"
);
code
.
startLine
(
"*/"
);
}
}
p
rivate
static
void
makeFallbackMethod
(
CodeWriter
code
,
MethodNode
mth
)
{
p
ublic
void
addFallbackMethodCode
(
CodeWriter
code
)
{
if
(
mth
.
getInstructions
()
==
null
)
{
if
(
mth
.
getInstructions
()
==
null
)
{
// loadFile original instructions
// loadFile original instructions
try
{
try
{
...
@@ -285,10 +287,10 @@ public class MethodGen {
...
@@ -285,10 +287,10 @@ public class MethodGen {
if
(
mth
.
getThisArg
()
!=
null
)
{
if
(
mth
.
getThisArg
()
!=
null
)
{
code
.
startLine
(
getFallbackMethodGen
(
mth
).
makeArgName
(
mth
.
getThisArg
())).
add
(
" = this;"
);
code
.
startLine
(
getFallbackMethodGen
(
mth
).
makeArgName
(
mth
.
getThisArg
())).
add
(
" = this;"
);
}
}
make
FallbackInsns
(
code
,
mth
,
mth
.
getInstructions
(),
true
);
add
FallbackInsns
(
code
,
mth
,
mth
.
getInstructions
(),
true
);
}
}
public
static
void
make
FallbackInsns
(
CodeWriter
code
,
MethodNode
mth
,
List
<
InsnNode
>
insns
,
boolean
addLabels
)
{
public
static
void
add
FallbackInsns
(
CodeWriter
code
,
MethodNode
mth
,
List
<
InsnNode
>
insns
,
boolean
addLabels
)
{
InsnGen
insnGen
=
new
InsnGen
(
getFallbackMethodGen
(
mth
),
mth
,
true
);
InsnGen
insnGen
=
new
InsnGen
(
getFallbackMethodGen
(
mth
),
mth
,
true
);
for
(
InsnNode
insn
:
insns
)
{
for
(
InsnNode
insn
:
insns
)
{
AttributesList
attrs
=
insn
.
getAttributes
();
AttributesList
attrs
=
insn
.
getAttributes
();
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java
浏览文件 @
2b300341
...
@@ -165,7 +165,7 @@ public class DotGraphVisitor extends AbstractVisitor {
...
@@ -165,7 +165,7 @@ public class DotGraphVisitor extends AbstractVisitor {
return
str
.
toString
();
return
str
.
toString
();
}
else
{
}
else
{
CodeWriter
code
=
new
CodeWriter
(
0
);
CodeWriter
code
=
new
CodeWriter
(
0
);
MethodGen
.
make
FallbackInsns
(
code
,
mth
,
block
.
getInstructions
(),
false
);
MethodGen
.
add
FallbackInsns
(
code
,
mth
,
block
.
getInstructions
(),
false
);
String
str
=
escape
(
code
.
newLine
().
toString
());
String
str
=
escape
(
code
.
newLine
().
toString
());
if
(
str
.
startsWith
(
NL
))
{
if
(
str
.
startsWith
(
NL
))
{
str
=
str
.
substring
(
NL
.
length
());
str
=
str
.
substring
(
NL
.
length
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录