如何在 NSIS 中使用 kernel32 中的 ReadFile

How to use ReadFile from kernel32 with NSIS

我正在尝试使用 NSIS 安装程序打开一个文件并读取缓冲区中的内容。 不幸的是,除 KERNEL32::ReadFile 外,一切正常。我了解到很多人对此有一些疑问 API,我找不到解决方案。

这是我的代码:

StrCpy  \TOS.TXT
System::Call 'Kernel32::CreateFile(t, i, i, i, i, i, i) i (r2, 0x80000000, 0, 0, 4, 0x80, 0) .r3' 
System::Call 'kernel32::GetFileSize(pr3, p0)i.r7' ; Call API to read 32-bit file size
System::Call "kernel32::VirtualAlloc(i0, ir7, i0x3000, i0x40) .r1"
System::Call "KERNEL32::ReadFile(pr3,pr1,ir7,*i,p0)i.r3"

文件打开良好,缓冲区大小正确。

感谢任何帮助, 谢谢, 克里斯

您的 VirtualAlloc 调用缺少 .r1 之前的输出类型。

不需要使用系统插件来读取一个简单的文件。

!macro MakeTestFile
FileOpen [=10=] "$temp\nsis_test.txt" w
FileWrite [=10=] "Hello$\nWorld!"
FileClose [=10=]
!macroend


StrCpy  "$temp\nsis_test.txt"

!insertmacro MakeTestFile
FileOpen [=10=] "" r
FileRead [=10=]  ; Line 1
FileRead [=10=]  ; Line 2
FileClose [=10=]
MessageBox MB_OK 

!insertmacro MakeTestFile
FileOpen [=10=] "" r
FileSeek [=10=] 1 SET
FileReadByte [=10=] 
FileClose [=10=]
IntFmt  "0x%.2X" 
MessageBox MB_OK "Byte #2 is "

!insertmacro MakeTestFile
System::Call 'KERNEL32::CreateFile(t, i, i, p, i, i, p) p (r9, 0x80000000, 0, 0, 4, 0x80, 0) .r3' 
System::Call 'KERNEL32::GetFileSize(pr3, p0)i.r7'
System::Call "KERNEL32::VirtualAlloc(p0, pr7, i0x3000, i0x40)p.r1"
System::Call "KERNEL32::ReadFile(pr3,pr1,ir7,*i,p0)i.r3"
System::Call "USER32::MessageBoxA(p$hwndparent,pr1,t 'System::Call',i0)"
System::Call "KERNEL32::VirtualFree(pr1,p0,i0x8000)"

System插件也有System::Alloc/StrAlloc/Free所以需要内存的不用直接调用VirtualAlloc