Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

500 points Win2000 NTFS question

Posted on 2000-05-15
10
321 Views
Last Modified: 2013-12-03
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/WriteEncryptedFileRaw 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_FUNC)RRead, NULL, g_pv);
CloseEncryptedFileRaw(g_pv);

OpenEncryptedFileRaw("c:\\TestCpy.txt", CREATE_FOR_IMPORT, &g_pv);
WriteEncryptedFileRaw((PFE_IMPORT_FUNC)WWrite, NULL, g_pv);
CloseEncryptedFileRaw(g_pv);

What is wrong with this code?
0
Comment
Question by:alex1234
  • 5
  • 5
10 Comments
 
LVL 15

Expert Comment

by:NickRepin
ID: 2812784
For 500 points + grade A, I'll answer this question.
But you have to increase the points first.
0
 
LVL 1

Author Comment

by:alex1234
ID: 2813952
What is "grade A" and how many points do you want?
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2814720
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.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Author Comment

by:alex1234
ID: 2814912
Adjusted points from 0 to 500
0
 
LVL 1

Author Comment

by:alex1234
ID: 2814913
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.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2815217
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,pbData,ulLength);
   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+written,*ulLength);
   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((PFE_EXPORT_FUNC)RRead,0,pContext);
   cout<<"Read result="<<r<<' '<<GetLastError()<<endl;
   cout<<"Buf len="<<g_BufLen<<endl;
   CloseEncryptedFileRaw(pContext);
   cout<<"Closed "<<endl<<endl;

   r=OpenEncryptedFileRaw("d:\\aa2", CREATE_FOR_IMPORT, &pContext);
   cout<<"Open result="<<r<<' '<<GetLastError()<<endl;
   r=WriteEncryptedFileRaw((PFE_IMPORT_FUNC)WWrite,0,pContext);
   cout<<"Write result="<<r<<' '<<GetLastError()<<endl;
   CloseEncryptedFileRaw(pContext);
   cout<<"Closed "<<endl;
}
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 500 total points
ID: 2815220
The answer is above
0
 
LVL 1

Author Comment

by:alex1234
ID: 2817368
// 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.  
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2819115
Also you incorrectly used callback functions...
0
 
LVL 1

Author Comment

by:alex1234
ID: 2819166
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.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question