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
1b98be0b
Commit
1b98be0b
authored
Feb 17, 2015
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix array type for new-array instruction (fix #50)
parent
e5b84d94
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
95 additions
and
11 deletions
+95
-11
InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+2
-1
FilledNewArrayNode.java
...n/java/jadx/core/dex/instructions/FilledNewArrayNode.java
+3
-1
InsnDecoder.java
...src/main/java/jadx/core/dex/instructions/InsnDecoder.java
+3
-2
NewArrayNode.java
...rc/main/java/jadx/core/dex/instructions/NewArrayNode.java
+41
-0
ConstInlinerVisitor.java
...main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java
+3
-1
ModVisitor.java
...core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
+3
-1
ReSugarCode.java
...ore/src/main/java/jadx/core/dex/visitors/ReSugarCode.java
+8
-5
TestArrays3.java
.../test/java/jadx/tests/integration/arrays/TestArrays3.java
+32
-0
No files found.
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
View file @
1b98be0b
...
...
@@ -20,6 +20,7 @@ import jadx.core.dex.instructions.IndexInsnNode;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.InvokeNode
;
import
jadx.core.dex.instructions.InvokeType
;
import
jadx.core.dex.instructions.NewArrayNode
;
import
jadx.core.dex.instructions.SwitchNode
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.FieldArg
;
...
...
@@ -341,7 +342,7 @@ public class InsnGen {
break
;
case
NEW_ARRAY:
{
ArgType
arrayType
=
insn
.
getResult
().
get
Type
();
ArgType
arrayType
=
((
NewArrayNode
)
insn
).
getArray
Type
();
code
.
add
(
"new "
);
useType
(
code
,
arrayType
.
getArrayRootElement
());
code
.
add
(
'['
);
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/FilledNewArrayNode.java
View file @
1b98be0b
...
...
@@ -3,11 +3,13 @@ package jadx.core.dex.instructions;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.nodes.InsnNode
;
import
org.jetbrains.annotations.NotNull
;
public
class
FilledNewArrayNode
extends
InsnNode
{
private
final
ArgType
elemType
;
public
FilledNewArrayNode
(
ArgType
elemType
,
int
size
)
{
public
FilledNewArrayNode
(
@NotNull
ArgType
elemType
,
int
size
)
{
super
(
InsnType
.
FILLED_NEW_ARRAY
,
size
);
this
.
elemType
=
elemType
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java
View file @
1b98be0b
...
...
@@ -535,8 +535,9 @@ public class InsnDecoder {
InsnArg
.
reg
(
insn
,
0
,
dex
.
getType
(
insn
.
getIndex
())));
case
Opcodes
.
NEW_ARRAY
:
return
insn
(
InsnType
.
NEW_ARRAY
,
InsnArg
.
reg
(
insn
,
0
,
dex
.
getType
(
insn
.
getIndex
())),
ArgType
arrType
=
dex
.
getType
(
insn
.
getIndex
());
return
new
NewArrayNode
(
arrType
,
InsnArg
.
reg
(
insn
,
0
,
arrType
),
InsnArg
.
reg
(
insn
,
1
,
ArgType
.
INT
));
case
Opcodes
.
FILL_ARRAY_DATA
:
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/NewArrayNode.java
0 → 100644
View file @
1b98be0b
package
jadx
.
core
.
dex
.
instructions
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.nodes.InsnNode
;
import
org.jetbrains.annotations.NotNull
;
public
class
NewArrayNode
extends
InsnNode
{
private
final
ArgType
arrType
;
public
NewArrayNode
(
@NotNull
ArgType
arrType
,
RegisterArg
res
,
InsnArg
size
)
{
super
(
InsnType
.
NEW_ARRAY
,
1
);
this
.
arrType
=
arrType
;
setResult
(
res
);
addArg
(
size
);
}
public
ArgType
getArrayType
()
{
return
arrType
;
}
@Override
public
boolean
isSame
(
InsnNode
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(!(
obj
instanceof
NewArrayNode
)
||
!
super
.
isSame
(
obj
))
{
return
false
;
}
NewArrayNode
other
=
(
NewArrayNode
)
obj
;
return
arrType
==
other
.
arrType
;
}
@Override
public
String
toString
()
{
return
super
.
toString
()
+
" type: "
+
arrType
;
}
}
jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java
View file @
1b98be0b
...
...
@@ -222,7 +222,9 @@ public class ConstInlinerVisitor extends AbstractVisitor {
break
;
case
NEW_ARRAY:
litArg
.
merge
(
ArgType
.
INT
);
if
(
litArg
==
insn
.
getArg
(
0
))
{
litArg
.
merge
(
ArgType
.
INT
);
}
break
;
default
:
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
View file @
1b98be0b
...
...
@@ -12,6 +12,7 @@ import jadx.core.dex.instructions.FilledNewArrayNode;
import
jadx.core.dex.instructions.IndexInsnNode
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.InvokeNode
;
import
jadx.core.dex.instructions.NewArrayNode
;
import
jadx.core.dex.instructions.SwitchNode
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
...
...
@@ -108,7 +109,8 @@ public class ModVisitor extends AbstractVisitor {
InsnNode
ni
=
block
.
getInstructions
().
get
(
next
);
if
(
ni
.
getType
()
==
InsnType
.
FILL_ARRAY
)
{
ni
.
getResult
().
merge
(
insn
.
getResult
());
((
FillArrayNode
)
ni
).
mergeElementType
(
insn
.
getResult
().
getType
().
getArrayElement
());
ArgType
arrType
=
((
NewArrayNode
)
insn
).
getArrayType
();
((
FillArrayNode
)
ni
).
mergeElementType
(
arrType
.
getArrayElement
());
remover
.
add
(
insn
);
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ReSugarCode.java
View file @
1b98be0b
...
...
@@ -9,6 +9,7 @@ import jadx.core.dex.instructions.FilledNewArrayNode;
import
jadx.core.dex.instructions.IndexInsnNode
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.InvokeNode
;
import
jadx.core.dex.instructions.NewArrayNode
;
import
jadx.core.dex.instructions.SwitchNode
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
...
...
@@ -70,19 +71,21 @@ public class ReSugarCode extends AbstractVisitor {
*/
private
static
InsnNode
processNewArray
(
MethodNode
mth
,
List
<
InsnNode
>
instructions
,
int
i
,
InstructionRemover
remover
)
{
InsnNode
insn
=
instructions
.
get
(
i
);
InsnArg
arg
=
i
nsn
.
getArg
(
0
);
NewArrayNode
newArrayInsn
=
(
NewArrayNode
)
instructions
.
get
(
i
);
InsnArg
arg
=
newArrayI
nsn
.
getArg
(
0
);
if
(!
arg
.
isLiteral
())
{
return
null
;
}
int
len
=
(
int
)
((
LiteralArg
)
arg
).
getLiteral
();
int
size
=
instructions
.
size
();
if
(
len
<=
0
||
i
+
len
>=
size
||
instructions
.
get
(
i
+
len
).
getType
()
!=
InsnType
.
APUT
)
{
if
(
len
<=
0
||
i
+
len
>=
size
||
instructions
.
get
(
i
+
len
).
getType
()
!=
InsnType
.
APUT
)
{
return
null
;
}
ArgType
arrType
=
insn
.
getResult
().
get
Type
();
ArgType
arrType
=
newArrayInsn
.
getArray
Type
();
InsnNode
filledArr
=
new
FilledNewArrayNode
(
arrType
.
getArrayElement
(),
len
);
filledArr
.
setResult
(
i
nsn
.
getResult
());
filledArr
.
setResult
(
newArrayI
nsn
.
getResult
());
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
InsnNode
put
=
instructions
.
get
(
i
+
1
+
j
);
if
(
put
.
getType
()
!=
InsnType
.
APUT
)
{
...
...
jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays3.java
0 → 100644
View file @
1b98be0b
package
jadx
.
tests
.
integration
.
arrays
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestArrays3
extends
IntegrationTest
{
public
static
class
TestCls
{
private
Object
test
(
byte
[]
bArr
)
{
return
new
Object
[]{
bArr
};
}
public
void
check
()
{
assertThat
(
test
(
new
byte
[]{
1
,
2
}),
instanceOf
(
Object
[].
class
));
}
}
@Test
public
void
test
()
{
noDebugInfo
();
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"return new Object[]{bArr};"
));
}
}
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