-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
157 lines (136 loc) · 4.61 KB
/
Copy pathProgram.cs
File metadata and controls
157 lines (136 loc) · 4.61 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
namespace FuckNetherNet;
internal static class Program
{
private const string DefaultFileName = "bedrock_server.exe";
private static int Main(string[] args)
{
if (args.Length == 0)
{
PrintUsage();
return 1;
}
if (IsHelp(args[0]))
{
PrintUsage();
return 0;
}
string command = args[0].ToLowerInvariant();
if (command is not ("check" or "patch" or "restore"))
{
Console.Error.WriteLine($"error: unknown command '{args[0]}'");
Console.Error.WriteLine();
PrintUsage();
return 1;
}
string? path = null;
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg is "-f" or "--file")
{
if (i + 1 >= args.Length)
{
Console.Error.WriteLine("error: --file requires a path");
return 1;
}
path = args[++i];
}
else if (path is null && !arg.StartsWith('-'))
{
path = arg;
}
else
{
Console.Error.WriteLine($"error: unexpected argument '{arg}'");
return 1;
}
}
string target;
try
{
target = ResolveTarget(path);
}
catch (FileNotFoundException ex)
{
Console.Error.WriteLine($"error: {ex.Message}");
return 1;
}
try
{
return command switch
{
"check" => Patcher.Check(target),
"patch" => Patcher.Patch(target),
"restore" => Patcher.Restore(target),
_ => 1,
};
}
catch (PatchException ex)
{
Console.Error.WriteLine($"error: {ex.Message}");
return 1;
}
catch (IOException ex)
{
Console.Error.WriteLine($"error: cannot access '{target}': {ex.Message}");
Console.Error.WriteLine(" stop the server (and any debugger) before patching.");
return 1;
}
catch (UnauthorizedAccessException ex)
{
Console.Error.WriteLine($"error: access denied for '{target}': {ex.Message}");
return 1;
}
}
private static bool IsHelp(string arg) => arg is "-h" or "--help" or "-?" or "/?" or "help";
private static string ResolveTarget(string? path)
{
if (!string.IsNullOrWhiteSpace(path))
{
string full = Path.GetFullPath(path);
if (!File.Exists(full))
{
throw new FileNotFoundException($"file not found: {full}");
}
return full;
}
string[] candidates =
[
Path.Combine(AppContext.BaseDirectory, DefaultFileName),
Path.Combine(Environment.CurrentDirectory, DefaultFileName),
];
foreach (string candidate in candidates)
{
if (File.Exists(candidate))
{
return Path.GetFullPath(candidate);
}
}
throw new FileNotFoundException(
$"'{DefaultFileName}' was not found next to this tool or in the current directory; pass a path with --file");
}
private static void PrintUsage()
{
Console.WriteLine("""
FuckNetherNet - disables the forced NetherNet transport check in bedrock_server.exe
Usage:
FuckNetherNet <command> [path] [--file <path>]
Commands:
check show the current state of the binary (never writes)
patch rewrite the transport check so the error block is unreachable
restore revert the binary from the '<file>.orig' backup
Arguments:
path, --file <path> path to bedrock_server.exe
(default: next to this tool, then the current directory)
Exit codes:
0 success (for check: the binary is ORIGINAL or PATCHED)
1 failure (for check: unrecognised bytes)
Patch applied (bedrock_server.exe):
the forced NetherNet transport check is located by a byte signature
(cmp dword ptr [rax+0x104], 2 followed by 'je'), so no server-build
address is hardcoded. The conditional jump is rewritten into an
unconditional one, making the 'TRANSPORT TYPE ERROR' logging block
dead code.
""");
}
}