如何“按原样"写入二进制数据到注册表(即:我只有来自 regedit 的可见二进制数据作为字符串) [英] How to write Binary Data "as is" to Registry (ie: i have visible binary data as string from regedit only)

查看:22
本文介绍了如何“按原样"写入二进制数据到注册表(即:我只有来自 regedit 的可见二进制数据作为字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在谷歌上搜索,一整天都没有找到可行的解决方案.我对二进制数据类型一无所知(因为我从来没有故意使用它们)并且我正在尝试将我在注册表中看到的二进制值写入注册表.现在,我看到的只是以下 [如下所示] ...如果我尝试将其作为字符串传递给 WinAPI 中的 RegSetValueEx 并且当然它会出错...我没有知道我需要将哪些数字"传递给 RegSetValueExlpData As Any, 参数(我尝试了一个位数组),以便它如下所示[如下所示] 在注册表中.我真的不知道,我在位数组中放置随机数的测试只会产生相应的随机数字",正如在 regedit 中可见的那样,我不明白如何在逻辑上将它们绑定"在一起.

这是罪魁祸首!

<上一页>Windows 注册表编辑器版本 5.00[HKEY_CURRENT_USERSoftwareSomeRegistryLocation]"RegistryKey"=hex:01,00,00,00,d0,8c,9d,df,01,15,d1,11,8c,7a,00,c0,4f,c2,97,eb,1,00,00,00,7b,96,8a,78,b9,cc,c1,4f,b1,35,11,01,5e,3c,25,9b,00,00,00,00,02,0,00,00,00,00,10,66,00,00,00,01,00,00,20,00,00,00,22,1c,b6,ea,e3,a5,06,8b,58,69,7b,89,19,b3,1f,a3,1d,d8,b7,5b,30,72,65,4b,22,41,a8,73,d1,92,bb,36,00,0,00,00,0e,80,00,00,00,02,00,00,20,00,00,00,87,a0,1a,79,a7,c9,fe,7a,1b,24,9a,71,5d,cf,7b,87,bc,1b,14,6e,59,96,e3,42,c6,f5,08,78,00,a6,42,3d,30,00,00,0,02,0a,2a,ea,d9,49,0a,fa,48,b3,f1,e2,ae,e2,f8,42,a2,54,1e,56,dc,dd,9b,0d,9b,73,41,72,54,cc,64,49,99,f1,5c,12,70,33,8e,fb,b1,31,66,df,b4,e0,02,bb,40,0,00,00,13,c2,7d,88,16,af,56,ac,82,21,39,95,43,04,50,71,c2,4c,6a,44,a6,03,ea,32,4d,d9,f3,0f,22,2e,41,17,2e,26,11,9b,10,9d,99,60,fc,12,d2,ce,7c,1c,78,6b,f0,59,23,fd,84,46,2c,58,41,ee,31,7a,f8,95,57,54

如果我在字符串或位数组中有以下内容,我必须用什么填充位数组,以便注册表在写入时输出此 [上方]?或者,我怎样才能弄清楚该怎么做?我希望有一个函数可以读取我的二进制数据字符串并将其转换为真正的二进制格式以提交给 VB6 中的 RegSetValueEx 函数或 VB.Net 或 C# 中的其他函数(这确实是一个与语言无关的问题,并且问题存在于所有语言中;即:相同的过程).

我希望有一个解决方案或我可以遵循的线索.谢谢大家,当我要拔头发的时候,你们是最棒的!

解决方案

没有必要为此使用 API..NET 框架中内置了一个注册表类

试试这个代码,让我知道会发生什么:

Dim rk = Registry.CurrentUser.OpenSubKey("KEY_TO_OPEN", True)rk.SetValue("BinaryValue", New Byte() {10, 43, 44, 45, 14, 255}, _RegistryValueKind.Binary)rk.Close()

您还可以阅读 注册表文档在 MSDN 上以获取更多信息.

I have been googling this and have not come along a working solution for an entire day. I don't know anything about binary data types (as I've never knowingly used them) and I'm trying to write a binary value that I see in the registry, to the registry. Now, all I see is the following [shown below]... and if I try to pass that as a string to the RegSetValueEx in the WinAPI and of course it errors out... I do not know what 'numbers' I need to pass into the lpData As Any, argument of RegSetValueEx (i tried a bit array) in order for it to come out as the following [shown below] in the regedit. I really have no idea, and my tests to place random numbers in the bit array just produce corresponding random "figures" as visible in regedit that I do not understand how to 'tie' them together logically.

here is the culprit!

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USERSoftwareSomeRegistryLocation]
"RegistryKey"=hex:01,00,00,00,d0,8c,9d,df,01,15,d1,11,8c,7a,00,c0,4f,c2,97,eb,
  01,00,00,00,7b,96,8a,78,b9,cc,c1,4f,b1,35,11,01,5e,3c,25,9b,00,00,00,00,02,
  00,00,00,00,00,10,66,00,00,00,01,00,00,20,00,00,00,22,1c,b6,ea,e3,a5,06,8b,
  58,69,7b,89,19,b3,1f,a3,1d,d8,b7,5b,30,72,65,4b,22,41,a8,73,d1,92,bb,36,00,
  00,00,00,0e,80,00,00,00,02,00,00,20,00,00,00,87,a0,1a,79,a7,c9,fe,7a,1b,24,
  9a,71,5d,cf,7b,87,bc,1b,14,6e,59,96,e3,42,c6,f5,08,78,00,a6,42,3d,30,00,00,
  00,02,0a,2a,ea,d9,49,0a,fa,48,b3,f1,e2,ae,e2,f8,42,a2,54,1e,56,dc,dd,9b,0d,
  9b,73,41,72,54,cc,64,49,99,f1,5c,12,70,33,8e,fb,b1,31,66,df,b4,e0,02,bb,40,
  00,00,00,13,c2,7d,88,16,af,56,ac,82,21,39,95,43,04,50,71,c2,4c,6a,44,a6,03,
  ea,32,4d,d9,f3,0f,22,2e,41,17,2e,26,11,9b,10,9d,99,60,fc,12,d2,ce,7c,1c,78,
  6b,f0,59,23,fd,84,46,2c,58,41,ee,31,7a,f8,95,57,54

If I had the following in a string or a bit array, what must I populate the bitarray with so that the registry outputs this [above] when written? or, how can I figure out how to do it? I was hoping there'd be a function that reads my string of binary data and transforms it into the real binary format to submit to the RegSetValueEx function in VB6 or other function in VB.Net or C# (this really is a language agnostic question, and the problem exists in all languages; ie: same process).

I hope there is a solution to this or a lead that I can follow. Thanks guys, you are all the best when I've come to the point of pulling my hair out!

解决方案

There is no need to use APIs for this. There is a registry class built into the .NET framework

Try this code and let me know what happens:

Dim rk = Registry.CurrentUser.OpenSubKey("KEY_TO_OPEN", True)
rk.SetValue("BinaryValue", New Byte() {10, 43, 44, 45, 14, 255}, _
            RegistryValueKind.Binary)
rk.Close()

You can also read the Registry documentation on MSDN for more information.

这篇关于如何“按原样"写入二进制数据到注册表(即:我只有来自 regedit 的可见二进制数据作为字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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