text stringlengths 1 93.6k |
|---|
if i + fileBufferLength <= len(zipped):
|
hasher.update(zipped[i: i + fileBufferLength])
|
else:
|
hasher.update(zipped[i: len(zipped)])
|
digest = hasher.finalize()
|
return private_key.sign(digest, padding.PKCS1v15(), utils.Prehashed(chosen_hash))
|
def zipdir(directory, inject=None):
|
zip_memory = io.BytesIO()
|
with zipfile.ZipFile(zip_memory, 'w', zipfile.ZIP_DEFLATED) as zf:
|
def _rec_zip(path, parent='', inject=None):
|
if inject:
|
for fname, fdata in inject.items():
|
zf.writestr(fname, fdata)
|
for d in os.listdir(path):
|
child = os.path.join(path, d)
|
name = '%s/%s' % (parent, d)
|
if os.path.isfile(child):
|
zf.write(child, name)
|
if os.path.isdir(child):
|
_rec_zip(child, name)
|
_rec_zip(directory, '', inject=inject)
|
zf.close()
|
zipdata = zip_memory.getvalue()
|
return zipdata
|
raise IOError('Failed to create zip')
|
def argparser():
|
parser = argparse.ArgumentParser(description='crx3 creator')
|
parser.add_argument(
|
'src',
|
type=str,
|
default='',
|
help='Source directory containing unpacked chrome ext',
|
)
|
parser.add_argument(
|
'-o', '--output', type=str, default='', help='File location for packed .crx'
|
)
|
parser.add_argument(
|
'-pem',
|
'--private-key',
|
type=str,
|
default='',
|
help='Private key location if no private key script will generate and save private key',
|
)
|
return parser
|
def cli():
|
parser = argparser()
|
args = parser.parse_args()
|
package(args.src, args.private_key, args.output)
|
def get_crx_id(public_key):
|
digest = hashes.Hash(hashes.SHA256(), backend=default_backend())
|
digest.update(public_key)
|
hased = digest.finalize()
|
return hased[0:16]
|
def create_signed_header_data_str(public_key):
|
signed_header_data = crx3_pb2.SignedData()
|
signed_header_data.crx_id = get_crx_id(public_key)
|
return signed_header_data.SerializeToString()
|
def create_header_str(public_key, signed, signed_header_data_str):
|
header = crx3_pb2.CrxFileHeader()
|
proof = header.sha256_with_rsa.add()
|
proof.public_key = public_key
|
proof.signature = signed
|
header.signed_header_data = signed_header_data_str
|
return header.SerializeToString()
|
def save_crx_file(header_str, zipped, path, crdx):
|
header_size_octets = struct.pack('<I', len(header_str))
|
fileLocation = path if path else '%s.crx' % crdx
|
with open(fileLocation, 'wb') as crx:
|
data = [kCrxFileHeaderMagic, VERSION, header_size_octets, header_str, zipped]
|
for d in data:
|
crx.write(d)
|
if __name__ == '__main__':
|
cli()
|
# <FILESEP>
|
#
|
# A wrapper script to quantise models with GPTQ, from one of various datasets
|
#
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.