8 def save_exists(project_dir
):
9 files
= list(glob
.glob(project_dir
+ "/project.aspace*"))
13 def ensure_project_dir(project_dir
):
14 if not os
.path
.isdir(project_dir
):
15 os
.makedirs(project_dir
)
17 def backup_by_prefix(prefix
):
18 for fname
in glob
.glob(prefix
):
19 if not fname
.endswith(".bak"):
20 os
.rename(fname
, fname
+ ".bak")
22 def save_state(project_dir
):
23 ensure_project_dir(project_dir
)
24 files
= ["project.aspace", "project.aprops"]
26 backup_by_prefix(project_dir
+ "/" + fname
+ "*")
28 for area
in engine
.ADDRESS_SPACE
.get_areas():
29 with
open(project_dir
+ "/project.aspace.%08x" % area
[engine
.START
], "w") as f
:
30 engine
.ADDRESS_SPACE
.save_area(f
, area
)
32 engine
.ADDRESS_SPACE
.save_addr_props(project_dir
+ "/project.aprops")
35 def load_state(project_dir
):
36 files
= list(glob
.glob(project_dir
+ "/project.aprops*"))
39 Cannot find project.aprops file. Possibly, you use old database format.
40 Use version 0.9 to migrate.
44 print("Loading state...")
46 for area
in engine
.ADDRESS_SPACE
.get_areas():
47 fname
= project_dir
+ "/project.aspace.%08x" % area
[engine
.START
]
48 with
open(fname
) as f
:
49 engine
.ADDRESS_SPACE
.load_area(f
, area
)
51 fname
= project_dir
+ "/project.aprops.%08x" % area
[engine
.START
]
52 if os
.path
.exists(fname
):
53 with
open(fname
) as f
:
54 engine
.ADDRESS_SPACE
.load_addr_props(f
)
56 print("Warning: %s doesn't exist" % fname
)
59 # Save user-specific session parameter, like current address,
61 def save_session(project_dir
, disasm_viewer
):
62 ensure_project_dir(project_dir
)
63 with
open(project_dir
+ "/session.addr_stack", "w") as f
:
64 for a
in disasm_viewer
.addr_stack
:
65 if isinstance(a
, tuple):
68 f
.write("%08x\n" % disasm_viewer
.cur_addr())
71 def load_addr_stack(project_dir
):
73 with
open(project_dir
+ "/session.addr_stack") as f
:
75 stack
.append(int(l
, 16))