1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: md5.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_desktop.hxx"
35 #define WIN32_LEAN_AND_MEAN
37 #pragma warning(push, 1)
48 #include "sal/config.h"
49 #include "tools/pathutils.hxx"
51 #define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
52 #define MY_STRING(s) (s), MY_LENGTH(s)
54 const int FORMAT_MESSAGE_SIZE
= 4096;
55 const DWORD PE_Signature
= 0x00004550;
56 const DWORD BASEVIRTUALADDRESS
= 0x10000000;
61 bool IsValidHandle( HANDLE handle
)
63 return ((NULL
!= handle
) && (INVALID_HANDLE_VALUE
!= handle
));
70 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
71 GetLastError(), 0, reinterpret_cast< LPWSTR
>(&buf
), 0, NULL
);
72 MessageBoxW(NULL
, buf
, NULL
, MB_OK
| MB_ICONERROR
);
74 TerminateProcess(GetCurrentProcess(), 255);
77 bool rebaseImage( wchar_t* pszFilePath
, ULONG nNewImageBase
)
80 ULONG_PTR lpOldImageBase
;
82 ULONG_PTR lpNewImageBase
= nNewImageBase
;
83 ULONG ulDateTimeStamp
= 0;
86 char cszFilePath
[_MAX_PATH
+1] = {0};
87 int nResult
= WideCharToMultiByte(CP_ACP
, 0, pszFilePath
, -1, cszFilePath
, _MAX_PATH
, NULL
, NULL
);
91 BOOL bResult
= ReBaseImage(
108 wchar_t* getBrandPath(wchar_t * path
)
110 DWORD n
= GetModuleFileNameW(NULL
, path
, MAX_PATH
);
111 if (n
== 0 || n
>= MAX_PATH
) {
114 return tools::filename(path
);
117 void rebaseImagesInFolder( wchar_t* pszFolder
, DWORD nNewImageBase
)
119 wchar_t szPattern
[MAX_PATH
];
120 wchar_t *lpLastSlash
= wcsrchr( pszFolder
, '\\' );
123 size_t len
= lpLastSlash
- pszFolder
+ 1;
124 wcsncpy( szPattern
, pszFolder
, len
);
125 wcsncpy( szPattern
+ len
, TEXT("*.dll"), sizeof(szPattern
)/sizeof(szPattern
[0]) - len
);
128 WIN32_FIND_DATA aFindFileData
;
129 HANDLE hFind
= FindFirstFile( szPattern
, &aFindFileData
);
131 if ( IsValidHandle(hFind
) )
133 BOOL fSuccess
= false;
137 wchar_t szLibFilePath
[MAX_PATH
];
138 wchar_t *lpLastSlash
= wcsrchr( pszFolder
, '\\' );
141 size_t len
= lpLastSlash
- pszFolder
+ 1;
142 wcsncpy( szLibFilePath
, pszFolder
, len
);
143 wcsncpy( szLibFilePath
+ len
, aFindFileData
.cFileName
, sizeof(szLibFilePath
)/sizeof(szLibFilePath
[0]) - len
);
146 rebaseImage( szLibFilePath
, nNewImageBase
);
147 fSuccess
= FindNextFile( hFind
, &aFindFileData
);
157 extern "C" int APIENTRY
WinMain( HINSTANCE
, HINSTANCE
, LPSTR
, int )
159 wchar_t path
[MAX_PATH
];
161 wchar_t * pathEnd
= getBrandPath(path
);
163 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"")) == NULL
)
165 rebaseImagesInFolder(path
, BASEVIRTUALADDRESS
);
167 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"..\\basis-link")) == NULL
)
169 pathEnd
= tools::resolveLink(path
);
171 if ( pathEnd
== NULL
)
174 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"\\program\\")) == NULL
)
176 rebaseImagesInFolder(path
, BASEVIRTUALADDRESS
);
178 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"\\ure-link")) == NULL
)
180 pathEnd
= tools::resolveLink(path
);
182 if ( pathEnd
== NULL
)
185 if (tools::buildPath(path
, path
, pathEnd
, MY_STRING(L
"\\bin\\")) == NULL
)
187 rebaseImagesInFolder(path
, BASEVIRTUALADDRESS
);