delphi编写的虚拟磁盘开发源码分析Word文档格式.docx
- 文档编号:20191497
- 上传时间:2023-01-17
- 格式:DOCX
- 页数:56
- 大小:47.51KB
delphi编写的虚拟磁盘开发源码分析Word文档格式.docx
《delphi编写的虚拟磁盘开发源码分析Word文档格式.docx》由会员分享,可在线阅读,更多相关《delphi编写的虚拟磁盘开发源码分析Word文档格式.docx(56页珍藏版)》请在冰豆网上搜索。
FILE_END_OF_FILE_INFORMATIONfile_eof;
FILE_BASIC_INFORMATIONfile_basic;
FILE_STANDARD_INFORMATIONfile_standard;
FILE_ALIGNMENT_INFORMATIONfile_alignment;
DbgPrint("
VCDOpenFile\n"
);
device_extension=(PDEVICE_EXTENSION)DeviceObject->
DeviceExtension;
filename=(PCHAR)Irp->
AssociatedIrp.SystemBuffer;
RtlCopyMemory(device_extension->
oldfile_name,
filename,
MAX_PATH);
if(filename[0]=='
\\'
)
{
if(filename[1]=='
//\\server\share\path\XXX.iso->
\?
?
\UNC\\server\share\path\XXX.iso
{
strcpy(afile_name,"
\\?
\\UNC"
strcat(afile_name,filename);
}
else
//\Device\Harddisk0\Partition1\path\XXX.iso不变
strcpy(afile_name,filename);
}
else
//c:
\path\XXX.iso->
\c:
\path\XXX.iso
strcpy(afile_name,"
\\"
strcat(afile_name,filename);
device_extension->
file_name.Length=(USHORT)strlen(afile_name);
file_name.MaximumLength=device_extension->
file_name.Length;
file_name.Buffer=ExAllocatePool(NonPagedPool,device_extension->
file_name.Length);
RtlCopyMemory(
device_extension->
file_name.Buffer,
afile_name,
file_name.Length
);
status=RtlAnsiStringToUnicodeString(
&
ufile_name,
device_extension->
file_name,
TRUE
if(!
NT_SUCCESS(status))
ExFreePool(device_extension->
file_name.Buffer);
Irp->
IoStatus.Status=status;
IoStatus.Information=0;
returnstatus;
InitializeObjectAttributes(
object_attributes,
OBJ_CASE_INSENSITIVE,
NULL,
NULL
status=ZwCreateFile(
file_handle,
GENERIC_READ,
Irp->
IoStatus,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE|FILE_RANDOM_ACCESS|FILE_NO_INTERMEDIATE_BUFFERING|FILE_SYNCHRONOUS_IO_NONALERT,
0
if(status==STATUS_OBJECT_NAME_NOT_FOUND||status==STATUS_NO_SUCH_FILE)
//如果长度是0
ExFreePool(device_extension->
RtlFreeUnicodeString(&
ufile_name);
Irp->
IoStatus.Status=STATUS_NO_SUCH_FILE;
DbgPrint("
文件不存在!
\n"
returnSTATUS_NO_SUCH_FILE;
elseif(!
RtlFreeUnicodeString(&
DbgPrint("
打开文件失败!
RtlFreeUnicodeString(&
//获取虚拟光盘文件基础信息
status=ZwQueryInformationFile(
file_basic,
sizeof(FILE_BASIC_INFORMATION),
FileBasicInformation
ZwClose(device_extension->
file_handle);
1获取文件信息失败!
file_standard,
sizeof(FILE_STANDARD_INFORMATION),
FileStandardInformation
2获取文件信息失败!
file_size.QuadPart=file_standard.EndOfFile.QuadPart;
文件长度[%d]!
device_extension->
file_size.QuadPart);
file_alignment,
sizeof(FILE_ALIGNMENT_INFORMATION),
FileAlignmentInformation
3获取文件信息失败!
DeviceObject->
AlignmentRequirement=file_alignment.AlignmentRequirement;
//只读
Characteristics|=FILE_READ_ONLY_DEVICE;
//媒体在光驱内
media_in_device=TRUE;
Irp->
IoStatus.Status=STATUS_SUCCESS;
returnSTATUS_SUCCESS;
}
VCDCloseFile(
VCDCloseFile\n"
ASSERT(DeviceObject!
=NULL);
ASSERT(Irp!
ExFreePool(device_extension->
ZwClose(device_extension->
media_in_device=FALSE;
PDEVICE_OBJECTdevice_object;
PLIST_ENTRYrequest;
PIRPirp;
PIO_STACK_LOCATIONio_stack;
PUCHARsystem_buffer;
PUCHARbuffer;
DeviceThread\n"
device_object=(PDEVICE_OBJECT)Context;
device_extension=(PDEVICE_EXTENSION)device_object->
//把线程自身优先级设置较低-----必须如此才能保证对文件读写正常.否则内核模式优先级别高的话写文件会失败
KeSetPriorityThread(KeGetCurrentThread(),LOW_REALTIME_PRIORITY);
for(;
;
//等待事件被触发
KeWaitForSingleObject(
&
k_event,
Executive,
KernelMode,
FALSE,
NULL
KeWaitForSingleObject被触发\n"
//如果线程结束标志被设置了,就结束自身
if(device_extension->
terminate_thread)
PsTerminateSystemThread(STATUS_SUCCESS);
//解锁
while(request=ExInterlockedRemoveHeadList(
list_head,
list_lock
))
irp=CONTAINING_RECORD(request,IRP,Tail.Overlay.ListEntry);
io_stack=IoGetCurrentIrpStackLocation(irp);
io_stack->
MajorFunction=[%u]\n"
io_stack->
MajorFunction);
switch(io_stack->
MajorFunction)
{
//读
caseIRP_MJ_READ:
system_buffer=(PUCHAR)MmGetSystemAddressForMdlSafe(irp->
MdlAddress,NormalPagePriority);
if(system_buffer==NULL)
{
irp->
IoStatus.Status=STATUS_INSUFFICIENT_RESOURCES;
break;
}
buffer=(PUCHAR)ExAllocatePool(PagedPool,io_stack->
Parameters.Read.Length);
if(buffer==NULL)
ZwReadFile(
device_extension->
NULL,
&
irp->
buffer,
io_stack->
Parameters.Read.Length,
Parameters.Read.ByteOffset,
NULL
);
RtlCopyMemory(system_buffer,buffer,io_stack->
ExFreePool(buffer);
break;
//写,直接返回写保护
caseIRP_MJ_WRITE:
irp->
IoStatus.Status=STATUS_MEDIA_WRITE_PROTECTED;
//设备控制
caseIRP_MJ_DEVICE_CONTROL:
switch(io_stack->
Parameters.DeviceIoControl.IoControlCode)
//我们定义的打开文件
caseIOCTL_VCD_OPEN_FILE:
SeImpersonateClient(device_extension->
security_client_context,NULL);
IoStatus.Status=VCDOpenFile(device_object,irp);
VCDOpenFile=[%u]\n"
irp->
IoStatus.Status);
PsRevertToSelf();
PsRevertToSelf\n"
);
//我们定义的关闭文件
caseIOCTL_VCD_CLOSE_FILE:
IoStatus.Status=VCDCloseFile(device_object,irp);
default:
IoStatus.Status=STATUS_DRIVER_INTERNAL_ERROR;
default:
irp->
}
IoCompleteRequest(
irp,
(CCHAR)(NT_SUCCESS(irp->
IoStatus.Status)?
IO_DISK_INCREMENT:
IO_NO_INCREMENT)
(3)、VCD.h
#ifndef_VCD_
#define_VCD_
#ifndef__T
#ifdef_NTDDK_
#define__T(x)L##x
#else
#define__T(x)x
#endif
#ifndef_T
#define_T(x)__T(x)
#defineDEVICE_BASE_NAME_T("
\\VCD"
#defineDEVICE_DIR_NAME_T("
\\Device"
)DEVICE_BASE_NAME
#defineDEVICE_FULL_NAMEDEVICE_DIR_NAMEDEVICE_BASE_NAME
#defineDEVICE_VCD0x8000
//打开文件
#defineIOCTL_VCD_OPEN_FILECTL_CODE(DEVICE_VCD,0x800,METHOD_BUFFERED,FILE_READ_ACCESS|FILE_WRITE_ACCESS)
//关闭文件
#defineIOCTL_VCD_CLOSE_FILECTL_CODE(DEVICE_VCD,0x801,METHOD_BUFFERED,FILE_READ_ACCESS|FILE_WRITE_ACCESS)
//查询设备信息
#defineIOCTL_VCD_QUERY_DEVICECTL_CODE(DEVICE_VCD,0x802,METHOD_BUFFERED,FILE_READ_ACCESS)
#defineMAX_PATH260
#defineDWORDunsignedlong
#defineWORDunsignedshort
#defineBOOLunsignedlong
#defineBYTEunsignedchar
/*
//虚拟光驱文件信息
typedefstruct_VCD_FILE_INFORMATION{
LARGE_INTEGERFileSize;
//文件大小
UCHARFileName[MAX_PATH];
//文件名
}VCD_FILE_INFORMATION,*PVCD_FILE_INFORMATION;
*/
//设备的信息
typedefstruct_VCD_DEVICE_INFORMATION{
ULONGMagic;
//标示,符和这个标示就认为是VCD设备
ULONGVersion;
//版本
ULONGIndex;
//设备序号
BOOLMediaIn;
//设备中是否有媒体
UCHARDescaption[MAX_PATH];
//设备描述
}VCD_DEVICE_INFORMATION,*PVCD_DEVICE_INFORMATION;
#defineDEVICE_MAGIC0xAAFFFFAA
#defineDEVICE_VERSION0x00000001
//创建多少个CDROM设备,我定为4个.
#defineDEVICE_COUNT0x4
//驱动对象扩展信息
typedefstruct_DEVICE_EXTENSION{
ULONGindex;
//设备的ID
BOOLEANmedia_in_device;
//设备里是否有媒体
HANDLEfile_handle;
//文件句柄
UCHARoldfile_name[MAX_PATH];
//传进来的原始文件名
ANSI_STRINGfile_name;
LARGE_INTEGERfile_size;
//文件大小
PSECURITY_CLIENT_CONTEXTsecurity_client_context;
//客户端安全上下文
LIST_E
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- delphi 编写 虚拟 磁盘 开发 源码 分析