<commit_before>#!/usr/bin/env python

import argparse
import ast
import json

alignment = 4096
db = json.loads(open('symbols.json').read())

def identify_libc(**kwargs):
    global db
    query_symbols = filter(lambda k: kwargs[k] is None, kwargs.keys())
    known_symbols = {key: kwargs[key] for key in kwargs if key not in query_symbols}
    for libc in db:
        libc_symbols = db[libc]
        for key in known_symbols:
            # Checks on each known symbol (presence, alignment)
            if ((key not in libc_symbols) or
                (known_symbols[key] % alignment != libc_symbols[key] % alignment) or
                (known_symbols[key] < libc_symbols[key])):
                break
        else:
            # Checks on symbol-pairs (address differences must match)
            known_symbol_names = known_symbols.keys()
            first = known_symbol_names[0]
            if len(known_symbol_names) > 1:
                for other in known_symbol_names[1:]:
                    if known_symbols[first] - known_symbols[other] != libc_symbols[first] - libc_symbols[other]:
                        continue
            # Yielding results
            offset = known_symbols[first] - libc_symbols[first]
            found_symbols = {symbol: libc_symbols[symbol] + offset for symbol in query_symbols}
            yield libc, found_symbols

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Identify the libc version and find unknown symbol addresses based on known symbol addresses.')
    parser.add_argument('symbol', nargs='+', metavar='symbol=address|?')
    args = parser.parse_args()

    symbols = {}
    for symbol in args.symbol:
        if '=' not in symbol:
            symbol += '=?'<commit_msg>Fix a bug with symbol-pairs<commit_after>#!/usr/bin/env python

import argparse
import ast
import json

alignment = 4096
db = json.loads(open('symbols.json').read())

def identify_libc(**kwargs):
    global db
    query_symbols = filter(lambda k: kwargs[k] is None, kwargs.keys())
    known_symbols = {key: kwargs[key] for key in kwargs if key not in query_symbols}
    for libc in db:
        libc_symbols = db[libc]
        for key in known_symbols:
            # Checks on each known symbol (presence, alignment)
            if ((key not in libc_symbols) or
                (known_symbols[key] % alignment != libc_symbols[key] % alignment) or
                (known_symbols[key] < libc_symbols[key])):
                break
        else:
            # Checks on symbol-pairs (address differences must match)
            known_symbol_names = known_symbols.keys()
            first = known_symbol_names[0]
            if len(known_symbol_names) > 1:
                ok = True
                for other in known_symbol_names[1:]:
                    if known_symbols[first] - known_symbols[other] != libc_symbols[first] - libc_symbols[other]:
                        ok = False
                        break
                if not ok:
                    continue
            # Yielding results
            offset = known_symbols[first] - libc_symbols[first]
            found_symbols = {symbol: libc_symbols[symbol] + offset for symbol in query_symbols}
            yield libc, found_symbols

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Identify the libc version and find unknown symbol addresses based on known symbol addresses.')
    parser.add_argument('symbol', nargs='+', metavar='symbol=address|?')
    args = parser.parse_args()

    symbols = {}
    for symbol in args.symbol:
        if '=' not in symbol:
            symbol += '=?'
{'fraction_non_alphanumeric': 0.09497515184980673, 'fraction_numerical': 0.003865267807840972, 'mean_word_length': 2.3238532110091743, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '854379', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1026, 'n_words': 292}