NSIS获取产品版本解决方案失败

时间:2018-11-29 15:48:11

标签: nsis

我一直在尝试使用系统调用GetFileVersionInfo和VerQueryValue来获取exe的产品版本。我使用的是旧版NSIS v2.0b3(很多脚本已在使用中,只想做些小改动)。

搜索了一段时间后,我看到了这个解决方案 Product version string from an exe - nsis ...但是在使其正常工作方面存在问题。

主要电话似乎有效...即

System::Call 'VERSION::GetFileVersionInfo(tr3,i,ir4,ir5)i.r0'
MessageBox MB_OK "GetFileVersionInfo returned dwLen=[$4] and lpData=[$5] for the block of Version Info"

...显示合理的PTR在$ 5。 下一个电话是哪里出了问题...

System::Call 'VERSION::VerQueryValue(ir5,t"\",*i.r6,*i.r7)i.r0'
StrCmp $0 0 fail
MessageBox MB_OK "VS_FIXEDFILEINFO returned as lplpBuffer=[$6] and PUINT=[$7]"

此调用返回0,0,分别为$ 6和$ 7。然后解析当然会失败...

;;---Parse buffer at $6 (lplp)
System::Call '*$6(i,i,i,i,i.r2,i.r1)'
MessageBox MB_OK "Read data from struct @$6: skip 4 ints then ints are dwProductVersionMS:[$2] dwProductVersionLS:[$1]"

...返回0,0。

我在想问题是这里的$ 6间接指针。 也就是说,$ 6是类型    LPVOID * lplpBuffer ....所以我认为设置$ 6值的调用语法可能需要不同。

欢迎任何帮助...我尝试了一些变体而没有成功。

===以下请求已发布,这是我尝试过的许多变化中的最新结果...希望可以帮助阐明我在做什么===

Function GetDllProductVersion
; https://stackoverflow.com/questions/34616470/nsis-get-product-version?rq=1
; https://stackoverflow.com/questions/38707235/product-version-string-from-an-exe-nsis slightly different System::Call's, but also later nsis not compatible

    ;;System::Store S   ;;;removed this and the matching Store L, as that crashes
    Pop $3

;;  System::Call 'VERSION::GetFileVersionInfoSize(tr3,*i)i.r4'
;;  MessageBox MB_OK "GetFileVersionInfoSize gets size [$4]"        ; cannot get a sensible answer, returns "error" in $4

    ;;---allocate block, address into $5
    StrCpy $4 0
    IntOp $4 $4 + 10000     ; set $4 to 10000
    System::Call '*(&i$4,t""r1,t""r2)i.r5' ; Set $1 and $2 to "" so they are empty if we fail
    MessageBox MB_OK "System::Call allocs [$4] bytes at addr [$5], next call GetFileVersionInfo"
    StrCmp $4 0 fail
    StrCmp $5 0 fail

    ;;---GetFileVersionInfo now-----
    System::Call 'VERSION::GetFileVersionInfo(tr3,i,ir4,ir5)i.r0'       ;; ir5 not isr5 ?? diff between solutions
    StrCmp $0 0 fail
    MessageBox MB_OK "GetFileVersionInfo returned dwLen=[$4] and lpData=[$5] for the block of Version Info"

    ;;---Now we get the VS_FIXEDFILEINFO structure using $5.... $6 will be lplpBuffer for it and $7 will be PUINT ptr to size of data in lplpBuffer
    System::Call 'VERSION::VerQueryValue(ir5,t"\",*i.r6,*i.r7)i.r0'     ;; using &i.r6 etc, not *i.r6 gives 0,0 no good, go back to *
    StrCmp $0 0 fail
    MessageBox MB_OK "VS_FIXEDFILEINFO returned as lplpBuffer=[$6] and PUINT=[$7]"

    ;;---Parse buffer at $6 (lplp)
    System::Call '**$6(i,i,i,i,i.r2,i.r1)'
    MessageBox MB_OK "Read data from struct @$6: skip 4 ints then ints are dwProductVersionMS:[$2] dwProductVersionLS:[$1]"

    ;;;or?????
    System::Call '**$6(i,i,i,i,&i.r2,&i.r1)'
    MessageBox MB_OK "Read data using & from struct @$6: skip 4 ints then ints are dwProductVersionMS:[$2] dwProductVersionLS:[$1]"

fail:
System::Free $5

    MessageBox MB_OK "After System::Free [$5]"
Push $1
Push $2
;;System::Store L       ;;;this crashes!!! so push and pop indiv registers used
FunctionEnd

1 个答案:

答案 0 :(得分:0)

我无法解释为何System::Store崩溃,据记载即使在v2.0b3中它也可以工作。再说一次,您使用的是15年历史的 beta 软件,因此您不能指望一切都能正常工作。可能与错误v163(11年前)中修复的错误1620178有关。

您的主要问题是v2.0b3不自动支持带有A后缀的函数名(大多数采用/返回字符串的函数)。似乎在v2.0b4中添加了对此功能的支持。

您可以通过对后缀进行硬编码来修改发现的兼容代码:

Function GetDllProductVersion
Exch $3
Push $1
Push $2
Exch 2
Push $4
Push $5
Push $6
Push $7
Push $0
System::Call 'VERSION::GetFileVersionInfoSizeA(tr3,*i)i.r4'
System::Call '*(&i$4,t""r1,t""r2)i.r5' ; Set $1 and $2 to "" so they are empty if we fail
StrCmp $4 0 fail
StrCmp $5 0 fail
    System::Call 'VERSION::GetFileVersionInfoA(tr3,i,ir4,ir5)i.r0'
    StrCmp $0 0 fail
    System::Call 'VERSION::VerQueryValueA(ir5,t"\",*i.r6,*i.r7)i.r0'
    StrCmp $0 0 fail
    System::Call '*$6(i,i,i,i,i.r2,i.r1)'
fail:
System::Free $5
Pop $0
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Exch $1
Exch
Exch $2
FunctionEnd


Section
!define DllName "c:\windows\system32\ComCtl32.dll"

Push "${DllName}"
Call GetDllProductVersion
Pop $R0
Pop $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
DetailPrint 'ProdVer: $R2.$R3.$R4.$R5'
SectionEnd

但我强烈建议您升级到最新版本。至少要获得v2.51才能获得所有安全修复程序。