Feature #4963
closedImplement an interactive pysim-shell
100%
Description
pySim-prog was nice when there were only 5 parameters on a SIM that we could program, and where the use case was pretty limited. Today, we have SIM/USIM/ISIM cards with hundreds of files and even more parameters to program. We cannot add a command line argument for each file to pySim-prog.
Instead, this introduces an interactive command-line shell / REPL, in which one can navigate the file system of the card, read and update files both in raw format and in decoded/parsed format.
The idea is primarily inspired by Henryk Ploetz' venerable cyberflex-shell, but implemented on a more modern basis using the cmd2 python module.
You can see the very first prototype in the laforge/shell
branch of pysim.git
You can do things with it like this:
Start-up and authenticate with adm pin¶
$ ./pysim-shell.py -p 0 Using PC/SC reader interface Autodetected card type: sysmoISIM-SJA2 AIDs on card: ['a0000000871002ffffffff8907090000', 'a0000000871004ffffffff8907090000'] Welcome to pySim-shell! pySIM-shell (3f00)> verify_adm 92990895
interactive help¶
pySIM-shell (3f00)> help Documented commands (use 'help -v' for verbose/'help <topic>' for details): ISO7816 Commands ================ read_binary select_adf select_file update_binary update_record verify_chv pySim Commands ============== intro verify_adm USIM Commands ============= read_ehplmn ust_service_activate ust_service_deactivate pySim-shell built-in commands ============================= alias help macro quit run_script shell edit history py run_pyscript set shortcuts
more interactive help¶
pySIM-shell (3f00)> help read_binary usage: read_binary [-h] [--file-id FILE_ID] [--offset OFFSET] [--length LENGTH] [--record-nr RECORD_NR] Read binary data from a transparent EF optional arguments: -h, --help show this help message and exit --file-id FILE_ID File ID --offset OFFSET Byte offset for start of read --length LENGTH Number of bytes to read --record-nr RECORD_NR Number of record to read
navigating the FS and reading files¶
pySIM-shell (3f00)> select_file 7f20 ['622c8202782183027f20a509800171830400018d088a01058b032f0601c60f90017083010183018183010a83010b'] pySIM-shell (3f00/7f20)> read_binary --file-id 6f07 089910070000400310
interaction with local filesystem, i.e. I/O redirect + shell commands¶
pySIM-shell (3f00)> select_adf a0000000871002 pySIM-shell (a0000000871002)> select_file 5f3b pySIM-shell (a0000000871002/5f3b)> read_binary --file-id 4f20 > /tmp/f pySIM-shell (a0000000871002/5f3b)> !cat /tmp/f ffffffffffffffff07
piping output through shell tools like grep¶
pySIM-shell (3f00)> read_ust | grep 86 Service 86 - Allowed CSG Lists and corresponding indications
enabling/disabling services¶
pySIM-shell (3f00/7f20)> ust_service_activate 123 pySIM-shell (3f00/7f20)> ust_service_deactivate 123
The major tasks I see to make this go anywhere is:
- have "File" class with encoder/decoder methods, which are registered automatically with a 'file system' layer that knows about the DF/ADF hierarchy
- this allows us to have a "read-decoded" command, which will call the decode method of the file, automatically resolved by the selected FID/path
- automatic mapping of file-name -> FID and FID -> file name
- when printing (like in the path), use the human-readable names
- allow users to use human-readable names in SELECT
- decode + display the TLVs / FCPs after a SELECT (like cyberflex-shell
- ability to enable/disable APDU trace
- dynamically register/deregster commands based on the path, i.e. offer USIM commands only when in ADF_USIM
Related issues
Updated by laforge about 3 years ago
- Related to Bug #4962: add setup.py to pySim added
Updated by dexter about 3 years ago
- Assignee changed from laforge to dexter
- % Done changed from 30 to 40
I have continued the development now. I have worked myself through the code now and added some new features:
- dir command: At the moment we can only use the tab completion to display the directory tree, however I think its more convenient to have a dir command that unless otherwise specified only shows the files and directories by their names.
- export command: This command recursively walks through the file system and generates a script that consists of update_binary and update_record commands. This is effectively a backup of the card. To restore the backup the script can be executed in pySim-shell. It is also error tolerant. If for some reason a file can not be red during creation a comment is printed to the script and the script generation just moves on.
- tree command: This is basically a byproduct of the export command. It walks through the filesystem and displays and displays a tree, this is very handy if one does not know where exactly a specific file is located.
The next steps will be to have specific support for sysmo-usim-sjs1 and sysmo-isim-sja2. We basically need to check the ATR and add the matching proprietary files to the card. I am currently on this.
The current status can be found on pmaier/shell
Updated by laforge about 3 years ago
- first apply all infrastructure changes in the existing code, so we can test them without introducing pySim-shell
- squash a number of small, non-controversial @dexter's fixes into the main pySim-shell commit
The result has been pushed, with the main shell commit in https://gerrit.osmocom.org/c/pysim/+/23175
Updated by laforge about 3 years ago
- Status changed from In Progress to Resolved
- Assignee changed from dexter to laforge
- % Done changed from 40 to 100