Skip to content

Commit 53a2e0f

Browse files
committed
GetMachineCode return None on error
1 parent d0e9a6c commit 53a2e0f

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

licensing/methods.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,20 +967,47 @@ def GetMachineCode(v=1):
967967
"""
968968
Get a unique identifier for this device. If you want the machine code to be the same in .NET on Windows, you
969969
can set v=2. More information is available here: https://help.cryptolens.io/faq/index#machine-code-generation
970+
971+
Note: if we are unable to compute the machine code, None will be returned. Please make sure
972+
to check this in production code.
970973
"""
971974

972975
if "windows" in platform.platform().lower():
973-
if v==2:
974-
return HelperMethods.get_SHA256(HelperMethods.start_process_ps_v2())
976+
977+
seed = ""
978+
979+
if v==2:
980+
seed = HelperMethods.start_process_ps_v2()
975981
else:
976-
return HelperMethods.get_SHA256(HelperMethods.start_process(["cmd.exe", "/C", "wmic","csproduct", "get", "uuid"],v))
982+
seed = HelperMethods.start_process(["cmd.exe", "/C", "wmic","csproduct", "get", "uuid"],v)
983+
984+
if seed == "":
985+
return None
986+
else:
987+
return HelperMethods.get_SHA256(seed)
988+
989+
977990
elif "mac" in platform.platform().lower() or "darwin" in platform.platform().lower():
978991
res = HelperMethods.start_process(["system_profiler","SPHardwareDataType"])
979-
return HelperMethods.get_SHA256(res[res.index("UUID"):].strip())
992+
seed = res[res.index("UUID"):].strip()
993+
994+
if seed == "":
995+
return None
996+
else:
997+
return HelperMethods.get_SHA256(seed)
998+
980999
elif "linux" in platform.platform().lower() :
981-
return HelperMethods.get_SHA256(HelperMethods.compute_machine_code())
1000+
seed = HelperMethods.compute_machine_code()
1001+
if seed == "":
1002+
return None
1003+
else:
1004+
return HelperMethods.get_SHA256(seed)
9821005
else:
983-
return HelperMethods.get_SHA256(HelperMethods.compute_machine_code())
1006+
seed = HelperMethods.compute_machine_code()
1007+
if seed == "":
1008+
return None
1009+
else:
1010+
return HelperMethods.get_SHA256(seed)
9841011

9851012
@staticmethod
9861013
def IsOnRightMachine(license_key, is_floating_license = False, allow_overdraft=False, v = 1, custom_machine_code = None):

0 commit comments

Comments
 (0)