WiX:在自定义操作中提取二进制字符串会产生类似“???good data”的字符串

发布于 2024-08-30 14:30:54 字数 744 浏览 1 评论 0原文

我刚刚在尝试从 MSI 的二进制表中提取字符串时发现了一个奇怪的行为。

我有一个包含 Hello world 的文件,我得到的数据是 ???Hello world。 (文学问号。)

这是预期的吗?
开头总是正好 3 个字符吗?


Sample code:

[CustomAction]
public static ActionResult CustomAction2(Session session)
{
    View v = session.Database.OpenView("SELECT `Name`,`Data` FROM `Binary`");
    v.Execute();

    Record r = v.Fetch();
    int datalen = r.GetDataSize("Data");
    System.IO.Stream strm = r.GetStream("Data");
    byte[] rawData = new byte[datalen];
    int res = strm.Read(rawData, 0, datalen);
    strm.Close();

    String s = System.Text.Encoding.ASCII.GetString(rawData);
    // s == "???Hello World"

    return ActionResult.Success;
}

I just found a weird behavior when attempting to extract a string from the Binary table in the MSI.

I have a file containing Hello world, the data I get is ???Hello world. (Literary question mark.)

Is this as intended?
Will it always be exactly 3 characters in the beginning?


Sample code:

[CustomAction]
public static ActionResult CustomAction2(Session session)
{
    View v = session.Database.OpenView("SELECT `Name`,`Data` FROM `Binary`");
    v.Execute();

    Record r = v.Fetch();
    int datalen = r.GetDataSize("Data");
    System.IO.Stream strm = r.GetStream("Data");
    byte[] rawData = new byte[datalen];
    int res = strm.Read(rawData, 0, datalen);
    strm.Close();

    String s = System.Text.Encoding.ASCII.GetString(rawData);
    // s == "???Hello World"

    return ActionResult.Success;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏日落 2024-09-06 14:30:54

大胆猜测,但如果您使用记事本创建文件,那难道不是您的字节顺序标记?

Wild guess, but if you created the file using Notepad, couldn't that just be your byte order mark?

秉烛思 2024-09-06 14:30:54

尝试

String s = System.Text.Encoding.UTF8.GetString(rawData);
if (s.Length > 0 && s[0] == '\uFEFF')
{
    s = s.Substring(1);
}

代替 String s = System.Text.Encoding.ASCII.GetString(rawData);

Try

String s = System.Text.Encoding.UTF8.GetString(rawData);
if (s.Length > 0 && s[0] == '\uFEFF')
{
    s = s.Substring(1);
}

instead of String s = System.Text.Encoding.ASCII.GetString(rawData);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文