Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
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
c7ed9857
Commit
c7ed9857
authored
Apr 28, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various code improvements
parent
a6f61151
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
45 deletions
+46
-45
InsnGen.java
src/main/java/jadx/codegen/InsnGen.java
+9
-14
MethodGen.java
src/main/java/jadx/codegen/MethodGen.java
+30
-24
ExcHandlerAttr.java
src/main/java/jadx/dex/trycatch/ExcHandlerAttr.java
+3
-1
ExceptionHandler.java
src/main/java/jadx/dex/trycatch/ExceptionHandler.java
+3
-3
TryCatchBlock.java
src/main/java/jadx/dex/trycatch/TryCatchBlock.java
+1
-3
No files found.
src/main/java/jadx/codegen/InsnGen.java
View file @
c7ed9857
...
@@ -54,9 +54,6 @@ public class InsnGen {
...
@@ -54,9 +54,6 @@ public class InsnGen {
NO_RESULT
,
NO_RESULT
,
BODY_ONLY
,
BODY_ONLY
,
INC_INDENT
,
DEC_INDENT
,
}
}
public
InsnGen
(
MethodGen
mgen
,
MethodNode
mth
,
boolean
fallback
)
{
public
InsnGen
(
MethodGen
mgen
,
MethodNode
mth
,
boolean
fallback
)
{
...
@@ -92,13 +89,13 @@ public class InsnGen {
...
@@ -92,13 +89,13 @@ public class InsnGen {
if
(
insn
.
getAttributes
().
contains
(
AttributeType
.
DECLARE_VARIABLE
))
{
if
(
insn
.
getAttributes
().
contains
(
AttributeType
.
DECLARE_VARIABLE
))
{
return
declareVar
(
arg
);
return
declareVar
(
arg
);
}
else
{
}
else
{
return
arg
(
arg
);
return
mgen
.
makeArgName
(
arg
);
}
}
}
catch
(
CodegenException
e
)
{
}
catch
(
CodegenException
e
)
{
LOG
.
error
(
"Assign var codegen error"
,
e
);
LOG
.
error
(
"Assign var codegen error"
,
e
);
}
return
"<error>"
;
return
"<error>"
;
}
}
}
public
String
declareVar
(
RegisterArg
arg
)
throws
CodegenException
{
public
String
declareVar
(
RegisterArg
arg
)
throws
CodegenException
{
return
useType
(
arg
.
getType
())
+
" "
+
mgen
.
assignArg
(
arg
);
return
useType
(
arg
.
getType
())
+
" "
+
mgen
.
assignArg
(
arg
);
...
@@ -142,11 +139,11 @@ public class InsnGen {
...
@@ -142,11 +139,11 @@ public class InsnGen {
return
TypeGen
.
translate
(
mgen
.
getClassGen
(),
type
);
return
TypeGen
.
translate
(
mgen
.
getClassGen
(),
type
);
}
}
public
void
makeInsn
(
InsnNode
insn
,
CodeWriter
code
)
throws
CodegenException
{
public
boolean
makeInsn
(
InsnNode
insn
,
CodeWriter
code
)
throws
CodegenException
{
makeInsn
(
insn
,
code
,
false
);
return
makeInsn
(
insn
,
code
,
false
);
}
}
private
void
makeInsn
(
InsnNode
insn
,
CodeWriter
code
,
boolean
bodyOnly
)
throws
CodegenException
{
private
boolean
makeInsn
(
InsnNode
insn
,
CodeWriter
code
,
boolean
bodyOnly
)
throws
CodegenException
{
try
{
try
{
EnumSet
<
InsnGenState
>
state
=
EnumSet
.
noneOf
(
InsnGenState
.
class
);
EnumSet
<
InsnGenState
>
state
=
EnumSet
.
noneOf
(
InsnGenState
.
class
);
if
(
bodyOnly
)
{
if
(
bodyOnly
)
{
...
@@ -156,10 +153,8 @@ public class InsnGen {
...
@@ -156,10 +153,8 @@ public class InsnGen {
CodeWriter
body
=
new
CodeWriter
(
code
.
getIndent
());
CodeWriter
body
=
new
CodeWriter
(
code
.
getIndent
());
makeInsnBody
(
body
,
insn
,
state
);
makeInsnBody
(
body
,
insn
,
state
);
if
(
state
.
contains
(
InsnGenState
.
SKIP
))
if
(
state
.
contains
(
InsnGenState
.
SKIP
))
return
;
return
false
;
if
(
state
.
contains
(
InsnGenState
.
DEC_INDENT
))
code
.
decIndent
();
if
(
insn
.
getResult
()
!=
null
&&
!
state
.
contains
(
InsnGenState
.
NO_RESULT
))
if
(
insn
.
getResult
()
!=
null
&&
!
state
.
contains
(
InsnGenState
.
NO_RESULT
))
code
.
startLine
(
assignVar
(
insn
)).
add
(
" = "
);
code
.
startLine
(
assignVar
(
insn
)).
add
(
" = "
);
else
else
...
@@ -169,12 +164,11 @@ public class InsnGen {
...
@@ -169,12 +164,11 @@ public class InsnGen {
if
(!
state
.
contains
(
InsnGenState
.
NO_SEMICOLON
))
if
(!
state
.
contains
(
InsnGenState
.
NO_SEMICOLON
))
code
.
add
(
';'
);
code
.
add
(
';'
);
if
(
state
.
contains
(
InsnGenState
.
INC_INDENT
))
code
.
incIndent
();
}
}
}
catch
(
Throwable
th
)
{
}
catch
(
Throwable
th
)
{
throw
new
CodegenException
(
mth
,
"Error generate insn: "
+
insn
,
th
);
throw
new
CodegenException
(
mth
,
"Error generate insn: "
+
insn
,
th
);
}
}
return
true
;
}
}
private
void
makeInsnBody
(
CodeWriter
code
,
InsnNode
insn
,
EnumSet
<
InsnGenState
>
state
)
throws
CodegenException
{
private
void
makeInsnBody
(
CodeWriter
code
,
InsnNode
insn
,
EnumSet
<
InsnGenState
>
state
)
throws
CodegenException
{
...
@@ -549,7 +543,7 @@ public class InsnGen {
...
@@ -549,7 +543,7 @@ public class InsnGen {
private
void
addArgs
(
CodeWriter
code
,
InsnNode
insn
,
int
k
)
throws
CodegenException
{
private
void
addArgs
(
CodeWriter
code
,
InsnNode
insn
,
int
k
)
throws
CodegenException
{
code
.
add
(
'('
);
code
.
add
(
'('
);
for
(
int
i
=
k
;
i
<
insn
.
getArgsCount
();
i
++)
{
for
(
int
i
=
k
;
i
<
insn
.
getArgsCount
();
i
++)
{
code
.
add
(
arg
(
insn
.
getArg
(
i
)
));
code
.
add
(
arg
(
insn
,
i
));
if
(
i
<
insn
.
getArgsCount
()
-
1
)
if
(
i
<
insn
.
getArgsCount
()
-
1
)
code
.
add
(
", "
);
code
.
add
(
", "
);
}
}
...
@@ -562,6 +556,7 @@ public class InsnGen {
...
@@ -562,6 +556,7 @@ public class InsnGen {
if
(
op
==
ArithOp
.
INC
||
op
==
ArithOp
.
DEC
)
{
if
(
op
==
ArithOp
.
INC
||
op
==
ArithOp
.
DEC
)
{
code
.
add
(
v1
+
op
.
getSymbol
());
code
.
add
(
v1
+
op
.
getSymbol
());
state
.
add
(
InsnGenState
.
NO_RESULT
);
}
else
{
}
else
{
String
res
=
arg
(
insn
.
getResult
());
String
res
=
arg
(
insn
.
getResult
());
String
v2
=
arg
(
insn
.
getArg
(
1
));
String
v2
=
arg
(
insn
.
getArg
(
1
));
...
...
src/main/java/jadx/codegen/MethodGen.java
View file @
c7ed9857
...
@@ -60,9 +60,9 @@ public class MethodGen {
...
@@ -60,9 +60,9 @@ public class MethodGen {
if
(
mth
.
getMethodInfo
().
isClassInit
())
{
if
(
mth
.
getMethodInfo
().
isClassInit
())
{
code
.
startLine
(
"static"
);
code
.
startLine
(
"static"
);
}
else
{
}
else
{
if
(
mth
.
getAttributes
().
contains
(
AttributeFlag
.
INCONSISTENT_CODE
)
)
{
if
(
mth
.
getAttributes
().
contains
(
AttributeFlag
.
INCONSISTENT_CODE
)
code
.
startLine
(
"// FIXME: Jadx generate inconsistent code"
);
&&
!
mth
.
getAttributes
().
contains
(
AttributeType
.
JADX_ERROR
))
{
LOG
.
debug
(
ErrorsCounter
.
formatErrorMsg
(
mth
,
" Inconsistent code"
)
);
code
.
startLine
(
"// jadx: inconsistent code"
);
}
}
annotationGen
.
addForMethod
(
code
,
mth
);
annotationGen
.
addForMethod
(
code
,
mth
);
...
@@ -217,32 +217,24 @@ public class MethodGen {
...
@@ -217,32 +217,24 @@ public class MethodGen {
code
.
add
(
"\");"
);
code
.
add
(
"\");"
);
JadxErrorAttr
err
=
(
JadxErrorAttr
)
mth
.
getAttributes
().
get
(
AttributeType
.
JADX_ERROR
);
JadxErrorAttr
err
=
(
JadxErrorAttr
)
mth
.
getAttributes
().
get
(
AttributeType
.
JADX_ERROR
);
code
.
startLine
(
"//
FIXME: Jadx error processing method
"
);
code
.
startLine
(
"//
jadx: method processing error
"
);
Throwable
cause
=
err
.
getCause
();
Throwable
cause
=
err
.
getCause
();
if
(
cause
!=
null
)
{
if
(
cause
!=
null
)
{
code
.
endl
()
.
add
(
"/*"
)
;
code
.
endl
();
code
.
startLine
(
"Message: "
).
add
(
cause
.
getMessage
()
);
code
.
add
(
"/*"
);
code
.
startLine
(
"Error: "
).
add
(
Utils
.
getStackTrace
(
cause
));
code
.
startLine
(
"Error: "
).
add
(
Utils
.
getStackTrace
(
cause
));
code
.
add
(
"*/"
);
code
.
add
(
"*/"
);
}
}
makeMethodDump
(
code
,
mth
);
// load original instructions
try
{
mth
.
load
();
DepthTraverser
.
visit
(
new
FallbackModeVisitor
(),
mth
);
}
catch
(
DecodeException
e
)
{
// ignore
return
code
;
}
code
.
startLine
(
"/*"
);
makeFullMethodDump
(
code
,
mth
);
code
.
startLine
(
"*/"
);
}
else
{
}
else
{
if
(
mth
.
getRegion
()
!=
null
)
{
if
(
mth
.
getRegion
()
!=
null
)
{
CodeWriter
insns
=
new
CodeWriter
(
mthIndent
+
1
);
CodeWriter
insns
=
new
CodeWriter
(
mthIndent
+
1
);
(
new
RegionGen
(
this
,
mth
)).
makeRegion
(
insns
,
mth
.
getRegion
());
(
new
RegionGen
(
this
,
mth
)).
makeRegion
(
insns
,
mth
.
getRegion
());
if
(
mth
.
getAttributes
().
contains
(
AttributeFlag
.
INCONSISTENT_CODE
))
{
LOG
.
debug
(
ErrorsCounter
.
formatErrorMsg
(
mth
,
" Inconsistent code"
));
// makeMethodDump(code, mth);
}
makeInitCode
(
code
);
makeInitCode
(
code
);
code
.
add
(
insns
);
code
.
add
(
insns
);
}
else
{
}
else
{
...
@@ -252,7 +244,8 @@ public class MethodGen {
...
@@ -252,7 +244,8 @@ public class MethodGen {
return
code
;
return
code
;
}
}
private
void
makeFullMethodDump
(
CodeWriter
code
,
MethodNode
mth
)
{
public
void
makeMethodDump
(
CodeWriter
code
,
MethodNode
mth
)
{
code
.
startLine
(
"/*"
);
getFallbackMethodGen
(
mth
).
addDefinition
(
code
);
getFallbackMethodGen
(
mth
).
addDefinition
(
code
);
code
.
add
(
" {"
);
code
.
add
(
" {"
);
code
.
incIndent
();
code
.
incIndent
();
...
@@ -261,9 +254,21 @@ public class MethodGen {
...
@@ -261,9 +254,21 @@ public class MethodGen {
code
.
decIndent
();
code
.
decIndent
();
code
.
startLine
(
"}"
);
code
.
startLine
(
"}"
);
code
.
startLine
(
"*/"
);
}
}
private
void
makeFallbackMethod
(
CodeWriter
code
,
MethodNode
mth
)
{
private
void
makeFallbackMethod
(
CodeWriter
code
,
MethodNode
mth
)
{
if
(
mth
.
getInstructions
()
==
null
)
{
// load original instructions
try
{
mth
.
load
();
DepthTraverser
.
visit
(
new
FallbackModeVisitor
(),
mth
);
}
catch
(
DecodeException
e
)
{
// ignore
code
.
startLine
(
"Can't load method instructions"
);
return
;
}
}
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;"
);
}
}
...
@@ -283,13 +288,14 @@ public class MethodGen {
...
@@ -283,13 +288,14 @@ public class MethodGen {
}
}
}
}
try
{
try
{
insnGen
.
makeInsn
(
insn
,
code
);
if
(
insnGen
.
makeInsn
(
insn
,
code
))
{
CatchAttr
_catch
=
(
CatchAttr
)
attrs
.
get
(
AttributeType
.
CATCH_BLOCK
);
if
(
_catch
!=
null
)
code
.
add
(
"\t //"
+
_catch
);
}
}
catch
(
CodegenException
e
)
{
}
catch
(
CodegenException
e
)
{
code
.
startLine
(
"// error: "
+
insn
);
code
.
startLine
(
"// error: "
+
insn
);
}
}
CatchAttr
_catch
=
(
CatchAttr
)
attrs
.
get
(
AttributeType
.
CATCH_BLOCK
);
if
(
_catch
!=
null
)
code
.
add
(
"\t // "
+
_catch
);
}
}
}
}
...
...
src/main/java/jadx/dex/trycatch/ExcHandlerAttr.java
View file @
c7ed9857
...
@@ -28,6 +28,8 @@ public class ExcHandlerAttr implements IAttribute {
...
@@ -28,6 +28,8 @@ public class ExcHandlerAttr implements IAttribute {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"ExcHandler: "
+
(
handler
.
isCatchAll
()
?
"all"
:
handler
.
getCatchType
());
return
"ExcHandler: "
+
(
handler
.
isCatchAll
()
?
"all"
:
handler
.
getCatchType
())
+
" "
+
handler
.
getArg
();
}
}
}
}
src/main/java/jadx/dex/trycatch/ExceptionHandler.java
View file @
c7ed9857
...
@@ -71,7 +71,7 @@ public class ExceptionHandler {
...
@@ -71,7 +71,7 @@ public class ExceptionHandler {
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
31
*
(
catchType
==
null
?
0
:
catchType
.
hashCode
())
+
handleOffset
;
return
(
catchType
==
null
?
0
:
31
*
catchType
.
hashCode
())
+
handleOffset
;
}
}
@Override
@Override
...
@@ -88,8 +88,8 @@ public class ExceptionHandler {
...
@@ -88,8 +88,8 @@ public class ExceptionHandler {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
(
catchType
==
null
?
"all"
:
catchType
.
getShortName
())
return
(
catchType
==
null
?
"all"
+
" -> "
+
InsnUtils
.
formatOffset
(
handleOffset
);
:
catchType
.
getShortName
())
+
" -> "
+
InsnUtils
.
formatOffset
(
handleOffset
);
}
}
}
}
src/main/java/jadx/dex/trycatch/TryCatchBlock.java
View file @
c7ed9857
...
@@ -117,9 +117,7 @@ public class TryCatchBlock {
...
@@ -117,9 +117,7 @@ public class TryCatchBlock {
if
(
obj
==
null
)
return
false
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
TryCatchBlock
other
=
(
TryCatchBlock
)
obj
;
TryCatchBlock
other
=
(
TryCatchBlock
)
obj
;
if
(
handlers
==
null
)
{
if
(!
handlers
.
equals
(
other
.
handlers
))
return
false
;
if
(
other
.
handlers
!=
null
)
return
false
;
}
else
if
(!
handlers
.
equals
(
other
.
handlers
))
return
false
;
return
true
;
return
true
;
}
}
...
...
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