Esempio n. 1
0
def compile_source(fas, source_c_file_name, function_name):
    tmp_executable_file_name = "bin_tmp"
    tmp_source_file_name = "source_tmp.c"
    
    with open(source_c_file_name) as f:
        source = f.read()

    for function in fas:
        if function in source:
            source = source.replace(function, fas[function])

    with open(tmp_source_file_name, "w") as f:
        f.write(source)
   
    system("gcc " +  tmp_source_file_name+ " -fPIC -fno-stack-protector -o " + tmp_executable_file_name)
    e = ELF(tmp_executable_file_name)
    f = e.functions[function_name]
    f_bytes = e.read(f.address, f.size)

    return_type = get_return_type(tmp_source_file_name, function_name)
    
    delete_file(tmp_executable_file_name)
    delete_file(tmp_source_file_name)
    
    return format(len(return_type), "02x").decode("hex") + return_type + f_bytes