1 import os
2 import sys
3 import ctypes
4 import logging
5 import msvc_details
6 from ctypes import *
7 from ctypes.wintypes import ULONG
8 from ctypes.wintypes import DWORD
9 from ctypes.wintypes import BOOL
10 from ctypes.wintypes import BYTE
11 from ctypes.wintypes import WORD
12 from ctypes.wintypes import UINT
13
14 sys.path.append( r'../..' )
15
16 from pygccxml import utils
17 from pygccxml import declarations
18
19
20 STRING = c_char_p
21 _libraries = {}
22 _libraries['msvcr70.dll'] = CDLL(msvc_details.msvcr_path, mode=RTLD_GLOBAL)
23 _libraries['msbsc70.dll'] = CDLL(msvc_details.msbsc_path, mode=RTLD_GLOBAL)
24
25
26 qyMac = 9
27 refreshAllOp = 4
28 qyDervOf = 7
29 delOp = 1
30 qyImpMembers = 8
31 changeOp = 2
32 qyRefs = 4
33 qyCalls = 2
34 changeIinstOp = 3
35 qyContains = 1
36 qyCalledBy = 3
37 noOp = 5
38 qyBaseOf = 6
39 qyNil = 0
40 addOp = 0
41 qyDefs = 5
42 PULONG = POINTER(ULONG)
43 USHORT = c_ushort
44 PUSHORT = POINTER(USHORT)
45 UCHAR = c_ubyte
46 PUCHAR = POINTER(UCHAR)
47 PSZ = STRING
48 FLOAT = c_float
49 PFLOAT = POINTER(FLOAT)
50 PBOOL = POINTER(BOOL)
51 LPBOOL = POINTER(BOOL)
52 PBYTE = POINTER(BYTE)
53 LPBYTE = POINTER(BYTE)
54 PINT = POINTER(c_int)
55 LPINT = POINTER(c_int)
56 PWORD = POINTER(WORD)
57 LPWORD = POINTER(WORD)
58 LPLONG = POINTER(c_long)
59 PDWORD = POINTER(DWORD)
60 LPDWORD = POINTER(DWORD)
61 LPVOID = c_void_p
62 LPCVOID = c_void_p
63 INT = c_int
64 PUINT = POINTER(c_uint)
65 ULONG_PTR = POINTER(ULONG)
66 NI = ULONG
67 IINST = ULONG
68 IREF = ULONG
69 IDEF = ULONG
70 IMOD = USHORT
71 LINE = USHORT
72 TYP = BYTE
73 ATR = USHORT
74 ATR32 = ULONG
75 MBF = ULONG
76 SZ = STRING
77 SZ_CONST = STRING
78
79 -class Bsc(Structure):
81
82
83 OPERATION = c_int
86 IinstInfo._fields_ = [
87 ('m_iinst', IINST),
88 ('m_szName', SZ_CONST),
89 ('m_ni', NI),
90 ]
93 BSC_STAT._fields_ = [
94 ('cDef', ULONG),
95 ('cRef', ULONG),
96 ('cInst', ULONG),
97 ('cMod', ULONG),
98 ('cUseLink', ULONG),
99 ('cBaseLink', ULONG),
100 ]
101 -class NiQ(Structure):
103 NiQ._fields_ = [
104 ('m_iinstOld', IINST),
105 ('m_iInfoNew', IinstInfo),
106 ('m_op', OPERATION),
107 ('m_typ', TYP),
108 ]
109 pfnNotifyChange = CFUNCTYPE(BOOL, POINTER(NiQ), ULONG, ULONG_PTR)
110
111
112 _qy_ = c_int
113 QY = _qy_
114 Bsc._fields_ = [
115 ]
116 BSCOpen = _libraries['msbsc70.dll'].BSCOpen
117 BSCOpen.restype = BOOL
118 BSCOpen.argtypes = [SZ_CONST, POINTER(POINTER(Bsc))]
119 BSCClose = _libraries['msbsc70.dll'].BSCClose
120 BSCClose.restype = BOOL
121 BSCClose.argtypes = [POINTER(Bsc)]
122 BSCIinstInfo = _libraries['msbsc70.dll'].BSCIinstInfo
123 BSCIinstInfo.restype = BOOL
124 BSCIinstInfo.argtypes = [POINTER(Bsc), IINST, POINTER(SZ), POINTER(TYP), POINTER(ATR)]
125 BSCIrefInfo = _libraries['msbsc70.dll'].BSCIrefInfo
126 BSCIrefInfo.restype = BOOL
127 BSCIrefInfo.argtypes = [POINTER(Bsc), IREF, POINTER(SZ), POINTER(LINE)]
128 BSCIdefInfo = _libraries['msbsc70.dll'].BSCIdefInfo
129 BSCIdefInfo.restype = BOOL
130 BSCIdefInfo.argtypes = [POINTER(Bsc), IDEF, POINTER(SZ), POINTER(LINE)]
131 BSCImodInfo = _libraries['msbsc70.dll'].BSCImodInfo
132 BSCImodInfo.restype = BOOL
133 BSCImodInfo.argtypes = [POINTER(Bsc), IMOD, POINTER(SZ)]
134 BSCSzFrTyp = _libraries['msbsc70.dll'].BSCSzFrTyp
135 BSCSzFrTyp.restype = SZ
136 BSCSzFrTyp.argtypes = [POINTER(Bsc), TYP]
137 BSCSzFrAtr = _libraries['msbsc70.dll'].BSCSzFrAtr
138 BSCSzFrAtr.restype = SZ
139 BSCSzFrAtr.argtypes = [POINTER(Bsc), ATR]
140 BSCGetIinstByvalue = _libraries['msbsc70.dll'].BSCGetIinstByvalue
141 BSCGetIinstByvalue.restype = BOOL
142 BSCGetIinstByvalue.argtypes = [POINTER(Bsc), SZ, TYP, ATR, POINTER(IINST)]
143 BSCGetOverloadArray = _libraries['msbsc70.dll'].BSCGetOverloadArray
144 BSCGetOverloadArray.restype = BOOL
145 BSCGetOverloadArray.argtypes = [POINTER(Bsc), SZ, MBF, POINTER(POINTER(IINST)), POINTER(ULONG)]
146 BSCGetUsedByArray = _libraries['msbsc70.dll'].BSCGetUsedByArray
147 BSCGetUsedByArray.restype = BOOL
148 BSCGetUsedByArray.argtypes = [POINTER(Bsc), IINST, MBF, POINTER(POINTER(IINST)), POINTER(ULONG)]
149 BSCGetUsesArray = _libraries['msbsc70.dll'].BSCGetUsesArray
150 BSCGetUsesArray.restype = BOOL
151 BSCGetUsesArray.argtypes = [POINTER(Bsc), IINST, MBF, POINTER(POINTER(IINST)), POINTER(ULONG)]
152 BSCGetBaseArray = _libraries['msbsc70.dll'].BSCGetBaseArray
153 BSCGetBaseArray.restype = BOOL
154 BSCGetBaseArray.argtypes = [POINTER(Bsc), IINST, POINTER(POINTER(IINST)), POINTER(ULONG)]
155 BSCGetDervArray = _libraries['msbsc70.dll'].BSCGetDervArray
156 BSCGetDervArray.restype = BOOL
157 BSCGetDervArray.argtypes = [POINTER(Bsc), IINST, POINTER(POINTER(IINST)), POINTER(ULONG)]
158 BSCGetMembersArray = _libraries['msbsc70.dll'].BSCGetMembersArray
159 BSCGetMembersArray.restype = BOOL
160 BSCGetMembersArray.argtypes = [POINTER(Bsc), IINST, MBF, POINTER(POINTER(IINST)), POINTER(ULONG)]
161 BSCGetDefArray = _libraries['msbsc70.dll'].BSCGetDefArray
162 BSCGetDefArray.restype = BOOL
163 BSCGetDefArray.argtypes = [POINTER(Bsc), IINST, POINTER(POINTER(IREF)), POINTER(ULONG)]
164 BSCGetRefArray = _libraries['msbsc70.dll'].BSCGetRefArray
165 BSCGetRefArray.restype = BOOL
166 BSCGetRefArray.argtypes = [POINTER(Bsc), IINST, POINTER(POINTER(IREF)), POINTER(ULONG)]
167 BSCGetModuleContents = _libraries['msbsc70.dll'].BSCGetModuleContents
168 BSCGetModuleContents.restype = BOOL
169 BSCGetModuleContents.argtypes = [POINTER(Bsc), IMOD, MBF, POINTER(POINTER(IINST)), POINTER(ULONG)]
170 BSCGetModuleByName = _libraries['msbsc70.dll'].BSCGetModuleByName
171 BSCGetModuleByName.restype = BOOL
172 BSCGetModuleByName.argtypes = [POINTER(Bsc), SZ, POINTER(IMOD)]
173 BSCGetAllModulesArray = _libraries['msbsc70.dll'].BSCGetAllModulesArray
174 BSCGetAllModulesArray.restype = BOOL
175 BSCGetAllModulesArray.argtypes = [POINTER(Bsc), POINTER(POINTER(IMOD)), POINTER(ULONG)]
176 BSCDisposeArray = _libraries['msbsc70.dll'].BSCDisposeArray
177 BSCDisposeArray.restype = None
178 BSCDisposeArray.argtypes = [POINTER(Bsc), c_void_p]
179 BSCFormatDname = _libraries['msbsc70.dll'].BSCFormatDname
180 BSCFormatDname.restype = SZ
181 BSCFormatDname.argtypes = [POINTER(Bsc), SZ]
182 BSCFInstFilter = _libraries['msbsc70.dll'].BSCFInstFilter
183 BSCFInstFilter.restype = BOOL
184 BSCFInstFilter.argtypes = [POINTER(Bsc), IINST, MBF]
185 BSCIinstFrIref = _libraries['msbsc70.dll'].BSCIinstFrIref
186 BSCIinstFrIref.restype = IINST
187 BSCIinstFrIref.argtypes = [POINTER(Bsc), IREF]
188 BSCIinstFrIdef = _libraries['msbsc70.dll'].BSCIinstFrIdef
189 BSCIinstFrIdef.restype = IINST
190 BSCIinstFrIdef.argtypes = [POINTER(Bsc), IDEF]
191 BSCIinstContextIref = _libraries['msbsc70.dll'].BSCIinstContextIref
192 BSCIinstContextIref.restype = IINST
193 BSCIinstContextIref.argtypes = [POINTER(Bsc), IREF]
194 BSCGetStatistics = _libraries['msbsc70.dll'].BSCGetStatistics
195 BSCGetStatistics.restype = BOOL
196 BSCGetStatistics.argtypes = [POINTER(Bsc), POINTER(BSC_STAT)]
197 BSCGetModuleStatistics = _libraries['msbsc70.dll'].BSCGetModuleStatistics
198 BSCGetModuleStatistics.restype = BOOL
199 BSCGetModuleStatistics.argtypes = [POINTER(Bsc), IMOD, POINTER(BSC_STAT)]
200 BSCFCaseSensitive = _libraries['msbsc70.dll'].BSCFCaseSensitive
201 BSCFCaseSensitive.restype = BOOL
202 BSCFCaseSensitive.argtypes = [POINTER(Bsc)]
203 BSCSetCaseSensitivity = _libraries['msbsc70.dll'].BSCSetCaseSensitivity
204 BSCSetCaseSensitivity.restype = BOOL
205 BSCSetCaseSensitivity.argtypes = [POINTER(Bsc), BOOL]
206 BSCGetAllGlobalsArray = _libraries['msbsc70.dll'].BSCGetAllGlobalsArray
207 BSCGetAllGlobalsArray.restype = BOOL
208 BSCGetAllGlobalsArray.argtypes = [POINTER(Bsc), MBF, POINTER(POINTER(IINST)), POINTER(ULONG)]
209 BSCSzFrAtr2 = _libraries['msbsc70.dll'].BSCSzFrAtr2
210 BSCSzFrAtr2.restype = SZ
211 BSCSzFrAtr2.argtypes = [POINTER(Bsc), ATR32]
212 BSCIinstInfo2 = _libraries['msbsc70.dll'].BSCIinstInfo2
213 BSCIinstInfo2.restype = BOOL
214 BSCIinstInfo2.argtypes = [POINTER(Bsc), IINST, POINTER(SZ), POINTER(TYP), POINTER(ATR32)]
215 BSCGetIinstByvalue2 = _libraries['msbsc70.dll'].BSCGetIinstByvalue2
216 BSCGetIinstByvalue2.restype = BOOL
217 BSCGetIinstByvalue2.argtypes = [POINTER(Bsc), SZ, TYP, ATR32, POINTER(IINST)]
218 OpenBSCQuery = _libraries['msbsc70.dll'].OpenBSCQuery
219 OpenBSCQuery.restype = BOOL
220 OpenBSCQuery.argtypes = [POINTER(Bsc)]
221 CloseBSCQuery = _libraries['msbsc70.dll'].CloseBSCQuery
222 CloseBSCQuery.restype = BOOL
223 CloseBSCQuery.argtypes = []
224 BOB = ULONG
225 InitBSCQuery = _libraries['msbsc70.dll'].InitBSCQuery
226 InitBSCQuery.restype = BOOL
227 InitBSCQuery.argtypes = [QY, BOB]
228 BobNext = _libraries['msbsc70.dll'].BobNext
229 BobNext.restype = BOB
230 BobNext.argtypes = []
231 BobFrName = _libraries['msbsc70.dll'].BobFrName
232 BobFrName.restype = BOB
233 BobFrName.argtypes = [SZ]
234 LszNameFrBob = _libraries['msbsc70.dll'].LszNameFrBob
235 LszNameFrBob.restype = SZ
236 LszNameFrBob.argtypes = [BOB]
237 CLS = USHORT
240 - class MBF(utils.enum):
255
256 - class TYPES(utils.enum):
274
288
317
318 @utils.cached
321
368
369
370 @utils.cached
372 definitions_len = ULONG(0)
373 definitions_ids = pointer( IDEF() )
374
375 if not BSCGetDefArray( self.__bsc, self.inst_id, byref( definitions_ids ), byref( definitions_len ) ):
376 raise RuntimeError( "Unable to call BSCGetDefArray" )
377
378 definitions = map( lambda i: definition_t( definitions_ids[i], self.__bsc )
379 , range( definitions_len.value ) )
380
381 BSCDisposeArray( self.__bsc, definitions_ids )
382 return definitions
383
384 @utils.cached
386 instances_len = ULONG(0)
387 instances_ids = pointer( IINST() )
388
389 if not BSCGetMembersArray( self.__bsc, self.inst_id, enums.MBF.ALL, byref( instances_ids ), byref( instances_len ) ):
390 raise RuntimeError( "Unable to call BSCGetMembersArray" )
391
392 instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] )
393 , range( instances_len.value ) )
394
395 BSCDisposeArray( self.__bsc, instances_ids )
396 return instances
397
398 @utils.cached
400 instances_len = ULONG(0)
401 instances_ids = pointer( IINST() )
402
403 if not BSCGetUsesArray( self.__bsc, self.inst_id, enums.MBF.ALL, byref( instances_ids ), byref( instances_len ) ):
404 raise RuntimeError( "Unable to call BSCGetUsesArray" )
405
406 instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] )
407 , range( instances_len.value ) )
408
409 BSCDisposeArray( self.__bsc, instances_ids )
410 return instances
411
412 @utils.cached
414 instances_len = ULONG(0)
415 instances_ids = pointer( IINST() )
416
417 if not BSCGetBaseArray( self.__bsc, self.inst_id, byref( instances_ids ), byref( instances_len ) ):
418 raise RuntimeError( "Unable to call BSCGetBaseArray" )
419
420 instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] )
421 , range( instances_len.value ) )
422
423 BSCDisposeArray( self.__bsc, instances_ids )
424 return instances
425
426 @utils.cached
428 instances_len = ULONG(0)
429 instances_ids = pointer( IINST() )
430
431 if not BSCGetDervArray( self.__bsc, self.inst_id, byref( instances_ids ), byref( instances_len ) ):
432 raise RuntimeError( "Unable to call BSCGetDervArray" )
433
434 instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] )
435 , range( instances_len.value ) )
436
437 BSCDisposeArray( self.__bsc, instances_ids )
438 return instances
439
441
443 self.__bsc = bsc
444 self.__mod_id = mod_id
445
446 @property
449
450 @utils.cached
455
456 @utils.cached
458 instances_len = ULONG(0)
459 instances_ids = pointer( IINST() )
460
461 if not BSCGetModuleContents( self.__bsc, self.mod_id, enums.MBF.ALL, byref( instances_ids ), byref( instances_len ) ):
462 raise RuntimeError( "Unable to call BSCGetModuleContents" )
463
464 instances = map( lambda i: self.__bsc.create_instance( instances_ids[i] )
465 , range( instances_len.value ) )
466
467 BSCDisposeArray( self.__bsc, instances_ids )
468 return instances
469
472 self.logger = utils.loggers.pdb_reader
473 self.logger.setLevel(logging.INFO)
474
475 self.__bsc_file = bsc_file
476 self.__bsc = pointer( Bsc() )
477 if not BSCOpen( self.__bsc_file, byref( self.__bsc ) ):
478 raise RuntimeError( "Unable to open bsc file '%s'" % self.__bsc_file )
479
480 self.__instances_cache = {}
481 self.__bsc.create_instance = lambda inst_id: self.__create_instance( inst_id )
482
484 try:
485 return self.__instances_cache[ inst_id ]
486 except KeyError:
487 inst = instance_t( inst_id, self.__bsc )
488 self.__instances_cache[ inst_id ] = inst
489 return inst
490
500
501 @utils.cached
504
505 @utils.cached
507 module_ids = pointer( IMOD() )
508 module_len = ULONG()
509 bs = BSC_STAT()
510
511 if not BSCGetAllModulesArray( self.__bsc, module_ids, byref(module_len) ):
512 raise RuntimeError( "Unable to load all modules" )
513
514 modules = map( lambda i: module_t( module_ids[i], self.__bsc )
515 , range( module_len.value ) )
516
517 BSCDisposeArray( self.__bsc, module_ids )
518
519 return modules
520
526
528 for m in self.files:
529 if file_name and m.path != file_name:
530 continue
531 print 'File: ', m.path
532 if m.instances:
533 print '\tInstances:'
534 for inst in m.instances:
535 print '\t\t', str(inst)
536 if inst.definitions:
537 print '\t\t\tDefinitions:'
538 for definition in inst.definitions:
539 print '\t\t\t\t', str( definition )
540 if inst.members:
541 print '\t\t\tMembers:'
542 for member in inst.members:
543 print '\t\t\t\t', str( member )
544 if inst.used_symbols:
545 print '\t\t\tUsed symbols:'
546 for used_symbol in inst.used_symbols:
547 print '\t\t\t\t', str( used_symbol )
548 if inst.base_classes:
549 print '\t\t\tBase classes:'
550 for base_class in inst.base_classes:
551 print '\t\t\t\t', str( base_class )
552 if inst.derived_classes:
553 print '\t\t\tDerived classes:'
554 for derived_class in inst.derived_classes:
555 print '\t\t\t\t', str( derived_class )
556
558 if self.__bsc:
559 BSCClose( self.__bsc )
560
561 if __name__ == '__main__':
562 control_bsc = r'xxx.bsc'
563 reader = bsc_reader_t( control_bsc )
564 reader.print_stat()
565 print 'is_case_sensitive', reader.is_case_sensitive
566
567
568 reader.print_classes( )
569