mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-20 12:28:33 +03:00
saip-tool: Add 'extract-apps' to dump all applications from eSIM profile
This new action can be used to dump all java applications as either raw IJC file or converted to CAP format (the usual format generated by JavaCard toolchains). Change-Id: I51cffa5ba3ddbea491341d678ec9249d7cf470a5
This commit is contained in:
@@ -617,7 +617,19 @@ class ProfileElementSequence:
|
||||
# TODO: remove any records related to the ADFs from EF.DIR
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "PESequence(%s)" % ', '.join([str(x) for x in self.pe_list])
|
||||
return "PESequence(%s: %s)" % (self.iccid, ', '.join([str(x) for x in self.pe_list]))
|
||||
|
||||
def __iter__(self) -> str:
|
||||
yield from self.pe_list
|
||||
|
||||
@property
|
||||
def iccid(self) -> Optional[str]:
|
||||
"""The ICCID of the profile."""
|
||||
if not 'header' in self.pe_by_type:
|
||||
return None
|
||||
if len(self.pe_by_type['header']) < 1:
|
||||
return None
|
||||
pe_hdr_dec = self.pe_by_type['header'][0].decoded
|
||||
if not 'iccid' in pe_hdr_dec:
|
||||
return None
|
||||
return b2h(pe_hdr_dec['iccid'])
|
||||
|
||||
19
pySim/javacard.py
Normal file
19
pySim/javacard.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# JavaCard related utilities
|
||||
|
||||
import zipfile
|
||||
import struct
|
||||
import sys
|
||||
import io
|
||||
|
||||
def ijc_to_cap(in_file: io.IOBase, out_zip: zipfile.ZipFile, p : str = "foo"):
|
||||
"""Convert an ICJ (Interoperable Java Card) file [back] to a CAP file."""
|
||||
TAGS = ["Header", "Directory", "Applet", "Import", "ConstantPool", "Class", "Method", "StaticField", "RefLocation", "Export", "Descriptor", "Debug"]
|
||||
b = in_file.read()
|
||||
while len(b):
|
||||
tag, size = struct.unpack('!BH', b[0:3])
|
||||
out_zip.writestr(p+"/javacard/"+TAGS[tag-1]+".cap", b[0:3+size])
|
||||
b = b[3+size:]
|
||||
|
||||
# example usage:
|
||||
# with io.open(sys.argv[1],"rb") as f, zipfile.ZipFile(sys.argv[2], "wb") as z:
|
||||
# ijc_to_cap(f, z)
|
||||
Reference in New Issue
Block a user