简体   繁体   English

检测密码保护的C / C ++中的MS Office文件

[英]Detection password protected MS Office files in C/C++

How can I detect password protected Ms Office Files? 如何检测受密码保护的Ms Office文件? I'm using C/C++ on Linux. 我在Linux上使用C / C ++。

If the files are in Office 2007 format (eg .docx), then their internal storage is either: 如果文件是Office 2007格式(例如.docx),那么它们的内部存储是:

1) A zip file of xml docs (if it's not password protected) 1)xml docs的zip文件(如果没有密码保护)

2) The old style compound file format (if it IS password protected). 2)旧式复合文件格式(如果它受密码保护)。

Therefore you could probably do something like this: 因此你可能会做这样的事情:

1) Check the first few bytes of the file 1)检查文件的前几个字节

2) If it's a zip file (non password protected), it'll start with 0x50 0x4b 0x03 0x04. 2)如果它是一个zip文件(非密码保护),它将以0x50 0x4b 0x03 0x04开头。

3) If it's not a zip file, then it's probably password protected. 3)如果它不是zip文件,那么它可能是密码保护的。 It will start with a different binary signature (eg Word 2007 docs start with 0xd0 0xcf 0x11 0xe0 in this case) 它将以不同的二进制签名开始(例如,Word 2007 docs以0xd0 0xcf 0x11 0xe0开头)

Basically, if it's a new .docx or .xlsx, and it DOESN'T start with the zip signature of 0x50 0x4b 0x03 0x04, it's probably password protected. 基本上,如果它是一个新的.docx或.xlsx,并且它不以0x50 0x4b 0x03 0x04的zip签名开头,它可能是密码保护的。

For other versions of MS Office, it's a bit trickier... 对于其他版本的MS Office,它有点棘手......

The file signature of the encrypted file should be different. 加密文件的文件签名应该不同。 for an un-encrypted it is 50 4B 03 04 The first 4 bytes of an encrypted are D0 CF 11 E0 (at least for a docx, might be different for excel,ppt,... 对于未加密的,它是50 4B 03 04加密的前4个字节是D0 CF 11 E0(至少对于docx,对于excel,ppt,......可能有所不同)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM