Deadlock in CloseEncryptedFileRaw()

  • Thread starter Thread starter toalexjin
  • Start date Start date
T

toalexjin

I'm trying to write a simple code to export raw data of an encrypted
file with OpenEncryptedFileRaw(), ReadEncryptedFileRaw() and
CloseEncryptedFileRaw(). If not all raw data of the encrypted file were
exported, calling CloseEncryptedFileRaw() will enter deadlock in
Windows 2000 or Windows 2003. But in Windows XP, the program will work
well.

Here is my sample code:
// efs1.c
#include <windows.h>
#include <tchar.h>

static int st_error_code = 0;
static int st_times = 0;

void help( const TCHAR* exe )
{
_tprintf( _T("Usage: %s efs_file error_code read_times\n"), exe );
}

DWORD WINAPI export_callback(
PBYTE pbData,
PVOID pvCallbackContext,
ULONG ulLength
)
{
int count = ++ *((int*)pvCallbackContext);
_tprintf( _T("export_callback (%d): length:%u.\n"), count, ulLength
);

if ( count >= st_times )
{
return st_error_code;
}
else
{
return 0;
}
}


int _tmain( int argc, TCHAR* argv[] )
{
void* fp = 0;
DWORD result;
int count = 0;

if ( argc != 4
|| ( st_error_code = _ttoi( argv[2] ) ) == 0
|| ( st_times = _ttoi( argv[3] ) ) <= 0 )
{
help( argv[0] );
return -1;
}

result = OpenEncryptedFileRaw( argv[1], 0, &fp );
if ( result != ERROR_SUCCESS )
{
_tprintf( _T("OpenEncryptedFileRaw failed:%u.\n"), result );
return -1;
}
else
{
_tprintf( _T("OpenEncryptedFileRaw ok.\n") );
}

result = ReadEncryptedFileRaw( &export_callback, &count, fp );
if ( result != ERROR_SUCCESS )
{
_tprintf( _T("ReadEncryptedFileRaw failed:%u.\n"), result );
}
else
{
_tprintf( _T("ReadEncryptedFileRaw ok.\n") );
}

CloseEncryptedFileRaw( fp );
fp = 0;

_tprintf( _T("CloseEncryptedFileRaw ok.\n") );

return 0;
}

The command line is "efs1.exe c:\my_encrypted_big_file 1 2", let the
program read only two blocks of raw data and exit, but the program
hangs at line CloseEncryptedFileRaw( fp );

I want to know if anyone can help me, thanks!!

Alex Jin.
 
Back
Top