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
1ba19d36
Commit
1ba19d36
authored
Oct 22, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix annotations number decoder
parent
07402ba4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
29 deletions
+84
-29
TypeGen.java
jadx-core/src/main/java/jadx/core/codegen/TypeGen.java
+3
-3
AnnotationsParser.java
...in/java/jadx/core/dex/nodes/parser/AnnotationsParser.java
+6
-7
EncValueParser.java
.../main/java/jadx/core/dex/nodes/parser/EncValueParser.java
+25
-19
TestAnnotations.java
...re/src/test/java/jadx/tests/internal/TestAnnotations.java
+50
-0
No files found.
jadx-core/src/main/java/jadx/core/codegen/TypeGen.java
View file @
1ba19d36
...
...
@@ -106,9 +106,9 @@ public class TypeGen {
}
private
static
String
wrapNegNum
(
boolean
lz
,
String
str
)
{
if
(
lz
)
return
"("
+
str
+
")"
;
else
//
if (lz)
//
return "(" + str + ")";
//
else
return
str
;
}
}
jadx-core/src/main/java/jadx/core/dex/nodes/parser/AnnotationsParser.java
View file @
1ba19d36
...
...
@@ -11,7 +11,7 @@ import jadx.core.dex.nodes.MethodNode;
import
jadx.core.utils.exceptions.DecodeException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.
Linked
HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -43,7 +43,6 @@ public class AnnotationsParser {
for
(
int
i
=
0
;
i
<
annotated_methods_size
;
i
++)
{
MethodNode
m
=
cls
.
searchMethodById
(
section
.
readInt
());
m
.
getAttributes
().
add
(
readAnnotationSet
(
section
.
readInt
()));
// LOG.info(m + " " + m.getAttributes());
}
for
(
int
i
=
0
;
i
<
annotated_parameters_size
;
i
++)
{
...
...
@@ -80,17 +79,17 @@ public class AnnotationsParser {
};
public
static
Annotation
readAnnotation
(
DexNode
dex
,
Section
s
,
boolean
readVisibility
)
throws
DecodeException
{
EncValueParser
ep
=
new
EncValueParser
(
dex
,
s
);
EncValueParser
parser
=
new
EncValueParser
(
dex
,
s
);
Visibility
visibility
=
null
;
if
(
readVisibility
)
if
(
readVisibility
)
{
visibility
=
visibilities
[
s
.
readByte
()];
}
int
typeIndex
=
s
.
readUleb128
();
int
size
=
s
.
readUleb128
();
Map
<
String
,
Object
>
values
=
new
HashMap
<
String
,
Object
>(
size
);
Map
<
String
,
Object
>
values
=
new
Linked
HashMap
<
String
,
Object
>(
size
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
String
name
=
dex
.
getString
(
s
.
readUleb128
());
values
.
put
(
name
,
ep
.
parseValue
());
values
.
put
(
name
,
parser
.
parseValue
());
}
return
new
Annotation
(
visibility
,
dex
.
getType
(
typeIndex
),
values
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/parser/EncValueParser.java
View file @
1ba19d36
...
...
@@ -22,9 +22,9 @@ public class EncValueParser extends EncodedValueReader {
}
public
Object
parseValue
()
throws
DecodeException
{
int
argAndType
=
in
.
readByte
()
&
0x
ff
;
int
type
=
argAndType
&
0x1
f
;
int
arg
=
(
argAndType
&
0x
e
0
)
>>
5
;
int
argAndType
=
in
.
readByte
()
&
0x
FF
;
int
type
=
argAndType
&
0x1
F
;
int
arg
=
(
argAndType
&
0x
E
0
)
>>
5
;
int
size
=
arg
+
1
;
switch
(
type
)
{
...
...
@@ -32,34 +32,35 @@ public class EncValueParser extends EncodedValueReader {
return
null
;
case
ENCODED_BOOLEAN:
return
Boolean
.
valueOf
(
arg
==
1
)
;
return
arg
==
1
;
case
ENCODED_BYTE:
return
Byte
.
valueOf
((
byte
)
parseNumber
(
size
));
return
in
.
readByte
();
case
ENCODED_SHORT:
return
Short
.
valueOf
((
short
)
parseNumber
(
size
)
);
return
(
short
)
parseNumber
(
size
,
true
);
case
ENCODED_CHAR:
return
Character
.
valueOf
((
char
)
parseNumber
(
size
)
);
return
(
char
)
parseNumber
(
size
,
false
);
case
ENCODED_INT:
return
Integer
.
valueOf
((
int
)
parseNumber
(
size
)
);
return
(
int
)
parseNumber
(
size
,
true
);
case
ENCODED_LONG:
return
Long
.
valueOf
(
parseNumber
(
size
)
);
return
parseNumber
(
size
,
true
);
case
ENCODED_FLOAT:
return
Float
.
intBitsToFloat
((
int
)
parseNumber
(
size
));
return
Float
.
intBitsToFloat
((
int
)
parseNumber
(
size
,
false
));
case
ENCODED_DOUBLE:
return
Double
.
longBitsToDouble
(
parseNumber
(
size
));
return
Double
.
longBitsToDouble
(
parseNumber
(
size
,
false
));
case
ENCODED_STRING:
return
dex
.
getString
((
int
)
parseNumber
(
size
));
return
dex
.
getString
((
int
)
parseNumber
(
size
,
false
));
case
ENCODED_TYPE:
return
dex
.
getType
((
int
)
parseNumber
(
size
));
return
dex
.
getType
((
int
)
parseNumber
(
size
,
false
));
case
ENCODED_METHOD:
return
MethodInfo
.
fromDex
(
dex
,
(
int
)
parseNumber
(
size
));
return
MethodInfo
.
fromDex
(
dex
,
(
int
)
parseNumber
(
size
,
false
));
case
ENCODED_FIELD:
case
ENCODED_ENUM:
return
FieldInfo
.
fromDex
(
dex
,
(
int
)
parseNumber
(
size
));
return
FieldInfo
.
fromDex
(
dex
,
(
int
)
parseNumber
(
size
,
false
));
case
ENCODED_ARRAY:
int
count
=
Leb128Utils
.
readUnsignedLeb128
(
in
);
...
...
@@ -75,11 +76,16 @@ public class EncValueParser extends EncodedValueReader {
throw
new
DecodeException
(
"Unknown encoded value type: 0x"
+
Integer
.
toHexString
(
type
));
}
private
long
parseNumber
(
int
byteCount
)
{
private
long
parseNumber
(
int
byteCount
,
boolean
isSignExtended
)
{
long
result
=
0
;
int
shift
=
0
;
for
(
int
i
=
0
;
i
<
byteCount
;
i
++)
{
result
|=
(
long
)
(
in
.
readByte
()
&
0xff
)
<<
shift
;
int
shift
=
8
;
int
first
=
in
.
readByte
()
&
0xFF
;
if
(
isSignExtended
&&
(
first
&
0x80
)
!=
0
)
{
result
=
~
result
<<
shift
;
}
result
|=
(
long
)
first
;
for
(
int
i
=
1
;
i
<
byteCount
;
i
++)
{
result
|=
(
long
)
(
in
.
readByte
()
&
0xFF
)
<<
shift
;
shift
+=
8
;
}
return
result
;
...
...
jadx-core/src/test/java/jadx/tests/internal/TestAnnotations.java
0 → 100644
View file @
1ba19d36
package
jadx
.
tests
.
internal
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestAnnotations
extends
InternalJadxTest
{
public
static
class
TestCls
{
private
static
@interface
A
{
int
a
();
}
@A
(
a
=
-
1
)
public
void
method1
()
{
}
private
static
@interface
V
{
boolean
value
();
}
@V
(
false
)
public
void
method2
()
{
}
private
static
@interface
D
{
float
value
()
default
1.1f
;
}
@D
public
void
method3
()
{
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
not
(
containsString
(
"@A(a = 255)"
)));
assertThat
(
code
,
containsString
(
"@A(a = -1)"
));
assertThat
(
code
,
containsString
(
"@V(false)"
));
assertThat
(
code
,
not
(
containsString
(
"@D()"
)));
}
}
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