Beispiel #1
0
def process_tag_decrypt(rule_file_name, tag, data):
    rule_file = RuleXml(rule_file_name)
    tag_decrypt_nodes = rule_file.get_nodes(rule_file.root_element,
                                            'TagDecrypt')
    for node in tag_decrypt_nodes:
        attrs = rule_file.get_attributes(node)
        if attrs['tag'] == tag:
            start_pos = 0
            data_len = 0
            delete80 = False
            is_bcd = False
            data = algorithm.des3_ecb_decrypt(attrs['key'], data)
            start_pos = int(attrs['startPos']) if 'startPos' in attrs else 0
            data_len = int(attrs['len']) if 'len' in attrs else len(data)
            delete80 = True if 'delete80' in attrs else False
            is_bcd = True if 'bcd' in attrs else False
            if delete80:
                index = data.rfind('80')
                if index != -1:
                    data = data[:42]
            if is_bcd:
                data = utils.bcd_to_str(data)
            data = data[start_pos:start_pos + data_len]
            return data
    return data
Beispiel #2
0
def process_tag_decrypt(rule_file_name,tag,data):
    rule_file = RuleXml(rule_file_name)
    tag_decrypt_nodes = rule_file.get_nodes(rule_file.root_element,'TagDecrypt')
    for node in tag_decrypt_nodes:
        attrs = rule_file.get_attributes(node)
        if attrs['tag'] == tag:
            data = algorithm.des3_ecb_decrypt(attrs['key'],data)
            if 'startPos' in attrs:
                start_pos = int(attrs['startPos'])
            else:
                start_pos = 0
            if 'len' in attrs:
                data_len = int(attrs['len'])
            else:
                data_len = len(data)
            data = data[start_pos : start_pos + data_len]
            return data
    return data