【问题标题】:NSIS ReadCustomerdata no data errorNSIS ReadCustomerdata 没有数据错误
【发布时间】:2017-03-09 12:32:55
【问题描述】:
; Example:
;   Push "CUSTDATA:"
;   Call ReadCustomerData
;   Pop $1
;   StrCmp $1 "" 0 +3
;   MessageBox MB_OK "No data found"
;   Abort
;   MessageBox MB_OK "Customer data: '$1'"
!include LogicLib.nsh
!include StrLoc.nsi
Section
   Push "CUSTDATA:"
   Call ReadCustomerData
   Pop $1
   StrCmp $1 "" 0 +3
   MessageBox MB_OK "No data found"
   Abort
   MessageBox MB_OK "Customer data: '$1'"
SectionEnd
Function ReadCustomerData
  ; arguments
  Exch $R1            ; customer data magic value
  ; locals
  Push $1             ; file name or (later) file handle
  Push $2             ; current trial offset
  Push $3             ; current trial string (which will match $R1 when customer data is found)
  Push $4             ; length of $R1
  Push $5             ; half length of $R1
  Push $6             ; first half of $R1
  Push $7             ; tmp

  FileOpen $1 $EXEPATH r

; change 4096 here to, e.g., 2048 to scan just the last 2Kb of EXE file
  IntOp $2 0 - 4096

  StrLen $4 $R1

  IntOp $5 $4 / 2
  StrCpy $6 $R1 $5


loop:
  FileSeek $1 $2 END
  FileRead $1 $3 $4
  StrCmpS $3 $R1 found

  ${StrLoc} $7 $3 $6 ">"
  StrCmpS $7 "" NotFound
    IntCmp $7 0 FoundAtStart
      ; We can jump forwards to the position at which we found the partial match
      IntOp $2 $2 + $7
      IntCmp $2 0 loop loop
FoundAtStart:
    ; We should make progress
    IntOp $2 $2 + 1
    IntCmp $2 0 loop loop
NotFound:
    ; We can safely jump forward half the length of the magic
    IntOp $2 $2 + $5
    IntCmp $2 0 loop loop

  StrCpy $R1 ""
  goto fin

found:
  IntOp $2 $2 + $4
  FileSeek $1 $2 END
  FileRead $1 $3
  StrCpy $R1 $3

fin:
  Pop $7
  Pop $6
  Pop $5
  Pop $4
  Pop $3
  Pop $2
  Pop $1
  Exch $R1
FunctionEnd

当我运行这个文件时,我没有找到任何数据。我的问题是 1 .我如何编辑它 2. 检索数据。我可以推送什么样的数据以及如何推送。

  1. 我也想用 python 推送数据,我该如何实现呢
  2. 如何使用python编辑exe文件 前两个问题对我很重要

提前致谢 感谢stackoverflow

【问题讨论】:

    标签: python nsis


    【解决方案1】:

    如果你没有添加任何数据,它如何找到数据?您可以添加任何您想要的数据,但ReadCustomerData 函数无法处理二进制数据,只能处理字符串。您可以使用任何可用的方法来写入数据,只需以 CUSTDATA: 开头:

    makensis Test.nsi
    >>"Test.exe" echo.CUSTDATA:Hello World
    start Test.exe
    

    【讨论】:

    • 使用上面的例子,我使用命令 makensis test.nsi 创建一个 test.exe 文件,然后在 cmd 中运行命令“test.exe” echo.CUSTDATA:Hello World exe 自动启动它说没有找到数据我认为我上面的代码已经磨损了我不知道它在哪里打破
    • 您需要>> 部分来回显文件。您也可以只使用十六进制编辑器来附加数据。
    • 当我打开 exe 文件十六进制编辑器时,我只看到奇怪的数字。如果你有一个例子在这里解释一下,我是新手,请安德斯
    • 如果您无法学习有关二进制文件和十六进制编辑器的基础知识,那么这可能不是适合您的项目。 ReadCustomerData 只需要您将一些 ASCII 数据附加到生成的 .exe 的末尾
    • 我如何在 python 中做到这一点
    猜你喜欢
    • 1970-01-01
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    相关资源
    最近更新 更多