从C#处理注册表配置单元文件 [英] Manipulate Registry Hive files from C#

查看:184
本文介绍了从C#处理注册表配置单元文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1。)
如何为C#注册表加载,编辑和保存二元Hive文件



Win32 api。
http://msdn.microsoft.com /en-us/library/ee210770%28VS.85%29.aspx



这个人共享代码以将二进制Hive文件的内容转储为文本。
http://www.codeproject.com/KB/recipes/RegistryDumper.aspx除了操作Hive文件,我还会搜索一种方法在运行时使用Hive文件加载到注册表中C#
(与File many中的Load Hive和Unload Hive命令类似于regedit)



/ Thanks $ / b>

解决方案

下面的文章解释了如何在不使用WinAPI(advapi32.dll)的情况下分析注册表文件。在这个特殊情况下,这个人正在使用单声道:

http://volatile-minds.blogspot.com/2011/01/analyzing-windows-nt-registry-without.html

 使用(FileStream fs = File.OpenRead(path)){
var data = new byte [checked((int)fs.Length )];
int i = 0;
int读取;

using(var ms = new MemoryStream(checked((int)fs.Length))){

while((read = fs.Read(data,0,data .Length))> 0){
ms.Write(data,0,read);
i + =读;
}

byte [] hive = ms.ToArray();
char [] cList = new char [fs.Length];

i = 0;
foreach(hive中的字节b)
cList [i ++] =(char)b;

字符串d =新字符串(cList);


int all = 0;

foreach(在lf.Matches(d)中匹配mx){//你可以在这里更改你想要的正则表达式。
byte [] bb =新字节[mx.Value.Length];
char [] cb = new char [mx.Value.Length]; (int k = 0; k bb [k] =(byte)mx.Value [k];

;
cb [k] =(char)bb [k];

}

all ++;

//Console.WriteLine(new string(cb));
}

Console.WriteLine(all.ToString());
all = 0;
}
}


1.) How do Load, Edit and Save binary Hive files for registry from C#?

I found this Win32 api. http://msdn.microsoft.com/en-us/library/ee210770%28VS.85%29.aspx

This guy shared the code to dump the content of binary Hive files to text. http://www.codeproject.com/KB/recipes/RegistryDumper.aspx

2.) In addition to manipulating the Hive files, I also search for a method to load the Hive file into registry at runtime using C# (similar to the Load Hive and Unload Hive commands on the File many in regedit)

/Thanks

解决方案

The article below explains how to analyze the registry file without using WinAPI (advapi32.dll). In this particular case the guy is using Mono:

http://volatile-minds.blogspot.com/2011/01/analyzing-windows-nt-registry-without.html

using (FileStream fs = File.OpenRead (path)) {
 var data = new byte[checked((int)fs.Length)];
 int i = 0;
 int read;

 using (var ms = new MemoryStream (checked((int)fs.Length))) {

  while ((read = fs.Read (data, 0, data.Length)) > 0) {
   ms.Write (data, 0, read);
   i += read;
  }

  byte[] hive = ms.ToArray ();
  char[] cList = new char[fs.Length];

  i = 0;
  foreach (byte b in hive)
   cList[i++] = (char)b;

         string d = new string (cList);


  int all = 0;

  foreach (Match mx in lf.Matches (d)) { //you can change out the regex you want here.
   byte[] bb = new byte[mx.Value.Length];
   char[] cb = new char[mx.Value.Length];

   for (int k = 0; k < mx.Value.Length; k++) {
    bb[k] = (byte)mx.Value[k];
    cb[k] = (char)bb[k];

   }

   all++;

   //Console.WriteLine (new string (cb));
  }

  Console.WriteLine (all.ToString ());
  all = 0;
 }
}

这篇关于从C#处理注册表配置单元文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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