alex1234
asked on
500 points Win2000 NTFS question
I give 500 points for this question:
I need to read a Win2000 encrypted file and then write its entire contents to an other file using ReadEncryptedFileRaw/Write EncryptedF ileRaw APIs from advapi.dll
These APIs seem not to work properly. This is the code I use:
BYTE g_Buf[10000];
DWORD g_BufLen;
void *d_pv;
DWORD RRead(PBYTE pbData, PVOID pvCallbackContext, ULONG ulLength)
{
memcpy(g_Buf, pbData, ulLength);
g_BufLen = ulLength;
return 0;
}
DWORD WWrite(PBYTE pbData, PVOID pvCallbackContext, PULONG ulLength)
{
memcpy(pbData, g_Buf, g_BufLen);
*ulLength = g_BufLen;
return 0;
}
OpenEncryptedFileRaw("c:\\ Test.txt", 0, &g_pv);
ReadEncryptedFileRaw((PFE_ EXPORT_FUN C)RRead, NULL, g_pv);
CloseEncryptedFileRaw(g_pv );
OpenEncryptedFileRaw("c:\\ TestCpy.tx t", CREATE_FOR_IMPORT, &g_pv);
WriteEncryptedFileRaw((PFE _IMPORT_FU NC)WWrite, NULL, g_pv);
CloseEncryptedFileRaw(g_pv );
What is wrong with this code?
I need to read a Win2000 encrypted file and then write its entire contents to an other file using ReadEncryptedFileRaw/Write
These APIs seem not to work properly. This is the code I use:
BYTE g_Buf[10000];
DWORD g_BufLen;
void *d_pv;
DWORD RRead(PBYTE pbData, PVOID pvCallbackContext, ULONG ulLength)
{
memcpy(g_Buf, pbData, ulLength);
g_BufLen = ulLength;
return 0;
}
DWORD WWrite(PBYTE pbData, PVOID pvCallbackContext, PULONG ulLength)
{
memcpy(pbData, g_Buf, g_BufLen);
*ulLength = g_BufLen;
return 0;
}
OpenEncryptedFileRaw("c:\\
ReadEncryptedFileRaw((PFE_
CloseEncryptedFileRaw(g_pv
OpenEncryptedFileRaw("c:\\
WriteEncryptedFileRaw((PFE
CloseEncryptedFileRaw(g_pv
What is wrong with this code?
ASKER
What is "grade A" and how many points do you want?
The title of your question is "500 points Win2000 NTFS question".
But the actual price is ZERO.
So, increase the actual price to 500 points, and I'll answer your question.
But the actual price is ZERO.
So, increase the actual price to 500 points, and I'll answer your question.
ASKER
Adjusted points from 0 to 500
ASKER
Go ahead...
However, I won't accept the answer if these APIs don't work just because of a bug in Windows files (advapi.dll or somewhere else). In this case please don't post the "answer", just use "comments" so I could delete this question later and not to loose the points.
However, I won't accept the answer if these APIs don't work just because of a bug in Windows files (advapi.dll or somewhere else). In this case please don't post the "answer", just use "comments" so I could delete this question later and not to loose the points.
Don't worry, it works fine...
#include <windows.h>
#include <iostream.h>
//------------------------ ----
// There is a bug in the winbase.h, at least
// in my Platform SDK RC2.
// Callback functions must be defined as WINAPI:
//
// DWORD (WINAPI *PFE_EXPORT_FUNC)(...)
// DWORD (WINAPI *PFE_IMPORT_FUNC)(...)
//
//------------------------ ----
// The buffer must be large enough.
BYTE g_Buf[1024*1024*10];
DWORD g_BufLen=0,written=0;
PVOID pContext;
//
// Callbacks must be defined with WINAPI
//
DWORD WINAPI RRead(PBYTE pbData, PVOID /*pvCallbackContext*/, ULONG ulLength)
{
cout<<"Read callback, len="<<ulLength<<endl;
memcpy(g_Buf+g_BufLen,pbDa ta,ulLengt h);
g_BufLen+=ulLength;
return ERROR_SUCCESS;
}
DWORD WINAPI WWrite(PBYTE pbData,PVOID /*pvCallbackContext*/, PULONG ulLength)
{
cout<<"Write callback, len="<<*ulLength;
if(*ulLength>g_BufLen) *ulLength=g_BufLen;
cout<<", used="<<*ulLength<<endl;
memcpy(pbData,g_Buf+writte n,*ulLengt h);
written+=*ulLength;
g_BufLen-=*ulLength;
return ERROR_SUCCESS;
}
void main()
{
DWORD r;
r=OpenEncryptedFileRaw("d: \\aa", 0, &pContext);
cout<<"Open result="<<r<<' '<<GetLastError()<<endl;
r=ReadEncryptedFileRaw((PF E_EXPORT_F UNC)RRead, 0,pContext );
cout<<"Read result="<<r<<' '<<GetLastError()<<endl;
cout<<"Buf len="<<g_BufLen<<endl;
CloseEncryptedFileRaw(pCon text);
cout<<"Closed "<<endl<<endl;
r=OpenEncryptedFileRaw("d: \\aa2", CREATE_FOR_IMPORT, &pContext);
cout<<"Open result="<<r<<' '<<GetLastError()<<endl;
r=WriteEncryptedFileRaw((P FE_IMPORT_ FUNC)WWrit e,0,pConte xt);
cout<<"Write result="<<r<<' '<<GetLastError()<<endl;
CloseEncryptedFileRaw(pCon text);
cout<<"Closed "<<endl;
}
#include <windows.h>
#include <iostream.h>
//------------------------
// There is a bug in the winbase.h, at least
// in my Platform SDK RC2.
// Callback functions must be defined as WINAPI:
//
// DWORD (WINAPI *PFE_EXPORT_FUNC)(...)
// DWORD (WINAPI *PFE_IMPORT_FUNC)(...)
//
//------------------------
// The buffer must be large enough.
BYTE g_Buf[1024*1024*10];
DWORD g_BufLen=0,written=0;
PVOID pContext;
//
// Callbacks must be defined with WINAPI
//
DWORD WINAPI RRead(PBYTE pbData, PVOID /*pvCallbackContext*/, ULONG ulLength)
{
cout<<"Read callback, len="<<ulLength<<endl;
memcpy(g_Buf+g_BufLen,pbDa
g_BufLen+=ulLength;
return ERROR_SUCCESS;
}
DWORD WINAPI WWrite(PBYTE pbData,PVOID /*pvCallbackContext*/, PULONG ulLength)
{
cout<<"Write callback, len="<<*ulLength;
if(*ulLength>g_BufLen) *ulLength=g_BufLen;
cout<<", used="<<*ulLength<<endl;
memcpy(pbData,g_Buf+writte
written+=*ulLength;
g_BufLen-=*ulLength;
return ERROR_SUCCESS;
}
void main()
{
DWORD r;
r=OpenEncryptedFileRaw("d:
cout<<"Open result="<<r<<' '<<GetLastError()<<endl;
r=ReadEncryptedFileRaw((PF
cout<<"Read result="<<r<<' '<<GetLastError()<<endl;
cout<<"Buf len="<<g_BufLen<<endl;
CloseEncryptedFileRaw(pCon
cout<<"Closed "<<endl<<endl;
r=OpenEncryptedFileRaw("d:
cout<<"Open result="<<r<<' '<<GetLastError()<<endl;
r=WriteEncryptedFileRaw((P
cout<<"Write result="<<r<<' '<<GetLastError()<<endl;
CloseEncryptedFileRaw(pCon
cout<<"Closed "<<endl;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
// There is a bug in the winbase.h, at least
// in my Platform SDK RC2.
// Callback functions must be defined as WINAPI:
Nick,
that is exactly what I suspected: a bug in Windows files. I just couldn'd find where...
This "WINAPI" declaration makes whole the difference. Anyway, I accept your answer. Thanks.
// in my Platform SDK RC2.
// Callback functions must be defined as WINAPI:
Nick,
that is exactly what I suspected: a bug in Windows files. I just couldn'd find where...
This "WINAPI" declaration makes whole the difference. Anyway, I accept your answer. Thanks.
Also you incorrectly used callback functions...
ASKER
My callback functions were used for a "single callback" call only (really small file). The whole idea is those WINAPI. Whithout WINAPI callback functions get called only one time.
But you have to increase the points first.