def parse_transaction_log_records(log_format_str, log_record_strings): ''' return (csv_header_line, [csv_record_line]) ''' log_format_byte_list = bit_tools.hex_string_to_byte_list(log_format_str) log_format = tlv_utils.parse_concatted_dol_list_to_ordered_list_of_tag_and_length( log_format_byte_list) records = [] for record_string in log_record_strings: records.append(bit_tools.hex_string_to_byte_list(record_string)) parsed_records = [] for orig_rec in records: rec = list(orig_rec) parsed = [] for (tag_name, tag_length) in log_format: value = [] for i in range(tag_length): value.append(rec.pop(0)) parsed.append(value) parsed_records.append(parsed) #fname = 'c:/dev/logs/parsed_txn_log.log' #f = open(fname, 'w') csv_header = ','.join([ tag_meanings.emv_tags[tag_name] for (tag_name, tag_length) in log_format ]) #f.write(headers + '\n') csv_lines = [] for parsed_rec in parsed_records: csv_string = '' for rec_element in parsed_rec: csv_string = (csv_string + bit_tools.byte_list_to_hex_string(rec_element) + ',') csv_lines.append(csv_string) #for line in csv_lines: # f.write(line + '\n') #f.close() return (csv_header, csv_lines)
def parse_cvr(cvr_hex_string): report = [] for l in report_header('CVR : Card Verification Results', '='): report.append(l) report.append('raw hex %s' % cvr_hex_string) cvr_byte_list = hex_string_to_byte_list(cvr_hex_string) report.append(' hex %s' % '.'.join(['%02X' % x for x in cvr_byte_list])) report.append(' dec %s' % '.'.join(['%i' % x for x in cvr_byte_list])) for l in report_header('Bit Flags', '-'): report.append(l) cvr_flags = construct_cvr_bit_flags() for flag in cvr_flags: if (bit_flag_is_set_in_byte_list(cvr_byte_list, flag) == True): report.append(flag.description) for l in report_header('Composite Bit Flags', '-'): report.append(l) cvr_sub_bytes = construct_cvr_composite_bit_flags() for sub_byte in cvr_sub_bytes: for line in sub_byte.evaluate_on_byte_list_and_report(cvr_byte_list): report.append(line) for l in report_header('Nibbles', '-'): report.append(l) cvr_nibbles = construct_cvr_nibbles() for nibble in cvr_nibbles: for line in nibble.evaluate_on_byte_list_and_report(cvr_byte_list): report.append(line) for line in report: logging.info(line)
def parse_transaction_log_records(log_format_str, log_record_strings): ''' return (csv_header_line, [csv_record_line]) ''' log_format_byte_list = bit_tools.hex_string_to_byte_list(log_format_str) log_format = tlv_utils.parse_concatted_dol_list_to_ordered_list_of_tag_and_length(log_format_byte_list) records = [] for record_string in log_record_strings: records.append(bit_tools.hex_string_to_byte_list(record_string)) parsed_records = [] for orig_rec in records: rec = list(orig_rec) parsed = [] for (tag_name, tag_length) in log_format: value = [] for i in range(tag_length): value.append(rec.pop(0)) parsed.append(value) parsed_records.append(parsed) #fname = 'c:/dev/logs/parsed_txn_log.log' #f = open(fname, 'w') csv_header = ','.join([tag_meanings.emv_tags[tag_name] for (tag_name, tag_length) in log_format]) #f.write(headers + '\n') csv_lines = [] for parsed_rec in parsed_records: csv_string = '' for rec_element in parsed_rec: csv_string = (csv_string + bit_tools.byte_list_to_hex_string(rec_element) + ',') csv_lines.append(csv_string) #for line in csv_lines: # f.write(line + '\n') #f.close() return (csv_header, csv_lines)
def parse_tsi(tsi_hex_string): report = [] for l in report_header('TSI : Transaction Status Information', '='): report.append(l) report.append('raw hex %s' % tsi_hex_string) tsi_byte_list = hex_string_to_byte_list(tsi_hex_string) report.append(' hex %s' % '.'.join(['%02X' % x for x in tsi_byte_list])) report.append(' dec %s' % '.'.join(['%i' % x for x in tsi_byte_list])) for l in report_header('Bit Flags', '-'): report.append(l) tsi_flags = construct_tsi_bit_flags() for flag in tsi_flags: if (bit_flag_is_set_in_byte_list(tsi_byte_list, flag) == True): report.append(flag.description) for line in report: logging.info(line)
def parse_tvr(tvr_hex_string): report = [] for l in report_header('TVR : Terminal Verification Results', '='): report.append(l) report.append('raw hex %s' % tvr_hex_string) tvr_byte_list = hex_string_to_byte_list(tvr_hex_string) report.append(' hex %s' % '.'.join(['%02X' % x for x in tvr_byte_list])) report.append(' dec %s' % '.'.join(['%i' % x for x in tvr_byte_list])) for l in report_header('Bit Flags', '-'): report.append(l) tvr_flags = construct_tvr_bit_flags() for flag in tvr_flags: if (bit_flag_is_set_in_byte_list(tvr_byte_list, flag) == True): report.append(flag.description) for line in report: logging.info(line)