Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
e4e6f379
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,发现更多精彩内容 >>
提交
e4e6f379
编写于
11月 19, 2019
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: sort inner classes and methods by source lines
上级
4b314e9d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
73 addition
and
38 deletion
+73
-38
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
+38
-37
jadx-core/src/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
...c/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
+34
-0
jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers2.java
...va/jadx/tests/integration/debuginfo/TestLineNumbers2.java
+1
-1
未找到文件。
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
浏览文件 @
e4e6f379
...
...
@@ -10,6 +10,7 @@ import java.util.Objects;
import
java.util.Set
;
import
com.android.dx.rop.code.AccessFlags
;
import
com.google.common.collect.Streams
;
import
jadx.api.JadxArgs
;
import
jadx.core.dex.attributes.AFlag
;
...
...
@@ -130,7 +131,8 @@ public class ClassGen {
annotationGen
.
addForClass
(
clsCode
);
insertRenameInfo
(
clsCode
,
cls
);
CodeGenUtils
.
addSourceFileInfo
(
clsCode
,
cls
);
clsCode
.
startLine
(
af
.
makeString
());
clsCode
.
startLineWithNum
(
cls
.
getSourceLine
());
clsCode
.
add
(
af
.
makeString
());
if
(
af
.
isInterface
())
{
if
(
af
.
isAnnotation
())
{
clsCode
.
add
(
'@'
);
...
...
@@ -222,21 +224,32 @@ public class ClassGen {
clsDeclLine
=
clsCode
.
getLine
();
clsCode
.
incIndent
();
addFields
(
clsCode
);
addInnerClasses
(
clsCode
,
cls
);
addMethods
(
clsCode
);
addInnerClsAndMethods
(
clsCode
);
clsCode
.
decIndent
();
clsCode
.
startLine
(
'}'
);
}
private
void
addInnerClasses
(
CodeWriter
code
,
ClassNode
cls
)
throws
CodegenException
{
for
(
ClassNode
innerCls
:
cls
.
getInnerClasses
())
{
if
(
innerCls
.
contains
(
AFlag
.
DONT_GENERATE
))
{
continue
;
}
private
void
addInnerClsAndMethods
(
CodeWriter
clsCode
)
{
Streams
.
concat
(
cls
.
getInnerClasses
().
stream
(),
cls
.
getMethods
().
stream
())
.
filter
(
node
->
!
node
.
contains
(
AFlag
.
DONT_GENERATE
))
.
sorted
(
Comparator
.
comparingInt
(
LineAttrNode:
:
getSourceLine
))
.
forEach
(
node
->
{
if
(
node
instanceof
ClassNode
)
{
addInnerClass
(
clsCode
,
(
ClassNode
)
node
);
}
else
{
addMethod
(
clsCode
,
(
MethodNode
)
node
);
}
});
}
private
void
addInnerClass
(
CodeWriter
code
,
ClassNode
innerCls
)
{
try
{
ClassGen
inClGen
=
new
ClassGen
(
innerCls
,
getParentGen
());
code
.
newLine
();
inClGen
.
addClassCode
(
code
);
imports
.
addAll
(
inClGen
.
getImports
());
}
catch
(
Exception
e
)
{
ErrorsCounter
.
classError
(
innerCls
,
"Inner class code generation error"
,
e
);
}
}
...
...
@@ -249,38 +262,26 @@ public class ClassGen {
return
false
;
}
private
void
addMethods
(
CodeWriter
code
)
{
List
<
MethodNode
>
methods
=
sortMethodsByLine
(
cls
.
getMethods
());
for
(
MethodNode
mth
:
methods
)
{
if
(
mth
.
contains
(
AFlag
.
DONT_GENERATE
))
{
continue
;
}
if
(
code
.
getLine
()
!=
clsDeclLine
)
{
code
.
newLine
();
}
int
savedIndent
=
code
.
getIndent
();
try
{
addMethod
(
code
,
mth
);
}
catch
(
Exception
e
)
{
if
(
mth
.
getParentClass
().
getTopParentClass
().
contains
(
AFlag
.
RESTART_CODEGEN
))
{
throw
new
JadxRuntimeException
(
"Method generation error"
,
e
);
}
code
.
newLine
().
add
(
"/*"
);
code
.
newLine
().
addMultiLine
(
ErrorsCounter
.
methodError
(
mth
,
"Method generation error"
,
e
));
Utils
.
appendStackTrace
(
code
,
e
);
code
.
newLine
().
add
(
"*/"
);
code
.
setIndent
(
savedIndent
);
mth
.
addError
(
"Method generation error: "
+
e
.
getMessage
(),
e
);
private
void
addMethod
(
CodeWriter
code
,
MethodNode
mth
)
{
if
(
code
.
getLine
()
!=
clsDeclLine
)
{
code
.
newLine
();
}
int
savedIndent
=
code
.
getIndent
();
try
{
addMethodCode
(
code
,
mth
);
}
catch
(
Exception
e
)
{
if
(
mth
.
getParentClass
().
getTopParentClass
().
contains
(
AFlag
.
RESTART_CODEGEN
))
{
throw
new
JadxRuntimeException
(
"Method generation error"
,
e
);
}
code
.
newLine
().
add
(
"/*"
);
code
.
newLine
().
addMultiLine
(
ErrorsCounter
.
methodError
(
mth
,
"Method generation error"
,
e
));
Utils
.
appendStackTrace
(
code
,
e
);
code
.
newLine
().
add
(
"*/"
);
code
.
setIndent
(
savedIndent
);
mth
.
addError
(
"Method generation error: "
+
e
.
getMessage
(),
e
);
}
}
private
static
List
<
MethodNode
>
sortMethodsByLine
(
List
<
MethodNode
>
methods
)
{
List
<
MethodNode
>
out
=
new
ArrayList
<>(
methods
);
out
.
sort
(
Comparator
.
comparingInt
(
LineAttrNode:
:
getSourceLine
));
return
out
;
}
private
boolean
isMethodsPresents
()
{
for
(
MethodNode
mth
:
cls
.
getMethods
())
{
if
(!
mth
.
contains
(
AFlag
.
DONT_GENERATE
))
{
...
...
@@ -290,7 +291,7 @@ public class ClassGen {
return
false
;
}
public
void
addMethod
(
CodeWriter
code
,
MethodNode
mth
)
throws
CodegenException
{
public
void
addMethod
Code
(
CodeWriter
code
,
MethodNode
mth
)
throws
CodegenException
{
CodeGenUtils
.
addComments
(
code
,
mth
);
if
(
mth
.
getAccessFlags
().
isAbstract
()
||
mth
.
getAccessFlags
().
isNative
())
{
MethodGen
mthGen
=
new
MethodGen
(
this
,
mth
);
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
浏览文件 @
e4e6f379
...
...
@@ -8,9 +8,12 @@ import java.util.Set;
import
org.jetbrains.annotations.Nullable
;
import
com.google.common.collect.Streams
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.nodes.DeclareVariablesAttr
;
import
jadx.core.dex.attributes.nodes.LineAttrNode
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.ArithOp
;
import
jadx.core.dex.instructions.InsnType
;
...
...
@@ -20,6 +23,7 @@ import jadx.core.dex.instructions.args.RegisterArg;
import
jadx.core.dex.instructions.mods.ConstructorInsn
;
import
jadx.core.dex.instructions.mods.TernaryInsn
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.InsnContainer
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
...
...
@@ -44,6 +48,14 @@ import jadx.core.utils.exceptions.JadxException;
)
public
class
PrepareForCodeGen
extends
AbstractVisitor
{
@Override
public
boolean
visit
(
ClassNode
cls
)
throws
JadxException
{
if
(
cls
.
root
().
getArgs
().
isDebugInfo
())
{
setClassSourceLine
(
cls
);
}
return
true
;
}
@Override
public
void
visit
(
MethodNode
mth
)
throws
JadxException
{
List
<
BlockNode
>
blocks
=
mth
.
getBasicBlocks
();
...
...
@@ -246,4 +258,26 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
return
null
;
}
/**
* Use source line from top method
*/
private
void
setClassSourceLine
(
ClassNode
cls
)
{
for
(
ClassNode
innerClass
:
cls
.
getInnerClasses
())
{
setClassSourceLine
(
innerClass
);
}
int
minLine
=
Streams
.
concat
(
cls
.
getMethods
().
stream
(),
cls
.
getInnerClasses
().
stream
(),
cls
.
getFields
().
stream
())
.
filter
(
mth
->
!
mth
.
contains
(
AFlag
.
DONT_GENERATE
))
.
filter
(
mth
->
mth
.
getSourceLine
()
!=
0
)
.
mapToInt
(
LineAttrNode:
:
getSourceLine
)
.
min
()
.
orElse
(
0
);
if
(
minLine
!=
0
)
{
cls
.
setSourceLine
(
minLine
-
1
);
}
}
}
jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers2.java
浏览文件 @
e4e6f379
...
...
@@ -39,7 +39,7 @@ public class TestLineNumbers2 extends IntegrationTest {
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
Map
<
Integer
,
Integer
>
lineMapping
=
cls
.
getCode
().
getLineMapping
();
assertEquals
(
"{8=18, 11=22, 12=23, 13=24, 14=28, 16=25, 17=26, 18=28, 21=31, 22=32}"
,
assertEquals
(
"{
5=17,
8=18, 11=22, 12=23, 13=24, 14=28, 16=25, 17=26, 18=28, 21=31, 22=32}"
,
lineMapping
.
toString
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录