EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Copying a locked file doesn't work anymore ?

Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.
#14002
Posted: 07/23/2010 12:25:21
by stephane  (Standard support level)
Joined: 03/17/2009
Posts: 39

Hello,

I'm using rawdisk for a long time now and I wrote a CopyLockedFile() function that worked great but I've made some new testing recently on windows vista premium edition and it fails.

Driver version: 2.1.23.89
* TRawdisk.GetDriverStatus() is OK (sys driver is installed)
* TRawdisk.CreateFile(name,GENERIC_READ,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,key) is OK (return a valid file handle)
* But after that Windows.ReadFile() functions "waits" a few seconds (instead of returning instantly) and returns always false on the locked file (this is a simple text file that I opened with exclusive access in another application).

In order to be sure that my code is not buggy, can anyone show me a correct way to create a CopyLockedFile() function with Rawdisk driver ?

Thanks !
#14003
Posted: 07/23/2010 15:07:29
by Volodymyr Zinin (EldoS Corp.)

Hello Stephane,

I've tried to reproduce it but without success. Could you give us a test code (with sources) that has this problem?
Thanks.
#14005
Posted: 07/24/2010 11:20:25
by stephane  (Standard support level)
Joined: 03/17/2009
Posts: 39

Here is a very simple delphi code example (just tries to read the first 8192 bytes of a file with rawdisk).

[Note: you must first create a 'test.txt' file with some text inside]
[NOTE2: the elrawdsk.sys driver must be in the same directory as the executable]

=> All is ok except ReadFile(): hangs a few seconds and then returns false with GetLastError() =ERROR_IO_DEVICE 1117 (0x45D)

This occurs whenever 'test.txt' file is locked or not !
If I replace TRawdisk.CreateFile() with the standard windows CreateFile() then all is OK (returns an invalid handle if file is locked, else ReadFile() is ok).

Code
uses RawDisk;

const  rawdiskkey:string='myvalidkey';

function GetFileSize(const APath: string): int64;
var
  Sr : TSearchRec;
begin
  if FindFirst(APath,faAnyFile,Sr)=0 then
  try
    Result := Int64(Sr.FindData.nFileSizeHigh) shl 32 + Sr.FindData.nFileSizeLow;
  finally
    FindClose(Sr);
  end
  else
    Result := 0;
end;


procedure ReadLocked(s:String);
const BUF_SIZE=1024*8;
var h:THandle;
    Buf2:array of Byte;
    BytesRead: Cardinal;
    InitialFileSize: int64;
    ok:boolean;
begin
  s:='\??\'+s;
  h:=TRawDisk.CreateFile(s,GENERIC_READ,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,rawdiskkey);
  //h:=CreateFile(PChar(s),GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
  if (h=0) or (h=INVALID_HANDLE_VALUE) then
  begin
    ShowMessage('unable to open the file with rawdisk !');
    exit;
  end;
  InitialFileSize:=GetFileSize(s);
  if InitialFileSize>0 then
  begin
    SetLength(Buf2,BUF_SIZE);
    Try
      ok:=ReadFile(h,Buf2[1],BUF_SIZE,BytesRead,nil);  
      if not ok  then ShowMessage(Format('READ ERROR code=%d',[GetLastError()]))
      else ShowMessage('Read OK');
    except
      ShowMessage('Exception !');
    end;
  end;

  try CloseHandle(h); except end;
  ShowMessage('Read end !');
end;

procedure TForm1.Button1Click(Sender: TObject);
var RebootNeeded:longbool;
    path:string;
    name:string;
begin
  name:=ExtractFilePath(Application.ExeName)+'elrawdsk.sys';
  if not TRawdisk.InstallDriver(name,'demoapp',RebootNeeded) then
  begin
    ShowMessage('unable to install driver !');  exit;
  end;
  path:=ExtractFilePath(Application.Exename);
  // just read first 8ko bytes of locked file  test.txt  (locked by another delphi app : opened with exclusive access)
  ReadLocked(path+'test.txt');

  if not TRawdisk.UninstallDriver('demoapp',RebootNeeded) then
  begin
    Showmessage('unable to uninstall driver !'); exit;
  end;
end;
#14008
Posted: 07/25/2010 07:14:29
by goubin dylan (Standard support level)
Joined: 09/19/2006
Posts: 13

I confirm this issue on my Windows 7 Pro 64 bits edition since a few time.

It used to work before and suddenly it stops working.
#14010
Posted: 07/26/2010 04:50:55
by stephane  (Standard support level)
Joined: 03/17/2009
Posts: 39

As a side note and confirmation : I have tried the last elrawdsk.sys driver + the same delphi application on an old Windows XP SP3 virtual machine and all works fine.

There seems to be an issue with the last windows updates on vista/seven.
#14014
Posted: 07/26/2010 06:27:51
by Eugene Mayevski (EldoS Corp.)

Yes, we will check the issue this week. Vladimir Zinin is on vacation this week, and he asked to leave the issue to him, so he will investigate it either this or next week.


Sincerely yours
Eugene Mayevski
#14081
Posted: 08/02/2010 17:57:51
by goubin dylan (Standard support level)
Joined: 09/19/2006
Posts: 13

Hello,
any news ?
#14083
Posted: 08/03/2010 01:29:41
by Volodymyr Zinin (EldoS Corp.)

Answered to the ticket you created in helpdesk.
#14127
Posted: 08/06/2010 07:55:35
by goubin dylan (Standard support level)
Joined: 09/19/2006
Posts: 13

We are still waiting for answers in our helpdesk;

i confirm Rawdisk does not work anymore on updated Windows 7 / Vista
#14128
Posted: 08/06/2010 09:40:22
by stephane  (Standard support level)
Joined: 03/17/2009
Posts: 39

We made some more testing (always with the example code) and the results are :

* Windows XP SP2 or Sp3 : OK [under virtual pc 2007 and oracle virtualbox]
* Windows 2003 server: OK [under oracle virtual box]
* one vista returns always : ERROR_INVALID_FUNCTION [real computer]
* another vista returns always: ERROR_IO_DEVICE [real computer]
* two 32 bit seven systems (french and english): ERROR_INVALID_FUNCTION [under oracle virtual box]
* one 64 bit seven system: ERROR_INVALID_FUNCTION [real computer]
* one 2008 server: ERROR_INVALID_FUNCTION [under oracle virtual box]

So it seems that the driver works on XP and 2003, but stopped working on 2008/Vista/Seven.

The most frequent error is ERROR_INVALID_FUNCTION when calling the win32 ReadFile() function.

Please note also that a try on an outlook.pst file (when outlook is running) hangs at the same time the test application (blocked in the readfile()) and the outlook interface => no other choice than a reboot !

This is obviously not a dephi code issue because this works fine on XP and 2003.

Hope this helps !
Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.

Reply

Statistics

Topic viewed 15049 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!