WiX:在自定义操作中提取二进制字符串会产生类似“???good data”的字符串
我刚刚在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大胆猜测,但如果您使用记事本创建文件,那难道不是您的字节顺序标记?
Wild guess, but if you created the file using Notepad, couldn't that just be your byte order mark?
尝试
代替
String s = System.Text.Encoding.ASCII.GetString(rawData);
Try
instead of
String s = System.Text.Encoding.ASCII.GetString(rawData);