diff options
-rw-r--r-- | plugins/PluginUpdater/src/checksum.cpp | 33 | ||||
-rw-r--r-- | tools/checksum/checksum.cpp | 26 |
2 files changed, 43 insertions, 16 deletions
diff --git a/plugins/PluginUpdater/src/checksum.cpp b/plugins/PluginUpdater/src/checksum.cpp index 889696c4b0..2a1fd1b5a9 100644 --- a/plugins/PluginUpdater/src/checksum.cpp +++ b/plugins/PluginUpdater/src/checksum.cpp @@ -17,6 +17,7 @@ #define DEBUG_REALLOCS 1
int debug = 0;
+DWORD dwVersion = 0;
struct MFileMapping
{
@@ -48,24 +49,29 @@ struct MFileMapping }
};
-static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase);
+static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase, DWORD dwType);
-static void PatchResourceEntry(PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE, PBYTE pBase)
+static void PatchResourceEntry(PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE, PBYTE pBase, DWORD dwType)
{
if (pIRDE->DataIsDirectory)
- PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY(pBase + pIRDE->OffsetToDirectory), pBase);
+ PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY(pBase + pIRDE->OffsetToDirectory), pBase, dwType == 0 ? pIRDE->Name : dwType);
+ else if (dwType == 16) {
+ PIMAGE_RESOURCE_DATA_ENTRY pItem = PIMAGE_RESOURCE_DATA_ENTRY(pBase + pIRDE->OffsetToData);
+ dwVersion = pItem->OffsetToData;
+ }
}
-static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase)
+static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase, DWORD dwType)
{
+ UINT i;
pIRD->TimeDateStamp = 0;
PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE = PIMAGE_RESOURCE_DIRECTORY_ENTRY(pIRD + 1);
- for (UINT i = 0; i < pIRD->NumberOfNamedEntries; i++, pIRDE++)
- PatchResourceEntry(pIRDE, pBase);
+ for (i = 0; i < pIRD->NumberOfNamedEntries; i++, pIRDE++)
+ PatchResourceEntry(pIRDE, pBase, dwType);
- for (UINT i = 0; i < pIRD->NumberOfIdEntries; i++, pIRDE++)
- PatchResourceEntry(pIRDE, pBase);
+ for (i = 0; i < pIRD->NumberOfIdEntries; i++, pIRDE++)
+ PatchResourceEntry(pIRDE, pBase, dwType);
}
__forceinline bool Contains(PIMAGE_SECTION_HEADER pISH, DWORD address, DWORD size = 0)
@@ -190,9 +196,18 @@ LBL_NotPE: // patch resources
if (resSize > 0 && Contains(pISH, resAddr, resSize)) {
+ dwVersion = 0;
+
DWORD shift = resAddr - pISH->VirtualAddress + pISH->PointerToRawData;
IMAGE_RESOURCE_DIRECTORY *pIRD = (IMAGE_RESOURCE_DIRECTORY*)(map.ptr + shift);
- PatchResourcesDirectory(pIRD, map.ptr + shift);
+ PatchResourcesDirectory(pIRD, map.ptr + shift, 0);
+
+ // patch version
+ if (dwVersion) {
+ shift = dwVersion - pISH->VirtualAddress + pISH->PointerToRawData;
+ VS_FIXEDFILEINFO *pVersion = (VS_FIXEDFILEINFO*)(map.ptr + shift);
+ pVersion->dwProductVersionLS = pVersion->dwProductVersionMS = 0;
+ }
}
// rebase to zero address
diff --git a/tools/checksum/checksum.cpp b/tools/checksum/checksum.cpp index a3aefec80f..affaea11a4 100644 --- a/tools/checksum/checksum.cpp +++ b/tools/checksum/checksum.cpp @@ -16,26 +16,31 @@ #define RESULT_NONE 100
int debug = 0;
+DWORD dwVersion = 0;
-static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase);
+static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase, DWORD dwType);
-static void PatchResourceEntry(PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE, PBYTE pBase)
+static void PatchResourceEntry(PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE, PBYTE pBase, DWORD dwType)
{
if (pIRDE->DataIsDirectory)
- PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY(pBase + pIRDE->OffsetToDirectory), pBase);
+ PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY(pBase + pIRDE->OffsetToDirectory), pBase, dwType == 0 ? pIRDE->Name : dwType);
+ else if (dwType == 16) {
+ PIMAGE_RESOURCE_DATA_ENTRY pItem = PIMAGE_RESOURCE_DATA_ENTRY(pBase + pIRDE->OffsetToData);
+ dwVersion = pItem->OffsetToData;
+ }
}
-static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase)
+static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase, DWORD dwType)
{
UINT i;
pIRD->TimeDateStamp = 0;
PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE = PIMAGE_RESOURCE_DIRECTORY_ENTRY(pIRD + 1);
for (i = 0; i < pIRD->NumberOfNamedEntries; i++, pIRDE++)
- PatchResourceEntry(pIRDE, pBase);
+ PatchResourceEntry(pIRDE, pBase, dwType);
for (i = 0; i < pIRD->NumberOfIdEntries; i++, pIRDE++)
- PatchResourceEntry(pIRDE, pBase);
+ PatchResourceEntry(pIRDE, pBase, dwType);
}
__forceinline bool Contains(PIMAGE_SECTION_HEADER pISH, DWORD address, DWORD size = 0)
@@ -214,7 +219,14 @@ int PEChecksum(wchar_t *filename, BYTE digest[16]) if (resSize > 0 && resAddr >= pISH->VirtualAddress && resAddr + resSize <= pISH->VirtualAddress + pISH->SizeOfRawData) {
DWORD shift = resAddr - pISH->VirtualAddress + pISH->PointerToRawData;
IMAGE_RESOURCE_DIRECTORY *pIRD = (IMAGE_RESOURCE_DIRECTORY*)(ptr + shift);
- PatchResourcesDirectory(pIRD, ptr + shift);
+ PatchResourcesDirectory(pIRD, ptr + shift, 0);
+
+ // patch version
+ if (dwVersion) {
+ shift = dwVersion - pISH->VirtualAddress + pISH->PointerToRawData;
+ VS_FIXEDFILEINFO *pVersion = (VS_FIXEDFILEINFO*)(ptr + shift);
+ pVersion->dwProductVersionLS = pVersion->dwProductVersionMS = 0;
+ }
}
// rebase to zero address
|