FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jeb-samplecode/scripts/AndroidXrefResId.py at master · pnfsoftware/jeb-samplecode · GitHub
pnfsoftware
jeb-samplecode
Repository navigation
Code
Pull requests
3
(3)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
jeb-samplecode
/
scripts
/
AndroidXrefResId.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
96 lines (87 loc) · 3.58 KB
Breadcrumbs
jeb-samplecode
/
scripts
/
AndroidXrefResId.py
Copy path
File metadata and controls
96 lines (87 loc) · 3.58 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#?description=Android APK cross-reference navigation from Resource XML units to DEX Disassembly unit
#?shortcut=
from
com
.
pnfsoftware
.
jeb
.
client
.
api
import
IScript
,
IGraphicalClientContext
from
com
.
pnfsoftware
.
jeb
.
core
import
IPlugin
from
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
import
IApkUnit
,
IDexUnit
from
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
dex
import
IDalvikInstruction
from
com
.
pnfsoftware
.
jeb
.
util
.
encoding
import
Conversion
"""
Sample script for JEB Decompiler.
Usage:
- Position the caret on a resource id in XML (eg, ' <public id="0x7f05000d" ...')
- Run the script, select your target xref, and press Enter to navigate to it
Hint: set a shortcut entry in the metadata line at the top of this file, e.g. Shift+X,
to allow the execution of this script via hotkeys.
"""
class
AndroidXrefResId
(
IScript
):
def
run
(
self
,
ctx
):
if
not
isinstance
(
ctx
,
IGraphicalClientContext
):
print
(
'This script must be run within a graphical client'
)
return
apk
=
ctx
.
getMainProject
().
findUnit
(
IApkUnit
)
if
not
apk
:
print
(
'APK unit not found'
)
return
dex
=
ctx
.
getMainProject
().
findUnit
(
IDexUnit
)
if
not
dex
:
print
(
'DEX unit not found'
)
return
f
=
ctx
.
getFocusedFragment
()
if
not
f
:
print
(
'Focus must be on a UI fragment'
)
return
sel
=
f
.
getSelectedText
()
or
f
.
getActiveItemAsText
()
if
not
sel
:
print
(
'Please position the caret on an item or select a piece of text'
)
return
resid
=
Conversion
.
stringToInt
(
sel
)
if
not
resid
:
print
(
'Not a resource ID: "%s"'
%
sel
)
return
print
(
'Searching for code xrefs to id: 0x%X'
%
resid
)
# building a database of integer immediate usage location
# map: int_imm -> list_of_usage_addresses
# opti: to avoid rebuilding the map each time the script is called, we cache it in the client transient store
immdb
=
ctx
.
getTransientStore
().
get
(
'intImmDb'
)
if
immdb
==
None
:
immdb
=
{}
ctx
.
getTransientStore
().
put
(
'intImmDb'
,
immdb
)
for
m
in
dex
.
getMethods
():
if
m
.
isInternal
():
ci
=
m
.
getData
().
getCodeItem
()
if
ci
:
for
insn
in
ci
.
getInstructions
():
for
param
in
insn
.
getParameters
():
if
param
.
getType
()
==
IDalvikInstruction
.
TYPE_IMM
:
val
=
param
.
getValue
()
addr
=
'%s+%Xh'
%
(
m
.
getSignature
(
False
),
insn
.
getOffset
())
if
val
not
in
immdb
:
immdb
[
val
]
=
[]
immdb
[
val
].
append
(
addr
)
#print(immdb)
candidate_addresses
=
immdb
.
get
(
resid
)
if
not
candidate_addresses
:
print
(
'No location found'
)
return
# pick the best candidate xref; if there are multiple, pop-up a dialog and let the user pick
if
len
(
candidate_addresses
)
==
1
:
addr
=
candidate_addresses
[
0
]
else
:
rows
=
[]
for
candidate_address
in
candidate_addresses
:
rows
.
append
([
candidate_address
])
print
'Found %d locations: %s'
%
(
len
(
candidate_address
),
candidate_address
)
index
=
ctx
.
displayList
(
'Select a location (%d candidates)'
%
len
(
candidate_addresses
),
None
, [
'Addresses'
],
rows
)
if
index
<
0
:
return
addr
=
candidate_addresses
[
index
]
print
(
'Navigating to: %s'
%
addr
)
# find, bring up, and focus on the DEX unit Disassembly fragment
for
view
in
ctx
.
getViews
(
dex
):
for
fragment
in
view
.
getFragments
():
if
view
.
getFragmentLabel
(
fragment
)
==
'Disassembly'
:
view
.
setFocus
()
view
.
setActiveFragment
(
fragment
)
fragment
.
setActiveAddress
(
addr
)
return
print
(
'Assembly fragment was not found?'
)
Back
|
FazBrowse Home
|
New Git URL