Package IDAscope :: Package idascope :: Package core :: Package structures :: Module IDAscopeConfiguration
[hide private]
[frames] | no frames]

Source Code for Module IDAscope.idascope.core.structures.IDAscopeConfiguration

  1  #!/usr/bin/python 
  2  ######################################################################## 
  3  # Copyright (c) 2012 
  4  # Daniel Plohmann <daniel.plohmann<at>gmail<dot>com> 
  5  # Alexander Hanel <alexander.hanel<at>gmail<dot>com> 
  6  # All rights reserved. 
  7  ######################################################################## 
  8  # 
  9  #  This file is part of IDAscope 
 10  # 
 11  #  IDAscope is free software: you can redistribute it and/or modify it 
 12  #  under the terms of the GNU General Public License as published by 
 13  #  the Free Software Foundation, either version 3 of the License, or 
 14  #  (at your option) any later version. 
 15  # 
 16  #  This program is distributed in the hope that it will be useful, but 
 17  #  WITHOUT ANY WARRANTY; without even the implied warranty of 
 18  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 19  #  General Public License for more details. 
 20  # 
 21  #  You should have received a copy of the GNU General Public License 
 22  #  along with this program.  If not, see 
 23  #  <http://www.gnu.org/licenses/>. 
 24  # 
 25  ######################################################################## 
 26   
 27  import os 
 28  import json 
 29   
 30  from idascope.core import JsonHelper 
 31   
 32   
33 -class IDAscopeConfiguration():
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 # FIXME: second level path problem of referencing modules when accessing os.path.* 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
60 - def _load_config(self, config_filename):
61 # extract the root file dir from the path to the config file 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 # print "This path has", self.root_file_path 66 self.root_file_path = config_filename.split(self.os.sep)[0] + self.os.sep 67 # load config 68 config = self.json.loads(open(config_filename, "r").read(), object_hook=JsonHelper.decode_dict) 69 # file path to the directory containing icons used by IDAscope 70 self.icon_file_path = self.root_file_path + "idascope" + self.os.sep + "icons" + self.os.sep 71 # parse other paths 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 # widget related configurations 77 self.winapi_shortcut = config["winapi"]["search_hotkey"] 78 self.winapi_load_keyword_database = config["winapi"]["load_keyword_database"]
79
80 - def _normalize_path(self, path):
81 if self.os_path_normpath is None: 82 # print "Skipping path normalization.", path 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
88 - def __str__(self):
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