<s> import argparse <EOL> import ast <EOL> import json <EOL> import os <EOL> alignment = <NUM_LIT> <EOL> db = None <EOL> def identify_libc ( ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> global db <EOL> if db is None : <EOL> current_dir = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> db = json . loads ( open ( os . path . join ( current_dir , '<STR_LIT>' ) ) . read ( ) ) <EOL> query_symbols = filter ( lambda k : kwargs [ k ] is None , kwargs . keys ( ) ) <EOL> known_symbols = { key : kwargs [ key ] for key in kwargs if key not in query_symbols } <EOL> for libc in db : <EOL> libc_symbols = db [ libc ] <EOL> for key in known_symbols : <EOL> if ( ( key not in libc_symbols ) or <EOL> ( known_symbols [ key ] % alignment != libc_symbols [ key ] % alignment ) or <EOL> ( known_symbols [ key ] < libc_symbols [ key ] ) ) : <EOL> break <EOL> else : <EOL> known_symbol_names = known_symbols . keys ( ) <EOL> first = known_symbol_names [ <NUM_LIT:0> ] <EOL> if len ( known_symbol_names ) > <NUM_LIT:1> : <EOL> ok = True <EOL> for other in known_symbol_names [ <NUM_LIT:1> : ] : <EOL> if known_symbols [ first ] - known_symbols [ other ] != libc_symbols [ first ] - libc_symbols [ other ] : <EOL> ok = False <EOL> break <EOL> if not ok : <EOL> continue <EOL> offset = known_symbols [ first ] - libc_symbols [ first ] <EOL> found_symbols = { symbol : ( libc_symbols [ symbol ] + offset if symbol in libc_symbols else None ) for symbol in query_symbols } <EOL> yield libc , found_symbols <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:+>' , metavar = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> symbols = { } <EOL> for symbol in args . symbol : <EOL> if '<STR_LIT:=>' not in symbol : <EOL> symbol += '<STR_LIT>' <EOL> [ name , address ] = symbol . split ( '<STR_LIT:=>' ) <EOL> symbols [ name ] = None if ( address == '<STR_LIT:?>' ) else ast . literal_eval ( address ) <EOL> for libc , identified_symbols in identify_libc ( ** symbols ) : <EOL> for symbol in identified_symbols : <EOL> print '<STR_LIT>' % ( symbol , identified_symbols [ symbol ] or <NUM_LIT:0> ) , <EOL> print libc </s>
