op 似乎删除了他作为评论提出的一些问题并接受了答案,
因此该答案可能与当前上下文无关
op 评论了是否可以在 user_mode 中调用 api 而不加载 ntdll.dll
或调用 api 的两个变体中的任何一个,即 NtSetEaFile 或 ZwSetEaFile
这个答案显示了如何做到
这一点 系统调用号属于 win7 sp1 32 位
编译和执行 0 字节文本文件将被创建,
其扩展信息可以使用ladislav zezulas filetest实用程序或通过检查 ntfs usn 更改记录来检查
#include <windows.h>
#include <winternl.h>
typedef struct _MYEABUFF {
ULONG neoff; UCHAR flg; UCHAR nlen; USHORT vlen; char eaname[0x100];
}MyEaBuff, *PMyEaBuff;
int main() {
HANDLE fhand = CreateFileA("testec.txt", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
const char *Eaname="EATEST";const char *EaValue="This is the text For EATEST";
UCHAR nlen=(UCHAR)strlen(Eaname);USHORT EaValueLen=(USHORT)strlen(EaValue);
IO_STATUS_BLOCK iosb ={0}; MyEaBuff Buff ={0};
Buff.neoff = 0; Buff.flg = 0; Buff.nlen = nlen; Buff.vlen = EaValueLen;
strcpy_s(Buff.eaname, nlen + 1, Eaname);
strcpy_s(Buff.eaname + nlen + 1, EaValueLen + 1, EaValue);
PVOID iosb_ptr = &iosb; PVOID Buff_ptr = &Buff;
__asm {
push 108h
push Buff_ptr
push iosb_ptr
push fhand
call ntseaf
jmp exit
}
ntseaf:
__asm {
mov eax, 142h
mov edx, 7ffe0300h
call dword ptr ds : [edx]
retn 4
}
exit:
return 0;
}
使用 cjdump.exe(旧 msdn mag 代码)检查 bin 的结果
C:\testea>cl /nologo testea.cpp
testea.cpp
C:\testea>testea.exe
C:\testea>CJDump.exe | grep testec.txt
Usn(0x0000000129433C28) Reason(0x00000100) testec.txt < USN_REASON_FILE_CREATE
Usn(0x0000000129433C78) Reason(0x00000500) testec.txt < USN_REASON_EA_CHANGE|0x100
Usn(0x0000000129433CC8) Reason(0x80000500) testec.txt < USN_REASON_CLOSE|0x500