Kernel mode - برمجة Driver Filter
#25
بارك الله فيك أستاد

سأجرب و أظع النتيجة !! .

سؤال تاني خارج عن الموضوع لكن أحتاجه :

PHP كود :
unit ZwDeleteFileFromRing3;

interface

uses  nt_status, ntoskrnl, macros;

function 
_DriverEntry(DriverObject: PDriverObject; RegistryPath: PUnicodeString): NTSTATUS; stdcall;

implementation

var
  
DeviceName, SymbolicLinkName: UNICODE_STRING;
  
//********************************************************************************//
Function Example_IsStringTerminated(pString:PAnsiChar; uiLength: ULONG):Boolean; stdCall;
var
  
bStringIsTerminated:Boolean;
  
uiIndex:ULONG;
begin
  bStringIsTerminated
:= False;
  
uiIndex := 0; { here, uiIndex must be initialized! }
  while(
uiIndex < uiLength) and (bStringIsTerminated = False) do
  
begin
    
if pString[uiIndex] = #0 then
      
bStringIsTerminated := True
    
else
      
Inc(uiIndex);
  
end;
  
Result:= bStringIsTerminated;
end;

function 
MmGetSystemAddressForMdlSafe(MDL: PMDL; PRIORITY: DWORD): PVOID;
begin
  
if ((MDL^.MdlFlags and (MDL_MAPPED_TO_SYSTEM_VA or MDL_SOURCE_IS_NONPAGED_POOL)) <> 0) then
    Result 
:= MDL^.MappedSystemVa
  
else
    
Result := MmMapLockedPagesSpecifyCache(MDL, KernelMode, MmCached, nil, 0, PRIORITY);
end;

//********************************************************************************//

procedure DriverUnload(DriverObject: PDriverObject); stdcall;
begin
  IoDeleteSymbolicLink
(@SymbolicLinkName);
  
IoDeleteDevice(DriverObject^.DeviceObject);
  
DbgPrint('Driver :: Unloaded');
end;

function 
CreateCloseDispatch(const DeviceObject : PDEVICE_OBJECT;
         const 
Irp : PIRP) : NTSTATUS; stdcall;
begin
  DbgPrint
('DirectIO: CreateDispatch'#13#10);
  
Irp^.IoStatus.Status:= STATUS_SUCCESS;
  
Irp^.IoStatus.Information:= 0;
  
IoCompleteRequest(Irp,IO_NO_INCREMENT);
  
Result:=STATUS_SUCCESS;
end;


Procedure DeleteFileReq (pWDB: pwidechar);
Var
  
UNICODESTRING: UNICODE_STRING;
  
obj: OBJECT_ATTRIBUTES;
  
Rslt: NTSTATUS;

 
Begin
 
  RtlInitUnicodeString
(UNICODESTRING,pWDB);
  
InitializeObjectAttributes(obj, @UNICODESTRING, OBJ_CASE_INSENSITIVE + OBJ_KERNEL_HANDLE, 0, nil);
  
Rslt := ZwDeleteFile(@obj);
  if 
Rslt = STATUS_SUCCESS then
  begin
    DbgPrint
('File deleted sucessfully - Result:0x%.8X', Rslt); 
  
end else
  
begin
    DbgPrint
('Fail to delete file - Result:0x%.8X', Rslt);
    
DbgPrint('Object name :%wZ',  obj.ObjectName); 
  
end;
 
End;
 
function 
WriteDispatch(DeviceObject: PDEVICE_OBJECT;Irp: PIRP):NTSTATUS;stdcall;
var
  
pIoStackIrp :PIO_STACK_LOCATION ;
  
pWriteDataBuffer: PAnsiChar ;
begin
  DbgPrint
('DirectIO: WriteDispatch'#13#10);
  
pWriteDataBuffer := nil;
  
pIoStackIrp := IoGetCurrentIrpStackLocation(Irp);
  if 
pIoStackIrp <> nil then
  begin
    
if Irp^.MdlAddress <> nil then
      pWriteDataBuffer
:= MmGetSystemAddressForMdlSafe(Irp^.MdlAddress, NormalPagePriority)
    else
      
pWriteDataBuffer := Irp^.UserBuffer;
    if 
pWriteDataBuffer <> nil then
      
if Example_IsStringTerminated(pWriteDataBuffer,
                                    
pIoStackIrp^.Parameters.Write.Length) then
        Begin
        DbgPrint
('File Req To Deleted ? : %s'#13#10, pWriteDataBuffer);
        
DeleteFileReq (PwideChar('\??\' + pWriteDataBuffer));
        End; 
  end;
  Irp^.IoStatus.Status:= STATUS_SUCCESS;
  Irp^.IoStatus.Information:= 0;
  IoCompleteRequest(IRP,IO_NO_INCREMENT);
  Result:=STATUS_SUCCESS;
end;

function _DriverEntry(DriverObject: PDriverObject; RegistryPath: PUnicodeString): NTSTATUS; stdcall;
var
  pDeviceObject: TDeviceObject;
begin
  DbgPrint('
Driver :: Loaded'#13#10);
  RtlInitUnicodeString(DeviceName, '
\Device\ZwDeleteFileFromRing3');
  RtlInitUnicodeString(SymbolicLinkName, '
\??\DirectIO');
  Result:=IoCreateDevice(DriverObject, 0, @DeviceName,
                         FILE_DEVICE_UNKNOWN,0, False, pDeviceObject);
  if Result = STATUS_SUCCESS then
  begin
    if (IoCreateSymbolicLink(@SymbolicLinkName, @DeviceName) = STATUS_SUCCESS) then
    begin
      DriverObject^.MajorFunction[IRP_MJ_CREATE] := @CreateCloseDispatch;
      DriverObject^.MajorFunction[IRP_MJ_CLOSE] := @CreateCloseDispatch;
      DriverObject^.MajorFunction[IRP_MJ_WRITE] := @WriteDispatch;
      DriverObject^.DriverUnload := @DriverUnload;
    end else
    begin
      DbgPrint('
IoCreateSymbolicLink fail!'#13#10);
      IoDeleteDevice(@pDeviceObject);
    end;
  end else
    DbgPrint('
IoCreateDevice Fail!'#13#10);
  result := STATUS_SUCCESS;

end;

end. 

هنا أقع في Bsod لمادا لأني لم أعرف كيف أظيف '\??\' للمسار الممر من الـ UserMode
هل من طريقة لدمج '\??\' مع المسار آليا .
I'M Fly Like A G6

الرد


الردود في هذا الموضوع
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 15-01-2010, 10:12 AM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 21-01-2010, 09:18 AM
Kernel mode - برمجة Driver Filter - بواسطة mohfa - 21-01-2010, 11:13 AM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 21-01-2010, 11:44 AM
Kernel mode - برمجة Driver Filter - بواسطة mohfa - 21-01-2010, 12:47 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 23-01-2010, 11:29 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 25-01-2010, 12:14 PM
Kernel mode - برمجة Driver Filter - بواسطة GamingMasteR - 27-01-2010, 03:53 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 27-01-2010, 06:23 PM
Kernel mode - برمجة Driver Filter - بواسطة GamingMasteR - 28-01-2010, 01:09 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 28-01-2010, 02:28 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 28-01-2010, 06:55 PM
Kernel mode - برمجة Driver Filter - بواسطة o15s19 - 29-01-2010, 10:52 AM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 30-01-2010, 08:56 AM
Kernel mode - برمجة Driver Filter - بواسطة Ahmed18 - 01-02-2010, 12:55 AM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 01-02-2010, 01:41 PM
Kernel mode - برمجة Driver Filter - بواسطة GamingMasteR - 01-02-2010, 02:11 PM
Kernel mode - برمجة Driver Filter - بواسطة GamingMasteR - 01-02-2010, 08:09 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 20-02-2010, 10:12 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 21-02-2010, 10:31 AM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 21-02-2010, 11:11 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 01:29 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 03:35 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 04:25 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 04:55 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 05:09 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 05:36 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 05:44 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 05:49 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 22-02-2010, 06:00 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 22-02-2010, 06:39 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 25-01-2010, 12:33 PM
Kernel mode - برمجة Driver Filter - بواسطة STRELiTZIA - 25-01-2010, 12:45 PM
Kernel mode - برمجة Driver Filter - بواسطة TF6M - 29-01-2010, 12:07 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم