@@ -91,22 +91,22 @@ def string_to_bytes(x):
9191 return bytes (x , 'ascii' )
9292
9393
94- if __name__ == '__main__' :
94+ def main ( args , debug : bool = True ) :
9595 from .ecWrapper import PrivateKey
9696 from .comm import getDongle
9797 from .hexParser import IntelHexParser , IntelHexPrinter
98- from .hexLoader import HexLoader
99- from .hexLoader import *
98+ from .hexLoader import HexLoader , encodetlv , BOLOS_TAG_APPNAME , BOLOS_TAG_DERIVEPATH
10099 from .deployed import getDeployedSecretV1 , getDeployedSecretV2
101100 import struct
102101 import binascii
103102
104- args = get_argparser ().parse_args ()
103+ args = get_argparser ().parse_args (args )
105104
106105 if args .rootPrivateKey == None :
107106 privateKey = PrivateKey ()
108107 publicKey = binascii .hexlify (privateKey .pubkey .serialize (compressed = False ))
109- print ("Generated random root public key : %s" % publicKey )
108+ if debug :
109+ print ("Generated random root public key : %s" % publicKey )
110110 args .rootPrivateKey = privateKey .serialize ()
111111
112112 args .appName = string_to_bytes (args .appName )
@@ -270,16 +270,25 @@ def close(self):
270270
271271 hash = loader .load (0x0 , 0xF0 , printer , targetId = args .targetId , targetVersion = args .targetVersion , doCRC = not (args .nocrc or NOCRC ))
272272
273- print ("Application full hash : " + hash )
273+ if debug :
274+ print ("Application full hash : " + hash )
274275
275276 if signature == None and args .signApp :
276277 masterPrivate = PrivateKey (bytes (bytearray .fromhex (args .signPrivateKey )))
277278 signature = masterPrivate .ecdsa_serialize (masterPrivate .ecdsa_sign (bytes (binascii .unhexlify (hash )), raw = True ))
278- print ("Application signature: " + str (binascii .hexlify (signature )))
279+ if debug :
280+ print ("Application signature: " + str (binascii .hexlify (signature )))
279281
280282 if args .tlv :
281283 loader .commit (signature )
282284 else :
283285 loader .run (args .bootAddr - printer .minAddr (), signature )
284286
285287 dongle .close ()
288+ return hash
289+
290+
291+ if __name__ == '__main__' :
292+ import sys
293+
294+ sys .exit (main (sys .argv [1 :]))
0 commit comments