This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
/
__init__.py
111 lines (88 loc) · 3.05 KB
/
__init__.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Author: hluwa <hluwa888@gmail.com>
# HomePage: https://github.com/hluwa
# CreatedTime: 2020/3/8 23:33
__description__ = "a plugin to help you understand java world."
import os
from objection.utils.plugin import Plugin
from .wallbreaker.agent.command import CommandAgent
class ObjectionAgent(CommandAgent):
def __init__(self, objection_plugin):
self.plugin = objection_plugin
super().__init__()
def attach(self):
self._rpc = self.plugin.api
class WallBreaker(Plugin):
def __init__(self, ns):
"""
Creates a new instance of the plugin
:param ns:
"""
self.script_path = os.path.join(os.path.dirname(__file__), "agent/_agent.js")
implementation = {
'meta': 'help you understand java world.',
'commands': {
'classdump': {
'meta': 'quick view a class struct',
'flags': ['--fullname'],
'exec': self.classdump
},
'classsearch': {
'meta': 'search class by pattern',
'flags': [],
'exec': self.classsearch
},
'objectdump': {
'meta': 'quick view an object internal',
'flags': ['--fullname', "--as-class"],
'exec': self.objectdump
},
'objectsearch': {
'meta': 'search instance in heap',
'flags': [],
'exec': self.objectsearch
}
}
}
super().__init__(__file__, ns, implementation)
self.inject()
self.plugin_agent = ObjectionAgent(self)
def classdump(self, args=None):
"""
"""
short_name = True
target_name = ""
for arg in args:
if arg == "--fullname":
short_name = False
else:
target_name = arg
self.plugin_agent.class_dump(target_name, pretty_print=True, short_name=short_name)
def classsearch(self, args=None):
pattern = args[0]
instances = self.plugin_agent.class_match(pattern)
print("\n".join(instances))
def objectdump(self, args=None):
"""
"""
short_name = True
as_class = None
handle = ""
idx = 0
while idx < len(args):
arg = args[idx]
if arg == "--fullname":
short_name = False
elif arg == "--as-class":
as_class = args[idx + 1]
idx += 1
else:
handle = arg
idx += 1
self.plugin_agent.object_dump(handle, as_class=as_class, pretty_print=True, short_name=short_name)
def objectsearch(self, args=None):
clsname = args[0]
instances = self.plugin_agent.object_search(clsname, stop=False)
for handle in instances:
print("[{}]: {}".format(handle, instances[handle]))
namespace = 'wallbreaker'
plugin = WallBreaker