diff options
author | George Hazan <george.hazan@gmail.com> | 2012-08-05 18:17:35 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-08-05 18:17:35 +0000 |
commit | 1d9eac7a1e91e9eacc33b00aa9340ff716bb2e57 (patch) | |
tree | 28130c84c50ac9a13fea0be521d485a863d3ea29 | |
parent | 5a20e63269ffb3904a130a327af66f271e738313 (diff) |
fix for delphi resource directory checking
git-svn-id: http://svn.miranda-ng.org/main/trunk@1365 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | tools/checksum/checksum.cpp | 375 |
1 files changed, 187 insertions, 188 deletions
diff --git a/tools/checksum/checksum.cpp b/tools/checksum/checksum.cpp index fa8e2e4c5a..e8658140ae 100644 --- a/tools/checksum/checksum.cpp +++ b/tools/checksum/checksum.cpp @@ -20,9 +20,28 @@ #define DEBUG_SECTIONS 1
#define DEBUG_REALLOCS 1
-
int debug = 0;
+static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, BYTE* pBase);
+
+static void PatchResourceEntry(PIMAGE_RESOURCE_DIRECTORY_ENTRY pIRDE, BYTE* pBase)
+{
+ if ( pIRDE->DataIsDirectory )
+ PatchResourcesDirectory( PIMAGE_RESOURCE_DIRECTORY(pBase + pIRDE->OffsetToDirectory), pBase);
+}
+
+static void PatchResourcesDirectory(PIMAGE_RESOURCE_DIRECTORY pIRD, PBYTE pBase)
+{
+ 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);
+
+ for ( i=0; i < pIRD->NumberOfIdEntries; i++, pIRDE++ )
+ PatchResourceEntry(pIRDE, pBase);
+}
int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] )
{
@@ -38,9 +57,8 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) hFile = CreateFile( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
- if ( hFile == INVALID_HANDLE_VALUE ) {
+ if ( hFile == INVALID_HANDLE_VALUE )
return RESULT_NOTFOUND;
- }
// check minimum and maximum size
filesize = GetFileSize( hFile, &hsize );
@@ -51,7 +69,7 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) return RESULT_INVALID;
}
- if ( filesize < sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS) )
+ if ( filesize < sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS))
{
CloseHandle( hFile );
return RESULT_NOTPE;
@@ -75,7 +93,7 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) if ( !pINTH)
res = RESULT_NOTPE;
else
- if ( (PBYTE)pINTH + sizeof(IMAGE_NT_HEADERS) >= ptr + filesize )
+ if ((PBYTE)pINTH + sizeof(IMAGE_NT_HEADERS) >= ptr + filesize )
res = RESULT_CORRUPTED;
else
if ( pINTH->Signature != IMAGE_NT_SIGNATURE )
@@ -85,21 +103,19 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) machine = pINTH->FileHeader.Machine;
#ifdef DEBUG_SECTIONS
- if ( debug )
- {
+ if ( debug ) {
switch(machine) {
-
case IMAGE_FILE_MACHINE_I386:
- _ftprintf( stderr, _T("Build: x86\n") );
+ _ftprintf( stderr, _T("Build: x86\n"));
break;
case IMAGE_FILE_MACHINE_AMD64:
- _ftprintf( stderr, _T("Build: x64\n") );
+ _ftprintf( stderr, _T("Build: x64\n"));
break;
case IMAGE_FILE_MACHINE_IA64:
- _ftprintf( stderr, _T("Build: IA64 :-)\n") );
+ _ftprintf( stderr, _T("Build: IA64 :-)\n"));
break;
default:
- _ftprintf( stderr, _T("Build: unknown :-(\n") );
+ _ftprintf( stderr, _T("Build: unknown :-(\n"));
break;
}
}
@@ -110,36 +126,34 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) res = RESULT_INVALID;
else
{
- PIMAGE_DATA_DIRECTORY pIDD = 0;
- PIMAGE_DEBUG_DIRECTORY pDBG = 0;
- DWORD dbgsize = 0;
- DWORD dbgvaddr = 0;
- DWORD expsize = 0;
- DWORD expvaddr = 0;
+ PIMAGE_DATA_DIRECTORY pIDD = 0;
+ PIMAGE_DEBUG_DIRECTORY pDBG = 0;
+ DWORD dbgSize = 0, dbgAddr = 0; // debug information
+ DWORD expSize = 0, expAddr = 0; // export table
+ DWORD resSize = 0, resAddr = 0; // resource directory
+ DWORD relocSize = 0, relocAddr = 0; // relocation table
PBYTE pRealloc = 0;
- DWORD realvaddr = 0;
- DWORD realsize = 0;
DWORD offset;
ULONGLONG base = 0;
// try to found correct offset independent of architectures
offset = pIDH->e_lfanew + pINTH->FileHeader.SizeOfOptionalHeader + sizeof(IMAGE_NT_HEADERS) - sizeof(IMAGE_OPTIONAL_HEADER);
- if ( ( machine == IMAGE_FILE_MACHINE_I386 ) &&
- ( pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER32) ) &&
- ( pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ) )
+ if (( machine == IMAGE_FILE_MACHINE_I386 ) &&
+ ( pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER32)) &&
+ ( pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC ))
{
- pIDD = (PIMAGE_DATA_DIRECTORY)( (PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory ) );
- base = *(DWORD*)( (PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS32, OptionalHeader.ImageBase ) );
+ pIDD = (PIMAGE_DATA_DIRECTORY)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory ));
+ base = *(DWORD*)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS32, OptionalHeader.ImageBase ));
}
else
- if ( ( machine == IMAGE_FILE_MACHINE_AMD64 ) &&
- ( pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER64) ) &&
- ( pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC ) )
+ if (( machine == IMAGE_FILE_MACHINE_AMD64 ) &&
+ ( pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER64)) &&
+ ( pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC ))
{
- pIDD = (PIMAGE_DATA_DIRECTORY)( (PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory ) );
- base = *(ULONGLONG*)( (PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS64, OptionalHeader.ImageBase ) );
+ pIDD = (PIMAGE_DATA_DIRECTORY)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory ));
+ base = *(ULONGLONG*)((PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS64, OptionalHeader.ImageBase ));
}
else
res = RESULT_CORRUPTED;
@@ -151,201 +165,191 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) if ( pIDD )
{
// Debugging information entry
- dbgvaddr = pIDD[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
- dbgsize = pIDD[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
+ dbgAddr = pIDD[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
+ dbgSize = pIDD[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
// Export information entry
- expvaddr = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
- expsize = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
+ expAddr = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
+ expSize = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
+
+ // Resource directory
+ resAddr = pIDD[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;
+ resSize = pIDD[IMAGE_DIRECTORY_ENTRY_RESOURCE].Size;
// Reallocation information entry
- realvaddr = pIDD[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
- realsize = pIDD[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
+ relocAddr = pIDD[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
+ relocSize = pIDD[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
}
- if ( dbgsize || expsize || realsize )
+ // verify image integrity
+ for (DWORD idx=0; idx < sections; idx++)
{
- DWORD idx = 0;
- PIMAGE_SECTION_HEADER pISH = 0;
+ PIMAGE_SECTION_HEADER pISH = (PIMAGE_SECTION_HEADER)( ptr + offset + idx * sizeof(IMAGE_SECTION_HEADER));
- while ( idx < sections )
+ if (((PBYTE)pISH + sizeof(IMAGE_SECTION_HEADER) > ptr + filesize ) || ( pISH->PointerToRawData + pISH->SizeOfRawData > filesize ))
{
- pISH = (PIMAGE_SECTION_HEADER)( ptr + offset + idx * sizeof(IMAGE_SECTION_HEADER) );
-
- if ( ( (PBYTE)pISH + sizeof(IMAGE_SECTION_HEADER) > ptr + filesize ) || ( pISH->PointerToRawData + pISH->SizeOfRawData > filesize ) )
- {
- res = RESULT_CORRUPTED;
- break;
- }
+ res = RESULT_CORRUPTED;
+ break;
+ }
- // erase timestamp
- if (( dbgsize >= sizeof( IMAGE_DEBUG_DIRECTORY ) ) &&
- ( dbgvaddr >= pISH->VirtualAddress ) &&
- ( dbgvaddr + dbgsize <= pISH->VirtualAddress + pISH->SizeOfRawData )
- )
- {
- DWORD shift = dbgvaddr - pISH->VirtualAddress;
- pDBG = (PIMAGE_DEBUG_DIRECTORY)( ptr + shift + pISH->PointerToRawData );
+ // erase timestamp
+ if (( dbgSize >= sizeof( IMAGE_DEBUG_DIRECTORY )) &&
+ ( dbgAddr >= pISH->VirtualAddress ) &&
+ ( dbgAddr + dbgSize <= pISH->VirtualAddress + pISH->SizeOfRawData ))
+ {
+ DWORD shift = dbgAddr - pISH->VirtualAddress;
+ pDBG = (PIMAGE_DEBUG_DIRECTORY)( ptr + shift + pISH->PointerToRawData );
+ pDBG->TimeDateStamp = 0;
- pDBG->TimeDateStamp = 0;
- //ZeroMemory( ptr + pISH->PointerToRawData + shift, dbgsize );
#ifdef DEBUG_SECTIONS
if ( debug )
- _ftprintf( stderr, _T("Found debug section entry at 0x%08X (%d), data at 0x%08X (%d)\n"), pISH->PointerToRawData + shift, dbgsize, pDBG->PointerToRawData, pDBG->SizeOfData );
+ _ftprintf( stderr, _T("Found debug section entry at 0x%08X (%d), data at 0x%08X (%d)\n"), pISH->PointerToRawData + shift, dbgSize, pDBG->PointerToRawData, pDBG->SizeOfData );
#endif
- }
+ }
- // erase export timestamp
- if (( expsize >= sizeof( IMAGE_EXPORT_DIRECTORY ) ) &&
- ( expvaddr >= pISH->VirtualAddress ) &&
- ( expvaddr + expsize <= pISH->VirtualAddress + pISH->SizeOfRawData ) )
- {
- DWORD shift = expvaddr - pISH->VirtualAddress;
- PIMAGE_EXPORT_DIRECTORY pEXP = (PIMAGE_EXPORT_DIRECTORY)( ptr + shift + pISH->PointerToRawData );
+ // erase export timestamp
+ if (( expSize >= sizeof( IMAGE_EXPORT_DIRECTORY )) &&
+ ( expAddr >= pISH->VirtualAddress ) &&
+ ( expAddr + expSize <= pISH->VirtualAddress + pISH->SizeOfRawData ))
+ {
+ DWORD shift = expAddr - pISH->VirtualAddress;
+ PIMAGE_EXPORT_DIRECTORY pEXP = (PIMAGE_EXPORT_DIRECTORY)( ptr + shift + pISH->PointerToRawData );
- pEXP->TimeDateStamp = 0;
+ pEXP->TimeDateStamp = 0;
#ifdef DEBUG_SECTIONS
if ( debug )
_ftprintf( stderr, _T("Found export section entry at 0x%08X\n"), pISH->PointerToRawData + shift );
#endif
- }
+ }
- // find realocation table
- if (( realsize >= sizeof( IMAGE_BASE_RELOCATION ) ) &&
- ( realvaddr >= pISH->VirtualAddress ) &&
- ( realvaddr + realsize <= pISH->VirtualAddress + pISH->SizeOfRawData ) )
- {
- DWORD shift = realvaddr - pISH->VirtualAddress;
- pRealloc = ptr + shift + pISH->PointerToRawData;
+ // find realocation table
+ if (( relocSize >= sizeof( IMAGE_BASE_RELOCATION )) &&
+ ( relocAddr >= pISH->VirtualAddress ) &&
+ ( relocAddr + relocSize <= pISH->VirtualAddress + pISH->SizeOfRawData ))
+ {
+ DWORD shift = relocAddr - pISH->VirtualAddress;
+ pRealloc = ptr + shift + pISH->PointerToRawData;
#ifdef DEBUG_SECTIONS
if ( debug )
- _ftprintf( stderr, _T("Found reallocation table entry at 0x%08X (%d)\n"), pISH->PointerToRawData + shift, realsize );
+ _ftprintf( stderr, _T("Found reallocation table entry at 0x%08X (%d)\n"), pISH->PointerToRawData + shift, relocSize );
#endif
-
- }
-
- idx++;
}
-
}
-
- if ( res == RESULT_OK )
- {
- PIMAGE_SECTION_HEADER pISH = 0;
- DWORD idx = 0;
+ if ( res == RESULT_OK )
+ {
mir_md5_state_t pms;
-
mir_md5_init( &pms );
- while ( idx < sections )
+ for (size_t idx=0; idx < sections; idx++)
{
- pISH = (PIMAGE_SECTION_HEADER)( ptr + offset + idx * sizeof(IMAGE_SECTION_HEADER) );
+ PIMAGE_SECTION_HEADER pISH = (PIMAGE_SECTION_HEADER)( ptr + offset + idx * sizeof(IMAGE_SECTION_HEADER));
- if ( ( (PBYTE)pISH + sizeof(IMAGE_SECTION_HEADER) > ptr + filesize ) || ( pISH->PointerToRawData + pISH->SizeOfRawData > filesize ) )
+ if (((PBYTE)pISH + sizeof(IMAGE_SECTION_HEADER) > ptr + filesize ) || ( pISH->PointerToRawData + pISH->SizeOfRawData > filesize ))
{
- res = RESULT_CORRUPTED;
- break;
+ res = RESULT_CORRUPTED;
+ break;
}
// erase debug information
- if ( pDBG && ( pDBG->SizeOfData > 0 ) &&
- ( pDBG->PointerToRawData >= pISH->PointerToRawData ) &&
- ( pDBG->PointerToRawData + pDBG->SizeOfData <= pISH->PointerToRawData + pISH->SizeOfRawData )
- )
+ if ( pDBG && pDBG->SizeOfData > 0 &&
+ pDBG->PointerToRawData >= pISH->PointerToRawData &&
+ pDBG->PointerToRawData + pDBG->SizeOfData <= pISH->PointerToRawData + pISH->SizeOfRawData )
{
ZeroMemory( ptr + pDBG->PointerToRawData, pDBG->SizeOfData );
}
+ // patch resources
+ 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);
+ }
+
// rebase to zero address
if ( pRealloc )
{
- PIMAGE_BASE_RELOCATION pIBR = 0;
-
- DWORD blocklen = realsize;
- PWORD pw;
- DWORD type;
- int len;
- PBYTE pAddr;
- DWORD shift;
- DWORD addr;
-
- pIBR = (PIMAGE_BASE_RELOCATION)pRealloc;
-
+ DWORD blocklen = relocSize;
+ PWORD pw;
+ DWORD type;
+ int len;
+ PBYTE pAddr;
+ DWORD shift;
+ DWORD addr;
+
+ PIMAGE_BASE_RELOCATION pIBR = (PIMAGE_BASE_RELOCATION)pRealloc;
while( pIBR )
{
- if ( ( pIBR->VirtualAddress >= pISH->VirtualAddress ) &&
- ( pIBR->VirtualAddress < pISH->VirtualAddress + pISH->SizeOfRawData ) &&
- ( pIBR->SizeOfBlock <= blocklen ) )
+ if (( pIBR->VirtualAddress >= pISH->VirtualAddress ) &&
+ ( pIBR->VirtualAddress < pISH->VirtualAddress + pISH->SizeOfRawData ) &&
+ ( pIBR->SizeOfBlock <= blocklen ))
{
shift = pIBR->VirtualAddress - pISH->VirtualAddress + pISH->PointerToRawData;
-
- len = pIBR->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION);
- pw = (PWORD)( (PBYTE)pIBR + sizeof(IMAGE_BASE_RELOCATION) );
+ len = pIBR->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION);
+
+ pw = (PWORD)((PBYTE)pIBR + sizeof(IMAGE_BASE_RELOCATION));
#ifdef DEBUG_REALLOCS
if ( debug )
_ftprintf( stderr, _T("Realloc block at %08X (%d)\n"), pIBR->VirtualAddress, pIBR->SizeOfBlock );
#endif
- while( len > 0 )
- {
- type = *pw >> 12;
+ while( len > 0 )
+ {
+ type = *pw >> 12;
- addr = ( *pw & 0x0FFF );
+ addr = ( *pw & 0x0FFF );
- pAddr = ptr + shift + addr;
+ pAddr = ptr + shift + addr;
- switch( type )
- {
- case IMAGE_REL_BASED_HIGHLOW:
- if ( addr + pIBR->VirtualAddress + sizeof(DWORD) >= pISH->VirtualAddress + pISH->SizeOfRawData )
- {
- len = 0;
- break;
- }
+ switch( type ) {
+ case IMAGE_REL_BASED_HIGHLOW:
+ if ( addr + pIBR->VirtualAddress + sizeof(DWORD) >= pISH->VirtualAddress + pISH->SizeOfRawData )
+ {
+ len = 0;
+ break;
+ }
#ifdef DEBUG_REALLOCS
-
- if ( debug && ( *(PDWORD)pAddr < (DWORD)base ) )
- _ftprintf( stderr, _T("Realloc address is less than base\n"));
+ if ( debug && ( *(PDWORD)pAddr < (DWORD)base ))
+ _ftprintf( stderr, _T("Realloc address is less than base\n"));
#endif
- *(PDWORD)pAddr = (DWORD)( (*(PDWORD)pAddr) - (DWORD)base );
- break;
+ *(PDWORD)pAddr = (DWORD)((*(PDWORD)pAddr) - (DWORD)base );
+ break;
- case IMAGE_REL_BASED_DIR64:
- if ( addr + pIBR->VirtualAddress + sizeof(ULONGLONG) >= pISH->VirtualAddress + pISH->SizeOfRawData )
- {
- len = 0;
- break;
- }
+ case IMAGE_REL_BASED_DIR64:
+ if ( addr + pIBR->VirtualAddress + sizeof(ULONGLONG) >= pISH->VirtualAddress + pISH->SizeOfRawData )
+ {
+ len = 0;
+ break;
+ }
#ifdef DEBUG_REALLOCS
-
- if ( debug && ( *(ULONGLONG*)pAddr < base ) )
- _ftprintf( stderr, _T("Realloc address is less than base\n"));
+ if ( debug && ( *(ULONGLONG*)pAddr < base ))
+ _ftprintf( stderr, _T("Realloc address is less than base\n"));
#endif
- *(ULONGLONG*)pAddr = (ULONGLONG)( (*(ULONGLONG*)pAddr) - base );
- break;
+ *(ULONGLONG*)pAddr = (ULONGLONG)((*(ULONGLONG*)pAddr) - base );
+ break;
- case IMAGE_REL_BASED_ABSOLUTE:
- // stop processing
- len = 0;
- break;
-
- case IMAGE_REL_BASED_HIGH:
- case IMAGE_REL_BASED_LOW:
- case IMAGE_REL_BASED_HIGHADJ:
+ case IMAGE_REL_BASED_ABSOLUTE:
+ // stop processing
+ len = 0;
+ break;
+
+ case IMAGE_REL_BASED_HIGH:
+ case IMAGE_REL_BASED_LOW:
+ case IMAGE_REL_BASED_HIGHADJ:
#ifdef DEBUG_REALLOCS
- if ( debug )
- _ftprintf( stderr, _T("Unexpected block type %d\n"), type );
+ if ( debug )
+ _ftprintf( stderr, _T("Unexpected block type %d\n"), type );
#endif
- break;
+ break;
- default:
+ default:
#ifdef DEBUG_REALLOCS
- if ( debug )
- _ftprintf( stderr, _T("Unknown block type %d\n"), type );
+ if ( debug )
+ _ftprintf( stderr, _T("Unknown block type %d\n"), type );
#endif
- break;
+ break;
}
len -= sizeof(WORD);
@@ -354,15 +358,15 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) }
blocklen -= pIBR->SizeOfBlock;
- if ( blocklen > sizeof(IMAGE_BASE_RELOCATION) )
- pIBR = (PIMAGE_BASE_RELOCATION)( (PBYTE)pIBR + pIBR->SizeOfBlock );
+ if ( blocklen > sizeof(IMAGE_BASE_RELOCATION))
+ pIBR = (PIMAGE_BASE_RELOCATION)((PBYTE)pIBR + pIBR->SizeOfBlock );
else
break;
}
}
#ifdef DEBUG_SECTIONS
- if ( debug )
- {
+ if ( debug )
+ {
int i;
mir_md5_byte_t digest2[16];
mir_md5_state_t pms2;
@@ -372,16 +376,14 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) mir_md5_finish( &pms2, digest2 );
_ftprintf( stderr, _T("%s - %08X - %d "), pISH->Name, pISH->PointerToRawData, pISH->SizeOfRawData);
-
+
for ( i = 0; i < sizeof( digest2 ) / sizeof( digest2[0] ); i++ )
_ftprintf( stderr, _T("%02X"), digest2[i] );
- _ftprintf( stderr, _T("\n") );
+ _ftprintf( stderr, _T("\n"));
}
#endif
- mir_md5_append( &pms, ptr + pISH->PointerToRawData, pISH->SizeOfRawData );
-
- idx++;
+ mir_md5_append( &pms, ptr + pISH->PointerToRawData, pISH->SizeOfRawData );
}
if ( res == RESULT_OK )
@@ -393,7 +395,7 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) else
res = RESULT_READERROR;
- if ( ptr )
+ if ( ptr )
UnmapViewOfFile( ptr );
if ( hMap )
@@ -404,7 +406,6 @@ int PEChecksum( TCHAR *filename, mir_md5_byte_t digest[16] ) return res;
}
-
TCHAR* trtrim( TCHAR *str )
{
if ( str == NULL )
@@ -413,12 +414,11 @@ TCHAR* trtrim( TCHAR *str ) TCHAR* p = _tcschr( str, 0 );
while ( --p >= str )
{
- switch ( *p )
- {
- case L' ': case L'\t': case L'\n': case L'\r':
- *p = 0; break;
- default:
- return str;
+ switch ( *p ) {
+ case L' ': case L'\t': case L'\n': case L'\r':
+ *p = 0; break;
+ default:
+ return str;
}
}
return str;
@@ -432,8 +432,7 @@ int process(TCHAR *filename) res = PEChecksum( filename, digest);
- switch(res)
- {
+ switch(res) {
case RESULT_NOTFOUND:
_ftprintf( stderr, _T("'%s'... not found!\n"), filename );
break;
@@ -452,7 +451,7 @@ int process(TCHAR *filename) _ftprintf( stdout, _T("%s "), filename );
for ( i = 0; i < sizeof( digest ) / sizeof( digest[0] ); i++ )
_ftprintf( stdout, _T("%02X"), digest[i] );
- _ftprintf( stdout, _T("\n") );
+ _ftprintf( stdout, _T("\n"));
break;
}
default:
@@ -478,18 +477,18 @@ int _tmain( int argc, TCHAR *argv[] ) for ( i = 1; i < argc; i++ )
{
- if ( !_tcscmp( argv[i], _T("/debug") ) || !_tcscmp( argv[i], _T("/DEBUG") ) )
+ if ( !_tcscmp( argv[i], _T("/debug")) || !_tcscmp( argv[i], _T("/DEBUG")))
{
debug = 1;
break;
}
}
- _ftprintf( stderr, _T("Processing ... \n") );
+ _ftprintf( stderr, _T("Processing ... \n"));
for ( i = 1; i < argc; i++ )
{
- if ( !_tcscmp( argv[i], _T("/stdin") ) || !_tcscmp( argv[i], _T("/STDIN") ) )
+ if ( !_tcscmp( argv[i], _T("/stdin")) || !_tcscmp( argv[i], _T("/STDIN")))
{
while ( _fgetts( buf, sizeof( buf ), stdin ) != NULL )
{
@@ -504,25 +503,25 @@ int _tmain( int argc, TCHAR *argv[] ) while( hFind != INVALID_HANDLE_VALUE )
{
- if ( ! ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
- {
+ if ( ! ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ))
+ {
res = process( ffd.cFileName );
cnt++;
}
- if ( !FindNextFile( hFind, &ffd ) )
+ if ( !FindNextFile( hFind, &ffd ))
break;
}
FindClose( hFind );
}
- _ftprintf( stderr, _T("%d file(s) processed.\n"), cnt );
+ _ftprintf( stderr, _T("%d file(s) processed.\n"), cnt );
}
else
{
- _ftprintf( stderr, _T("Usage: checksum.exe [/debug] [/stdin] [*.dll] ... [*.exe]\n") );
- _ftprintf( stderr, _T("Example: dir /b /s | checksum.exe /stdin > hashes.txt\n") );
- res = RESULT_NONE;
+ _ftprintf( stderr, _T("Usage: checksum.exe [/debug] [/stdin] [*.dll] ... [*.exe]\n"));
+ _ftprintf( stderr, _T("Example: dir /b /s | checksum.exe /stdin > hashes.txt\n"));
+ res = RESULT_NONE;
}
return res;
|