summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorhg <hg@oosvn01.>2009-10-08 16:03:52 +0000
committerhg <hg@oosvn01.>2009-10-08 16:03:52 +0000
commita2c13d415f8ea659279d0e863924f5a01f45503a (patch)
tree009e76ad7bf6e26412022bcd7fe596ea5a14ffec /tools
parente0b99ef4ddf793db58e34378c748441ee982447f (diff)
parent15929d6d5da7c38a6cbe7aabcd56ed1a5a23faf6 (diff)
merge with m55
Diffstat (limited to 'tools')
-rw-r--r--tools/bootstrp/md5.cxx64
-rw-r--r--tools/source/fsys/urlobj.cxx9
-rw-r--r--tools/workben/urltest.cxx19
3 files changed, 90 insertions, 2 deletions
diff --git a/tools/bootstrp/md5.cxx b/tools/bootstrp/md5.cxx
index bca89725fac2..a234f278cc9d 100644
--- a/tools/bootstrp/md5.cxx
+++ b/tools/bootstrp/md5.cxx
@@ -44,8 +44,62 @@
#define FILE_OPEN_READ "r"
#endif
+// Extended calc_md5_checksum to recognize Windows executables and libraries. To
+// create the same md5 checksum for a (code/data) identical file it ignores a different
+// date and header checksum. Please see crashrep/source/win32/soreport.cpp
+// where the same method is also used. The crash reporter uses the MD5
+// checksums to transfer them to the crash database. You have to make sure that both
+// methods use the same algorithm otherwise there could be problems with stack reports.
+
+void normalize_pe_image(sal_uInt8* buffer, size_t nBufferSize)
+{
+ const int OFFSET_PE_OFFSET = 0x3c;
+ const int OFFSET_COFF_TIMEDATESTAMP = 4;
+ const int PE_SIGNATURE_SIZE = 4;
+ const int COFFHEADER_SIZE = 20;
+ const int OFFSET_PE_OPTIONALHEADER_CHECKSUM = 64;
+
+ // Check the header part of the file buffer
+ if (buffer[0] == sal_uInt8('M') && buffer[1] == sal_uInt8('Z'))
+ {
+ unsigned long PEHeaderOffset = (long)buffer[OFFSET_PE_OFFSET];
+ if (PEHeaderOffset < nBufferSize-4)
+ {
+ if ( buffer[PEHeaderOffset+0] == sal_uInt8('P') &&
+ buffer[PEHeaderOffset+1] == sal_uInt8('E') &&
+ buffer[PEHeaderOffset+2] == 0 &&
+ buffer[PEHeaderOffset+3] == 0 )
+ {
+ PEHeaderOffset += PE_SIGNATURE_SIZE;
+ if (PEHeaderOffset+OFFSET_COFF_TIMEDATESTAMP < nBufferSize-4)
+ {
+ // Set timedatestamp and checksum fields to a normalized
+ // value to enforce the same MD5 checksum for identical
+ // Windows executables/libraries.
+ buffer[PEHeaderOffset+OFFSET_COFF_TIMEDATESTAMP+0] = 0;
+ buffer[PEHeaderOffset+OFFSET_COFF_TIMEDATESTAMP+1] = 0;
+ buffer[PEHeaderOffset+OFFSET_COFF_TIMEDATESTAMP+2] = 0;
+ buffer[PEHeaderOffset+OFFSET_COFF_TIMEDATESTAMP+3] = 0;
+ }
+
+ if (PEHeaderOffset+COFFHEADER_SIZE+OFFSET_PE_OPTIONALHEADER_CHECKSUM < nBufferSize-4)
+ {
+ // Set checksum to a normalized value
+ buffer[PEHeaderOffset+COFFHEADER_SIZE+OFFSET_PE_OPTIONALHEADER_CHECKSUM] = 0;
+ buffer[PEHeaderOffset+COFFHEADER_SIZE+OFFSET_PE_OPTIONALHEADER_CHECKSUM+1] = 0;
+ buffer[PEHeaderOffset+COFFHEADER_SIZE+OFFSET_PE_OPTIONALHEADER_CHECKSUM+2] = 0;
+ buffer[PEHeaderOffset+COFFHEADER_SIZE+OFFSET_PE_OPTIONALHEADER_CHECKSUM+3] = 0;
+ }
+ }
+ }
+ }
+}
+
rtlDigestError calc_md5_checksum( const char *filename, ByteString &aChecksum )
{
+ const size_t BUFFER_SIZE = 0x1000;
+ const size_t MINIMAL_SIZE = 512;
+
sal_uInt8 checksum[RTL_DIGEST_LENGTH_MD5];
rtlDigestError error = rtl_Digest_E_None;
@@ -58,11 +112,19 @@ rtlDigestError calc_md5_checksum( const char *filename, ByteString &aChecksum )
if ( digest )
{
size_t nBytesRead;
- sal_uInt8 buffer[0x1000];
+ sal_uInt8 buffer[BUFFER_SIZE];
+ bool bHeader(true);
while ( rtl_Digest_E_None == error &&
0 != (nBytesRead = fread( buffer, 1, sizeof(buffer), fp )) )
{
+ if (bHeader)
+ {
+ bHeader = false;
+ if (nBytesRead >= MINIMAL_SIZE && buffer[0] == sal_uInt8('M') && buffer[1] == sal_uInt8('Z') )
+ normalize_pe_image(buffer, nBytesRead);
+ }
+
error = rtl_digest_updateMD5( digest, buffer, nBytesRead );
}
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx
index e3484aee4e2d..2aff0d734bf6 100644
--- a/tools/source/fsys/urlobj.cxx
+++ b/tools/source/fsys/urlobj.cxx
@@ -1523,8 +1523,15 @@ bool INetURLObject::convertRelToAbs(rtl::OUString const & rTheRelURIRef,
else if (pEnd - q >= 2 && q[0] == '\\' && q[1] == '\\')
{
q += 2;
- if (scanDomain(q, pEnd) > 0 && (q == pEnd || *q == '\\'))
+ sal_Int32 n = rtl_ustr_indexOfChar_WithLength(
+ q, pEnd - q, '\\');
+ sal_Unicode const * qe = n == -1 ? pEnd : q + n;
+ if (parseHostOrNetBiosName(
+ q, qe, bOctets, ENCODE_ALL, RTL_TEXTENCODING_DONTKNOW,
+ true, NULL))
+ {
bFSys = true; // 1st
+ }
}
if (bFSys)
{
diff --git a/tools/workben/urltest.cxx b/tools/workben/urltest.cxx
index 542297eb4bd6..a232f8ebdd93 100644
--- a/tools/workben/urltest.cxx
+++ b/tools/workben/urltest.cxx
@@ -799,6 +799,25 @@ main()
bSuccess = false;
}
}
+ {
+ bool bWasAbsolute;
+ if (!rtl::OUString(INetURLObject(rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "file:///"))).
+ smartRel2Abs(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "\\\\unc_host\\path")),
+ bWasAbsolute).
+ GetMainURL(INetURLObject::NO_DECODE)).
+ equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM("file://unc_host/path"))
+ || !bWasAbsolute)
+ {
+ printf("BAD smartRel2Abs(\"\\\\unc_host\\path\")\n");
+ bSuccess = false;
+ }
+ }
}
if (true)