def process_rule_eps(rule_file_name, cps): key = '0123456789ABCDEF1111111111111111' #默认解密key rule_handle = RuleXml(rule_file_name) handle8020_node = rule_handle.get_first_node(rule_handle.root_element, 'Handle8020') if not handle8020_node: return cps key = rule_handle.get_attribute(handle8020_node, 'key') for dgi_item in cps.dgi_list: if dgi_item.name == '8020': tag8020 = '' tagA001 = '' value = dgi_item.get_value('8020') dgi_len = len(value) for i in range(0, dgi_len, 34): tagA001 += value[i:i + 2] + '010000FF0000' data = algorithm.des3_ecb_decrypt(key, value[i + 2:i + 34]) tag8020 += data dgi_item.modify_value('8020', tag8020) dgiA001 = Dgi() dgiA001.name = 'A001' dgiA001.add_tag_value('A001', tagA001) cps.add_dgi(dgiA001) if dgi_item.name == '9020': tag9020 = '' value = dgi_item.get_value('9020') for i in range(0, len(value), 8): tag9020 += value[i + 2:i + 8] dgi_item.modify_value('9020', tag9020) return cps
def process_mag_data(fh,rule_file_name): rule_file = RuleXml(rule_file_name) mag_node = rule_file.get_first_node(rule_file.root_element,'Magstrip') mag_flag = fh.read_str(fh.current_offset,6) if mag_flag != '000MAG': return False mag_data_len = fh.read_int64(fh.current_offset) track_flag_list = [] track_flag_list.append(fh.read(fh.current_offset,1)) track_flag_list.append(fh.read(fh.current_offset + 1,1)) track_flag_list.append(fh.read(fh.current_offset + 1,1)) mag_data = fh.read_binary(fh.current_offset,mag_data_len - 5) mag_data_list = [x for x in mag_data.split('7C') if len(x) > 0] Log.info('decrypt mag data: ',end='') Log.info(mag_data_list) dgi = Dgi() dgi.name = 'Magstrip' if mag_node is not None: mag_key = rule_file.get_attribute(mag_node,'key') decrypt_mag_list = [] for data in mag_data_list: data = utils.bcd_to_str(data) data = algorithm.des3_ecb_decrypt(mag_key,data) data = utils.bcd_to_str(data) data_len = int(data[0:4]) data = data[4:data_len + 4].rstrip() decrypt_mag_list.append(data) pos = 1 for mag in decrypt_mag_list: for index in range(pos,4): pos += 1 option = 'mag' + str(pos) if track_flag_list[index - 1] == '0': dgi.add_tag_value(option,'') continue dgi.add_tag_value(option,mag) break Log.info('decrypt mag data: ',end='') Log.info(decrypt_mag_list) return dgi