我正在尝试打开一个文件,并使用NSIS安装程序读取缓冲区中的内容。不幸的是,除了KERNEL32::ReadFile之外,一切都可以正常工作。我读到很多人对这个API有一些问题,而我找不到解决方案。
下面是我的代码:
StrCpy $2 $2\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"文件打开得很好,缓冲区也创建得很好,大小也是正确的。
感谢你的帮助,谢谢,克里斯
发布于 2020-02-27 23:11:13
您的VirtualAlloc调用缺少.r1之前的输出类型。
不需要仅仅为了读取一个简单的文件而使用系统插件。
!macro MakeTestFile
FileOpen $0 "$temp\nsis_test.txt" w
FileWrite $0 "Hello$\nWorld!"
FileClose $0
!macroend
StrCpy $9 "$temp\nsis_test.txt"
!insertmacro MakeTestFile
FileOpen $0 "$9" r
FileRead $0 $1 ; Line 1
FileRead $0 $2 ; Line 2
FileClose $0
MessageBox MB_OK $1$2
!insertmacro MakeTestFile
FileOpen $0 "$9" r
FileSeek $0 1 SET
FileReadByte $0 $1
FileClose $0
IntFmt $1 "0x%.2X" $1
MessageBox MB_OK "Byte #2 is $1"
!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::Alloc/StrAlloc/Free,因此如果您需要内存,则不需要直接调用VirtualAlloc。
https://stackoverflow.com/questions/60424329
复制相似问题