diff --git a/src/main.py b/src/main.py index 125a689..88c933d 100644 --- a/src/main.py +++ b/src/main.py @@ -32,7 +32,8 @@ def main(): ) parser.add_argument('--cli', action = 'store_true', help = 'Use a command prompt, allowing for interactive completion of commands.') - parser.add_argument('--efs-shell', action = 'store_true', help = 'Spawn an interactive shell to navigate within the embedded filesystem (EFS) of the baseband device.') + #parser.add_argument('--efs-shell', action = 'store_true', help = 'Spawn an interactive shell to navigate within the embedded filesystem (EFS) of the baseband device.') + parser.add_argument('--efs-shell', nargs='?', const='efs', default=False, choices=['efs', 'efs2'], help='Spawn an interactive shell to navigate within the embedded filesystem (EFS) of the baseband device. Optionally specify "primary" or "alternate" to choose the file system.') parser.add_argument('-v', '--verbose', action = 'store_true', help = 'Add output for each received or sent Diag packet.') input_mode = parser.add_argument_group(title = 'Input mode', description = 'Choose an one least input mode for DIAG data.') @@ -174,13 +175,13 @@ def parse_modules_args(args): diag_input.add_module(CommandLineInterface(diag_input, parser, parse_modules_args)) if args.efs_shell: - + #print("--efs-shell with", args.efs_shell) if diag_input.modules: error('You can not both specify the use of EFS shell and a module') exit() from .modules.efs_shell import EfsShell - diag_input.add_module(EfsShell(diag_input)) + diag_input.add_module(EfsShell(diag_input,args.efs_shell)) diff --git a/src/modules/efs_shell.py b/src/modules/efs_shell.py index 2aceed9..295af34 100644 --- a/src/modules/efs_shell.py +++ b/src/modules/efs_shell.py @@ -34,10 +34,11 @@ class EfsShell: - def __init__(self, diag_input : BaseInput): + def __init__(self, diag_input : BaseInput,fs_type: str = 'efs'): self.diag_input : BaseInput = diag_input - + self.fs_type = fs_type + #print("EfsShell", self.fs_type) self.parser = ArgumentParser(description = 'Spawn an interactive shell to navigate within the embedded filesystem (EFS) of the baseband device.', prog = '') self.sub_parsers : _SubParsersAction = self.parser.add_subparsers() @@ -45,8 +46,8 @@ def __init__(self, diag_input : BaseInput): self.sub_parser_command_name_to_command_object : Dict[str, BaseEfsShellCommand] = {} for command_class in ALL_COMMAND_CLASSES: - - command_object = command_class() + + command_object = command_class(fs_type) sub_parser = command_object.get_argument_parser(self.sub_parsers) # Will populate the "self.sub_parsers._name_parser_map" map, see the source of "argparse.py" in Python's standard library for reference @@ -129,9 +130,14 @@ def on_init(self): self.print_help() def send_efs_handshake(self): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") opcode, payload = self.diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: pass def execute_command(self, diag_input, args : Namespace): - pass diff --git a/src/modules/efs_shell_commands/cat.py b/src/modules/efs_shell_commands/cat.py index 7e299cb..2461009 100644 --- a/src/modules/efs_shell_commands/cat.py +++ b/src/modules/efs_shell_commands/cat.py @@ -15,6 +15,13 @@ class CatCommand(BaseEfsShellCommand): + #Add new parameter efs_type to the initialization method + def __init__(self, efs_type=None): + # Save efs_type for use by other methods of the class + self.efs_type = efs_type + # Call the parent class's initialization method, if necessary + super().__init__(fs_type=efs_type) + def get_argument_parser(self, subparsers_object : _SubParsersAction) -> ArgumentParser: argument_parser = subparsers_object.add_parser('cat', @@ -26,9 +33,14 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('chmod', @@ -34,7 +40,13 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") + try: assert int(args.octal_perms, 8) & ~0o777 == 0 except Exception: @@ -47,7 +59,7 @@ def execute_command(self, diag_input, args : Namespace): is_directory : bool = False opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('device_info', @@ -24,13 +30,18 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") # Obtain the EFS underlying flash device information sequence_number = randint(0, 0xffff) opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('get', @@ -27,7 +32,12 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") remote_src : str = args.remote_src local_dst : str = expanduser(args.local_dst or (getcwd() + '/' + basename(remote_src))) @@ -39,7 +49,7 @@ def execute_command(self, diag_input, args : Namespace): return opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('ln', @@ -27,11 +32,16 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") # Rename the target path opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('ls', @@ -26,9 +32,15 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + #print("LsCommand", self.fs_type) + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('md5sum', @@ -26,13 +31,18 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") # Obtain the file checksum sequence_number = randint(0, 0xffff) opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('mkdir', @@ -26,11 +31,16 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") # Create the directory opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('mv', @@ -27,11 +32,16 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") # Rename the target path opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('put', @@ -27,7 +32,12 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") local_src : str = expanduser(args.local_src) remote_dst : str = args.remote_dst @@ -48,7 +58,7 @@ def execute_command(self, diag_input, args : Namespace): is_directory : bool = False opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('rm', @@ -26,14 +31,19 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") # First, emit a stat() (EFS2_DIAG_STAT) call in order to understand whether # the remote path input by the user is a directory or not is_directory : bool = False opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack(' ArgumentParser: argument_parser = subparsers_object.add_parser('stat', @@ -26,11 +31,16 @@ def get_argument_parser(self, subparsers_object : _SubParsersAction) -> Argument return argument_parser def execute_command(self, diag_input, args : Namespace): - + if self.fs_type == 'efs': + subsys_code = DIAG_SUBSYS_FS # Assuming DIAG_SUBSYS_FS is the code for primary + elif self.fs_type == 'efs2': + subsys_code = DIAG_SUBSYS_FS_ALTERNATE + else: + raise ValueError("Invalid filesystem type specified.") encoded_path : bytes = args.path.encode('latin1').decode('unicode_escape').encode('latin1') + b'\x00' opcode, payload = diag_input.send_recv(DIAG_SUBSYS_CMD_F, pack('