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
20 lines
698 B
Python
20 lines
698 B
Python
# 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)
|