首页
社区
课程
招聘
一个源码函数看不懂,请高手指点
发表于: 2010-7-9 09:51 3464

一个源码函数看不懂,请高手指点

2010-7-9 09:51
3464
ULONGLONG *GetFileClusters(
                    PCHAR lpFileName,
                    ULONG ClusterSize,
                    ULONG *ClCount,
                    ULONG *FileSize
                    )
{
    HANDLE  hFile;
    ULONG   OutSize;
    ULONG   Bytes, Cls, CnCount, r;
    ULONGLONG *Clusters = NULL;
    BOOLEAN Result = FALSE;
    LARGE_INTEGER PrevVCN, Lcn;
    STARTING_VCN_INPUT_BUFFER  InBuf;
    PRETRIEVAL_POINTERS_BUFFER OutBuf;

    hFile = CreateFile(lpFileName, FILE_READ_ATTRIBUTES,
                       FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
                       NULL, OPEN_EXISTING, 0, 0);

    if (hFile != INVALID_HANDLE_VALUE)
    {
        *FileSize = GetFileSize(hFile, NULL);

        OutSize = sizeof(RETRIEVAL_POINTERS_BUFFER) + (*FileSize / ClusterSize) * sizeof(OutBuf->Extents);  //此处很不明白

        OutBuf = malloc(OutSize);

        InBuf.StartingVcn.QuadPart = 0;
               
        if (DeviceIoControl(hFile, FSCTL_GET_RETRIEVAL_POINTERS, &InBuf,
                            sizeof(InBuf), OutBuf, OutSize, &Bytes, NULL))
        {
            *ClCount = (*FileSize + ClusterSize - 1) / ClusterSize;  //如下不明白

            Clusters = malloc(*ClCount * sizeof(ULONGLONG));

            PrevVCN = OutBuf->StartingVcn;

            for (r = 0, Cls = 0; r < OutBuf->ExtentCount; r++)
            {
                Lcn = OutBuf->Extents[r].Lcn;

                for (CnCount = (ULONG)(OutBuf->Extents[r].NextVcn.QuadPart - PrevVCN.QuadPart);
                     CnCount; CnCount--, Cls++, Lcn.QuadPart++) Clusters[Cls] = Lcn.QuadPart;

                PrevVCN = OutBuf->Extents[r].NextVcn;
            }
        }
                       
        free(OutBuf);       

        CloseHandle(hFile);
    }
    return Clusters;
}

[课程]Android-CTF解题方法汇总!

收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 205
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
Contains the output for the FSCTL_GET_RETRIEVAL_POINTERS control code.

Syntax
Copytypedef struct RETRIEVAL_POINTERS_BUFFER {
  DWORD         ExtentCount;
  LARGE_INTEGER StartingVcn;
  struct {
    LARGE_INTEGER NextVcn;
    LARGE_INTEGER Lcn;
  } Extents[1];
} RETRIEVAL_POINTERS_BUFFER, *PRETRIEVAL_POINTERS_BUFFER;
Members
ExtentCount
The count of elements in the Extents array.

StartingVcn
The starting VCN returned by the function call. This is not necessarily the VCN requested by the function call, as the file system driver may round down to the first VCN of the extent in which the requested starting VCN is found.

Extents
Array of Extents structures. For the number of members in the array, see ExtentCount. Each member of the array has the following members.

NextVcn
The VCN at which the next extent begins. This value minus either StartingVcn (for the first Extents array member) or the NextVcn of the previous member of the array (for all other Extents array members) is the length, in clusters, of the current extent. The length is an input to the FSCTL_MOVE_FILE operation.

Lcn
The LCN at which the current extent begins on the volume. This value is an input to the FSCTL_MOVE_FILE operation. On the NTFS file system, the value (LONGLONG) –1 indicates either a compression unit that is partially allocated, or an unallocated region of a sparse file.
-------------------------------------------
这是msdn上结构的定义  OutBuf  就是存储这样一个结构 和 若干个Array of Extents structures 理解这个就知道Outsize为什么那么大小了
2010-7-10 14:26
0
雪    币: 273
活跃值: (64)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
3
不知道如何关闭帖子,问题解决了,谢谢楼上
2010-7-11 11:56
0
雪    币: 2067
活跃值: (82)
能力值: ( LV9,RANK:180 )
在线值:
发帖
回帖
粉丝
4
无法关闭
你需找个回帖人结算 Kx
给我吧. 谢谢
2010-7-11 11:58
0
雪    币: 273
活跃值: (64)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
5
你们两个人都流油了,还要..........
2010-7-11 15:49
0
雪    币: 44
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
进来看看问题是否可以解决 以赚够成会员  没想到。。。。。

  结不了贴的话 给我吧!
2010-7-11 18:18
0
游客
登录 | 注册 方可回帖
返回
//