Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Determine If An Excel File (.xls) Contains Macros

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

Also are there any methods to examine which certificate (including timestamp cert) these macros are signed with? Again without using 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.

like image 630
Gkakk McJkakk Avatar asked Jun 09 '10 13:06

Gkakk McJkakk


People also ask

How do I know if an Excel file has macros?

Open Excel 2007/2010/2013; go to View tab, click it and you will find the function Macros arranged in the Macros group. Click the arrow under Macros, and you can manage macro performances easily.

Can XLS files contain macros?

Macros can be stored inside xlsm file. If the Excel file extension is . xlsm, the file may contain macros. But the old Excel file format xls may or may not contain macros.

How do I find a macro script in Excel?

On the Developer tab, in the Code group, click Macros. In the Macro name box, click the macro that you want to edit. Click Edit.


1 Answers

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.

Sample code is available in this CodeProject article:

Another OLE Doc Viewer but with editing facility

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:

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

[MS-OFFCRYPTO]: Office Document Cryptography Structure Specification

like image 57
Dirk Vollmar Avatar answered Sep 26 '22 02:09

Dirk Vollmar