如何读入字节数组文件内容然后更新它们并写入另一个文件?
How to read into byte array file contents and then update them and write into another file?
我希望 nsis 能够从文件内容读取到字节数组,更新数组,然后将缓冲区的内容写入另一个文件。
我的代码
System::Call "kernel32::GetFileSize(i[=10=],i0)i.s"
Pop
System::Alloc ;Reading file contents into a buffer
Pop $buffer
System::Call "kernel32::ReadFile(i[=10=],i$buffer,i,*i.r6,i0)i.s"
loop2:
StrCpy $buffer 1
StrCmp '' end
IntOp + 1
goto loop2
我希望能够遍历从文件中读取的字节数组并能够更改其内容。 (例如 OR 字节)我想节省直接从文件读取字节然后将单个字节写入新文件的时间。所以这就是为什么要使用分配的缓冲区字节数组。
那可能吗?我看到nsis本身不支持数组。
NSIS 不支持字节数组,但系统插件结构语法允许您访问内存缓冲区中的原始字节:
!include LogicLib.nsh
!include Util.nsh
ShowInstDetails show
!macro DisplayTestFile
FileOpen [=10=] "$PluginsDir\Test.txt" r
FileRead [=10=]
FileClose [=10=]
DetailPrint Line1=
!macroend
Section
InitPluginsDir
FileOpen [=10=] "$PluginsDir\Test.txt" w
${If} [=10=] P<> 0
FileWrite [=10=] "HELLO World$\r$\n"
FileClose [=10=]
${EndIf}
!insertmacro DisplayTestFile
FileOpen [=10=] "$PluginsDir\Test.txt" a
${If} [=10=] P<> 0
FileSeek [=10=] 0 Set
System::Call "KERNEL32::GetFileSize(pr0,p0)i.r1"
${IfThen} = -1 ${|} Abort "Could not get file size" ${|}
System::Call '*(&i,i0)p.r2' ; Allocate the file size + a zero terminator just in case
${If} P<> 0
System::Call "KERNEL32::ReadFile(pr0,pr2,ir1,*i,p0)i.r3"
${If} <> 0
${For} 0 5 ; Change byte 0..5
System::Call '*(&i,&i1.r4)' ; Read a byte
IntOp | 32
System::Call '*(&i,&i1 r4)' ; Write a byte
${Next}
FileSeek [=10=] 0 Set
System::Call "KERNEL32::WriteFile(pr0,pr2,ir1,*i,p0)i.r3"
${EndIf}
System::Free
${EndIf}
FileClose [=10=]
${EndIf}
!insertmacro DisplayTestFile
SectionEnd
我希望 nsis 能够从文件内容读取到字节数组,更新数组,然后将缓冲区的内容写入另一个文件。
我的代码
System::Call "kernel32::GetFileSize(i[=10=],i0)i.s"
Pop
System::Alloc ;Reading file contents into a buffer
Pop $buffer
System::Call "kernel32::ReadFile(i[=10=],i$buffer,i,*i.r6,i0)i.s"
loop2:
StrCpy $buffer 1
StrCmp '' end
IntOp + 1
goto loop2
我希望能够遍历从文件中读取的字节数组并能够更改其内容。 (例如 OR 字节)我想节省直接从文件读取字节然后将单个字节写入新文件的时间。所以这就是为什么要使用分配的缓冲区字节数组。 那可能吗?我看到nsis本身不支持数组。
NSIS 不支持字节数组,但系统插件结构语法允许您访问内存缓冲区中的原始字节:
!include LogicLib.nsh
!include Util.nsh
ShowInstDetails show
!macro DisplayTestFile
FileOpen [=10=] "$PluginsDir\Test.txt" r
FileRead [=10=]
FileClose [=10=]
DetailPrint Line1=
!macroend
Section
InitPluginsDir
FileOpen [=10=] "$PluginsDir\Test.txt" w
${If} [=10=] P<> 0
FileWrite [=10=] "HELLO World$\r$\n"
FileClose [=10=]
${EndIf}
!insertmacro DisplayTestFile
FileOpen [=10=] "$PluginsDir\Test.txt" a
${If} [=10=] P<> 0
FileSeek [=10=] 0 Set
System::Call "KERNEL32::GetFileSize(pr0,p0)i.r1"
${IfThen} = -1 ${|} Abort "Could not get file size" ${|}
System::Call '*(&i,i0)p.r2' ; Allocate the file size + a zero terminator just in case
${If} P<> 0
System::Call "KERNEL32::ReadFile(pr0,pr2,ir1,*i,p0)i.r3"
${If} <> 0
${For} 0 5 ; Change byte 0..5
System::Call '*(&i,&i1.r4)' ; Read a byte
IntOp | 32
System::Call '*(&i,&i1 r4)' ; Write a byte
${Next}
FileSeek [=10=] 0 Set
System::Call "KERNEL32::WriteFile(pr0,pr2,ir1,*i,p0)i.r3"
${EndIf}
System::Free
${EndIf}
FileClose [=10=]
${EndIf}
!insertmacro DisplayTestFile
SectionEnd