mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 11:37:01 +00:00
update
This commit is contained in:
@@ -13,6 +13,9 @@ namespace CMLeonOS
|
||||
|
||||
private Shell shell;
|
||||
private UserSystem userSystem;
|
||||
|
||||
// 修复模式变量(硬编码,用于控制是否启用修复模式)
|
||||
public static bool FixMode = false;
|
||||
|
||||
protected override void BeforeRun()
|
||||
{
|
||||
@@ -21,7 +24,7 @@ namespace CMLeonOS
|
||||
Console.WriteLine(@" / ___| \/ | | ___ ___ _ __ / _ \/ ___| ");
|
||||
Console.WriteLine(@" | | | |\/| | | / _ \/ _ \| '_ \| | | \___ \ ");
|
||||
Console.WriteLine(@" | |___| | | | |__| __/ (_) | | | | |_| |___) |");
|
||||
Console.WriteLine(@" \____|_| |_|_____\___|\___/|_| |_|__/|____/ ");
|
||||
Console.WriteLine(@" \____|_| |_|_____\___|\___/|_| |_|____/|____/ ");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("CMLeonOS Test Project");
|
||||
Console.WriteLine("By LeonOS 2 Developement Team");
|
||||
|
||||
54
Shell.cs
54
Shell.cs
@@ -10,18 +10,25 @@ namespace CMLeonOS
|
||||
private List<string> commandHistory = new List<string>();
|
||||
private FileSystem fileSystem;
|
||||
private UserSystem userSystem;
|
||||
private bool fixMode;
|
||||
|
||||
public Shell()
|
||||
{
|
||||
fileSystem = new FileSystem();
|
||||
userSystem = new UserSystem();
|
||||
fixMode = Kernel.FixMode;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.Write(prompt);
|
||||
// 显示当前文件夹路径作为提示符(彩色)
|
||||
string currentPath = fileSystem.CurrentDirectory;
|
||||
ConsoleColor originalColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.Write($"{currentPath} | /");
|
||||
Console.ForegroundColor = originalColor;
|
||||
var input = Console.ReadLine();
|
||||
commandHistory.Add(input);
|
||||
var parts = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
@@ -72,6 +79,7 @@ namespace CMLeonOS
|
||||
Console.WriteLine(" pwd - Show current directory");
|
||||
Console.WriteLine(" mkdir <dir> - Create directory");
|
||||
Console.WriteLine(" rm <file> - Remove file");
|
||||
Console.WriteLine(" Use -norisk to delete files in sys folder");
|
||||
Console.WriteLine(" rmdir <dir> - Remove directory");
|
||||
Console.WriteLine(" cat <file> - Display file content");
|
||||
Console.WriteLine(" echo <text> > <file> - Write text to file");
|
||||
@@ -130,7 +138,36 @@ namespace CMLeonOS
|
||||
}
|
||||
else
|
||||
{
|
||||
fileSystem.DeleteFile(args);
|
||||
// 检查是否在sys文件夹中(修复模式下绕过检测)
|
||||
bool isInSysFolder = (args.Contains(@"\sys\") || args.Contains(@"/sys/")) && !fixMode;
|
||||
|
||||
if (isInSysFolder)
|
||||
{
|
||||
// 检查是否有-norisk参数
|
||||
string[] parts = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
bool hasNorisk = false;
|
||||
string filePath = args;
|
||||
|
||||
if (parts.Length > 1)
|
||||
{
|
||||
hasNorisk = Array.IndexOf(parts, "-norisk") >= 0;
|
||||
filePath = parts[0];
|
||||
}
|
||||
|
||||
if (!hasNorisk)
|
||||
{
|
||||
Console.WriteLine("Error: Cannot delete files in sys folder without -norisk parameter");
|
||||
Console.WriteLine("Usage: rm <file> -norisk");
|
||||
}
|
||||
else
|
||||
{
|
||||
fileSystem.DeleteFile(filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fileSystem.DeleteFile(args);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "rmdir":
|
||||
@@ -140,7 +177,18 @@ namespace CMLeonOS
|
||||
}
|
||||
else
|
||||
{
|
||||
fileSystem.DeleteDirectory(args);
|
||||
// 检查是否在sys文件夹中(修复模式下绕过检测)
|
||||
bool isInSysFolder = (args.Contains(@"\sys\") || args.Contains(@"/sys/")) && !fixMode;
|
||||
|
||||
if (isInSysFolder)
|
||||
{
|
||||
Console.WriteLine("Error: Cannot delete directories in sys folder");
|
||||
Console.WriteLine("Use fix mode to bypass this restriction");
|
||||
}
|
||||
else
|
||||
{
|
||||
fileSystem.DeleteDirectory(args);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "cat":
|
||||
|
||||
134
UserSystem.cs
134
UserSystem.cs
@@ -5,14 +5,36 @@ namespace CMLeonOS
|
||||
{
|
||||
public class UserSystem
|
||||
{
|
||||
private string adminPasswordFilePath = @"0:\admin_password.txt";
|
||||
private string sysDirectory = @"0:\sys";
|
||||
private string adminPasswordFilePath;
|
||||
private bool isPasswordSet = false;
|
||||
|
||||
public UserSystem()
|
||||
{
|
||||
// 确保sys目录存在
|
||||
EnsureSysDirectoryExists();
|
||||
|
||||
// 设置密码文件路径
|
||||
adminPasswordFilePath = Path.Combine(sysDirectory, "admin_password.txt");
|
||||
|
||||
CheckPasswordStatus();
|
||||
}
|
||||
|
||||
private void EnsureSysDirectoryExists()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(sysDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(sysDirectory);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 忽略目录创建错误
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckPasswordStatus()
|
||||
{
|
||||
try
|
||||
@@ -71,27 +93,117 @@ namespace CMLeonOS
|
||||
Console.WriteLine("Username: admin");
|
||||
Console.WriteLine("Password:");
|
||||
|
||||
string password = ReadPassword();
|
||||
|
||||
// 检测ALT+Space按键
|
||||
bool useFixMode = false;
|
||||
ConsoleKeyInfo keyInfo;
|
||||
try
|
||||
{
|
||||
string storedPassword = File.ReadAllText(adminPasswordFilePath);
|
||||
if (password == storedPassword)
|
||||
keyInfo = Console.ReadKey(true);
|
||||
if (keyInfo.Key == ConsoleKey.Spacebar && (keyInfo.Modifiers & ConsoleModifiers.Alt) != 0)
|
||||
{
|
||||
Console.WriteLine("Login successful!");
|
||||
return true;
|
||||
// 检测到ALT+Space,进入修复模式
|
||||
useFixMode = true;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Fix Mode Activated");
|
||||
Console.Write("Enter fix code: ");
|
||||
|
||||
string fixCode = "";
|
||||
while (true)
|
||||
{
|
||||
var codeKey = Console.ReadKey(true);
|
||||
if (codeKey.Key == ConsoleKey.Enter)
|
||||
{
|
||||
Console.WriteLine();
|
||||
break;
|
||||
}
|
||||
else if (codeKey.Key == ConsoleKey.Backspace)
|
||||
{
|
||||
if (fixCode.Length > 0)
|
||||
{
|
||||
fixCode = fixCode.Substring(0, fixCode.Length - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fixCode += codeKey.KeyChar;
|
||||
Console.Write(codeKey.KeyChar);
|
||||
}
|
||||
}
|
||||
|
||||
if (fixCode == "FixMyComputer")
|
||||
{
|
||||
Console.WriteLine("Fix mode enabled!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Invalid fix code. Exiting fix mode.");
|
||||
useFixMode = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Invalid password. Please try again.");
|
||||
return false;
|
||||
// 正常密码输入
|
||||
string password = "";
|
||||
password += keyInfo.KeyChar;
|
||||
Console.Write("*");
|
||||
|
||||
while (true)
|
||||
{
|
||||
var passKey = Console.ReadKey(true);
|
||||
if (passKey.Key == ConsoleKey.Enter)
|
||||
{
|
||||
Console.WriteLine();
|
||||
break;
|
||||
}
|
||||
else if (passKey.Key == ConsoleKey.Backspace)
|
||||
{
|
||||
if (password.Length > 0)
|
||||
{
|
||||
password = password.Substring(0, password.Length - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
password += passKey.KeyChar;
|
||||
Console.Write("*");
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string storedPassword = File.ReadAllText(adminPasswordFilePath);
|
||||
if (password == storedPassword)
|
||||
{
|
||||
Console.WriteLine("Login successful!");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Invalid password. Please try again.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error during login: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"Error during login: {ex.Message}");
|
||||
// 如果读取按键失败,使用普通登录
|
||||
Console.WriteLine("Error reading key input. Using normal login.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果使用了修复模式,返回true
|
||||
if (useFixMode)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string ReadPassword()
|
||||
|
||||
Reference in New Issue
Block a user