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 import os
28 import json
29
30 from idascope.core import JsonHelper
31
32
34 """
35 This class is an information container for a segment.
36 """
37
38 - def __init__(self, config_filename, os_ref=None):
39 self.json = json
40 if os_ref is not None:
41 self.os = os_ref
42 else:
43 self.os = os
44
45 try:
46 self.os_path_split = self.os.path.split
47 self.os_path_normpath = self.os.path.normpath
48 except:
49 self.os_path_split = None
50 self.os_path_normpath = None
51 self.root_file_path = ""
52 self.icon_file_path = ""
53 self.semantics_file = ""
54 self.winapi_keywords_file = ""
55 self.winapi_rootdir = ""
56 self.winapi_shortcut = "ctrl+y"
57 self.winapi_load_keyword_database = False
58 self._load_config(config_filename)
59
61
62 if self.os_path_split is not None:
63 self.root_file_path = self.os_path_split(config_filename)[0] + self.os.sep
64 else:
65
66 self.root_file_path = config_filename.split(self.os.sep)[0] + self.os.sep
67
68 config = self.json.loads(open(config_filename, "r").read(), object_hook=JsonHelper.decode_dict)
69
70 self.icon_file_path = self.root_file_path + "idascope" + self.os.sep + "icons" + self.os.sep
71
72 self.config_path_sep = config["config_path_sep"]
73 self.semantics_file = self.root_file_path + self._normalize_path(config["paths"]["semantics_file"])
74 self.winapi_keywords_file = self.root_file_path + self._normalize_path(config["paths"]["winapi_keywords_file"])
75 self.winapi_rootdir = self._normalize_path(config["paths"]["winapi_rootdir"]) + self.os.sep
76
77 self.winapi_shortcut = config["winapi"]["search_hotkey"]
78 self.winapi_load_keyword_database = config["winapi"]["load_keyword_database"]
79
81 if self.os_path_normpath is None:
82
83 return path
84 else:
85 parts = path.split(self.config_path_sep)
86 return self.os_path_normpath(self.os.sep.join(parts))
87
89 """
90 Convenience function.
91 @return: a nice string representation for this object
92 """
93 return "IDAscope configuration: \n" \
94 + " root_file_path: %s\n" % self.root_file_path \
95 + " icon_file_path: %s\n" % self.icon_file_path \
96 + " semantics_file: %s\n" % self.semantics_file \
97 + " winapi_keywords_file: %s\n" % self.winapi_keywords_file \
98 + " winapi_rootdir: %s" % self.winapi_rootdir
99