1 import inspect
2
3 from rekall import ipython_support
4
5
6 from rekall import plugins
7 from rekall import utils
8 from rekall import session
9
10 IPython = utils.ConditionalImport("IPython")
11
12
14 """Initialize a caller's environment.
15
16 Creates a new interactive environment and installs it into the caller's
17 local namespace. After this call the usual rekall interactive environment
18 will be added in the caller's local namespace.
19
20 For example:
21
22 from rekall import interactive
23
24 interactive.ImportEnvironment()
25
26 # Update the filename, load profile etc.
27 rekal filename="xpimage.dd"
28
29 # Run the pslist command rendering to stdout.
30 print pslist()
31 """
32 isession = session.InteractiveSession(use_config_file=True, **kwargs)
33
34 stack = inspect.stack()
35
36 isession._locals = stack[1][0].f_locals
37 isession._prepare_local_namespace()
38
39
40
41 try:
42 shell = IPython.get_ipython()
43 if shell:
44 shell.Completer.matchers.insert(
45 0,
46 lambda x: ipython_support.RekallCompleter(shell.Completer, x))
47
48 shell.Completer.merge_completions = False
49 except Exception as e:
50 print(e)
51
52 return isession
53