以编程方式确定Excel文件(.xls)是否包含宏

时间:2021-10-28 07:11:58

Is there any way to programmatically determine if an .xls contains macros, without actually opening it in Excel?

有没有办法以编程方式确定.xls是否包含宏,而不是在Excel中实际打开它?

Also are there any methods to examine which certificate (including timestamp cert) these macros are signed with? Again without using Excel.

还有什么方法可以检查这些宏签名的证书(包括时间戳证书)?再次不使用Excel。

I'm wondering in particular if there are any strings that always show up in the raw data of an Excel file when macros are present.

我特别想知道当宏存在时,是否有任何字符串总是出现在Excel文件的原始数据中。

2 个解决方案

#1


2  

Yes, you can open the .xls file as a compound document file and check whether is contains a VBA folder and streams containing VBA code.

是的,您可以将.xls文件作为复合文档文件打开,并检查是否包含VBA文件夹和包含VBA代码的流。

Sample code is available in this CodeProject article:

此CodeProject文章中提供了示例代码:

Another OLE Doc Viewer but with editing facility

另一个OLE Doc Viewer但具有编辑功能

The certificate information is stored in the DocumentSummaryInformation stream. If you want to read out the information from there you should dig into the file format specifications available from Microsoft:

证书信息存储在DocumentSummaryInformation流中。如果您想从那里读出信息,您应该深入了解Microsoft提供的文件格式规范:

[MS-OSHARED]: Office Common Data Types and Objects Structure Specification

[MS-OSHARED]:Office公共数据类型和对象结构规范

[MS-OFFCRYPTO]: Office Document Cryptography Structure Specification

[MS-OFFCRYPTO]:Office文档加密结构规范

#2


0  

An xls file containing a macro should contain a string looking something like

包含宏的xls文件应该包含类似的字符串

Keyboard Shortcut:

Don't know if this is a surefire solution though

不知道这是否是一个万无一失的解决方案

#1


2  

Yes, you can open the .xls file as a compound document file and check whether is contains a VBA folder and streams containing VBA code.

是的,您可以将.xls文件作为复合文档文件打开,并检查是否包含VBA文件夹和包含VBA代码的流。

Sample code is available in this CodeProject article:

此CodeProject文章中提供了示例代码:

Another OLE Doc Viewer but with editing facility

另一个OLE Doc Viewer但具有编辑功能

The certificate information is stored in the DocumentSummaryInformation stream. If you want to read out the information from there you should dig into the file format specifications available from Microsoft:

证书信息存储在DocumentSummaryInformation流中。如果您想从那里读出信息,您应该深入了解Microsoft提供的文件格式规范:

[MS-OSHARED]: Office Common Data Types and Objects Structure Specification

[MS-OSHARED]:Office公共数据类型和对象结构规范

[MS-OFFCRYPTO]: Office Document Cryptography Structure Specification

[MS-OFFCRYPTO]:Office文档加密结构规范

#2


0  

An xls file containing a macro should contain a string looking something like

包含宏的xls文件应该包含类似的字符串

Keyboard Shortcut:

Don't know if this is a surefire solution though

不知道这是否是一个万无一失的解决方案