首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在NSIS中使用kernel32中的ReadFile

如何在NSIS中使用kernel32中的ReadFile
EN

Stack Overflow用户
提问于 2020-02-27 07:54:09
回答 1查看 93关注 0票数 0

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

下面是我的代码:

代码语言:javascript
复制
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"

文件打开得很好,缓冲区也创建得很好,大小也是正确的。

感谢你的帮助,谢谢,克里斯

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-27 23:11:13

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

不需要仅仅为了读取一个简单的文件而使用系统插件。

代码语言:javascript
复制
!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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60424329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档