在VBA解析中已经介绍,VBAProject无论是03版本的还是07版本的,都是一个数据流。
所以,VBAProject就是一个特殊的复合文档,解析VBAProject就是解析一个复合文档。
在解析的时候,可以进一步去判断是否有dir流,这样就能够知道是不是一个VBAProject,而且也能够判断是03版本的还是07版本的:
新建一个类CVBAProject:
Private cf As CCompoundFile
Private PrePath As String '前缀路径,03版本是Root Entry\_VBA_PROJECT_CUR
' 07版本是Root Entry\
Function Parse(ir As IReadWrite) As String
Dim ret As String
ret = cf.Parse(ir)
If VBA.Len(ret) Then
Parse = ret
Exit Function
End If
Dim b() As Byte
ret = cf.GetStream(PrePath & "VBA\dir", b)
If VBA.Len(ret) Then
'继续尝试03版本的路径
PrePath = "Root Entry\_VBA_PROJECT_CUR\"
ret = cf.GetStream(PrePath & "VBA\dir", b)
If VBA.Len(ret) Then
Parse = "CVBAProject: 没有找到VBA\dir流"
Exit Function
End If
End If
'run length encoding解码dir流
Dim cr As CRLE
Set cr = New CRLE
ret = cr.UnCompress(b, b)
If VBA.Len(ret) Then
Parse = ret
Exit Function
End If
Set cr = Nothing
'解析dir流
Dim cd As CDir
Set cd = New CDir
ret = cd.GetModuleInfo(b, ModuleInfo_)
If VBA.Len(ret) Then
Parse = ret
Exit Function
End If
Set cd = Nothing
End Function
解析代码很简单,主要的处理过程都在CCompoundFile类中,具体查看VBA解析复合文档相关文章。
CRLE类和CDir后面再解析。