Windows 注册表中 DefaultConnectionSettings 值的格式是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4283027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the format of the DefaultConnectionSettings value in the Windows registry?
提问by Andrew Swan
The Windows registry key HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections contains a binary value called DefaultConnectionSettings that stores all sorts of data about the user's proxy configuration. What's the exact format of this data?
Windows 注册表项 HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections 包含一个名为 DefaultConnectionSettings 的二进制值,用于存储有关用户代理配置的各种数据。这些数据的确切格式是什么?
All I have been able to find out so far is what's in this forum post, which is by no means complete and seems to be wrong in some respects.
到目前为止,我所能找到的只是这个论坛帖子中的内容,这绝不是完整的,并且在某些方面似乎是错误的。
回答by Zain Ali
I have found this perhaps it helps you!
我发现这也许对你有帮助!
0. keep this value
1. "00" placeholder
2. "00" placeholder
3. "00" placeholder
4. "xx" increments if changed
5. "xx" increments if 4. is "FF"
6. "00" placeholder
7. "00" placeholder
8. "01"=proxy deaktivated; other value=proxy enabled
9. "00" placeholder
10. "00" placeholder
11. "00" placeholder
12. "xx" length of "proxyserver:port"
13. "00" placeholder
14. "00" placeholder
15. "00" placeholder
"proxyserver:port"
if 'Bypass proxy for local addresses':::
other stuff with unknown length
"<local>"
36 times "00"
if no 'Bypass proxy for local addresses':::
40 times "00"
回答by Remy Lebeau
Rather than read/write the Registry value directly, you should be using WinInet's InternetQueryOption()
and InternetSetOption()
functions instead.
与其直接读/写注册表值,不如改用 WinInetInternetQueryOption()
和InternetSetOption()
函数。
With that said, have a look at these:
话虽如此,看看这些:
How to set 'automatic configuration script' for a dial-up connection programmatically?
回答by Pascal
Steven's answer is quite complete, just the many "placeholders" surprised me. My researches show, that most of them are in fact 32-bit integers stored in little-endian format (i.e. lowest byte first, i.e. 0xa1b2c3d4ist stored as 0xd4 0xc3 0xb2 0xa1). This makes the magic DefaultConnectionSettingspretty simple:
史蒂文的回答很完整,只是许多“占位符”让我感到惊讶。我的研究表明,它们中的大多数实际上是以小端格式存储的 32 位整数(即最低字节在前,即0xa1b2c3d4 被存储为0xd4 0xc3 0xb2 0xa1)。这使得神奇的DefaultConnectionSettings变得非常简单:
4 bytes int: 0x46 or 0x3C (whatever that means)
4 bytes int: counter, increment upon every change
4 bytes int: proxy settings, i.e. a merge of these bits:
0x1 always present
0x2 enable manual proxy
0x4 enable autoconfig
0x8 enable autodetect
4 bytes int: length of proxyServer string (can be 0)
proxyServer string in ASCII (i.e. server:port)
4 bytes int: length of proxyOverrides string (can be 0)
proxyOverrides string in ASCII (domains separated by ;
use <local> for local override)
4 bytes int: length of autoconfigUrl string (can be 0)
autoconfigUrl string in ASCII
4 bytes int: 0x00 or 0x01 (whatever that means)
31 bytes: 0x00 (whatever that means)
回答by Steven Hall
Just want to expand upon Zain Ali's answer (as an answer, since I don't have enough reputation points to comment), and of Course, thank Zain for posting the information that they did as it helped me greatly when I was trying to figure the rest out.
只是想扩展 Zain Ali 的答案(作为答案,因为我没有足够的声望点来评论),当然,感谢 Zain 发布他们所做的信息,因为它在我试图弄清楚时对我帮助很大剩下的。
Number 8 is a little more complicated than just showing that the proxy is disabled or not. It also sets two other checkboxes in the settings.
数字 8 比仅显示代理是否被禁用要复杂一些。它还在设置中设置了另外两个复选框。
Setting number 8 to "01" unchecks the box to enable the proxy, and unchecks the box to "Automatically Detect Settings" and the box to use a script.
将数字 8 设置为“01”会取消选中启用代理的框,并取消选中“自动检测设置”框和使用脚本的框。
Setting number 8 to "0f" however enables everything.
然而,将数字 8 设置为“0f”可以启用所有功能。
To be clear, this 8th byte is basically setting flags. The least significant bit of the byte is always a "1" so far as i can tell. The second least significant bit is "1" if the manual proxy settings checkbox is checked. The 3rd least significant bit is a "1" if the box for using a script is checked and you provide an address for the script. The 4th least significant bit is to set the checkbox "Automatically Detect Settings" (basically, setting these bits to 1 checks the box, and 0 unchecks them)
需要明确的是,这第 8 个字节基本上是设置标志。据我所知,字节的最低有效位始终为“1”。如果选中手动代理设置复选框,则第二个最低有效位为“1”。如果选中了使用脚本的框并且您提供了脚本的地址,则第三个最低有效位为“1”。第 4 个最低有效位是设置复选框“Automatically Detect Settings”(基本上,将这些位设置为 1 选中复选框,0 取消选中它们)
I have gone for setting it to "03" which enables only the manual proxy
我已经将它设置为“03”,它只启用手动代理
Also, "Other stuff with unknown length" doesn't seem to be correct as the length is known. Stuff after that is being referred to is the exception list for the proxy delimited by a semi-colon. The length of this list is the byte right after the "proxyserver:port". That, combined withe the 3 "00"s of padding accounts for the difference of 4 bytes that was mentioned as being different depending on what else you had.
此外,“其他长度未知的东西”似乎不正确,因为长度是已知的。之后的内容是由分号分隔的代理的例外列表。这个列表的长度是紧跟在“proxyserver:port”之后的字节。那,再加上 3 个“00”的填充,就说明了 4 个字节的差异,这取决于您拥有的其他内容。
0. keep this value
1. "00" placeholder
2. "00" placeholder
3. "00" placeholder
4. "xx" increments if changed
5. "xx" increments if 4. is "FF"
6. "00" placeholder
7. "00" placeholder
8. "03"=enable proxy, enable auto detect settings, auto script etc
9. "00" placeholder
10. "00" placeholder
11. "00" placeholder
12. "xx" length of "proxyserver:port"
13. "00" placeholder
14. "00" placeholder
15. "00" placeholder
"proxyserver:port"
"xx" length of proxy exception list
"00" placeholder
"00" placeholder
"00" placeholder
Proxy Exception list delimited by semi-colons (use "<local>" to exclude local addresses)
36 times "00"
I have spent quite some time trying to figure this all out so hopefully I haven't missed something.
我花了很长时间试图弄清楚这一切,所以希望我没有错过任何东西。
I have made a batch script where you can give it the proxy server and port, along with your list of exceptions and it will automatically create the binary code and stick it into the registry where it needs to be (assuming that the 8th byte is "03").
我制作了一个批处理脚本,您可以在其中为其提供代理服务器和端口以及您的异常列表,它将自动创建二进制代码并将其粘贴到需要的注册表中(假设第 8 个字节是“ 03")。
It would be trivial to change the code to just print out the binary instead by just replacing the whole "reg add" line with "echo %data%".
只需将整个“reg add”行替换为“echo %data%”,即可将代码更改为仅打印出二进制文件,这将是微不足道的。
Also note that the script i have provided below is changing the HKLM key as I was using the script to set a machine-wide proxy in conjunction with GPOs. Changing to HKCU instead should fix that.
另请注意,我在下面提供的脚本正在更改 HKLM 密钥,因为我正在使用该脚本与 GPO 一起设置机器范围的代理。改为改用 HKCU 应该可以解决这个问题。
That can be found here (if you are good with batch, feel free to make the script better as I am not greatly familiar with it and I think it will probably show in the code): https://gist.github.com/hallzy/b7dfba5f71c0251f1139f8c531cd7817
可以在这里找到(如果您擅长批处理,请随时改进脚本,因为我对它不是很熟悉,我认为它可能会显示在代码中):https: //gist.github.com/ Hallzy/b7dfba5f71c0251f1139f8c531cd7817
回答by Shayan
Steven Hall and Zain Ali's answers are really good, but they are not accurate.
Steven Hall 和 Zain Ali 的回答非常好,但并不准确。
I tried my best to get it as accurate as I can, but as you know with reverse engineering an API which has no documentation of, there could be mistakes:
我尽我最大的努力让它尽可能准确,但正如你所知,逆向工程一个没有文档的 API,可能会出现错误:
1. 46
2. 00
3. 00
4. 00
5. Increments when you click the OK button on Lan Settings window
6. Inc overflow of 5
7. Inc overflow of 6
8. Inc overflow of 7
9. Toggle proxy* (This can have different values, read below)
10. 00
11. 00
12. 00
13. Length of server addresses and ports
14. Inc overflow of the length of server addresses and ports
15. Inc overflow of the length of server addresses and ports of above
16. Inc overflow of the length of server addresses and ports of above
17. Server addresses and ports (Omitted if length was 0)
??. Length of Exception addresses / Bypass local
??. Inc overflow of the length of Exception addresses / Bypass local
??. Inc overflow of the length of Exception addresses / Bypass local of above
??. Inc overflow of the length of Exception addresses / Bypass local of above
??. Exception addresses / Bypass local (Omitted if length was 0)
??. Length of Automatic Configuration Script Address and port
??. Inc overflow of the Length of Automatic Configuration Script Address and port
??. Inc overflow of the Length of Automatic Configuration Script Address and port of above
??. Inc overflow of the Length of Automatic Configuration Script Address and port of above
??. Automatic Configuration Script Address and port (Omitted if length was 0)
??. Mysterious 01: It only appears when: Automatically detect settings should be off and settings applied, now tick both Auto detect settings and auto config address (doesn't matter if it's empty). There's no way to get rid of this 01.
??. 31 00's at the end
Proxy toggle binary: Depending on what the value is, it could toggle the Proxy server, the Automatically detect settings and the Use automatic configuration script tick boxes.
代理切换二进制文件:根据值的不同,它可以切换代理服务器、自动检测设置和使用自动配置脚本复选框。
Disabled
1
5 autoconf
9 autodetect
4 autoconf
8 autodetect
0c (12) autoconf, autodetect
0d (13) autoconf, autodetect
Enabled
2
3
6 autoconf
7 autoconf
0a (10) autodetect
0b (11) autodetect
0e (14) autoconf, autodetect
0f (15) autoconf, autodetect
I went about figuring out all of this because I'm making a proxy manager AHK script on Github, once it's done I'll share the link here so you can use. And if I figure out what the rest of those 00's are, or any other finding, I'll update this answer.
我想弄清楚所有这些,因为我正在 Github 上制作代理管理器 AHK 脚本,一旦完成,我将在此处分享链接,以便您可以使用。如果我弄清楚剩下的那些 00 是什么,或任何其他发现,我会更新这个答案。