trent
驱动老牛
驱动老牛
  • 注册日期2002-03-01
  • 最后登录2014-09-18
  • 粉丝0
  • 关注0
  • 积分61分
  • 威望185点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
阅读:2166回复:15

文件加解密

楼主#
更多 发布于:2004-07-21 14:39
  对U盘进行动态加解密,但有些问题,当我吧文件拖到U盘里进行加密时系统给崩了,这是我的代码,情大家帮我看看
if ( Irp->MdlAddress )
{
    pInData =(CHAR *) MmGetSystemAddressForMdlSafe(Irp-     >MdlAddress, NormalPagePriority);
}
else
{
    pInData = (CHAR *) Irp->UserBuffer;
}
if ( pInData )
{
    pNewBuffer = ExAllocatePool( NonPagedPool, strlen(  pInData ) + 1 );
if ( pNewBuffer )
{
     RtlZeroMemory( pNewBuffer,strlen( pNewBuffer ) + 1 );
     EncryptInit( Mykey,sizeof(Mykey) );
     m_x = 0, m_y = 0;
     len = strlen( pInData );
if ( len > 0 )
{
     Encrypt( pNewBuffer,pInData,m_state,len );
     RtlZeroMemory( pInData,0,len );
     RtlCopyMemory( pInData,pNewBuffer,len );
     ExFreePool( pNewBuffer );
}
else
{
     ExFreePool( pNewBuffer );  
}
主要是RTL

最新喜欢:

ljmmaryljmmar...
我不仅要金子,我还要点石成金的手指!
wowocock
VIP专家组
VIP专家组
  • 注册日期2002-04-08
  • 最后登录2016-01-09
  • 粉丝16
  • 关注2
  • 积分601分
  • 威望1651点
  • 贡献值1点
  • 好评度1227点
  • 原创分1分
  • 专家分0分
沙发#
发布于:2004-07-21 18:20
在那个地方崩掉的???
花开了,然后又会凋零,星星是璀璨的,可那光芒也会消失。在这样 一瞬间,人降生了,笑者,哭着,战斗,伤害,喜悦,悲伤憎恶,爱。一切都只是刹那间的邂逅,而最后都要归入死亡的永眠
zhangc98
驱动牛犊
驱动牛犊
  • 注册日期2002-03-30
  • 最后登录2004-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-07-22 11:40
你的这段程序是放在哪里?
是在IRP_MJ_WRITE里面么?
最好把完整的代码贴出来,
这样不太容易看出什么问题,
目前:新手上路; 目标:高级站友; 理想:开国大佬; 方法:自己的努力+大家的关照!
trent
驱动老牛
驱动老牛
  • 注册日期2002-03-01
  • 最后登录2014-09-18
  • 粉丝0
  • 关注0
  • 积分61分
  • 威望185点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
地板#
发布于:2004-07-22 12:29
主要在COPY时崩了
是在IRP_MJ_WRITE里
有时我把文件拖到U盘里很正常,在覆盖文件时SOFTICE捕捉到KECHECKBUG错误,
我不仅要金子,我还要点石成金的手指!
trent
驱动老牛
驱动老牛
  • 注册日期2002-03-01
  • 最后登录2014-09-18
  • 粉丝0
  • 关注0
  • 积分61分
  • 威望185点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2004-07-23 08:51
没人理我哟!
埃!
只好自己发贴了!
我发现我的缓冲区是USERBUFFER,从来没有MDL,
再者不能改变原来缓冲区里的内容!
有哪位老大给解释下!
我不仅要金子,我还要点石成金的手指!
zhangc98
驱动牛犊
驱动牛犊
  • 注册日期2002-03-30
  • 最后登录2004-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2004-07-23 13:58
U盘的文件格式应该是FAT16的吧,
和N2000下的NTFS有比较大的区别,
我猜想可能是这个引起的问题。

你可以先在别的磁盘上试试看有没有同样的问题,
如果没有的话,估计就是文件格式的原因
如果也存在同样的问题,
就是程序本身的原因了:)

具体是那方面造成的, 因为没有研究过U盘,
所以还不好下结论,不过至少昨天我在做测试的时候
U盘好像还马马虎虎,但是也不是太完善,
这种东西最好是自己多做试验,
提问的话最好把代码、症状、测试条件、系统环境介绍的尽量详细,
因为这种东西可能出问题的地方非常多,祝你好运:)
目前:新手上路; 目标:高级站友; 理想:开国大佬; 方法:自己的努力+大家的关照!
trent
驱动老牛
驱动老牛
  • 注册日期2002-03-01
  • 最后登录2014-09-18
  • 粉丝0
  • 关注0
  • 积分61分
  • 威望185点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2004-07-23 15:08
zhangc98
你好!
你还在吗?
谢谢你的回复!
现在的现象是同时拷贝很多的文件时系统给崩了!
是PAGE_FAULT_IN_NONPAGED_AREA 错误代码为50
希望我们有更多的交流机会!
MYQQ:4932992
我不仅要金子,我还要点石成金的手指!
zhangc98
驱动牛犊
驱动牛犊
  • 注册日期2002-03-30
  • 最后登录2004-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2004-07-26 17:24
ok,你的pInData或者pNewBuffer是全局变量还是局部变量?
在copy的过程中,IRP_MJ_WRITE可能会同时发生、或者很快发来很多,而此时前面一个可能还没有处理完。
因此,如果使用全局变量的话,必须保证一段缓冲在加解密的过程中不被其他进程打断改写。
必要的话,可能需要将处理手工串行化。

检查一下是不是这个问题:)
good luck!

目前:新手上路; 目标:高级站友; 理想:开国大佬; 方法:自己的努力+大家的关照!
satanli1982
驱动牛犊
驱动牛犊
  • 注册日期2004-03-07
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分7分
  • 威望3点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
8楼#
发布于:2004-07-27 09:45
to zhangc98
串行化不影响速度吗?
trent
驱动老牛
驱动老牛
  • 注册日期2002-03-01
  • 最后登录2014-09-18
  • 粉丝0
  • 关注0
  • 积分61分
  • 威望185点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
9楼#
发布于:2004-07-27 12:39
谢谢大家的回复!
    死机的问题已经解决,我没有用原来的BUFFER,用新的BUFFER代替了老的!
    但还有一个问题:我在文件得头部加了16字节得标记,整样使系统确认文件得大小已改变呢?
    我把写得LENGTH得长度加了16系统会写两次,并且系统资源占用达到%110!
    希望大家能给些建议!
我不仅要金子,我还要点石成金的手指!
zhangc98
驱动牛犊
驱动牛犊
  • 注册日期2002-03-30
  • 最后登录2004-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
10楼#
发布于:2004-07-27 20:13
to zhangc98
串行化不影响速度吗?
 


当然会影响速度,不过需要实现别的功能,不得不在性能上有所损失,呵呵:)
目前:新手上路; 目标:高级站友; 理想:开国大佬; 方法:自己的努力+大家的关照!
zhangc98
驱动牛犊
驱动牛犊
  • 注册日期2002-03-30
  • 最后登录2004-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
11楼#
发布于:2004-07-27 20:15
谢谢大家的回复!
    死机的问题已经解决,我没有用原来的BUFFER,用新的BUFFER代替了老的!
    但还有一个问题:我在文件得头部加了16字节得标记,整样使系统确认文件得大小已改变呢?
    我把写得LENGTH得长度加了16系统会写两次,并且系统资源占用达到%110!
    希望大家能给些建议!


死机的问题解决了么?能不能把问题的原因、以及你解决的方法比较详细的介绍一下?呵呵:)
毕竟是一次经验的积累吗,你说清楚了别人就可以避免同样的错误,大家互相学习嘛:)
目前:新手上路; 目标:高级站友; 理想:开国大佬; 方法:自己的努力+大家的关照!
trent
驱动老牛
驱动老牛
  • 注册日期2002-03-01
  • 最后登录2014-09-18
  • 粉丝0
  • 关注0
  • 积分61分
  • 威望185点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
12楼#
发布于:2004-07-28 12:49
zhangc98
   你好!
   我当时犯了个低级的错误,用STRLEN取原来缓冲区的长度,当为零时就截断了,还有就是调试的问题,有时是需要磁盘扫描当系统启动时,搞的我很郁闷!
现在的问题我要做到透明的加解密!
不知你有何建议!整样算是透明的加解密!
我不仅要金子,我还要点石成金的手指!
zhangc98
驱动牛犊
驱动牛犊
  • 注册日期2002-03-30
  • 最后登录2004-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
13楼#
发布于:2004-07-28 18:10
你所说的调试的问题,磁盘扫描之类的,我不太明白你的意思:)
可以详细说说么?我怀疑我现在遇到类似的问题,呵呵:)

目前:新手上路; 目标:高级站友; 理想:开国大佬; 方法:自己的努力+大家的关照!
zdhe
驱动太牛
驱动太牛
  • 注册日期2001-12-26
  • 最后登录2018-06-02
  • 粉丝0
  • 关注0
  • 积分72362分
  • 威望362260点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
  • 社区居民
14楼#
发布于:2004-08-06 00:57
hello.

some times you can not InBuffer in IRP_MJ_WRTITE, because the pages is maked as READ ONLY.

you can modify it. ( i have done before, but how, forget how to)

i get same problem in my project. i know the reason , but i still can not resolve it.

if not , you program should have problem in
 
RtlCopyMemory( pInData,pNewBuffer,len );


reason:
for MDL write, the IRP_MJ_WRITE comes in two phases.
one is for IRP_MN_MDL
and one is for IRP_MN_MDL_COMPLETE

for irp_mn_mdl, before call low device, the Irp->MdlAddresss should be null.

after call, the mdl is allocated, but data has not been set.

in IRP_MN_MDL_COMPLETE phase, the data comes , but ...
now here's a new problem.

why?
take this look:
i use MmMdlGetByteCount to confirm, i get know the memroy i can use in mdl is 2f38 bytes.
when check Irpsp->Parameters.Write.Length, it's df38 bytes.

so when run to
RtlCopyMemory( pInData,pNewBuffer,len );

the len should be df38 in you program.(it seems CIFS always write data as 10c8 * n except last several bytes)

then , page fault.

when you share you U-disk and write through network share, it will happen ,almost 100% if file is larger then 300K.

OK.
I have checked full IRP_MJ_WRIET with various MINOR code,
with PAGEING IO. the minor code is always maked as IRP_MN_NORMAL. so you can get data from paging io .

it seem it can resolve you problem, but can not resolve mine.

i does not want to PAGINGIO. paging io is asyn and befoer PAGING IRP_MJ_WRITE, IRP_MJ_CLOSE or IRP_MJ_CLEANUP happens.

i do not want to wait....



--------------------------

following is a OSR document

Kernel mode callers of the read and write interface (IRP_MJ_READ and
IRP_MJ_WRITE) can utilize an interface that allows retrieval of a pointer to the data as
it is located in the file system data cache. This allows the kernel mode caller to retrieve
the data for the file without an additional data copy.
For example, the AFD file system driver has an API function it exports that takes a
socket handle and a file handle. The file contents are “copied” directly to the
corresponding communications socket. The AFD driver accomplishes this task by
sending an IRP_MJ_READ with the IRP_MN_MDL minor operation. The FSD then
retrieves an MDL describing the cached data (at Irp->MdlAddress) and completes the
request. When AFD has completed processing the operation it must return the MDL to
the FSD by sending an IRP_MJ_READ with the IRP_MN_MDL_COMPLETE minor
operation specified.
For a file system filter driver, the write operation may be a bit more confusing. When a
caller specifies IRP_MJ_WRITE/IRP_MN_MDL the returned MDL may point to
uninitialized data regions within the cache. That is because the cache manager will
refrain from reading the current data in from disk (unless necessary) in anticipation of the
caller replacing the data. When the caller has updated the data, it releases the buffer by
calling IRP_MJ_WRITE/IRP_MN_MDL_COMPLETE. At that point the data has
been written back to the cache.
An FSD that is integrated with the cache manager can implement these minor functions
by calling CcMdlRead and CcPrepareMdlWrite. The corresponding functions for
NTFSD Frequently Asked Questions
Content provided by 24
OSR Open Systems Resources, Inc.
completing these are CcMdlReadComplete and CcMdlWriteComplete. An FSD that
is not integrated with the cache manager can either indicate these operations are not
supported (in which case the caller must send a buffer and support the “standard”
read/write mechanism) or it can implement them in some other manner that is
appropriate.








[编辑 -  8/6/04 by  zdhe]

[编辑 -  8/6/04 by  zdhe]
trent
驱动老牛
驱动老牛
  • 注册日期2002-03-01
  • 最后登录2014-09-18
  • 粉丝0
  • 关注0
  • 积分61分
  • 威望185点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
15楼#
发布于:2004-08-06 09:03
谢谢大家的回复!
    现在我要做到透明的加解密,不知道大家对透明的加解密是整样理解的,他的应用又在哪些方面呢?
    还有CcFlushCache 这些函数是在哪个头文件里定义的呢?
我不仅要金子,我还要点石成金的手指!
游客

返回顶部