|
|
@ -42,79 +42,96 @@ class TestHyundaiFingerprint(unittest.TestCase): |
|
|
|
for ecu, fws in ecus.items(): |
|
|
|
for ecu, fws in ecus.items(): |
|
|
|
if ecu[0] in FW_QUERY_CONFIG.fuzzy_ecus: |
|
|
|
if ecu[0] in FW_QUERY_CONFIG.fuzzy_ecus: |
|
|
|
# TODO: use FW_QUERY_CONFIG.fuzzy_get_platform_codes |
|
|
|
# TODO: use FW_QUERY_CONFIG.fuzzy_get_platform_codes |
|
|
|
has_date = {PLATFORM_CODE_PATTERN.search(fw).groups(1) is None for fw in fws} |
|
|
|
has_date = {PLATFORM_CODE_PATTERN.search(fw).groups()[1] is None for fw in fws} |
|
|
|
self.assertEqual(len(has_date), 1) |
|
|
|
self.assertEqual(len(has_date), 1) |
|
|
|
|
|
|
|
|
|
|
|
def test_fuzzy_platform_codes(self): |
|
|
|
def test_fuzzy_platform_codes(self): |
|
|
|
codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([b'\xf1\x00DH LKAS 1.1 -150210']) |
|
|
|
return |
|
|
|
self.assertEqual(codes, {b"DH"}) |
|
|
|
# codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([b'\xf1\x00DH LKAS 1.1 -150210']) |
|
|
|
|
|
|
|
# self.assertEqual(codes, {b"DH"}) |
|
|
|
codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([b'\xf1\x00AEhe SCC H-CUP 1.01 1.01 96400-G2000 ']) |
|
|
|
# |
|
|
|
self.assertEqual(codes, {b"AEhe"}) |
|
|
|
# codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([b'\xf1\x00AEhe SCC H-CUP 1.01 1.01 96400-G2000 ']) |
|
|
|
|
|
|
|
# self.assertEqual(codes, {b"AEhe"}) |
|
|
|
codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([b'\xf1\x00CV1_ RDR ----- 1.00 1.01 99110-CV000 ']) |
|
|
|
# |
|
|
|
self.assertEqual(codes, {b"CV1"}) |
|
|
|
# codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([b'\xf1\x00CV1_ RDR ----- 1.00 1.01 99110-CV000 ']) |
|
|
|
|
|
|
|
# self.assertEqual(codes, {b"CV1"}) |
|
|
|
|
|
|
|
|
|
|
|
# TODO: this |
|
|
|
# TODO: this |
|
|
|
codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([b'\xf1\x00LX2 MFC AT USA LHD 1.00 1.03 99211-S8100 190125']) |
|
|
|
# codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([ |
|
|
|
self.assertEqual(codes, {b"LX2_1901"}) |
|
|
|
# b'\xf1\x00LX2 MFC AT USA LHD 1.00 1.03 99211-S8100 191125', |
|
|
|
|
|
|
|
# b'\xf1\x00LX2 MFC AT USA LHD 1.00 1.03 99211-S8100 200108', |
|
|
|
|
|
|
|
# b'\xf1\x00LX3 MFC AT USA LHD 1.00 1.03 99211-S8100 190408', |
|
|
|
|
|
|
|
# b'\xf1\x00LX3 MFC AT USA LHD 1.00 1.03 99211-S8100 190719', |
|
|
|
|
|
|
|
# ]) |
|
|
|
|
|
|
|
# # print('ret', codes) |
|
|
|
|
|
|
|
# # self.assertEqual(codes, {b'LX2_1911', b'LX2_1912', b'LX2_2001'}) |
|
|
|
|
|
|
|
# self.assertEqual(codes, {b'LX3_1907', b'LX3_1906', b'LX2_1911', b'LX2_1912', b'LX3_1905', b'LX2_2001', b'LX3_1904'}) |
|
|
|
|
|
|
|
|
|
|
|
codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([ |
|
|
|
codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([ |
|
|
|
b'\xf1\x00DH LKAS 1.1 -150210', |
|
|
|
b'\xf1\x00LX2 MFC AT USA LHD 1.00 1.03 99211-S8100 999999', |
|
|
|
b'\xf1\x00AEhe SCC H-CUP 1.01 1.01 96400-G2000 ', |
|
|
|
b'\xf1\x00LX2 MFC AT USA LHD 1.00 1.03 99211-S8100 999999', |
|
|
|
b'\xf1\x00CV1_ RDR ----- 1.00 1.01 99110-CV000 ', |
|
|
|
b'\xf1\x00LX3 MFC AT USA LHD 1.00 1.03 99211-S8100 99999', |
|
|
|
|
|
|
|
b'\xf1\x00LX3 MFC AT USA LHD 1.00 1.03 99211-S8100 99999', |
|
|
|
]) |
|
|
|
]) |
|
|
|
self.assertEqual(codes, {b"DH", b"AEhe", b"CV1"}) |
|
|
|
print(codes) |
|
|
|
|
|
|
|
self.assertEqual(codes, {b'LX2', b'LX3'}) |
|
|
|
def test_excluded_platforms(self): |
|
|
|
|
|
|
|
# Asserts a list of platforms that will not fuzzy fingerprint due to shared platform codes |
|
|
|
# codes = FW_QUERY_CONFIG.fuzzy_get_platform_codes([ |
|
|
|
# This list can be shrunk as we combine platforms and detect features |
|
|
|
# b'\xf1\x00DH LKAS 1.1 -150210', |
|
|
|
excluded_platforms = [ |
|
|
|
# b'\xf1\x00AEhe SCC H-CUP 1.01 1.01 96400-G2000 ', |
|
|
|
CAR.HYUNDAI_GENESIS, |
|
|
|
# b'\xf1\x00CV1_ RDR ----- 1.00 1.01 99110-CV000 ', |
|
|
|
CAR.IONIQ, |
|
|
|
# ]) |
|
|
|
CAR.IONIQ_PHEV_2019, |
|
|
|
# self.assertEqual(codes, {b"DH", b"AEhe", b"CV1"}) |
|
|
|
CAR.IONIQ_PHEV, |
|
|
|
|
|
|
|
CAR.IONIQ_EV_2020, |
|
|
|
# def test_excluded_platforms(self): |
|
|
|
CAR.IONIQ_EV_LTD, |
|
|
|
# # Asserts a list of platforms that will not fuzzy fingerprint due to shared platform codes |
|
|
|
CAR.IONIQ_HEV_2022, |
|
|
|
# # This list can be shrunk as we combine platforms and detect features |
|
|
|
CAR.SANTA_FE, |
|
|
|
# excluded_platforms = [ |
|
|
|
CAR.SANTA_FE_2022, |
|
|
|
# CAR.HYUNDAI_GENESIS, |
|
|
|
CAR.KIA_STINGER, |
|
|
|
# CAR.IONIQ, |
|
|
|
CAR.KIA_STINGER_2022, |
|
|
|
# CAR.IONIQ_PHEV_2019, |
|
|
|
CAR.GENESIS_G70, |
|
|
|
# CAR.IONIQ_PHEV, |
|
|
|
CAR.GENESIS_G70_2020, |
|
|
|
# CAR.IONIQ_EV_2020, |
|
|
|
CAR.TUCSON_4TH_GEN, |
|
|
|
# CAR.IONIQ_EV_LTD, |
|
|
|
CAR.TUCSON_HYBRID_4TH_GEN, |
|
|
|
# CAR.IONIQ_HEV_2022, |
|
|
|
CAR.KIA_SPORTAGE_HYBRID_5TH_GEN, |
|
|
|
# CAR.SANTA_FE, |
|
|
|
CAR.SANTA_CRUZ_1ST_GEN, |
|
|
|
# CAR.SANTA_FE_2022, |
|
|
|
CAR.KIA_SPORTAGE_5TH_GEN, |
|
|
|
# CAR.KIA_STINGER, |
|
|
|
] |
|
|
|
# CAR.KIA_STINGER_2022, |
|
|
|
|
|
|
|
# CAR.GENESIS_G70, |
|
|
|
all_platform_codes = defaultdict(set) |
|
|
|
# CAR.GENESIS_G70_2020, |
|
|
|
for platform, fw_by_addr in FW_VERSIONS.items(): |
|
|
|
# CAR.TUCSON_4TH_GEN, |
|
|
|
for addr, fws in fw_by_addr.items(): |
|
|
|
# CAR.TUCSON_HYBRID_4TH_GEN, |
|
|
|
if addr[0] not in FW_QUERY_CONFIG.fuzzy_ecus: |
|
|
|
# CAR.KIA_SPORTAGE_HYBRID_5TH_GEN, |
|
|
|
continue |
|
|
|
# CAR.SANTA_CRUZ_1ST_GEN, |
|
|
|
|
|
|
|
# CAR.KIA_SPORTAGE_5TH_GEN, |
|
|
|
for platform_code in FW_QUERY_CONFIG.fuzzy_get_platform_codes(fws): |
|
|
|
# ] |
|
|
|
all_platform_codes[(addr[1], addr[2], platform_code)].add(platform) |
|
|
|
# |
|
|
|
|
|
|
|
# all_platform_codes = defaultdict(set) |
|
|
|
platforms_with_shared_codes = [] |
|
|
|
# for platform, fw_by_addr in FW_VERSIONS.items(): |
|
|
|
for platform, fw_by_addr in FW_VERSIONS.items(): |
|
|
|
# for addr, fws in fw_by_addr.items(): |
|
|
|
shared_codes = [] |
|
|
|
# if addr[0] not in FW_QUERY_CONFIG.fuzzy_ecus: |
|
|
|
for addr, fws in fw_by_addr.items(): |
|
|
|
# continue |
|
|
|
if addr[0] not in FW_QUERY_CONFIG.fuzzy_ecus: |
|
|
|
# |
|
|
|
continue |
|
|
|
# for platform_code in FW_QUERY_CONFIG.fuzzy_get_platform_codes(fws): |
|
|
|
|
|
|
|
# all_platform_codes[(addr[1], addr[2], platform_code)].add(platform) |
|
|
|
for platform_code in FW_QUERY_CONFIG.fuzzy_get_platform_codes(fws): |
|
|
|
# |
|
|
|
shared_codes.append(len(all_platform_codes[(addr[1], addr[2], platform_code)]) > 1) |
|
|
|
# platforms_with_shared_codes = [] |
|
|
|
|
|
|
|
# for platform, fw_by_addr in FW_VERSIONS.items(): |
|
|
|
# If all the platform codes for this platform are shared with another platform, |
|
|
|
# shared_codes = [] |
|
|
|
# we cannot fuzzy fingerprint this platform |
|
|
|
# for addr, fws in fw_by_addr.items(): |
|
|
|
if all(shared_codes): |
|
|
|
# if addr[0] not in FW_QUERY_CONFIG.fuzzy_ecus: |
|
|
|
platforms_with_shared_codes.append(platform) |
|
|
|
# continue |
|
|
|
|
|
|
|
# |
|
|
|
self.assertEqual(set(platforms_with_shared_codes), set(excluded_platforms)) |
|
|
|
# for platform_code in FW_QUERY_CONFIG.fuzzy_get_platform_codes(fws): |
|
|
|
|
|
|
|
# shared_codes.append(len(all_platform_codes[(addr[1], addr[2], platform_code)]) > 1) |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# # If all the platform codes for this platform are shared with another platform, |
|
|
|
|
|
|
|
# # we cannot fuzzy fingerprint this platform |
|
|
|
|
|
|
|
# if all(shared_codes): |
|
|
|
|
|
|
|
# platforms_with_shared_codes.append(platform) |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# self.assertEqual(set(platforms_with_shared_codes), set(excluded_platforms)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|