<s> import json <EOL> import subprocess <EOL> import sys <EOL> import re <EOL> import os <EOL> def symbols_json_update ( symbols_file , callback ) : <EOL> other_file = open ( symbols_file + '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> other_file . write ( '<STR_LIT>' ) <EOL> for line in open ( symbols_file , '<STR_LIT:r>' ) . xreadlines ( ) : <EOL> if len ( line ) < <NUM_LIT:3> : <EOL> continue <EOL> [ ( lib , symbols ) ] = re . findall ( '<STR_LIT>' , line ) <EOL> symbols = json . loads ( symbols ) <EOL> replacement = callback ( lib , symbols ) <EOL> if replacement is None : <EOL> other_file . write ( line ) <EOL> else : <EOL> other_file . write ( '<STR_LIT>' % ( lib , json . dumps ( replacement ) ) ) <EOL> if replacement is not None : <EOL> other_file . seek ( - <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> other_file . write ( '<STR_LIT:\n>' ) <EOL> other_file . write ( '<STR_LIT>' ) <EOL> os . rename ( symbols_file + '<STR_LIT>' , symbols_file ) <EOL> def determine_main_call_site ( libc , symbols ) : <EOL> for printer in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> printer = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , printer ) <EOL> try : <EOL> output = subprocess . check_output ( '<STR_LIT>' % ( libc , printer ) , shell = True , stderr = subprocess . STDOUT ) <EOL> [ ( main_call_site , printf ) ] = re . findall ( '<STR_LIT>' , output ) <EOL> ( main_call_site , printf ) = ( int ( main_call_site , <NUM_LIT:16> ) , int ( printf , <NUM_LIT:16> ) ) <EOL> print libc , main_call_site , printf <EOL> symbols [ '<STR_LIT>' ] = symbols [ '<STR_LIT>' ] + ( main_call_site - printf ) <EOL> return symbols <EOL> except subprocess . CalledProcessError : <EOL> pass <EOL> except ValueError : <EOL> pass <EOL> symbols_json_update ( '<STR_LIT>' , determine_main_call_site ) </s>
