Guest User

Untitled

a guest
Apr 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. public class reg
  2. {
  3. public void write(string key, string valueName, string value)
  4. {
  5. Byte[] byteValue = System.Text.Encoding.UTF8.GetBytes(value);
  6.  
  7. Registry.SetValue(key, valueName, value, RegistryValueKind.Binary);
  8. }
  9. }
  10.  
  11. string key = @"HKEY_CLASSES_ROOT.sgdk2";
  12. string valueName = string.Empty; // "(Default)" value
  13. string value = "sgdk2file";
  14.  
  15. Microsoft.Win32.Registry.SetValue(key,valueName, value,
  16. Microsoft.Win32.RegistryValueKind.String);
  17.  
  18. static byte[] HexToBin(string hex)
  19. {
  20. var result = new byte[hex.Length/2];
  21. for (int i = 0; i < hex.Length; i += 2)
  22. {
  23. result[i / 2] = byte.Parse(hex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
  24. }
  25. return result;
  26. }
  27.  
  28. static string BytesToHex(byte[] bytes)
  29. {
  30. System.Text.StringBuilder sb = new StringBuilder();
  31. for (int i = 0; i < bytes.Length; i++)
  32. {
  33. sb.Append(bytes[i].ToString("x2"));
  34. }
  35. return sb.ToString();
  36. }
  37.  
  38. static void Main(string[] args)
  39. {
  40. byte[] bytes = HexToBin("0eff10");
  41. Console.WriteLine(BytesToBinaryString(bytes));
  42. }
  43.  
  44. static byte[] HexToBin(string hex)
  45. {
  46. var result = new byte[hex.Length / 2];
  47. for (int i = 0; i < hex.Length; i += 2)
  48. {
  49. result[i / 2] = byte.Parse(hex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
  50. }
  51. return result;
  52. }
  53.  
  54. static string BytesToBinaryString(byte[] bytes)
  55. {
  56. var ba = new System.Collections.BitArray(bytes);
  57. System.Text.StringBuilder sb = new StringBuilder();
  58. for (int i = 0; i < ba.Length; i++)
  59. {
  60. int byteStart = (i / 8) * 8;
  61. int bit = 7 - i % 8;
  62. sb.Append(ba[byteStart + bit] ? '1' : '0');
  63. if (i % 8 == 7)
  64. sb.Append(' ');
  65. }
  66. return sb.ToString();
  67. }
  68.  
  69. string valueString = "this is my test string";
  70. byte[] value = System.Text.Encoding.ASCII.GetBytes(valueString);
  71. Microsoft.Win32.Registry.SetValue(keyName, valueName, valueString, Microsoft.Win32.RegistryValueKind.Binary);
Add Comment
Please, Sign In to add comment