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
ddab4c26
Commit
ddab4c26
authored
Dec 22, 2014
by
YASME-Tim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed debug output.
parent
6ddb0036
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
72 deletions
+16
-72
BinaryXMLParser.java
...-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java
+16
-72
No files found.
jadx-core/src/main/java/jadx/core/xmlgen/BinaryXMLParser.java
View file @
ddab4c26
...
@@ -17,7 +17,17 @@ import java.util.HashMap;
...
@@ -17,7 +17,17 @@ import java.util.HashMap;
import
java.util.Map
;
import
java.util.Map
;
import
android.R.style
;
import
android.R.style
;
//import android.content.res.Resources;
/* TODO:
Don't die when error occurs
Check error cases, maybe checked const values are not always the same
Better error messages
What to do, when Binary XML Manifest is > size(int)?
Check for missung chunk size types
Implement missing data types
Use linenumbers to recreate EXACT AndroidManifest
Check Element chunk size
*/
public
class
BinaryXMLParser
{
public
class
BinaryXMLParser
{
private
byte
[]
bytes
;
private
byte
[]
bytes
;
...
@@ -28,10 +38,10 @@ public class BinaryXMLParser {
...
@@ -28,10 +38,10 @@ public class BinaryXMLParser {
private
String
currentTag
=
"ERROR"
;
private
String
currentTag
=
"ERROR"
;
private
int
numtabs
=-
1
;
private
int
numtabs
=-
1
;
private
boolean
wasOneLiner
=
false
;
private
boolean
wasOneLiner
=
false
;
PrintWriter
writer
;
private
PrintWriter
writer
;
Map
<
Integer
,
String
>
styleMap
=
null
;
private
Map
<
Integer
,
String
>
styleMap
=
null
;
public
BinaryXMLParser
(
String
xmlfilepath
,
String
xmloutfilepath
)
{
public
BinaryXMLParser
(
String
xmlfilepath
,
String
xmloutfilepath
)
{
//System.out.println(xmlfilepath);
try
{
try
{
writer
=
new
PrintWriter
(
xmloutfilepath
,
"UTF-8"
);
writer
=
new
PrintWriter
(
xmloutfilepath
,
"UTF-8"
);
}
catch
(
FileNotFoundException
fnfe
)
{
die
(
"FNFE"
);
}
}
catch
(
FileNotFoundException
fnfe
)
{
die
(
"FNFE"
);
}
...
@@ -83,10 +93,8 @@ public class BinaryXMLParser {
...
@@ -83,10 +93,8 @@ public class BinaryXMLParser {
else
if
(
type
==
0x0103
)
parseElementEnd
();
else
if
(
type
==
0x0103
)
parseElementEnd
();
else
if
(
type
==
0x0000
)
continue
;
// NullType is just doing nothing
else
if
(
type
==
0x0000
)
continue
;
// NullType is just doing nothing
else
die
(
"Type: "
+
Integer
.
toHexString
(
type
)
+
" not yet implemented"
);
else
die
(
"Type: "
+
Integer
.
toHexString
(
type
)
+
" not yet implemented"
);
//System.out.println("COUNT: "+Integer.toHexString(count));
}
}
writer
.
close
();
writer
.
close
();
//die("Done");
}
}
private
void
parseStringPool
()
{
private
void
parseStringPool
()
{
...
@@ -97,29 +105,18 @@ public class BinaryXMLParser {
...
@@ -97,29 +105,18 @@ public class BinaryXMLParser {
int
flags
=
cInt32
(
bytes
,
count
);
int
flags
=
cInt32
(
bytes
,
count
);
int
stringsStart
=
cInt32
(
bytes
,
count
);
int
stringsStart
=
cInt32
(
bytes
,
count
);
int
stylesStart
=
cInt32
(
bytes
,
count
);
int
stylesStart
=
cInt32
(
bytes
,
count
);
/*
System.out.println(hsize);
System.out.println(stringCount);
System.out.println(styleCount);
System.out.println(flags);
System.out.println(stringsStart);
System.out.println(stylesStart);
*/
int
[]
stringsOffsets
=
new
int
[
stringCount
];
int
[]
stringsOffsets
=
new
int
[
stringCount
];
for
(
int
i
=
0
;
i
<
stringCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
stringCount
;
i
++)
{
stringsOffsets
[
i
]
=
cInt32
(
bytes
,
count
);
stringsOffsets
[
i
]
=
cInt32
(
bytes
,
count
);
//System.out.println("i["+i+"]: " + stringsOffsets[i]);
}
}
strings
=
new
String
[
stringCount
];
strings
=
new
String
[
stringCount
];
for
(
int
i
=
0
;
i
<
stringCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
stringCount
;
i
++)
{
int
off
=
8
+
stringsStart
+
stringsOffsets
[
i
];
int
off
=
8
+
stringsStart
+
stringsOffsets
[
i
];
int
strlen
=
cInt16
(
bytes
,
off
);
int
strlen
=
cInt16
(
bytes
,
off
);
//System.out.println("strlen: " + strlen);
byte
[]
str
=
new
byte
[
strlen
*
2
];
byte
[]
str
=
new
byte
[
strlen
*
2
];
System
.
arraycopy
(
bytes
,
count
,
str
,
0
,
strlen
*
2
);
System
.
arraycopy
(
bytes
,
count
,
str
,
0
,
strlen
*
2
);
count
+=
strlen
*
2
;
count
+=
strlen
*
2
;
strings
[
i
]
=
new
String
(
str
,
Charset
.
forName
(
"UTF-16LE"
));
strings
[
i
]
=
new
String
(
str
,
Charset
.
forName
(
"UTF-16LE"
));
//System.out.println("index i["+i+"] string: " + strings[i]);
count
+=
2
;
count
+=
2
;
}
}
}
}
...
@@ -127,12 +124,9 @@ public class BinaryXMLParser {
...
@@ -127,12 +124,9 @@ public class BinaryXMLParser {
private
void
parseResourceMap
()
{
private
void
parseResourceMap
()
{
if
(
cInt16
(
bytes
,
count
)
!=
0x8
)
die
(
"Header size of resmap is not 8!"
);
if
(
cInt16
(
bytes
,
count
)
!=
0x8
)
die
(
"Header size of resmap is not 8!"
);
int
rhsize
=
cInt32
(
bytes
,
count
);
int
rhsize
=
cInt32
(
bytes
,
count
);
//System.out.println("RHeader Size: " + rhsize);
int
[]
ids
=
new
int
[(
rhsize
-
8
)/
4
];
int
[]
ids
=
new
int
[(
rhsize
-
8
)/
4
];
for
(
int
i
=
0
;
i
<
ids
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
ids
.
length
;
i
++)
{
ids
[
i
]=
cInt32
(
bytes
,
count
);
ids
[
i
]=
cInt32
(
bytes
,
count
);
//System.out.println("i["+i+"] ID: "+ids[i]);
//System.out.println("Hex: 0x0" + Integer.toHexString(ids[i]) + " should be: " + strings[i]);
}
}
}
}
...
@@ -140,49 +134,32 @@ public class BinaryXMLParser {
...
@@ -140,49 +134,32 @@ public class BinaryXMLParser {
if
(
cInt16
(
bytes
,
count
)
!=
0x0010
)
die
(
"NAMESPACE header is not 0x0010"
);
if
(
cInt16
(
bytes
,
count
)
!=
0x0010
)
die
(
"NAMESPACE header is not 0x0010"
);
if
(
cInt32
(
bytes
,
count
)
!=
0x18
)
die
(
"NAMESPACE header chunk is not 0x18 big"
);
if
(
cInt32
(
bytes
,
count
)
!=
0x18
)
die
(
"NAMESPACE header chunk is not 0x18 big"
);
int
beginLineNumber
=
cInt32
(
bytes
,
count
);
int
beginLineNumber
=
cInt32
(
bytes
,
count
);
//if(beginLineNumber!=2) die("NAMESPACE beginning line number != 2 not supported yet");
//System.out.println("NAMESPACE BEGIN Line: " + beginLineNumber);
int
comment
=
cInt32
(
bytes
,
count
);
int
comment
=
cInt32
(
bytes
,
count
);
//System.out.println("Comment: 0x" + Integer.toHexString(comment));
int
beginPrefix
=
cInt32
(
bytes
,
count
);
int
beginPrefix
=
cInt32
(
bytes
,
count
);
//System.out.println("Prefix: " + strings[beginPrefix]);
nsPrefix
=
strings
[
beginPrefix
];
nsPrefix
=
strings
[
beginPrefix
];
int
beginURI
=
cInt32
(
bytes
,
count
);
int
beginURI
=
cInt32
(
bytes
,
count
);
//System.out.println("URI: " + strings[beginURI]);
nsURI
=
strings
[
beginURI
];
nsURI
=
strings
[
beginURI
];
//System.out.println("COUNT: "+Integer.toHexString(count));
}
}
private
void
parseNameSpaceEnd
()
{
private
void
parseNameSpaceEnd
()
{
if
(
cInt16
(
bytes
,
count
)
!=
0x0010
)
die
(
"NAMESPACE header is not 0x0010"
);
if
(
cInt16
(
bytes
,
count
)
!=
0x0010
)
die
(
"NAMESPACE header is not 0x0010"
);
if
(
cInt32
(
bytes
,
count
)
!=
0x18
)
die
(
"NAMESPACE header chunk is not 0x18 big"
);
if
(
cInt32
(
bytes
,
count
)
!=
0x18
)
die
(
"NAMESPACE header chunk is not 0x18 big"
);
int
endLineNumber
=
cInt32
(
bytes
,
count
);
int
endLineNumber
=
cInt32
(
bytes
,
count
);
//if(endLineNumber!=2) die("NAMESPACE begining line number != 2 not supported yet");
//System.out.println("NAMESPACE END Line: " + endLineNumber);
int
comment
=
cInt32
(
bytes
,
count
);
int
comment
=
cInt32
(
bytes
,
count
);
//System.out.println("Comment: 0x" + Integer.toHexString(comment));
int
endPrefix
=
cInt32
(
bytes
,
count
);
int
endPrefix
=
cInt32
(
bytes
,
count
);
//System.out.println("Prefix: " + strings[endPrefix]);
nsPrefix
=
strings
[
endPrefix
];
nsPrefix
=
strings
[
endPrefix
];
int
endURI
=
cInt32
(
bytes
,
count
);
int
endURI
=
cInt32
(
bytes
,
count
);
nsURI
=
strings
[
endURI
];
nsURI
=
strings
[
endURI
];
//System.out.println("URI: " + strings[endURI]);
}
}
private
void
parseElement
()
{
private
void
parseElement
()
{
numtabs
+=
1
;
numtabs
+=
1
;
if
(
cInt16
(
bytes
,
count
)
!=
0x0010
)
die
(
"ELEMENT HEADER SIZE is not 0x10"
);
if
(
cInt16
(
bytes
,
count
)
!=
0x0010
)
die
(
"ELEMENT HEADER SIZE is not 0x10"
);
//if(cInt32(bytes, count) != 0x0060) die("ELEMENT CHUNK SIZE is not 0x60");
count
+=
4
;
// TODO: Check element chunk size
count
+=
4
;
int
elementBegLineNumber
=
cInt32
(
bytes
,
count
);
int
elementBegLineNumber
=
cInt32
(
bytes
,
count
);
//System.out.println("ELEMENT BEG Line: " + elementBegLineNumber + " of " + strings[startNSName]);
int
comment
=
cInt32
(
bytes
,
count
);
int
comment
=
cInt32
(
bytes
,
count
);
//System.out.println("Comment: 0x" + Integer.toHexString(comment));
//System.out.println("COUNT: "+Integer.toHexString(count));
int
startNS
=
cInt32
(
bytes
,
count
);
int
startNS
=
cInt32
(
bytes
,
count
);
//System.out.println("Namespace: 0x" + Integer.toHexString(startNS));
int
startNSName
=
cInt32
(
bytes
,
count
);
// actually is elementName...
int
startNSName
=
cInt32
(
bytes
,
count
);
// actually is elementName...
//System.out.println("Namespace name: " + strings[startNSName]);
if
(!
wasOneLiner
&&
!
"ERROR"
.
equals
(
currentTag
)
&&
!
currentTag
.
equals
(
strings
[
startNSName
]))
{
if
(!
wasOneLiner
&&
!
"ERROR"
.
equals
(
currentTag
)
&&
!
currentTag
.
equals
(
strings
[
startNSName
]))
{
writer
.
println
(
">"
);
writer
.
println
(
">"
);
}
}
...
@@ -195,13 +172,9 @@ public class BinaryXMLParser {
...
@@ -195,13 +172,9 @@ public class BinaryXMLParser {
int
attributeSize
=
cInt16
(
bytes
,
count
);
int
attributeSize
=
cInt16
(
bytes
,
count
);
if
(
attributeSize
!=
0x14
)
die
(
"startNS's attributeSize is not 0x14"
);
if
(
attributeSize
!=
0x14
)
die
(
"startNS's attributeSize is not 0x14"
);
int
attributeCount
=
cInt16
(
bytes
,
count
);
int
attributeCount
=
cInt16
(
bytes
,
count
);
//System.out.println("startNS: attributeCount: " + attributeCount);
int
idIndex
=
cInt16
(
bytes
,
count
);
int
idIndex
=
cInt16
(
bytes
,
count
);
//System.out.println("startNS: idIndex: " + idIndex);
int
classIndex
=
cInt16
(
bytes
,
count
);
int
classIndex
=
cInt16
(
bytes
,
count
);
//System.out.println("startNS: classIndex: " + classIndex);
int
styleIndex
=
cInt16
(
bytes
,
count
);
int
styleIndex
=
cInt16
(
bytes
,
count
);
if
(
styleIndex
!=
0
)
System
.
out
.
println
(
"startNS: styleIndex: "
+
styleIndex
);
if
(
"manifest"
.
equals
(
strings
[
startNSName
]))
writer
.
print
(
" xmlns:\""
+
nsURI
+
"\""
);
if
(
"manifest"
.
equals
(
strings
[
startNSName
]))
writer
.
print
(
" xmlns:\""
+
nsURI
+
"\""
);
if
(
attributeCount
>
0
)
writer
.
print
(
" "
);
if
(
attributeCount
>
0
)
writer
.
print
(
" "
);
for
(
int
i
=
0
;
i
<
attributeCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
attributeCount
;
i
++)
{
...
@@ -209,34 +182,21 @@ public class BinaryXMLParser {
...
@@ -209,34 +182,21 @@ public class BinaryXMLParser {
int
attributeName
=
cInt32
(
bytes
,
count
);
int
attributeName
=
cInt32
(
bytes
,
count
);
int
attributeRawValue
=
cInt32
(
bytes
,
count
);
int
attributeRawValue
=
cInt32
(
bytes
,
count
);
int
attrValSize
=
cInt16
(
bytes
,
count
);
int
attrValSize
=
cInt16
(
bytes
,
count
);
//System.out.println(attrValSize);
if
(
attrValSize
!=
0x08
)
die
(
"attrValSize != 0x08 not supported"
);
if
(
attrValSize
!=
0x08
)
die
(
"attrValSize != 0x08 not supported"
);
if
(
cInt8
(
bytes
,
count
)
!=
0
)
die
(
"res0 is not 0"
);
if
(
cInt8
(
bytes
,
count
)
!=
0
)
die
(
"res0 is not 0"
);
int
attrValDataType
=
cInt8
(
bytes
,
count
);
int
attrValDataType
=
cInt8
(
bytes
,
count
);
int
attrValData
=
cInt32
(
bytes
,
count
);
int
attrValData
=
cInt32
(
bytes
,
count
);
/*(
System.out.println("ai["+i+"] ns: " + attributeNS);
//if(attributeNS!=-1) System.out.println("ai["+i+"] Sns: " + strings[attributeNS]);
System.out.println("ai["+i+"] name: " + attributeName);
if(attributeName!=-1) System.out.println("ai["+i+"] Sns: " + strings[attributeName]);
System.out.println("ai["+i+"] rawval: " + attributeRawValue);
System.out.println("ai["+i+"] dt: " + attrValDataType);
System.out.println("ai["+i+"] d: " + attrValData);
*/
if
(
attributeNS
!=
-
1
)
writer
.
print
(
nsPrefix
+
":"
);
if
(
attributeNS
!=
-
1
)
writer
.
print
(
nsPrefix
+
":"
);
writer
.
print
(
strings
[
attributeName
]
+
"=\""
);
writer
.
print
(
strings
[
attributeName
]
+
"=\""
);
if
(
attrValDataType
==
0x3
)
writer
.
print
(
strings
[
attrValData
]);
if
(
attrValDataType
==
0x3
)
writer
.
print
(
strings
[
attrValData
]);
else
if
(
attrValDataType
==
0x10
)
writer
.
print
(
attrValData
);
else
if
(
attrValDataType
==
0x10
)
writer
.
print
(
attrValData
);
else
if
(
attrValDataType
==
0x12
)
{
else
if
(
attrValDataType
==
0x12
)
{
//
TODO: data is always -1, FIXME
//
FIXME: What to do, when data is always -1?
if
(
attrValData
==
0
)
writer
.
print
(
"false"
);
if
(
attrValData
==
0
)
writer
.
print
(
"false"
);
else
if
(
attrValData
==
1
||
attrValData
==-
1
)
writer
.
print
(
"true"
);
else
if
(
attrValData
==
1
||
attrValData
==-
1
)
writer
.
print
(
"true"
);
else
writer
.
print
(
"UNKNOWN_BOOLEAN_TYPE"
);
else
writer
.
print
(
"UNKNOWN_BOOLEAN_TYPE"
);
}
else
if
(
attrValDataType
==
0x1
)
{
}
else
if
(
attrValDataType
==
0x1
)
{
if
(
attrValData
<
0x7f000000
)
{
if
(
attrValData
<
0x7f000000
)
{
//System.out.println("0x"+Integer.toHexString(attrValData));
//System.out.println(styleMap.get(attrValData));
//System.out.println(android.R.style.class);
writer
.
print
(
"@*"
);
writer
.
print
(
"@*"
);
if
(
attributeNS
!=
-
1
)
writer
.
print
(
nsPrefix
+
":"
);
if
(
attributeNS
!=
-
1
)
writer
.
print
(
nsPrefix
+
":"
);
writer
.
print
(
"style/"
+
styleMap
.
get
(
attrValData
).
replaceAll
(
"_"
,
"."
));
writer
.
print
(
"style/"
+
styleMap
.
get
(
attrValData
).
replaceAll
(
"_"
,
"."
));
...
@@ -245,16 +205,6 @@ public class BinaryXMLParser {
...
@@ -245,16 +205,6 @@ public class BinaryXMLParser {
}
}
}
}
else
{
else
{
/*
//System.out.println("ai["+i+"] ns: " + attributeNS);
//if(attributeNS!=-1) System.out.println("ai["+i+"] Sns: " + strings[attributeNS]);
//System.out.println("ai["+i+"] name: " + attributeName);
if(attributeName!=-1) System.out.println("ai["+i+"] Sns: " + strings[attributeName]);
System.out.println("ai["+i+"] rawval: " + attributeRawValue);
if(attributeRawValue!=-1) System.out.println("ai["+i+"] Sns: " + strings[attributeRawValue]);
System.out.println("ai["+i+"] dt: " + attrValDataType);
System.out.println("ai["+i+"] d: " + attrValData);
*/
if
(
"configChanges"
.
equals
(
strings
[
attributeName
]))
{
if
(
"configChanges"
.
equals
(
strings
[
attributeName
]))
{
if
(
attrValData
==
1152
)
writer
.
print
(
"orientation"
);
if
(
attrValData
==
1152
)
writer
.
print
(
"orientation"
);
else
if
(
attrValData
==
4016
)
writer
.
print
(
"keyboard|keyboardHidden|orientation|screenLayout|uiMode"
);
else
if
(
attrValData
==
4016
)
writer
.
print
(
"keyboard|keyboardHidden|orientation|screenLayout|uiMode"
);
...
@@ -268,17 +218,13 @@ public class BinaryXMLParser {
...
@@ -268,17 +218,13 @@ public class BinaryXMLParser {
writer
.
print
(
"\""
);
writer
.
print
(
"\""
);
if
((
i
+
1
)<
attributeCount
)
writer
.
print
(
" "
);
if
((
i
+
1
)<
attributeCount
)
writer
.
print
(
" "
);
}
}
//writer.println(">");
//System.out.println("ELEMENT BEG Line: " + elementBegLineNumber + " of " + strings[startNSName]);
}
}
private
void
parseElementEnd
()
{
private
void
parseElementEnd
()
{
if
(
cInt16
(
bytes
,
count
)
!=
0x0010
)
die
(
"ELEMENT END header is not 0x0010"
);
if
(
cInt16
(
bytes
,
count
)
!=
0x0010
)
die
(
"ELEMENT END header is not 0x0010"
);
if
(
cInt32
(
bytes
,
count
)
!=
0x18
)
die
(
"ELEMENT END header chunk is not 0x18 big"
);
if
(
cInt32
(
bytes
,
count
)
!=
0x18
)
die
(
"ELEMENT END header chunk is not 0x18 big"
);
int
endLineNumber
=
cInt32
(
bytes
,
count
);
int
endLineNumber
=
cInt32
(
bytes
,
count
);
//if(endLineNumber!=2) die("NAMESPACE beginning line number != 2 not supported yet");
int
comment
=
cInt32
(
bytes
,
count
);
int
comment
=
cInt32
(
bytes
,
count
);
//System.out.println("Comment: 0x" + Integer.toHexString(comment));
int
elementNS
=
cInt32
(
bytes
,
count
);
int
elementNS
=
cInt32
(
bytes
,
count
);
int
elementName
=
cInt32
(
bytes
,
count
);
int
elementName
=
cInt32
(
bytes
,
count
);
if
(
currentTag
==
strings
[
elementName
])
{
if
(
currentTag
==
strings
[
elementName
])
{
...
@@ -291,8 +237,6 @@ public class BinaryXMLParser {
...
@@ -291,8 +237,6 @@ public class BinaryXMLParser {
writer
.
println
(
strings
[
elementName
]+
">"
);
writer
.
println
(
strings
[
elementName
]+
">"
);
}
}
numtabs
-=
1
;
numtabs
-=
1
;
//System.out.println("ELEMENT END Line: " + endLineNumber + " of " + strings[elementName]);
// TODO: Mind linenumbers for real original file ;)
}
}
private
int
cInt8
(
byte
[]
bytes
,
int
offset
)
{
private
int
cInt8
(
byte
[]
bytes
,
int
offset
)
{
...
...
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