forked from cbluoss/OpenHacknet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Programs.cs
1379 lines (1336 loc) · 54.7 KB
/
Programs.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Hacknet.Gui;
using Microsoft.Xna.Framework.Input;
namespace Hacknet
{
internal static class Programs
{
public static void doDots(int num, int msDelay, OS os)
{
for (var index = 0; index < num; ++index)
{
os.writeSingle(".");
Thread.Sleep(Utils.DebugGoFast() ? 1 : msDelay);
}
}
public static void typeOut(string s, OS os, int delay = 50)
{
os.write(string.Concat(s[0]));
Thread.Sleep(delay);
for (var index = 1; index < s.Length; ++index)
{
os.writeSingle(string.Concat(s[index]));
Thread.Sleep(Utils.DebugGoFast() ? 1 : delay);
}
}
public static void firstTimeInit(string[] args, OS os)
{
var flag = Settings.initShowsTutorial;
if (flag)
{
os.display.visible = false;
os.ram.visible = false;
os.netMap.visible = false;
os.terminal.visible = true;
os.mailicon.isEnabled = false;
}
var msDelay = Settings.isConventionDemo ? 80 : 200;
var millisecondsTimeout = Settings.isConventionDemo ? 150 : 300;
if (Settings.debugCommandsEnabled && GuiData.getKeyboadState().IsKeyDown(Keys.LeftAlt))
msDelay = millisecondsTimeout = 1;
typeOut("Initializing .", os, 50);
doDots(7, msDelay + 100, os);
typeOut("Loading modules.", os, 50);
doDots(5, msDelay, os);
os.writeSingle("Complete");
if (!Utils.DebugGoFast())
Thread.Sleep(millisecondsTimeout);
typeOut("Loading nodes.", os, 50);
doDots(5, msDelay, os);
os.writeSingle("Complete");
if (!Utils.DebugGoFast())
Thread.Sleep(millisecondsTimeout);
typeOut("Reticulating splines.", os, 50);
doDots(5, msDelay - 50, os);
os.writeSingle("Complete");
if (!Utils.DebugGoFast())
Thread.Sleep(millisecondsTimeout);
if (os.crashModule.BootLoadErrors.Length > 0)
{
typeOut("\n------ BOOT ERROS DETECTED ------", os, 50);
Thread.Sleep(200);
foreach (
var s in
os.crashModule.BootLoadErrors.Split(Utils.newlineDelim, StringSplitOptions.RemoveEmptyEntries))
{
typeOut(s, os, 50);
Thread.Sleep(100);
}
typeOut("---------------------------------\n", os, 50);
Thread.Sleep(200);
}
typeOut("\n--Initialization Complete--\n", os, 50);
GuiData.getFilteredKeys();
os.inputEnabled = true;
if (!Utils.DebugGoFast())
Thread.Sleep(millisecondsTimeout + 100);
if (!flag)
{
typeOut("For A Command List, type \"help\"", os, 50);
if (!Utils.DebugGoFast())
Thread.Sleep(millisecondsTimeout + 100);
}
os.write("");
if (!Utils.DebugGoFast())
Thread.Sleep(millisecondsTimeout);
os.write("");
if (!Utils.DebugGoFast())
Thread.Sleep(millisecondsTimeout);
os.write("");
if (!Utils.DebugGoFast())
Thread.Sleep(millisecondsTimeout);
os.write("\n");
if (flag)
{
os.write("Launching Tutorial...");
os.launchExecutable("Tutorial.exe", PortExploits.crackExeData[1], -1, null);
Settings.initShowsTutorial = false;
var num1 = 100;
for (var index = 0; index < num1; ++index)
{
var num2 = index/(double) num1;
if (Utils.random.NextDouble() < num2)
{
os.ram.visible = true;
os.netMap.visible = false;
os.terminal.visible = false;
}
else
{
os.ram.visible = false;
os.netMap.visible = false;
os.terminal.visible = true;
}
Thread.Sleep(16);
}
os.ram.visible = true;
os.netMap.visible = false;
os.terminal.visible = false;
}
else
os.runCommand("connect " + os.thisComputer.ip);
}
public static void connect(string[] args, OS os)
{
disconnect(args, os);
os.display.command = args[0];
os.display.commandArgs = args;
os.display.typeChanged();
if (args.Length < 2)
{
os.write("Usage: connect [WHERE TO CONNECT TO]");
}
else
{
os.write("Scanning For " + args[1]);
for (var index1 = 0; index1 < os.netMap.nodes.Count; ++index1)
{
if (os.netMap.nodes[index1].ip.Equals(args[1]) || os.netMap.nodes[index1].name.Equals(args[1]))
{
if (os.connectedComp != null && os.connectedComp.Equals(os.netMap.nodes[index1]))
{
os.write("Already Connected to this Computer");
return;
}
if (os.netMap.nodes[index1].connect(os.thisComputer.ip))
{
os.connectedComp = os.netMap.nodes[index1];
os.connectedIP = os.netMap.nodes[index1].ip;
os.write("Connection Established ::");
os.write("Connected To " + os.netMap.nodes[index1].name + "@" + os.netMap.nodes[index1].ip);
os.terminal.prompt = os.netMap.nodes[index1].ip + "@> ";
if (!os.netMap.visibleNodes.Contains(index1))
os.netMap.visibleNodes.Add(index1);
var fileEntry =
os.netMap.nodes[index1].files.root.searchForFolder("sys")
.searchForFile(ComputerTypeInfo.getDefaultBootDaemonFilename(os.netMap.nodes[index1]));
if (fileEntry == null)
return;
var str = fileEntry.data;
for (var index2 = 0; index2 < os.netMap.nodes[index1].daemons.Count; ++index2)
{
if (os.netMap.nodes[index1].daemons[index2].name == str)
{
os.netMap.nodes[index1].daemons[index2].navigatedTo();
os.display.command = os.netMap.nodes[index1].daemons[index2].name;
}
}
return;
}
os.write("External Computer Refused Connection");
}
}
os.write("Failed to Connect:\nCould Not Find Computer at " + args[1]);
}
}
public static void disconnect(string[] args, OS os)
{
os.navigationPath.Clear();
if (os.connectedComp != null)
os.connectedComp.disconnecting(os.thisComputer.ip);
os.connectedComp = null;
os.connectedIP = "";
os.terminal.prompt = "> ";
os.write("Disconnected \n");
lock (os.netMap.nodeEffect)
os.netMap.nodeEffect.reset();
lock (os.netMap.adminNodeEffect)
os.netMap.adminNodeEffect.reset();
}
public static void getString(string[] args, OS os)
{
var str = os.terminal.prompt;
os.getStringCache = "terminalString#$#$#$$#$&$#$#$#$#";
os.terminal.preventingExecution = true;
os.terminal.prompt = args[1] + " :";
os.terminal.usingTabExecution = true;
var num = os.terminal.commandsRun();
while (os.terminal.commandsRun() == num)
Thread.Sleep(16);
var lastRunCommand = os.terminal.getLastRunCommand();
os.getStringCache = "loginData#$#$#$$#$&$#$#$#$#" + lastRunCommand;
os.terminal.prompt = str;
os.terminal.preventingExecution = false;
os.terminal.usingTabExecution = false;
os.getStringCache += "#$#$#$$#$&$#$#$#$#done";
}
public static bool parseStringFromGetStringCommand(OS os, out string data)
{
var separator = new string[1]
{
"#$#$#$$#$&$#$#$#$#"
};
var strArray = os.getStringCache.Split(separator, StringSplitOptions.None);
string str = null;
if (strArray.Length > 1)
{
str = strArray[1];
if (str.Equals(""))
str = os.terminal.currentLine;
}
data = str;
return strArray.Length > 2;
}
public static void login(string[] args, OS os)
{
var str = os.terminal.prompt;
os.display.command = "login";
os.displayCache = "loginData#$#$#$$#$&$#$#$#$#";
os.terminal.preventingExecution = true;
os.terminal.prompt = "Username :";
os.terminal.usingTabExecution = true;
var num1 = os.terminal.commandsRun();
while (os.terminal.commandsRun() == num1)
Thread.Sleep(4);
var lastRunCommand1 = os.terminal.getLastRunCommand();
os.displayCache = "loginData#$#$#$$#$&$#$#$#$#" + lastRunCommand1 + "#$#$#$$#$&$#$#$#$#";
os.terminal.prompt = "Password :";
TextBox.MaskingText = true;
var num2 = os.terminal.commandsRun();
while (os.terminal.commandsRun() == num2)
Thread.Sleep(16);
var lastRunCommand2 = os.terminal.getLastRunCommand();
os.displayCache = os.displayCache + lastRunCommand2;
var num3 = (os.connectedComp == null ? os.thisComputer : os.connectedComp).login(lastRunCommand1,
lastRunCommand2, 1);
os.terminal.prompt = str;
os.terminal.preventingExecution = false;
os.terminal.usingTabExecution = false;
TextBox.MaskingText = false;
switch (num3)
{
case 1:
os.write("Admin Login Successful");
break;
case 2:
os.write("User " + lastRunCommand1 + " Login Successful");
os.connectedComp.userLoggedIn = true;
break;
default:
os.write("Login Failed");
break;
}
os.displayCache = string.Concat(os.displayCache, "#$#$#$$#$&$#$#$#$#", num3, "#$#$#$$#$&$#$#$#$#");
}
public static void ls(string[] args, OS os)
{
if (os.hasConnectionPermission(false))
{
var folder = getCurrentFolder(os);
if (args.Length >= 2)
folder = getFolderAtPath(args[1], os, null, false);
var num = 0;
for (var index = 0; index < folder.folders.Count; ++index)
{
os.write(":" + folder.folders[index].name);
++num;
}
for (var index = 0; index < folder.files.Count; ++index)
{
os.write(folder.files[index].name ?? "");
++num;
}
if (num != 0)
return;
os.write("--Folder Empty --");
}
else
os.write("Insufficient Privileges to Perform Operation");
}
public static void cat(string[] args, OS os)
{
if (os.connectedComp == null || os.connectedComp.adminIP == os.thisComputer.ip)
{
os.displayCache = "";
var currentFolder = getCurrentFolder(os);
if (args.Length < 2)
{
os.write("Usage: cat [FILENAME]");
}
else
{
for (var index = 0; index < currentFolder.files.Count; ++index)
{
if (currentFolder.files[index].name.Equals(args[1]))
{
var flag = false;
if (os.connectedComp != null)
{
if (os.connectedComp.canReadFile(os.thisComputer.ip, currentFolder.files[index], index))
flag = true;
}
else
flag = os.thisComputer.canReadFile(os.thisComputer.ip, currentFolder.files[index], index);
if (!flag)
return;
os.write(currentFolder.files[index].name + " : " +
currentFolder.files[index].size/1000.0 + "kb\n" + currentFolder.files[index].data +
"\n");
os.displayCache = currentFolder.files[index].data;
return;
}
}
os.displayCache = "File Not Found";
os.validCommand = false;
os.write("File Not Found\n");
}
}
else
{
os.displayCache = "Insufficient Privileges";
os.validCommand = false;
os.write("Insufficient Privileges to Perform Operation");
}
}
public static void ps(string[] args, OS os)
{
if (os.exes.Count > 0)
{
os.write("UID : PID : NAME");
Thread.Sleep(100);
for (var index = 0; index < os.exes.Count; ++index)
{
os.write(string.Concat("root : ", os.exes[index].PID, " : ", os.exes[index].IdentifierName));
Thread.Sleep(100);
}
os.write("");
}
else
os.write("No Running Processes");
}
public static void kill(string[] args, OS os)
{
try
{
var num = Convert.ToInt32(args[1].Replace("[", "").Replace("]", "").Replace("\"", ""));
var index1 = -1;
for (var index2 = 0; index2 < os.exes.Count; ++index2)
{
if (os.exes[index2].PID == num)
index1 = index2;
}
if (index1 < 0 || index1 >= os.exes.Count)
{
os.write("Invalid PID");
}
else
{
os.write("Process " + num + "[" + os.exes[index1].IdentifierName + "] Ended");
os.exes[index1].Killed();
os.exes.RemoveAt(index1);
}
}
catch
{
os.write("Error: Invalid PID or Input Format");
}
}
public static void scp(string[] args, OS os)
{
if (os.connectedComp == null)
os.write("Must be Connected to a Non-Local Host\n");
else if (args.Length < 2)
{
os.write("Not Enough Arguments");
}
else
{
var path = "bin";
var str1 = path;
var flag1 = false;
if (args.Length > 2)
{
str1 = args[2];
if (!args[2].Contains('.') || args[2].Contains('/') || args[2].Contains('\\'))
{
path = args[2];
flag1 = true;
}
}
var currentFolder = getCurrentFolder(os);
var flag2 = false;
var num1 = 0;
var index1 = -1;
for (var index2 = 0; index2 < currentFolder.files.Count; ++index2)
{
if (currentFolder.files[index2].name.ToLower().Equals(args[1].ToLower()))
{
flag2 = true;
num1 = currentFolder.files[index2].size;
index1 = index2;
break;
}
}
if (!flag2)
{
os.write("File \"" + args[1] + "\" Does Not Exist\n");
}
else
{
if (!flag1)
{
var str2 = currentFolder.files[index1].name.ToLower();
path = !str2.EndsWith(".exe") ? (!str2.EndsWith(".sys") ? "home" : "sys") : "bin";
}
var str3 = currentFolder.files[index1].name;
var strArray = str1.Split(Utils.directorySplitterDelim, StringSplitOptions.RemoveEmptyEntries);
if (strArray.Length > 0 && strArray[strArray.Length - 1].Contains("."))
{
str3 = strArray[strArray.Length - 1];
var stringBuilder = new StringBuilder();
var num2 = 0;
for (var index2 = 0; index2 < strArray.Length - 1; ++index2)
{
stringBuilder.Append(strArray[index2]);
stringBuilder.Append('/');
++num2;
}
if (num2 > 0)
{
path = stringBuilder.ToString();
if (path.Length > 0)
path = path.Substring(0, path.Length - 1);
}
}
string likelyFilename = null;
var folder = getFolderAtPathAsFarAsPossible(path, os, os.thisComputer.files.root, out likelyFilename);
if (likelyFilename != null)
str3 = likelyFilename;
if (likelyFilename == path && folder == os.thisComputer.files.root)
folder = getCurrentFolder(os);
if ((os.connectedComp != null ? os.connectedComp : os.thisComputer).canCopyFile(os.thisComputer.ip,
args[1]))
{
os.write("Copying Remote File " + args[1] + "\nto Local Folder /" + path);
os.write(".");
for (var index2 = 0; index2 < Math.Min(num1/500, 20); ++index2)
{
os.writeSingle(".");
OS.operationProgress = index2/(float) (num1/1000);
Thread.Sleep(200);
}
var nameEntry = str3;
var num2 = 0;
bool flag3;
do
{
flag3 = true;
for (var index2 = 0; index2 < folder.files.Count; ++index2)
{
if (folder.files[index2].name == nameEntry)
{
++num2;
nameEntry = string.Concat(str3, "(", num2, ")");
flag3 = false;
break;
}
}
} while (!flag3);
folder.files.Add(new FileEntry(currentFolder.files[index1].data, nameEntry));
os.write("Transfer Complete\n");
}
else
os.write("Insufficient Privileges to Perform Operation : This File Requires Admin Access\n");
}
}
}
public static void upload(string[] args, OS os)
{
if (os.connectedComp == null || os.connectedComp == os.thisComputer)
{
os.write("Must be Connected to a Non-Local Host\n");
os.write("Connect to a REMOTE host and run upload with a LOCAL filepath\n");
}
else if (args.Length < 2)
os.write("Not Enough Arguments");
else if (!os.hasConnectionPermission(false))
{
os.write("Insufficient user permissions to upload");
}
else
{
var folder = os.thisComputer.files.root;
var length = args[1].LastIndexOf('/');
if (length <= 0)
return;
var path = args[1].Substring(0, length);
var folderAtPath = getFolderAtPath(path, os, os.thisComputer.files.root, false);
if (folderAtPath == null)
{
os.write("Local Folder " + path + " not found.");
}
else
{
var fileName = args[1].Substring(length + 1);
var fileEntry = folderAtPath.searchForFile(fileName);
if (fileEntry == null)
{
os.write("File " + fileName + " not found at specified filepath.");
}
else
{
var currentFolder = getCurrentFolder(os);
var folderPath = os.navigationPath;
os.write("Uploading Local File " + fileName + "\nto Remote Folder /" + currentFolder.name);
var num = fileEntry.size;
for (var index = 0; index < num/300; ++index)
{
os.writeSingle(".");
OS.operationProgress = index/(float) (num/1000);
Thread.Sleep(200);
}
os.connectedComp.makeFile(os.thisComputer.ip, fileEntry.name, fileEntry.data, folderPath, true);
os.write("Transfer Complete\n");
}
}
}
}
public static void replace2(string[] args, OS os)
{
var currentFolder = getCurrentFolder(os);
FileEntry fileEntry = null;
var index1 = 2;
var strArray = Utils.SplitToTokens(args);
if (strArray.Length < 3)
{
os.write("Not Enough Arguments\n");
os.write("Usage: replace targetFile.txt \"Target String\" \"Replacement String\"");
}
else
{
if (strArray.Length <= 3)
{
if (os.display.command.StartsWith("cat"))
{
var fileName = os.display.commandArgs[1];
fileEntry = currentFolder.searchForFile(fileName);
if (fileEntry != null)
{
os.write("Assuming active flag file \"" + fileName + "\" For editing");
index1 = 1;
}
}
if (fileEntry == null)
os.write("Not Enough Arguments\n");
}
if (fileEntry == null)
{
for (var index2 = 0; index2 < currentFolder.files.Count; ++index2)
{
if (currentFolder.files[index2].name.Equals(args[1]))
fileEntry = currentFolder.files[index2];
}
if (fileEntry == null)
{
os.write("File " + args[1] + " not found.");
if (!os.display.command.StartsWith("cat"))
return;
var fileName = os.display.commandArgs[1];
if (currentFolder.searchForFile(fileName) == null)
return;
os.write("Assuming active file \"" + fileName + "\" for editing");
return;
}
}
var oldValue = strArray[index1].Replace("\"", "");
var newValue = strArray[index1 + 1].Replace("\"", "");
fileEntry.data = fileEntry.data.Replace(oldValue, newValue);
if (!os.display.command.ToLower().Equals("cat"))
return;
os.displayCache = fileEntry.data;
}
}
public static void replace(string[] args, OS os)
{
var currentFolder = getCurrentFolder(os);
FileEntry fileEntry = null;
var num1 = 2;
if (args.Length <= 3)
{
if (os.display.command.StartsWith("cat"))
{
var fileName = os.display.commandArgs[1];
fileEntry = currentFolder.searchForFile(fileName);
if (fileEntry != null)
{
os.write("Assuming active flag file \"" + fileName + "\" For editing");
num1 = 1;
}
}
if (fileEntry == null)
os.write("Not Enough Arguments\n");
}
if (fileEntry == null)
{
for (var index = 0; index < currentFolder.files.Count; ++index)
{
if (currentFolder.files[index].name.Equals(args[1]))
fileEntry = currentFolder.files[index];
}
if (fileEntry == null)
{
os.write("File " + args[1] + " not found.");
if (!os.display.command.StartsWith("cat"))
return;
var fileName = os.display.commandArgs[1];
if (currentFolder.searchForFile(fileName) == null)
return;
os.write("Assuming active file \"" + fileName + "\" for editing");
return;
}
}
var str1 = "";
for (var index = num1; index < args.Length; ++index)
str1 = str1 + args[index] + " ";
var str2 = str1.Trim();
if (str2[0] != 34)
return;
var num2 = str2.IndexOf('"', 1);
if (num2 >= 1)
{
var num3 = num2 - 1;
var length1 = num3;
var oldValue = str2.Substring(1, length1);
var startIndex1 = num3 + 2;
var num4 = str2.IndexOf(" \"", startIndex1);
if (num4 > num3)
{
var num5 = str2.LastIndexOf('"');
if (num5 > num4)
{
var startIndex2 = num4 + 2;
var length2 = num5 - startIndex2;
var newValue = str2.Substring(startIndex2, length2);
fileEntry.data = fileEntry.data.Replace(oldValue, newValue);
if (!os.display.command.ToLower().Equals("cat"))
return;
os.displayCache = fileEntry.data;
return;
}
}
}
os.write("Format Error: Target and Replacement strings not found.");
os.write("Usage: replace targetFile.txt \"Target String\" \"Replacement String\"");
}
public static void rm(string[] args, OS os)
{
var list = new List<FileEntry>();
if (args.Length <= 1)
{
os.write("Not Enough Arguments\n");
}
else
{
var computer = os.connectedComp != null ? os.connectedComp : os.thisComputer;
var length = args[1].LastIndexOf('/');
var str = args[1];
string path = null;
if (length > 0 && length < args[1].Length - 1)
{
str = args[1].Substring(length + 1);
path = args[1].Substring(0, length);
}
var rootFolder = getCurrentFolder(os);
if (path != null)
{
rootFolder = getFolderAtPath(path, os, rootFolder, true);
if (rootFolder == null)
{
os.write("Folder " + path + " Not found!");
return;
}
}
if (str.Equals("*"))
{
for (var index = 0; index < rootFolder.files.Count; ++index)
list.Add(rootFolder.files[index]);
}
else
{
var flag = false;
for (var index = 0; index < rootFolder.files.Count; ++index)
{
if (rootFolder.files[index].name.Equals(str))
{
list.Add(rootFolder.files[index]);
break;
}
if (flag)
break;
}
}
if (list.Count == 0)
{
os.write("File " + str + " not found!");
}
else
{
var folderPath = new List<int>();
for (var index = 0; index < os.navigationPath.Count; ++index)
folderPath.Add(os.navigationPath[index]);
if (path != null)
folderPath.AddRange(getNavigationPathAtPath(path, os, getCurrentFolder(os)));
for (var index1 = 0; index1 < list.Count; ++index1)
{
os.write("Deleting " + list[index1].name + ".");
for (var index2 = 0; index2 < Math.Min(Math.Max(list[index1].size/1000, 3), 26); ++index2)
{
Thread.Sleep(200);
os.writeSingle(".");
}
if (!computer.deleteFile(os.thisComputer.ip, list[index1].name, folderPath))
os.writeSingle("Error - Insufficient Privaliges");
else
os.writeSingle("Done");
}
os.write("");
}
}
}
public static void rm2(string[] args, OS os)
{
var list = new List<FileEntry>();
if (args.Length <= 1)
{
os.write("Not Enough Arguments\n");
}
else
{
var computer = os.connectedComp != null ? os.connectedComp : os.thisComputer;
var str1 = args[1];
var str2 = !(args[1].ToLower() == "-rf") || args.Length < 3 ? args[1] : args[2];
var length = str2.LastIndexOf('/');
var str3 = str2;
string path = null;
if (length > 0 && length < str2.Length - 1)
{
str3 = str2.Substring(length + 1);
path = str2.Substring(0, length);
}
var rootFolder = getCurrentFolder(os);
if (path != null)
{
rootFolder = getFolderAtPath(path, os, rootFolder, true);
if (rootFolder == null)
{
os.write("Folder " + path + " Not found!");
return;
}
}
if (str3.Equals("*"))
{
for (var index = 0; index < rootFolder.files.Count; ++index)
list.Add(rootFolder.files[index]);
}
else
{
var flag = false;
for (var index = 0; index < rootFolder.files.Count; ++index)
{
if (rootFolder.files[index].name.Equals(str3))
{
list.Add(rootFolder.files[index]);
break;
}
if (flag)
break;
}
}
if (list.Count == 0)
{
os.write("File " + str3 + " not found!");
}
else
{
var folderPath = new List<int>();
for (var index = 0; index < os.navigationPath.Count; ++index)
folderPath.Add(os.navigationPath[index]);
if (path != null)
folderPath.AddRange(getNavigationPathAtPath(path, os, getCurrentFolder(os)));
for (var index1 = 0; index1 < list.Count; ++index1)
{
os.write("Deleting " + list[index1].name + ".");
for (var index2 = 0; index2 < Math.Min(Math.Max(list[index1].size/1000, 3), 26); ++index2)
{
Thread.Sleep(200);
os.writeSingle(".");
}
if (!computer.deleteFile(os.thisComputer.ip, list[index1].name, folderPath))
os.writeSingle("Error - Insufficient Privaliges");
else
os.writeSingle("Done");
}
os.write("");
}
}
}
public static void mv(string[] args, OS os)
{
var computer = os.connectedComp != null ? os.connectedComp : os.thisComputer;
getCurrentFolder(os);
var folderPath = new List<int>();
for (var index = 0; index < os.navigationPath.Count; ++index)
folderPath.Add(os.navigationPath[index]);
if (args.Length < 3)
{
os.write("Not Enough Arguments. Usage: mv [FILE] [DESTINATION]");
}
else
{
var name = args[1];
var str = args[2];
var path = "";
var num = str.LastIndexOf('/');
string newName;
if (num > 0)
{
newName = str.Substring(num + 1);
path = str.Substring(0, num + 1);
if (newName.Length <= 0)
newName = name;
}
else
newName = str;
var navigationPathAtPath = getNavigationPathAtPath(path, os, null);
navigationPathAtPath.InsertRange(0, folderPath);
computer.moveFile(os.thisComputer.ip, name, newName, folderPath, navigationPathAtPath);
}
}
public static void analyze(string[] args, OS os)
{
var computer = os.connectedComp != null ? os.connectedComp : os.thisComputer;
if (computer.firewall != null)
{
computer.firewall.writeAnalyzePass(os, computer);
computer.hostileActionTaken();
}
else
os.write("No Firewall Detected");
}
public static void solve(string[] args, OS os)
{
var computer = os.connectedComp != null ? os.connectedComp : os.thisComputer;
if (computer.firewall != null)
{
if (args.Length >= 2)
{
var attempt = args[1];
os.write("");
doDots(30, 60, os);
if (computer.firewall.attemptSolve(attempt, os))
os.write("SOLVE SUCCESSFUL - Syndicated UDP Traffic Enabled");
else
os.write("SOLVE FAILED - Incorrect bypass sequence");
}
else
os.write("ERROR: No Solution provided");
}
else
os.write("No Firewall Detected");
}
public static void clear(string[] args, OS os)
{
os.terminal.reset();
}
public static void execute(string[] args, OS os)
{
if (os.connectedComp == null)
{
var computer1 = os.thisComputer;
}
else
{
var computer2 = os.connectedComp;
}
var folder = os.thisComputer.files.root.folders[2];
os.write("Avaliable Executables:\n");
os.write("PortHack");
os.write("ForkBomb");
os.write("Shell");
os.write("Tutorial");
for (var index1 = 0; index1 < folder.files.Count; ++index1)
{
for (var index2 = 0; index2 < PortExploits.exeNums.Count; ++index2)
{
if (folder.files[index1].data == PortExploits.crackExeData[PortExploits.exeNums[index2]])
{
os.write(folder.files[index1].name.Replace(".exe", ""));
break;
}
}
}
os.write(" ");
}
public static void scan(string[] args, OS os)
{
if (args.Length > 1)
{
var computer = getComputer(os, args[1]);
if (computer == null)
return;
os.netMap.discoverNode(computer);
os.write("Found Terminal : " + computer.name + "@" + computer.ip);
}
else
{
var computer = os.connectedComp != null ? os.connectedComp : os.thisComputer;
if (os.hasConnectionPermission(true))
{
os.write("Scanning...");
for (var index = 0; index < computer.links.Count; ++index)
{
if (!os.netMap.visibleNodes.Contains(computer.links[index]))
os.netMap.visibleNodes.Add(computer.links[index]);
os.netMap.nodes[computer.links[index]].highlightFlashTime = 1f;
os.write("Found Terminal : " + os.netMap.nodes[computer.links[index]].name + "@" +
os.netMap.nodes[computer.links[index]].ip);
os.netMap.lastAddedNode = os.netMap.nodes[computer.links[index]];
Thread.Sleep(400);
}
os.write("Scan Complete\n");
}
else
os.write("Scanning Requires Admin Access\n");
}
}
public static void fastHack(string[] args, OS os)
{
if (!OS.DEBUG_COMMANDS || os.connectedComp == null)
return;
os.connectedComp.adminIP = os.thisComputer.ip;
}
public static void revealAll(string[] args, OS os)
{
for (var index = 0; index < os.netMap.nodes.Count; ++index)
os.netMap.visibleNodes.Add(index);
}
public static void cd(string[] args, OS os)
{
if (os.hasConnectionPermission(false))
{
if (args.Length >= 2)
{
getCurrentFolder(os);
if (args[1].Equals("/"))
os.navigationPath.Clear();
if (args[1].Equals(".."))
{
if (os.navigationPath.Count > 0)