if (fs != null)
Close ();
fs = new FileStream (filename, FileMode.Open, FileAccess.Read, FileShare.Read);
+ blockNo = 0;
}
internal void Close ()
if (fs != null) {
fs.Close ();
fs = null;
- blockNo = 0;
}
}
- internal bool ReadFirstBlock ()
+ internal void ReadFirstBlock ()
+ {
+ int error = ProcessFirstBlock ();
+ if (error != 0) {
+ string msg = Locale.GetText ("Cannot sign non PE files, e.g. .CAB or .MSI files (error {0}).",
+ error);
+ throw new NotSupportedException (msg);
+ }
+ }
+
+ internal int ProcessFirstBlock ()
{
if (fs == null)
- return false;
+ return 1;
fs.Position = 0;
// read first block - it will include (100% sure)
blockLength = fs.Read (fileblock, 0, fileblock.Length);
blockNo = 1;
if (blockLength < 64)
- return false; // invalid PE file
+ return 2; // invalid PE file
// 1. Validate the MZ header informations
// 1.1. Check for magic MZ at start of header
if (BitConverterLE.ToUInt16 (fileblock, 0) != 0x5A4D)
- return false;
+ return 3;
// 1.2. Find the offset of the PE header
peOffset = BitConverterLE.ToInt32 (fileblock, 60);
throw new NotSupportedException (msg);
}
if (peOffset > fs.Length)
- return false;
+ return 4;
// 2. Read between DOS header and first part of PE header
// 2.1. Check for magic PE at start of header
// PE - NT header ('P' 'E' 0x00 0x00)
if (BitConverterLE.ToUInt32 (fileblock, peOffset) != 0x4550)
- return false;
+ return 5;
// 2.2. Locate IMAGE_DIRECTORY_ENTRY_SECURITY (offset and size)
dirSecurityOffset = BitConverterLE.ToInt32 (fileblock, peOffset + 152);
// (otherwise the signature won't work on MS and we don't want to support COFF for that)
coffSymbolTableOffset = BitConverterLE.ToInt32 (fileblock, peOffset + 12);
- return true;
+ return 0;
}
internal byte[] GetSecurityEntry ()
+2008-05-16 Sebastien Pouliot <sebastien@ximian.com>
+
+ * AuthenticodeFormatter.cs: Throw an NotSupportedException if we're
+ trying to sign a non-PE (portable executable) file. We do not support
+ signing CAB and MSI files (nor does mono generates them).
+ [Partial fix for #388602, kept open as Enhancement]
+
2008-01-10 Sebastien Pouliot <sebastien@ximian.com>
* AuthenticodeDeformatter.cs: Use RSAManaged and the new overloaded