NSIS Unicode - 如何获取 INI 文件部分中的所有条目

NSIS Unicode - How to get all entries in section of INI file

https://nsis.sourceforge.io/Get_all_entries_in_section_of_INI_file 有一个 ANSI 版本,但我需要一个 unicode 解决方案。

我的第一个尝试是删除 api 调用(GetPrivateProfileSection 和 lstrlen)中的 A,并将内存增加到 8192。

Function GetSection
    Exch 
    Exch
    Exch 
    Exch
    Exch 2
    Exch [=10=]
    Exch 2
    Push 
    Push 
    Push 
    Push 
    Push 
    Push 

    System::Alloc 8192
        Pop 
        StrCpy  

        System::Call "kernel32::GetPrivateProfileSection(t, i, i, t) i(r1, r4, 8192, r0) .r5"
     
    enumok:
        System::Call 'kernel32::lstrlen(t) i(i r4) .r6'
        StrCmp  '0' enumex
     
        System::Call '*(&t8192 .r9)'
     
    Push [=10=]
    Push 
    Push 
    Push 
    Push 
    Push 
    Push 
    Push 
    Call 
    Pop 
    Pop 
    Pop 
    Pop 
    Pop 
    Pop 
    Pop 
    Pop 
    Pop [=10=]
    StrCmp  'StopGetSection' enumex

        IntOp   + 
        IntOp   + 1
        goto enumok

    enumex:
        System::Free 
     
    Pop 
    Pop 
    Pop 
    Pop 
    Pop 
    Pop 
    Pop 
    Pop 
    Pop [=10=]
FunctionEnd

尽管我的应用程序崩溃了。

Unicode 字符是 2 个字节,使用 System::StrAlloc 分配缓冲区或将传递给 Alloc 的数字加倍。

ini 函数处理的是字符数,而不是字节数。它溢出了缓冲区,因为你没有像你告诉的那样分配。

我编辑了wiki页面,你可以试试新版本...