阅读:2413回复:15
各位老大帮帮忙,我给filedisk使用rc4加密读写,怎么就无法格式化生成的盘呢?
各位老大帮帮忙,我给filedisk使用rc4加密读写,怎么就无法格式化生成的盘呢?
使用的RC4算法在普通win32程序(MFC)里点问题都没有,完全可以正常的加解密。 搜遍了整个论坛,就是没看到一个完整的关于filedisk加解密的例子。郁闷啊!始终都弄不好,都有点泄气了。 在那个“文件系统驱动”群里叫拜师学艺也没人理,呵呵,没办法。 最近工作又不顺利,很郁闷啊,别人没完成工作说是因为我的关系,很不爽啊! 喜欢搞驱动,但感觉好难啊!希望大家帮帮忙啊!先谢谢了! 不想一直都搞数据库。不是特别喜欢。还是喜欢搞系统方面的了。 |
|
|
沙发#
发布于:2004-07-05 12:49
郁闷,没人愿意帮忙解决问题??
太没意思了。 这儿太没人气了。 |
|
|
板凳#
发布于:2004-07-06 12:37
郁闷,一天来看一回,结果还是没有一个人回复。
|
|
|
地板#
发布于:2004-07-06 12:51
大概是你在回应format的时候,给出的数据是错的,或者没有解密。
|
|
|
地下室#
发布于:2004-07-06 12:58
晕啊,现在代码也没在办公室,
但为什么在应用程序里都可以加解密啊? |
|
|
5楼#
发布于:2004-07-06 20:14
// CPP 文件
#include "RC4.h" #define BUFFER_SIZE 1024 static void SwapByte(unsigned char *a, unsigned char *b) { unsigned char swapByte; swapByte = *a; *a = *b; *b = swapByte; } void PrepareKey(unsigned char * pKeyData, int iKeyDataLen, RC4KEY * pKey) { // unsigned char ucSwapByte; unsigned char ucIndex1; unsigned char ucIndex2; unsigned char * state; unsigned short counter; state = &pKey->state[0]; for(counter = 0; counter < 256; counter++) state[counter] = (unsigned char)counter; pKey->x = 0; pKey->y = 0; ucIndex1 = 0; ucIndex2 = 0; for(counter = 0; counter < 256; counter++) { ucIndex2 = (pKeyData[ucIndex1] + state[counter] + ucIndex2) % 256; SwapByte(&state[counter], &state[ucIndex2]); ucIndex1 = (ucIndex1 + 1) % iKeyDataLen; } } void RC4(unsigned char * pBuffer, int iBufferLen, RC4KEY * pkey) { unsigned char x; unsigned char y; unsigned char * state; unsigned char xorIndex; unsigned short counter; x = pkey->x; y = pkey->y; state = &pkey->state[0]; for(counter = 0; counter < iBufferLen; counter ++) { x = (x + 1) % 256; y = (state[x] + y) % 256; SwapByte(&state[x], &state[y]); xorIndex = (state[x] + state[y]) % 256; pBuffer[counter] ^= state[xorIndex]; } pkey->x = x; pkey->y = y; } |
|
|
6楼#
发布于:2004-07-06 20:15
// 头文件
#ifndef _RC4_H_ #define _RC4_H_ typedef struct _RC4KEY { unsigned char state[256]; unsigned char x; unsigned char y; }RC4KEY; static void SwapByte(unsigned char *a, unsigned char *b); void PrepareKey(unsigned char * pKeyData, int iKeyDataLen, RC4KEY * pKey); void RC4(unsigned char * pBuffer, int iBufferLen, RC4KEY * pkey); #endif |
|
|
7楼#
发布于:2004-07-06 20:15
// 驱动代码
//--------------添加变量---------------- unsigned char * szKey; RC4KEY * pKey; //-------------------------------------- ASSERT(Context != NULL); device_object = (PDEVICE_OBJECT) Context; device_extension = (PDEVICE_EXTENSION) device_object->DeviceExtension; KeSetPriorityThread(KeGetCurrentThread(), LOW_REALTIME_PRIORITY); //--------------添加代码---------------- szKey = ExAllocatePool(NonPagedPool,8); RtlCopyMemory(szKey, "abcdefg", 8); //-------------------------------------- for (;;) { KeWaitForSingleObject( &device_extension->request_event, Executive, KernelMode, FALSE, NULL ); if (device_extension->terminate_thread) { PsTerminateSystemThread(STATUS_SUCCESS); } while (request = ExInterlockedRemoveHeadList( &device_extension->list_head, &device_extension->list_lock )) { irp = CONTAINING_RECORD(request, IRP, Tail.Overlay.ListEntry); io_stack = IoGetCurrentIrpStackLocation(irp); switch (io_stack->MajorFunction) { case IRP_MJ_READ: pCurrentAddress = MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority); pTempBuffer = ExAllocatePool(NonPagedPool,io_stack->Parameters.Read.Length); ZwReadFile( device_extension->file_handle, NULL, NULL, NULL, &irp->IoStatus, //MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority), pTempBuffer, io_stack->Parameters.Read.Length, &io_stack->Parameters.Read.ByteOffset, NULL ); //------------------解密pTempBuffer------------------ pKey = ExAllocatePool(NonPagedPool,sizeof(RC4KEY)); PrepareKey(szKey, 8, pKey); PrepareKey(szKey, 8, pKey); RC4(pTempBuffer,io_stack->Parameters.Read.Length,pKey); //--------------------------------------------------- RtlCopyMemory(pCurrentAddress,pTempBuffer,io_stack->Parameters.Read.Length); //----------------- ExFreePool(pKey); //----------------- ExFreePool(pTempBuffer); break; case IRP_MJ_WRITE: if ((io_stack->Parameters.Write.ByteOffset.QuadPart + io_stack->Parameters.Write.Length) > device_extension->file_information.AllocationSize.QuadPart) { irp->IoStatus.Status = STATUS_INVALID_PARAMETER; irp->IoStatus.Information = 0; } pCurrentAddress = MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority); pTempBuffer=ExAllocatePool(NonPagedPool,io_stack->Parameters.Write.Length); RtlCopyMemory(pTempBuffer,pCurrentAddress,io_stack->Parameters.Write.Length); //------------------加密pTempBuffer------------------ pKey = ExAllocatePool(NonPagedPool,sizeof(RC4KEY)); PrepareKey(szKey, 8, pKey); RC4(pTempBuffer,io_stack->Parameters.Write.Length,pKey); //--------------------------------------------------- ZwWriteFile( device_extension->file_handle, NULL, NULL, NULL, &irp->IoStatus, //MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority), pTempBuffer, io_stack->Parameters.Write.Length, &io_stack->Parameters.Write.ByteOffset, NULL ); //----------------- ExFreePool(pKey); //----------------- ExFreePool(pTempBuffer); break; |
|
|
8楼#
发布于:2004-07-06 20:17
上面的代码生成的sys,用filedisk.exe生成盘后不能成功的格式化,大家帮忙看看啊!!
|
|
|
9楼#
发布于:2004-07-06 20:29
帖这么多代码干嘛。
先把加密去掉,记录回应的各个数据,再和加上加密以后的比较,不就知道了嘛! |
|
|
10楼#
发布于:2004-07-06 21:32
怎么记录啊?弄不来啊!学驱动还没怎么入门啊!
感觉好难哦!! |
|
|
11楼#
发布于:2004-07-21 12:02
我有同样的问题,不知哪位大侠帮解决一下呀!
|
|
12楼#
发布于:2004-07-21 12:05
我跟踪发现格式化时是先进IRP_MJ_READ,那不成了先解密了吗,这时应该还没加密呢吧
|
|
13楼#
发布于:2004-07-23 13:19
我跟踪发现格式化时是先进IRP_MJ_READ,那不成了先解密了吗,这时应该还没加密呢吧 分组加密解密要注意边界对齐! 估计是你加密和解密的分组没有对齐。 |
|
|
14楼#
发布于:2009-12-20 20:03
不知,楼主这问题解决了没有,我也遇到了这样的问题.
|
|
15楼#
发布于:2009-12-21 16:29
同问,楼上的QQ多少,讨论下
|
|