Commit fd941d4d authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Implement ImageEnumerateCertificates and ImageGetCertificateHeader.

parent 89525a19
...@@ -44,12 +44,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(imagehlp); ...@@ -44,12 +44,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
* Read a file's PE header, and return the offset and size of the * Read a file's PE header, and return the offset and size of the
* security directory. * security directory.
*/ */
static BOOL IMAGEHLP_GetSecurityDirOffset( HANDLE handle, DWORD num, static BOOL IMAGEHLP_GetSecurityDirOffset( HANDLE handle,
DWORD *pdwOfs, DWORD *pdwSize ) DWORD *pdwOfs, DWORD *pdwSize )
{ {
IMAGE_DOS_HEADER dos_hdr; IMAGE_DOS_HEADER dos_hdr;
IMAGE_NT_HEADERS nt_hdr; IMAGE_NT_HEADERS nt_hdr;
DWORD size, count, offset, len; DWORD count;
BOOL r; BOOL r;
IMAGE_DATA_DIRECTORY *sd; IMAGE_DATA_DIRECTORY *sd;
...@@ -80,16 +80,35 @@ static BOOL IMAGEHLP_GetSecurityDirOffset( HANDLE handle, DWORD num, ...@@ -80,16 +80,35 @@ static BOOL IMAGEHLP_GetSecurityDirOffset( HANDLE handle, DWORD num,
sd = &nt_hdr.OptionalHeader. sd = &nt_hdr.OptionalHeader.
DataDirectory[IMAGE_FILE_SECURITY_DIRECTORY]; DataDirectory[IMAGE_FILE_SECURITY_DIRECTORY];
TRACE("len = %lx addr = %lx\n", sd->Size, sd->VirtualAddress); TRACE("size = %lx addr = %lx\n", sd->Size, sd->VirtualAddress);
*pdwSize = sd->Size;
*pdwOfs = sd->VirtualAddress;
offset = 0; return TRUE;
size = sd->Size; }
/***********************************************************************
* IMAGEHLP_GetCertificateOffset (INTERNAL)
*
* Read a file's PE header, and return the offset and size of the
* security directory.
*/
static BOOL IMAGEHLP_GetCertificateOffset( HANDLE handle, DWORD num,
DWORD *pdwOfs, DWORD *pdwSize )
{
DWORD size, count, offset, len, sd_VirtualAddr;
BOOL r;
r = IMAGEHLP_GetSecurityDirOffset( handle, &sd_VirtualAddr, &size );
if( !r )
return FALSE;
offset = 0;
/* take the n'th certificate */ /* take the n'th certificate */
while( 1 ) while( 1 )
{ {
/* read the length of the current certificate */ /* read the length of the current certificate */
count = SetFilePointer( handle, sd->VirtualAddress + offset, count = SetFilePointer( handle, sd_VirtualAddr + offset,
NULL, FILE_BEGIN ); NULL, FILE_BEGIN );
if( count == INVALID_SET_FILE_POINTER ) if( count == INVALID_SET_FILE_POINTER )
return FALSE; return FALSE;
...@@ -113,10 +132,10 @@ static BOOL IMAGEHLP_GetSecurityDirOffset( HANDLE handle, DWORD num, ...@@ -113,10 +132,10 @@ static BOOL IMAGEHLP_GetSecurityDirOffset( HANDLE handle, DWORD num,
return FALSE; return FALSE;
} }
*pdwOfs = sd->VirtualAddress + offset; *pdwOfs = sd_VirtualAddr + offset;
*pdwSize = len; *pdwSize = len;
TRACE("len = %lx addr = %lx\n", len, sd->VirtualAddress + offset); TRACE("len = %lx addr = %lx\n", len, sd_VirtualAddr + offset);
return TRUE; return TRUE;
} }
...@@ -140,14 +159,62 @@ BOOL WINAPI ImageAddCertificate( ...@@ -140,14 +159,62 @@ BOOL WINAPI ImageAddCertificate(
* ImageEnumerateCertificates (IMAGEHLP.@) * ImageEnumerateCertificates (IMAGEHLP.@)
*/ */
BOOL WINAPI ImageEnumerateCertificates( BOOL WINAPI ImageEnumerateCertificates(
HANDLE FileHandle, WORD TypeFilter, PDWORD CertificateCount, HANDLE handle, WORD TypeFilter, PDWORD CertificateCount,
PDWORD Indices, DWORD IndexCount) PDWORD Indices, DWORD IndexCount)
{ {
FIXME("(%p, %hd, %p, %p, %ld): stub\n", DWORD size, count, offset, sd_VirtualAddr;
FileHandle, TypeFilter, CertificateCount, Indices, IndexCount WIN_CERTIFICATE hdr;
); const size_t cert_hdr_size = sizeof hdr - sizeof hdr.bCertificate;
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); BOOL r;
TRACE("%p %hd %p %p %ld\n",
handle, TypeFilter, CertificateCount, Indices, IndexCount);
if( Indices )
{
FIXME("Indicies not handled!\n");
return FALSE;
}
r = IMAGEHLP_GetSecurityDirOffset( handle, &sd_VirtualAddr, &size );
if( !r )
return FALSE; return FALSE;
offset = 0;
*CertificateCount = 0;
while( offset < size )
{
/* read the length of the current certificate */
count = SetFilePointer( handle, sd_VirtualAddr + offset,
NULL, FILE_BEGIN );
if( count == INVALID_SET_FILE_POINTER )
return FALSE;
r = ReadFile( handle, &hdr, cert_hdr_size, &count, NULL );
if( !r )
return FALSE;
if( count != cert_hdr_size )
return FALSE;
TRACE("Size = %08lx id = %08hx\n",
hdr.dwLength, hdr.wCertificateType );
/* check the certificate is not too big or too small */
if( hdr.dwLength < cert_hdr_size )
return FALSE;
if( hdr.dwLength > (size-offset) )
return FALSE;
if( (TypeFilter == CERT_SECTION_TYPE_ANY) ||
(TypeFilter == hdr.wCertificateType) )
{
(*CertificateCount)++;
}
/* next certificate */
offset += hdr.dwLength;
}
return TRUE;
} }
/*********************************************************************** /***********************************************************************
...@@ -163,7 +230,7 @@ BOOL WINAPI ImageGetCertificateData( ...@@ -163,7 +230,7 @@ BOOL WINAPI ImageGetCertificateData(
TRACE("%p %ld %p %p\n", handle, Index, Certificate, RequiredLength); TRACE("%p %ld %p %p\n", handle, Index, Certificate, RequiredLength);
if( !IMAGEHLP_GetSecurityDirOffset( handle, Index, &ofs, &size ) ) if( !IMAGEHLP_GetCertificateOffset( handle, Index, &ofs, &size ) )
return FALSE; return FALSE;
if( !Certificate ) if( !Certificate )
...@@ -200,14 +267,32 @@ BOOL WINAPI ImageGetCertificateData( ...@@ -200,14 +267,32 @@ BOOL WINAPI ImageGetCertificateData(
* ImageGetCertificateHeader (IMAGEHLP.@) * ImageGetCertificateHeader (IMAGEHLP.@)
*/ */
BOOL WINAPI ImageGetCertificateHeader( BOOL WINAPI ImageGetCertificateHeader(
HANDLE FileHandle, DWORD CertificateIndex, HANDLE handle, DWORD index, PWIN_CERTIFICATE pCert)
PWIN_CERTIFICATE Certificateheader)
{ {
FIXME("(%p, %ld, %p): stub\n", DWORD r, offset, ofs, size, count;
FileHandle, CertificateIndex, Certificateheader const size_t cert_hdr_size = sizeof *pCert - sizeof pCert->bCertificate;
);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); TRACE("%p %ld %p\n", handle, index, pCert);
if( !IMAGEHLP_GetCertificateOffset( handle, index, &ofs, &size ) )
return FALSE;
if( size < cert_hdr_size )
return FALSE;
offset = SetFilePointer( handle, ofs, NULL, FILE_BEGIN );
if( offset == INVALID_SET_FILE_POINTER )
return FALSE; return FALSE;
r = ReadFile( handle, pCert, cert_hdr_size, &count, NULL );
if( !r )
return FALSE;
if( count != cert_hdr_size )
return FALSE;
TRACE("OK\n");
return TRUE;
} }
/*********************************************************************** /***********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment