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
c6f0c89c
Commit
c6f0c89c
authored
Feb 22, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix indent for anonymous class
parent
3c84975a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
44 deletions
+61
-44
CodeWriter.java
jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java
+4
-0
InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+50
-41
RegionGen.java
jadx-core/src/main/java/jadx/core/codegen/RegionGen.java
+7
-3
No files found.
jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java
View file @
c6f0c89c
...
...
@@ -184,6 +184,10 @@ public class CodeWriter {
}
}
public
int
length
()
{
return
buf
.
length
();
}
public
boolean
isEmpty
()
{
return
buf
.
length
()
==
0
;
}
...
...
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
View file @
c6f0c89c
...
...
@@ -44,7 +44,6 @@ import java.util.HashMap;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -78,16 +77,28 @@ public class InsnGen {
return
fallback
;
}
@Deprecated
public
CodeWriter
arg
(
InsnNode
insn
,
int
arg
)
throws
CodegenException
{
return
arg
(
insn
.
getArg
(
arg
));
}
@Deprecated
public
CodeWriter
arg
(
InsnArg
arg
)
throws
CodegenException
{
return
arg
(
arg
,
true
);
}
@Deprecated
public
CodeWriter
arg
(
InsnArg
arg
,
boolean
wrap
)
throws
CodegenException
{
CodeWriter
code
=
new
CodeWriter
();
addArg
(
code
,
arg
,
wrap
);
return
code
;
}
public
void
addArg
(
CodeWriter
code
,
InsnArg
arg
)
throws
CodegenException
{
addArg
(
code
,
arg
,
true
);
}
public
void
addArg
(
CodeWriter
code
,
InsnArg
arg
,
boolean
wrap
)
throws
CodegenException
{
if
(
arg
.
isRegister
())
{
code
.
add
(
mgen
.
makeArgName
((
RegisterArg
)
arg
));
}
else
if
(
arg
.
isLiteral
())
{
...
...
@@ -100,16 +111,15 @@ public class InsnGen {
}
else
if
(
arg
.
isField
())
{
FieldArg
f
=
(
FieldArg
)
arg
;
if
(
f
.
isStatic
())
{
code
.
add
(
s
f
ield
(
f
.
getField
()));
code
.
add
(
s
taticF
ield
(
f
.
getField
()));
}
else
{
RegisterArg
regArg
=
new
RegisterArg
(
f
.
getRegNum
());
regArg
.
replaceTypedVar
(
f
);
code
.
add
(
ifield
(
f
.
getField
(),
regArg
)
);
instanceField
(
code
,
f
.
getField
(),
regArg
);
}
}
else
{
throw
new
CodegenException
(
"Unknown arg type "
+
arg
);
}
return
code
;
}
public
String
assignVar
(
InsnNode
insn
)
throws
CodegenException
{
...
...
@@ -129,32 +139,20 @@ public class InsnGen {
return
TypeGen
.
literalToString
(
arg
.
getLiteral
(),
arg
.
getType
());
}
private
String
ifield
(
FieldInfo
field
,
InsnArg
arg
)
throws
CodegenException
{
private
void
instanceField
(
CodeWriter
code
,
FieldInfo
field
,
InsnArg
arg
)
throws
CodegenException
{
FieldNode
fieldNode
=
mth
.
getParentClass
().
searchField
(
field
);
if
(
fieldNode
!=
null
&&
fieldNode
.
getAttributes
().
contains
(
AttributeFlag
.
DONT_GENERATE
))
{
return
""
;
return
;
}
String
name
=
field
.
getName
();
// TODO: add jadx argument "add this"
// FIXME: check variable names in scope
if
(
false
&&
arg
.
isThis
())
{
boolean
useShort
=
true
;
List
<
RegisterArg
>
args
=
mth
.
getArguments
(
false
);
for
(
RegisterArg
param
:
args
)
{
String
paramName
=
param
.
getTypedVar
().
getName
();
if
(
paramName
!=
null
&&
paramName
.
equals
(
name
))
{
useShort
=
false
;
}
}
if
(
useShort
)
{
return
name
;
}
int
len
=
code
.
length
();
addArg
(
code
,
arg
);
if
(
code
.
length
()
!=
len
)
{
code
.
add
(
'.'
);
}
CodeWriter
argStr
=
arg
(
arg
);
return
argStr
.
isEmpty
()
?
name
:
argStr
+
"."
+
name
;
code
.
add
(
field
.
getName
());
}
protected
String
s
f
ield
(
FieldInfo
field
)
{
protected
String
s
taticF
ield
(
FieldInfo
field
)
{
String
thisClass
=
mth
.
getParentClass
().
getFullName
();
ClassInfo
declClass
=
field
.
getDeclClass
();
if
(
thisClass
.
startsWith
(
declClass
.
getFullName
()))
{
...
...
@@ -242,7 +240,7 @@ public class InsnGen {
break
;
case
MOVE:
code
.
add
(
arg
(
insn
.
getArg
(
0
),
false
)
);
addArg
(
code
,
insn
.
getArg
(
0
),
false
);
break
;
case
CHECK_CAST:
...
...
@@ -254,7 +252,7 @@ public class InsnGen {
code
.
add
(
"("
);
code
.
add
(
useType
(((
ArgType
)
((
IndexInsnNode
)
insn
).
getIndex
())));
code
.
add
(
") "
);
code
.
add
(
arg
(
insn
.
getArg
(
0
))
);
addArg
(
code
,
insn
.
getArg
(
0
),
true
);
if
(
wrap
)
{
code
.
add
(
")"
);
}
...
...
@@ -275,7 +273,8 @@ public class InsnGen {
case
RETURN:
if
(
insn
.
getArgsCount
()
!=
0
)
{
code
.
add
(
"return "
).
add
(
arg
(
insn
.
getArg
(
0
),
false
));
code
.
add
(
"return "
);
addArg
(
code
,
insn
.
getArg
(
0
),
false
);
}
else
{
code
.
add
(
"return"
);
}
...
...
@@ -290,7 +289,8 @@ public class InsnGen {
break
;
case
THROW:
code
.
add
(
"throw "
).
add
(
arg
(
insn
.
getArg
(
0
),
true
));
code
.
add
(
"throw "
);
addArg
(
code
,
insn
.
getArg
(
0
),
true
);
break
;
case
CMP_L:
...
...
@@ -342,31 +342,41 @@ public class InsnGen {
break
;
case
AGET:
code
.
add
(
arg
(
insn
.
getArg
(
0
))).
add
(
'['
).
add
(
arg
(
insn
.
getArg
(
1
),
false
)).
add
(
']'
);
addArg
(
code
,
insn
.
getArg
(
0
));
code
.
add
(
'['
);
addArg
(
code
,
insn
.
getArg
(
1
),
false
);
code
.
add
(
']'
);
break
;
case
APUT:
code
.
add
(
arg
(
insn
,
0
)).
add
(
'['
).
add
(
arg
(
insn
.
getArg
(
1
),
false
)).
add
(
"] = "
).
add
(
arg
(
insn
.
getArg
(
2
),
false
));
addArg
(
code
,
insn
.
getArg
(
0
));
code
.
add
(
'['
);
addArg
(
code
,
insn
.
getArg
(
1
),
false
);
code
.
add
(
"] = "
);
addArg
(
code
,
insn
.
getArg
(
2
),
false
);
break
;
case
IGET:
{
FieldInfo
fieldInfo
=
(
FieldInfo
)
((
IndexInsnNode
)
insn
).
getIndex
();
code
.
add
(
ifield
(
fieldInfo
,
insn
.
getArg
(
0
)
));
instanceField
(
code
,
fieldInfo
,
insn
.
getArg
(
0
));
break
;
}
case
IPUT:
{
FieldInfo
fieldInfo
=
(
FieldInfo
)
((
IndexInsnNode
)
insn
).
getIndex
();
code
.
add
(
ifield
(
fieldInfo
,
insn
.
getArg
(
1
))).
add
(
" = "
).
add
(
arg
(
insn
.
getArg
(
0
),
false
));
instanceField
(
code
,
fieldInfo
,
insn
.
getArg
(
1
));
code
.
add
(
" = "
);
addArg
(
code
,
insn
.
getArg
(
0
),
false
);
break
;
}
case
SGET:
code
.
add
(
s
f
ield
((
FieldInfo
)
((
IndexInsnNode
)
insn
).
getIndex
()));
code
.
add
(
s
taticF
ield
((
FieldInfo
)
((
IndexInsnNode
)
insn
).
getIndex
()));
break
;
case
SPUT:
IndexInsnNode
node
=
(
IndexInsnNode
)
insn
;
fieldPut
(
node
);
code
.
add
(
sfield
((
FieldInfo
)
node
.
getIndex
())).
add
(
" = "
).
add
(
arg
(
node
.
getArg
(
0
),
false
));
code
.
add
(
staticField
((
FieldInfo
)
node
.
getIndex
())).
add
(
" = "
);
addArg
(
code
,
node
.
getArg
(
0
),
false
);
break
;
case
STR_CONCAT:
...
...
@@ -552,9 +562,7 @@ public class InsnGen {
defCtr
.
getAttributes
().
add
(
AttributeFlag
.
DONT_GENERATE
);
}
code
.
add
(
"new "
).
add
(
parent
==
null
?
"Object"
:
useClass
(
parent
)).
add
(
"() "
);
code
.
incIndent
(
2
);
new
ClassGen
(
cls
,
mgen
.
getClassGen
().
getParentGen
(),
fallback
).
makeClassBody
(
code
);
code
.
decIndent
(
2
);
return
;
}
if
(
insn
.
isSelf
())
{
...
...
@@ -632,9 +640,10 @@ public class InsnGen {
InsnArg
arg
=
insn
.
getArg
(
i
);
ArgType
origType
=
originalType
.
get
(
origPos
);
if
(!
arg
.
getType
().
equals
(
origType
))
{
code
.
add
(
'('
).
add
(
useType
(
origType
)).
add
(
')'
).
add
(
arg
(
arg
,
true
));
code
.
add
(
'('
).
add
(
useType
(
origType
)).
add
(
')'
);
addArg
(
code
,
arg
,
true
);
}
else
{
code
.
add
(
arg
(
arg
,
false
)
);
addArg
(
code
,
arg
,
false
);
}
if
(
i
<
argsCount
-
1
)
{
code
.
add
(
", "
);
...
...
@@ -645,10 +654,10 @@ public class InsnGen {
}
else
{
code
.
add
(
'('
);
if
(
k
<
argsCount
)
{
code
.
add
(
arg
(
insn
.
getArg
(
k
),
false
)
);
addArg
(
code
,
insn
.
getArg
(
k
),
false
);
for
(
int
i
=
k
+
1
;
i
<
argsCount
;
i
++)
{
code
.
add
(
", "
);
code
.
add
(
arg
(
insn
.
getArg
(
i
),
false
)
);
addArg
(
code
,
insn
.
getArg
(
i
),
false
);
}
}
code
.
add
(
')'
);
...
...
@@ -688,7 +697,7 @@ public class InsnGen {
}
makeInsn
(
inl
,
code
,
IGState
.
BODY_ONLY
);
// revert changes
for
(
Entry
<
RegisterArg
,
InsnArg
>
e
:
toRevert
.
entrySet
())
{
for
(
Map
.
Entry
<
RegisterArg
,
InsnArg
>
e
:
toRevert
.
entrySet
())
{
inl
.
replaceArg
(
e
.
getValue
(),
e
.
getKey
());
}
}
...
...
jadx-core/src/main/java/jadx/core/codegen/RegionGen.java
View file @
c6f0c89c
...
...
@@ -183,7 +183,9 @@ public class RegionGen extends InsnGen {
}
private
void
makeSynchronizedRegion
(
SynchronizedRegion
cont
,
CodeWriter
code
)
throws
CodegenException
{
code
.
startLine
(
"synchronized("
).
add
(
arg
(
cont
.
getInsn
().
getArg
(
0
))).
add
(
") {"
);
code
.
startLine
(
"synchronized ("
);
addArg
(
code
,
cont
.
getInsn
().
getArg
(
0
));
code
.
add
(
") {"
);
makeRegionIndent
(
code
,
cont
.
getRegion
());
code
.
startLine
(
'}'
);
}
...
...
@@ -191,7 +193,9 @@ public class RegionGen extends InsnGen {
private
CodeWriter
makeSwitch
(
SwitchRegion
sw
,
CodeWriter
code
)
throws
CodegenException
{
SwitchNode
insn
=
(
SwitchNode
)
sw
.
getHeader
().
getInstructions
().
get
(
0
);
InsnArg
arg
=
insn
.
getArg
(
0
);
code
.
startLine
(
"switch("
).
add
(
arg
(
arg
)).
add
(
") {"
);
code
.
startLine
(
"switch ("
);
addArg
(
code
,
arg
);
code
.
add
(
") {"
);
int
size
=
sw
.
getKeys
().
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
...
...
@@ -200,7 +204,7 @@ public class RegionGen extends InsnGen {
for
(
Object
k
:
keys
)
{
code
.
startLine
(
"case "
);
if
(
k
instanceof
IndexInsnNode
)
{
code
.
add
(
s
f
ield
((
FieldInfo
)
((
IndexInsnNode
)
k
).
getIndex
()));
code
.
add
(
s
taticF
ield
((
FieldInfo
)
((
IndexInsnNode
)
k
).
getIndex
()));
}
else
{
code
.
add
(
TypeGen
.
literalToString
((
Integer
)
k
,
arg
.
getType
()));
}
...
...
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