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
56eac437
Commit
56eac437
authored
May 02, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix errors in AttributesList, refactoring
parent
b4d08bdc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
18 deletions
+62
-18
AttributeType.java
src/main/java/jadx/dex/attributes/AttributeType.java
+18
-3
AttributesList.java
src/main/java/jadx/dex/attributes/AttributesList.java
+44
-15
No files found.
src/main/java/jadx/dex/attributes/AttributeType.java
View file @
56eac437
...
@@ -8,12 +8,10 @@ public enum AttributeType {
...
@@ -8,12 +8,10 @@ public enum AttributeType {
// blocks
// blocks
LOOP
(
false
),
LOOP
(
false
),
CATCH_BLOCK
(
false
),
CATCH_BLOCK
(
false
),
EXC_HANDLER
(
true
),
EXC_HANDLER
(
true
),
SPLITTER_BLOCK
(
true
),
SPLITTER_BLOCK
(
true
),
FORCE_RETURN
(
true
),
FORCE_RETURN
(
true
),
// fields
// fields
...
@@ -32,8 +30,25 @@ public enum AttributeType {
...
@@ -32,8 +30,25 @@ public enum AttributeType {
DECLARE_VARIABLE
(
true
);
DECLARE_VARIABLE
(
true
);
private
static
final
int
notUniqCount
;
private
final
boolean
uniq
;
private
final
boolean
uniq
;
static
{
// place all not unique attributes at first
int
last
=
-
1
;
AttributeType
[]
vals
=
AttributeType
.
values
();
for
(
int
i
=
0
;
i
<
vals
.
length
;
i
++)
{
AttributeType
type
=
vals
[
i
];
if
(
type
.
notUniq
())
last
=
i
;
}
notUniqCount
=
last
+
1
;
}
public
static
int
getNotUniqCount
()
{
return
notUniqCount
;
}
private
AttributeType
(
boolean
isUniq
)
{
private
AttributeType
(
boolean
isUniq
)
{
this
.
uniq
=
isUniq
;
this
.
uniq
=
isUniq
;
}
}
...
...
src/main/java/jadx/dex/attributes/AttributesList.java
View file @
56eac437
...
@@ -14,6 +14,12 @@ import java.util.List;
...
@@ -14,6 +14,12 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
/**
* Storage for different attribute types:
* 1. flags - boolean attribute (set or not)
* 2. attribute - class instance associated for attribute type,
* only one attached to node for unique attributes, multiple for others
*/
public
class
AttributesList
{
public
class
AttributesList
{
private
final
Set
<
AttributeFlag
>
flags
;
private
final
Set
<
AttributeFlag
>
flags
;
...
@@ -24,16 +30,11 @@ public class AttributesList {
...
@@ -24,16 +30,11 @@ public class AttributesList {
public
AttributesList
()
{
public
AttributesList
()
{
flags
=
EnumSet
.
noneOf
(
AttributeFlag
.
class
);
flags
=
EnumSet
.
noneOf
(
AttributeFlag
.
class
);
uniqAttr
=
new
EnumMap
<
AttributeType
,
IAttribute
>(
AttributeType
.
class
);
uniqAttr
=
new
EnumMap
<
AttributeType
,
IAttribute
>(
AttributeType
.
class
);
attributes
=
new
ArrayList
<
IAttribute
>(
1
);
attributes
=
new
ArrayList
<
IAttribute
>(
0
);
attrCount
=
new
int
[
AttributeType
.
values
().
length
];
attrCount
=
new
int
[
AttributeType
.
getNotUniqCount
()
];
}
}
public
void
add
(
IAttribute
attr
)
{
// Flags
if
(
attr
.
getType
().
isUniq
())
uniqAttr
.
put
(
attr
.
getType
(),
attr
);
else
addMultiAttribute
(
attr
);
}
public
void
add
(
AttributeFlag
flag
)
{
public
void
add
(
AttributeFlag
flag
)
{
flags
.
add
(
flag
);
flags
.
add
(
flag
);
...
@@ -47,12 +48,21 @@ public class AttributesList {
...
@@ -47,12 +48,21 @@ public class AttributesList {
flags
.
remove
(
flag
);
flags
.
remove
(
flag
);
}
}
// Attributes
public
void
add
(
IAttribute
attr
)
{
if
(
attr
.
getType
().
isUniq
())
uniqAttr
.
put
(
attr
.
getType
(),
attr
);
else
addMultiAttribute
(
attr
);
}
private
void
addMultiAttribute
(
IAttribute
attr
)
{
private
void
addMultiAttribute
(
IAttribute
attr
)
{
attributes
.
add
(
attr
);
attributes
.
add
(
attr
);
attrCount
[
attr
.
getType
().
ordinal
()]++;
attrCount
[
attr
.
getType
().
ordinal
()]++;
}
}
private
int
getCountInternal
(
AttributeType
type
)
{
private
int
get
Multi
CountInternal
(
AttributeType
type
)
{
return
attrCount
[
type
.
ordinal
()];
return
attrCount
[
type
.
ordinal
()];
}
}
...
@@ -67,15 +77,14 @@ public class AttributesList {
...
@@ -67,15 +77,14 @@ public class AttributesList {
if
(
type
.
isUniq
())
if
(
type
.
isUniq
())
return
uniqAttr
.
containsKey
(
type
);
return
uniqAttr
.
containsKey
(
type
);
else
else
return
getCountInternal
(
type
)
!=
0
;
return
get
Multi
CountInternal
(
type
)
!=
0
;
}
}
public
IAttribute
get
(
AttributeType
type
)
{
public
IAttribute
get
(
AttributeType
type
)
{
if
(
type
.
isUniq
())
{
if
(
type
.
isUniq
())
{
return
uniqAttr
.
get
(
type
);
return
uniqAttr
.
get
(
type
);
}
else
{
}
else
{
int
count
=
getCountInternal
(
type
);
if
(
getMultiCountInternal
(
type
)
!=
0
)
{
if
(
count
!=
0
)
{
for
(
IAttribute
attr
:
attributes
)
for
(
IAttribute
attr
:
attributes
)
if
(
attr
.
getType
()
==
type
)
if
(
attr
.
getType
()
==
type
)
return
attr
;
return
attr
;
...
@@ -86,9 +95,9 @@ public class AttributesList {
...
@@ -86,9 +95,9 @@ public class AttributesList {
public
int
getCount
(
AttributeType
type
)
{
public
int
getCount
(
AttributeType
type
)
{
if
(
type
.
isUniq
())
{
if
(
type
.
isUniq
())
{
return
0
;
return
uniqAttr
.
containsKey
(
type
)
?
1
:
0
;
}
else
{
}
else
{
return
getCountInternal
(
type
);
return
get
Multi
CountInternal
(
type
);
}
}
}
}
...
@@ -103,7 +112,7 @@ public class AttributesList {
...
@@ -103,7 +112,7 @@ public class AttributesList {
public
List
<
IAttribute
>
getAll
(
AttributeType
type
)
{
public
List
<
IAttribute
>
getAll
(
AttributeType
type
)
{
assert
type
.
notUniq
();
assert
type
.
notUniq
();
int
count
=
getCountInternal
(
type
);
int
count
=
get
Multi
CountInternal
(
type
);
if
(
count
==
0
)
{
if
(
count
==
0
)
{
return
Collections
.
emptyList
();
return
Collections
.
emptyList
();
}
else
{
}
else
{
...
@@ -129,6 +138,26 @@ public class AttributesList {
...
@@ -129,6 +138,26 @@ public class AttributesList {
}
}
}
}
public
void
remove
(
IAttribute
attr
)
{
AttributeType
type
=
attr
.
getType
();
if
(
type
.
isUniq
())
{
IAttribute
a
=
uniqAttr
.
get
(
type
);
if
(
a
==
attr
)
uniqAttr
.
remove
(
type
);
}
else
{
if
(
getMultiCountInternal
(
type
)
==
0
)
return
;
for
(
Iterator
<
IAttribute
>
it
=
attributes
.
iterator
();
it
.
hasNext
();)
{
IAttribute
a
=
it
.
next
();
if
(
a
==
attr
)
{
it
.
remove
();
attrCount
[
type
.
ordinal
()]--;
}
}
}
}
public
void
clear
()
{
public
void
clear
()
{
flags
.
clear
();
flags
.
clear
();
uniqAttr
.
clear
();
uniqAttr
.
clear
();
...
...
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