1  import os 
  2  import sys 
  3  import logging 
  4  from c_wrapper import * 
  5  from .. import common_utils as msvc_utils 
 39   
 41       
 45   
 46      @property 
 49   
 50      @utils.cached 
 62   
 63      @utils.cached 
 66   
 67      @utils.cached 
 70   
 71      @utils.cached 
 74   
 75      @utils.cached 
 78   
 79      @utils.cached 
 84   
 94   
 95   
 96      @utils.cached 
 98          definitions_len = ULONG(0) 
 99          definitions_ids = pointer( IDEF() ) 
100   
101          if not BSCGetDefArray( self.__bsc, self.inst_id, byref( definitions_ids ), byref( definitions_len ) ): 
102              raise RuntimeError( "Unable to call BSCGetDefArray" ) 
103   
104          definitions = map( lambda i: definition_t( definitions_ids[i], self.__bsc ) 
105                             , range( definitions_len.value ) ) 
106   
107          BSCDisposeArray( self.__bsc, definitions_ids ) 
108          return definitions 
 109   
110      @utils.cached 
112          instances_len = ULONG(0) 
113          instances_ids = pointer( IINST() ) 
114   
115          if not BSCGetMembersArray( self.__bsc, self.inst_id, enums.MBF.ALL, byref( instances_ids ), byref( instances_len ) ): 
116              raise RuntimeError( "Unable to call BSCGetMembersArray" ) 
117   
118          instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] ) 
119                           , range( instances_len.value ) ) 
120   
121          BSCDisposeArray( self.__bsc, instances_ids ) 
122          return instances 
 123   
124      @utils.cached 
126          instances_len = ULONG(0) 
127          instances_ids = pointer( IINST() ) 
128   
129          if not BSCGetUsesArray( self.__bsc, self.inst_id, enums.MBF.ALL, byref( instances_ids ), byref( instances_len ) ): 
130              raise RuntimeError( "Unable to call BSCGetUsesArray" ) 
131   
132          instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] ) 
133                           , range( instances_len.value ) ) 
134   
135          BSCDisposeArray( self.__bsc, instances_ids ) 
136          return instances 
 137   
138      @utils.cached 
140          instances_len = ULONG(0) 
141          instances_ids = pointer( IINST() ) 
142   
143          if not BSCGetBaseArray( self.__bsc, self.inst_id, byref( instances_ids ), byref( instances_len ) ): 
144              raise RuntimeError( "Unable to call BSCGetBaseArray" ) 
145   
146          instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] ) 
147                           , range( instances_len.value ) ) 
148   
149          BSCDisposeArray( self.__bsc, instances_ids ) 
150          return instances 
 151   
152      @utils.cached 
154          instances_len = ULONG(0) 
155          instances_ids = pointer( IINST() ) 
156   
157          if not BSCGetDervArray( self.__bsc, self.inst_id, byref( instances_ids ), byref( instances_len ) ): 
158              raise RuntimeError( "Unable to call BSCGetDervArray" ) 
159   
160          instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] ) 
161                           , range( instances_len.value ) ) 
162   
163          BSCDisposeArray( self.__bsc, instances_ids ) 
164          return instances 
  165   
167       
169          self.__bsc = bsc 
170          self.__mod_id = mod_id 
 171   
172      @property 
175   
176      @utils.cached 
181   
182      @utils.cached 
184          instances_len = ULONG(0) 
185          instances_ids = pointer( IINST() ) 
186   
187          if not BSCGetModuleContents( self.__bsc, self.mod_id, enums.MBF.ALL, byref( instances_ids ), byref( instances_len ) ): 
188              raise RuntimeError( "Unable to call BSCGetModuleContents" ) 
189   
190          instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] ) 
191                           , range( instances_len.value ) ) 
192   
193          BSCDisposeArray( self.__bsc, instances_ids ) 
194          return instances 
  195   
198          self.logger = utils.loggers.pdb_reader 
199          self.logger.setLevel(logging.INFO) 
200   
201          self.__bsc_file = bsc_file 
202          self.__bsc = pointer( Bsc() ) 
203          if not BSCOpen( self.__bsc_file, byref( self.__bsc ) ): 
204              raise RuntimeError( "Unable to open bsc file '%s'" % self.__bsc_file ) 
205   
206          self.__instances_cache = {}  
207          self.__bsc.create_instance = lambda inst_id: self.__create_instance( inst_id ) 
 208   
209      @utils.cached 
211          return self.__instances_cache.values() 
 212   
214          try: 
215              return self.__instances_cache[ inst_id ] 
216          except KeyError: 
217              inst = instance_t( inst_id, self.__bsc ) 
218              self.__instances_cache[ inst_id ] = inst 
219              return inst 
 220   
222          instances_len = ULONG(0) 
223          instances_ids = pointer( IINST() ) 
224   
225          if not BSCGetAllGlobalsArray( self.__bsc, enums.MBF.ALL, byref( instances_ids ), byref( instances_len ) ): 
226              raise RuntimeError( "Unable to load all globals symbols" ) 
227   
228          for i in range( instances_len.value ): 
229              self.__create_instance( instances_ids[i] ) 
230   
231          BSCDisposeArray( self.__bsc, instances_ids ) 
 232   
233      @utils.cached 
236   
237      @utils.cached 
239          module_ids = pointer( IMOD() ) 
240          module_len = ULONG() 
241          bs = BSC_STAT() 
242   
243          if not BSCGetAllModulesArray( self.__bsc, module_ids, byref(module_len) ): 
244              raise RuntimeError( "Unable to load all modules" ) 
245   
246          modules = map( lambda i: module_t( module_ids[i], self.__bsc ) 
247                         , range( module_len.value ) ) 
248   
249          BSCDisposeArray( self.__bsc, module_ids ) 
250   
251          return modules 
 252   
258   
260          for m in self.files: 
261              if file_name and m.path != file_name: 
262                  continue 
263              print 'File: ', m.path 
264              if m.instances: 
265                  print '\tInstances:' 
266                  for inst in m.instances: 
267                      print '\t\t', str(inst) 
268                      if inst.definitions: 
269                          print '\t\t\tDefinitions:' 
270                          for definition in inst.definitions: 
271                              print '\t\t\t\t', str( definition ) 
272                      if inst.members: 
273                          print '\t\t\tMembers:' 
274                          for member in inst.members: 
275                              print '\t\t\t\t', str( member ) 
276                      if inst.used_symbols: 
277                          print '\t\t\tUsed symbols:' 
278                          for used_symbol in inst.used_symbols: 
279                              print '\t\t\t\t', str( used_symbol ) 
280                      if inst.base_classes: 
281                          print '\t\t\tBase classes:' 
282                          for base_class in inst.base_classes: 
283                              print '\t\t\t\t', str( base_class ) 
284                      if inst.derived_classes: 
285                          print '\t\t\tDerived classes:' 
286                          for derived_class in inst.derived_classes: 
287                              print '\t\t\t\t', str( derived_class ) 
 288   
290          if self.__bsc: 
291              BSCClose( self.__bsc )