This commit is contained in:
2026-01-30 23:36:08 +08:00
parent 5b5684cd43
commit cefeee7835
3 changed files with 178 additions and 15 deletions

View File

@@ -14,6 +14,9 @@ namespace CMLeonOS
private Shell shell;
private UserSystem userSystem;
// 修复模式变量(硬编码,用于控制是否启用修复模式)
public static bool FixMode = false;
protected override void BeforeRun()
{
Console.Clear();
@@ -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");

View File

@@ -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");
@@ -129,9 +137,38 @@ namespace CMLeonOS
Console.WriteLine("Error: Please specify a file name");
}
else
{
// 检查是否在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":
if (string.IsNullOrEmpty(args))
@@ -139,9 +176,20 @@ namespace CMLeonOS
Console.WriteLine("Error: Please specify a directory name");
}
else
{
// 检查是否在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":
if (string.IsNullOrEmpty(args))

View File

@@ -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,7 +93,81 @@ namespace CMLeonOS
Console.WriteLine("Username: admin");
Console.WriteLine("Password:");
string password = ReadPassword();
// 检测ALT+Space按键
bool useFixMode = false;
ConsoleKeyInfo keyInfo;
try
{
keyInfo = Console.ReadKey(true);
if (keyInfo.Key == ConsoleKey.Spacebar && (keyInfo.Modifiers & ConsoleModifiers.Alt) != 0)
{
// 检测到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
{
// 正常密码输入
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
{
@@ -93,6 +189,22 @@ namespace CMLeonOS
return false;
}
}
}
catch
{
// 如果读取按键失败,使用普通登录
Console.WriteLine("Error reading key input. Using normal login.");
return false;
}
// 如果使用了修复模式返回true
if (useFixMode)
{
return true;
}
return false;
}
private string ReadPassword()
{