enum USN 内存中的数据,结果数据不正确。我不知道该怎么办
public static void main(String[] args) throws IOException {
// get c volume handle
WinNT.HANDLE handle = Kernel32.INSTANCE.CreateFile("\\\\.\\C:",WinNT.GENERIC_READ|WinNT.GENERIC_WRITE,
WinNT.FILE_SHARE_READ|WinNT.FILE_SHARE_WRITE,null,WinNT.OPEN_EXISTING,0,null);
IntByReference bytesByReturned = new IntByReference();
// output to memory
Memory memory = new Memory(Integer.MAX_VALUE);
memory.clear();
// input query args
MFT_ENUM_DATA med = new MFT_ENUM_DATA();
med.StartFileReferenceNumber = 0;
med.LowUsn = 0;
med.HighUsn = 99999999;
med.write();
int FSCTL_ENUM_USN_DATA = 0x000900B3;
// access device, get usn data to memory buffer object
boolean ok = Kernel32.INSTANCE.DeviceIoControl(handle,FSCTL_ENUM_USN_DATA, med.getPointer(),
med.size(), memory, (int)memory.size(), bytesByReturned, null);
if(ok) {
// that's wrong!!! , get the wrong data!
int RecordLength = memory.getInt(0);
short MajorVersion = memory.getShort(4);
short MinorVersion = memory.getShort(6);
long FileReferenceNumber = memory.getLong(8);
// error value
System.out.println("RecordLength:\t"+RecordLength);
System.out.println("MajorVersion:\t"+MajorVersion);
System.out.println("MinorVersion:\t"+MinorVersion);
System.out.println("FileReferenceNumber:\t"+FileReferenceNumber);
// ...
}else {
System.out.println("ERROR "+Kernel32.INSTANCE.GetLastError()+" "+ Kernel32Util.getLastErrorMessage());
throw new IOException("DeviceIoControl() returned false", new Win32Exception(Kernel32.INSTANCE.GetLastError()));
}
}
static public class MFT_ENUM_DATA extends Structure {
public long StartFileReferenceNumber;
public long LowUsn;
public long HighUsn;
@Override
protected List<String> getFieldOrder() {
List<String> order = new ArrayList<>();
order.add("StartFileReferenceNumber");
order.add("LowUsn");
order.add("HighUsn");
return order;
}
}
我无法从内存缓冲区对象中获取结构数据,我该怎么办?
typedef struct USN_RECORD_V2 {
DWORD RecordLength;
WORD MajorVersion;
WORD MinorVersion;
DWORDLONG FileReferenceNumber;
DWORDLONG ParentFileReferenceNumber;
USN Usn;
LARGE_INTEGER TimeStamp;
DWORD Reason;
DWORD SourceInfo;
DWORD SecurityId;
DWORD FileAttributes;
WORD FileNameLength;
WORD FileNameOffset;
WCHAR FileName[1];
} *PUSN_RECORD_V2;
链接:
- DeviceIoControl FSCTL_ENUM_USN_DATA
-输入 MFT_ENUM_DATA_V0 结构
-输出内存 --> USN_RECORD_V2 结构
从内存中获取 USN_RECORD_V2。非常感谢。