如何在NSIS中使用kernel32的ReadFile

问题描述 投票:0回答:1

我正在尝试使用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"

文件已正确打开,并且缓冲区以正确的大小正确创建。

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

buffer nsis readfile kernel32
1个回答
0
投票

您的VirtualAlloc呼叫在.r1之前缺少输出类型。

不需要仅使用System插件来读取简单文件。

!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

© www.soinside.com 2019 - 2024. All rights reserved.