FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jeb-samplecode/scripts/RenameJavaMethodParameters.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
/
RenameJavaMethodParameters.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (41 loc) · 1.81 KB
Breadcrumbs
jeb-samplecode
/
scripts
/
RenameJavaMethodParameters.py
Copy path
File metadata and controls
45 lines (41 loc) · 1.81 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
#?description=Rename method parameters of decompiled Java methods based on their types
#?shortcut=
import
os
from
com
.
pnfsoftware
.
jeb
.
client
.
api
import
IScript
from
com
.
pnfsoftware
.
jeb
.
core
import
IPlugin
from
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
java
import
IJavaSourceUnit
,
IJavaClass
,
JavaElementType
"""
Sample script for JEB Decompiler.
This script demonstrates how to rename method parameters of decompiled Java methods.
In the example below, generic parameter names ('argX') are renamed based on their type.
"""
class
RenameJavaMethodParameters
(
IScript
):
def
run
(
self
,
ctx
):
prj
=
ctx
.
getMainProject
()
assert
prj
,
'Need a project'
# process all Java decompiled source units
for
unit
in
prj
.
findUnits
(
IJavaSourceUnit
):
elt
=
unit
.
getASTElement
()
if
isinstance
(
elt
,
IJavaClass
):
for
m
in
elt
.
getMethods
():
self
.
process
(
unit
,
m
)
def
process
(
self
,
unit
,
e
):
if
not
e
.
isExternal
():
print
'Method: %s'
%
e
namemap
=
{}
params
=
e
.
getParameters
()
for
param
in
e
.
getParameters
():
ident
=
param
.
getIdentifier
()
original_name
=
ident
.
getName
()
if
original_name
!=
'this'
:
debug_name
=
ident
.
getDebugName
()
effective_name
=
unit
.
getIdentifierName
(
ident
)
print
' Parameter: %s (debug name: %s) (effective: %s)'
%
(
param
,
debug_name
,
effective_name
)
if
not
effective_name
and
not
debug_name
and
original_name
.
startswith
(
'arg'
)
and
param
.
getType
().
isClassOrInterface
():
t
=
str
(
param
.
getType
())
simplename
=
t
[
t
.
rfind
(
'.'
)
+
1
:].
lower
()
v
=
namemap
.
get
(
simplename
,
0
)
namemap
[
simplename
]
=
v
+
1
effective_name
=
'%s%d'
%
(
simplename
,
v
)
print
' -> Renaming to: %s'
%
effective_name
unit
.
setIdentifierName
(
ident
,
effective_name
)
Back
|
FazBrowse Home
|
New Git URL