inno setup 中文乱码问题,在Inno Setup中将字符串编码为Base64(Inno Setup的Unicode版本)...

Problem

I tried to use the Pascal function EncodeStringBase64, assuming Inno Setup had access to the Pascal standard library but it fails to find it and provides an Unknown Identifier error.

I also found this code to carry out the conversion but it seems to be restricted to AnsiStrings.

Question

Ideally I'd like to use the standard library function, is there any way that I can access it?

If not, is the code using AnsiStrings safe to use on normal Unicode strings if I change the signature?

I'm going to carry out testing for it, but I'm worried that I'll test a good number of use cases, but this wouldn't guarantee that it's actually suitable for every character, and edge cases may exist.

解决方案

Base64 encodes bytes, not characters (strings). That's also probably the reason, why the Encode64 implementation, that you have found, takes AnsiString. AnsiString is commonly (ab)used in Inno Setup Pascal Script as a dynamic array of bytes. While string is an array of characters.

If you want to encode a string, you first have to represent the string as an array of bytes (in a way the recipient of the Base64-encoded string expects it) and then you can use your Encode64 implementation.

In case you encode ASCII characters only, you can just blindly cast string to AnsiString. If you use non-ascii characters, you will probably want to convert your UnicodeString to bytes using some encoding, like UTF-8.

As for the resulting string, you can just safely cast it from AnsiString to string, as Base64 uses ASCII characters only (though, it also makes sense to change function signature to return string, as it indeed returns a character string, not byte array).

So for an ASCII input, this will do:

Base64 := string(Encode64(AnsiString(S)));

If you want to use a "standard" function, you can use CryptBinaryToString WinAPI function. Though that won't spare you from solving the above, as the function takes an array of bytes on input (as expected).

The above makes a difference only, if you use Unicode Inno Setup (what you correctly do). Had you used Ansi Inno Setup (what you should not), string is AnsiString.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值