示例#1
0
文件: commands.py 项目: KBD2/HackSYS
 def run(self, sysCont, sys, terminal, comCont, *args, **kwargs):
     nameGet = args[0].split('/')[-1]
     if kwargs['-d']:
         pathTest = system.FilePath(args[0], sys.fileSystem)
     else:
         pathTest = system.FilePath(args[0], sys.fileSystem, True)
     if pathTest.status < 0:
         terminal.error("{} is not a valid path!".format(args[0]))
         return -1
     pathGet = system.FilePath(args[0][:-len(nameGet)], sys.fileSystem)
     nameSet = args[1].split('/')[-1]
     pathSet = system.FilePath(args[1][:-len(nameSet)], sys.fileSystem)
     if not kwargs['-f']:
         pathSetDir = sys.fileSystem.getDirectory(pathSet.iterList)
         if kwargs['-d']:
             setConts = pathSetDir.subdirectories
         else:
             setConts = pathSetDir.files
         if nameSet in setConts:
             terminal.error("{} already exists!".format(nameSet))
             return -1
     if pathSet.status < 0:
         terminal.error("{} is not a valid path!".format(args[1]))
         return -1
     ret = sys.fileSystem.move(pathGet, nameGet, pathSet, nameSet, kwargs['-d'])
     sys.addLog(sys.IP, "Moved {} to {}".format(args[0], args[1]))
     return 0
示例#2
0
文件: commands.py 项目: KBD2/HackSYS
 def run(self, sysCont, sys, terminal, comCont, *args, **kwargs):
     name = args[0].split('/')[-1]
     if name == '*':
         path = system.FilePath(args[0][:-len(name)], sys.fileSystem)
     else:
         path = system.FilePath(args[0], sys.fileSystem, True)
     if path.status != system.PathStatuses.PATH_VALID:
         terminal.error("{} is not a valid path!".format(args[0]))
         return -1
     else:
         if name == '*':
             directory = copy.deepcopy(sys.fileSystem.getDirectory(path))
             items = directory.files.items()
             for key, item in items:
                 ret = sys.fileSystem.remove(
                     path,
                     key
                     )
                 if ret == 0:
                     terminal.out("Removed " + item._name)
                     if item.getType() != 'LOG':
                         sys.addLog(sys.IP, "Removed " + key)
             return 0
         else:
             path = system.FilePath(args[0][:-len(name)], sys.fileSystem)
             file = path.directory.files[name]
             sys.fileSystem.remove(
                 path,
                 name
                 )
             if file.getType() != 'LOG':
                 sys.addLog(sys.IP, "Removed " + name)
             return 0
示例#3
0
文件: commands.py 项目: KBD2/HackSYS
 def run(self, sysCont, sys, terminal, comCont, *args, **kwargs):
     path = system.FilePath(args[0], sys.fileSystem, True)
     name = args[0].split('/')[-1]
     pathNoFile = system.FilePath(args[0][:-len(name)], sys.fileSystem)
     if path.status != system.PathStatuses.PATH_VALID:
         terminal.error("{} is not a valid path!".format(args[0]))
         return -1
     else:
         out = sys.fileSystem.output(pathNoFile, name)
         colour = Fore.GREEN
         cTable = {
             'c': Fore.CYAN,
             'y': Fore.YELLOW,
             'w': Fore.WHITE,
             'r': Fore.RED,
             'g': Fore.GREEN,
             'b': Fore.BLUE,
             'm': Fore.MAGENTA
             }
         if kwargs['-p']:
             skip = False
             for count, char in enumerate(out):
                 if skip:
                     skip = False
                     continue
                 if char == '\\':
                     if out[count + 1] == 'n':
                         skip = True
                         terminal.out('', colour, False)
                     elif out[count + 1] == 't':
                         skip = True
                         terminal.out('\t', colour, False, False)
                     elif out[count + 1] == '\\':
                         skip = True
                         terminal.out('\\', colour, True, False)
                     else:
                         terminal.error("\nUnrecognised escape sequence!")
                         return -1
                 elif char == '&':
                     if out[count + 1] in cTable:
                         skip = True
                         colour = cTable[out[count + 1]]
                     else:
                         terminal.out('&', colour, True, False)
                 else:
                     terminal.out(char, colour, True, False)
             terminal.out('')
             return 0
         else:
             terminal.out(out)
         return 0
示例#4
0
文件: commands.py 项目: KBD2/HackSYS
 def run(self, sysCont, sys, terminal, comCont, *args, **kwargs):
     path = system.FilePath(args[0], sys.fileSystem)
     if path.status == system.PathStatuses.PATH_NOT_EXIST:
         terminal.error("{} is not a valid path!".format(args[0]))
         return -1
     elif path.status == system.PathStatuses.PATH_NOT_DIR:
         terminal.error("{} is valid but is not a directory!".format(args[0]))
         return -1
     else:
         sys.fileSystem.changeDir(path)
         return 0
示例#5
0
文件: commands.py 项目: KBD2/HackSYS
 def run(self, sysCont, sys, terminal, comCont, *args, **kwargs):
     name = args[0].split('/')[-1]
     makePath = system.FilePath(args[0][:-len(name)], sys.fileSystem)
     if makePath.status != system.PathStatuses.PATH_VALID:
         terminal.error("{} is not a valid path!".format(args[0]))
         return -1
     else:
         ret = sys.fileSystem.make(makePath, name)
         if ret == -1:
             terminal.error("{} already exists!".format(args[0]))
             return -1
         else:
             sys.addLog(sys.IP, "Created {}".format(args[0]))
         return 0
示例#6
0
文件: commands.py 项目: KBD2/HackSYS
 def run(self, sysCont, sys, terminal, comCont, *args, **kwargs):
     name = args[0].split('/')[-1]
     if name == '*':
         path = system.FilePath(args[0][:-len(name)], sys.fileSystem)
     else:
         path = system.FilePath(args[0], sys.fileSystem)
     if path.status != system.PathStatuses.PATH_VALID:
         terminal.error("{} is not a valid path!".format(args[0]))
         return -1
     else:
         if name == '*':
             directory = copy.deepcopy(sys.fileSystem.getDirectory(path))
             items = list(directory.subdirectories.keys())
             for item in items:
                 ret = sys.fileSystem.remove(path, item, True)
                 if ret == 0:
                     terminal.out("Removed " + item)
                     sys.addLog(sys.IP, "Removed " + item)
             return 0
         else:
             path = system.FilePath(args[0][:-len(name)], sys.fileSystem)
             sys.fileSystem.remove(path, name, True)
             sys.addLog(sys.IP, "Removed " + name)
             return 0
示例#7
0
文件: commands.py 项目: KBD2/HackSYS
 def run(self, sysCont, sys, terminal, comCont, *args, **kwargs):
     out = []
     binPath = system.FilePath('/bin', sys.fileSystem)
     if binPath.status != system.PathStatuses.PATH_VALID:
         terminal.error("Cannot find executables directory!")
         return -1
     else:
         foundExecs = {}
         binDir = sys.fileSystem.getDirectory(['bin'])
         for item in binDir.files:
             file = binDir.files[item]
             if file.getType() == 'BIN':
                 if file.getHash() in comList:
                     foundExecs[item[:-4]] = comList[file.getHash()]
     if len(args) == 0:
         out.append("help <command> for a more detailed description.")
         out.append("Commands:\n")
         for command in foundExecs:
             out.append(command)
         terminal.out('\n'.join(out))
         return 0
     else:
         selected = args[0]
         if selected not in foundExecs:
             terminal.error("{} is not a command!".format(selected))
             return -1
         else:
             metaData =  foundExecs[selected].meta
             out.append(args[0] + ":")
             out.append(metaData['descriptor'])
             if metaData['params'][1] - metaData['params'][0] > 0:
                 out.append("Number of parameters: {} to {}".format(
                     metaData['params'][0],
                     metaData['params'][1])
                              )
             else:
                 out.append("Number of parameters: {}".format(
                     metaData['params'][0]
                     ))
             if metaData['switches']:
                 out.append("Switches: {}".format(
                     ', '.join(switch for switch in metaData['switches'])
                     ))
             terminal.out('\n'.join(out))
             return 0
示例#8
0
except:
    print("You need the colorama module! (python -m pip install colorama)")
    sysModule.exit()

sysModule.path.insert(1, './imports')
import utils, terminal, system, commands, save
system.init(system)
colorama.init()

from colorama import Fore

sysCont = save.load()
if not sysCont:
    sysCont = system.SystemsController()
#If user broke their system then quit
bootPath = system.FilePath('/sys/boot.sys', sysCont.userSystem.fileSystem,
                           True, system.sysFileHashes['boot.sys'])
if bootPath.status != system.PathStatuses.PATH_VALID:
    sysCont.userSystem.status = system.Statuses.UNBOOTABLE
comCont = commands.CommandController()

terminal = terminal.Terminal(comCont)
terminal.out(colorama.Style.BRIGHT, colorama.Fore.GREEN, False, False)

if 'idlelib.run' in sysModule.modules:
    print("You probably want to run this from the command line.")
else:
    terminal.out("""
    ██╗  ██╗ █████╗  ██████╗██╗  ██╗███████╗██╗   ██╗███████╗\n\
    ██║  ██║██╔══██╗██╔════╝██║ ██╔╝██╔════╝╚██╗ ██╔╝██╔════╝\n\
    ███████║███████║██║     █████╔╝ ███████╗ ╚████╔╝ ███████╗\n\
    ██╔══██║██╔══██║██║     ██╔═██╗ ╚════██║  ╚██╔╝  ╚════██║\n\
示例#9
0
文件: commands.py 项目: KBD2/HackSYS
 def feed(self, commandRaw, sysCont, sys, terminal):
     systemPath = system.FilePath(
         '/sys/command.sys',
         sys.fileSystem,
         True,
         system.sysFileHashes['command.sys']
         )
     if systemPath.status != system.PathStatuses.PATH_VALID:
         terminal.error("COMMAND.SYS ERROR")
         return -1
     if commandRaw == '':
         return 0
     commandsRaw = self.getRawCommands(commandRaw)
     commands = []
     for rawCommand in commandsRaw:
         commands.append(Command(rawCommand))
     for command in commands:
         self.outputType = 0
         if command.status == CommandStatuses.COMMAND_INVALID:
             terminal.error("Invalid command!")
             continue
         elif command.status == CommandStatuses.INVALID_NO_OUTFILE:
             terminal.error("No output file has been provided!")
             continue
         elif command.status == CommandStatuses.INVALID_ORDER_OUT:
             terminal.error("Invalid output symbol placement!")
             continue
         elif command.status == CommandStatuses.INVALID_ORDER_SWITCH:
             terminal.error("Invalid switch placement!")
             continue
         elif command.status == CommandStatuses.INVALID_MULTIPLE_OUT:
             terminal.error("Multiple output files provided!")
             continue
         if command.command in sys.aliasTable:
             aliased = command.rawCommand.replace(
                 command.command,
                 sys.aliasTable[command.command]
                 )
             self.feed(aliased, sysCont, sys, terminal)
             continue
         fileName = command.command + '.bin'
         contextTest = system.FilePath(
             './' + fileName,
             sys.fileSystem,
             True
             )
         systemTest = system.FilePath(
             '/bin/' + fileName,
             sys.fileSystem,
             True
             )
         if contextTest.status == system.PathStatuses.PATH_VALID:
             context = contextTest.directory
         elif systemTest.status == system.PathStatuses.PATH_VALID:
             context = systemTest.directory
         else:
             terminal.error("Cannot find {} executable!".format(command.command))
             continue
         file = context.files[fileName]
         if file.getHash() in comList:
             params = comList[file.getHash()].meta['params']
             tooFewArgs = len(command.args) < params[0]
             tooManyArgs = len(command.args) > params[1]
             if tooFewArgs or tooManyArgs:
                 terminal.error("Incorrect number of parameters!")
                 continue
             kwargs = {}
             switches = comList[file.getHash()].meta['switches']
             if switches is not None:
                 for switch in switches:
                     kwargs[switch] = False
             for switch in command.switches:
                 if switch in kwargs:
                     kwargs[switch] = True
                 else:
                     terminal.error("{} is not a switch!".format(switch))
                     continue
             if command.outType is not None:
                 outFileTest = system.FilePath(command.outFile, sys.fileSystem, True)
                 if outFileTest.status != system.PathStatuses.PATH_VALID:
                     if command.outType == 2:
                         terminal.error("Output file does not exist!")
                         continue
                     else:
                         filePath = system.FilePath(command.outFile, sys.fileSystem, True)
                         sys.fileSystem.make(filePath, command.outFile.split('/')[-1])
                         sys.addLog(sys.IP, 'Created {}'.format(command.outFile))
                 self.outputType = command.outType
                 self.contextFileSystem = sys.fileSystem
                 self.contextOutputPath = system.FilePath(command.outFile, sys.fileSystem, True)
             ret = comList[file.getHash()].run(
                 sysCont,
                 sys,
                 terminal,
                 self,
                 *command.args,
                 **kwargs
                 )
             if ret == 99:
                 return 99
         else:
             terminal.error("Error in {} executable!".format(fileName))