RegEnumValue和REG_MULTI_SZ类型 [英] RegEnumValue and REG_MULTI_SZ type

查看:230
本文介绍了RegEnumValue和REG_MULTI_SZ类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSDN说,有关RegEnumValue得到了

字符串数据

  

如果数据是REG_SZ,REG_MULTI_SZ或REG_EXPAND_SZ类型,
  串可能没有被存储在与适当的空终止
  字符。因此,即使该函数返回ERROR_SUCCESS,该
  应用程序应该确保该字符串是正确终止
  之前使用它;否则,可能会覆盖缓冲液。 (注意
  REG_MULTI_SZ字符串应该有两个空的结束字符。)


假设一个值是REG_MULTI_SZ,这是否意味着每个序列中的字符串可以或不可以是空值终止,或者只是只有最后的双空终止可能不存在,但所有的内空终结是present ?


解决方案

  

假设一个值是REG_MULTI_SZ,这是否意味着每个序列中的字符串可以或不可以是空值终止


序列中的字符串的必须的被空终止,否则这将是不可能的,以确定该字符串的一端和下一个字符串开头。从注册表值类型描述 REG_MULTI_SZ


空值终止字符串序列,用一个空字符串(\\ 0)终止。
下面是一个例子:    字符串1 \\ 0String2 \\ 0String3 \\ 0LastString \\ 0 \\ 0第一\\ 0终止所述第一字符串,第二个到最后\\ 0终止
最后一个字符串,以及最终\\ 0终止序列。
请注意,最终必须将端子计入串的长度。

该文档是模糊的,但我的跨pretation是最后的空终结可能会丢失:

 的String1 \\ 0String2 \\ 0String3 \\ 0LastString

和code读取值必须确保它们对后续的字符串提取present。

如果正在使用的缓冲区包含值足够大,包括终止空字符的空间,只要code确保尾随空是present没有什么可担心。

MSDN says about string data got by RegEnumValue that

If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, the string may not have been stored with the proper null-terminating characters. Therefore, even if the function returns ERROR_SUCCESS, the application should ensure that the string is properly terminated before using it; otherwise, it may overwrite a buffer. (Note that REG_MULTI_SZ strings should have two null-terminating characters.)

Suppose a value is REG_MULTI_SZ, does this mean that each of the strings in the sequence can or cannot be null-terminated, or just that only last double null terminator may be absent, but all inner null terminators are present?

解决方案

Suppose a value is REG_MULTI_SZ, does this mean that each of the strings in the sequence can or cannot be null-terminated

The strings in the sequence must be null terminated or else it would be impossible to determine where one of the string ends and the next string begins. From Registry Value Types describing REG_MULTI_SZ:

A sequence of null-terminated strings, terminated by an empty string (\0).
The following is an example:

    String1\0String2\0String3\0LastString\0\0

The first \0 terminates the first string, the second to the last \0 terminates
the last string, and the final \0 terminates the sequence.
Note that the final terminator must be factored into the length of the string.

The documentation is vague but my interpretation is that the last null terminators may be missing:

String1\0String2\0String3\0LastString

and code reading the value must ensure they are present for subsequent string extraction.

If the buffer being used to contain the value is large enough, including space for the terminating null characters, as long as the code ensures the trailing nulls are present there is nothing to be concerned about.

这篇关于RegEnumValue和REG_MULTI_SZ类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆