Created
November 8, 2017 21:55
-
-
Save CoderSherlock/c1e1480740e063bc95320005d27cec64 to your computer and use it in GitHub Desktop.
library_match
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # | |
| # | |
| # | |
| # | |
| # python map.py main-bin library-obj | |
| # | |
| # | |
| import os | |
| import sys | |
| import time | |
| import logging | |
| def get_all_o_files(main, lib): | |
| o_passed = 0 | |
| o_all = len(lib.keys()) | |
| for i in lib.keys(): | |
| # logging.debug("Checking: " + i + " ...") | |
| passed = 0 | |
| summary = len(lib[i]) | |
| for j in lib[i]: | |
| if j in main: | |
| # main.remove(j) | |
| passed+=1 | |
| logging.debug(str(passed)+"/" +str(summary)) | |
| if passed == summary: | |
| # logging.info("Found: " + i + " ...") | |
| o_passed += 1 | |
| logging.info("passed: " + str(o_passed) + "/" + str(o_all)) | |
| return main | |
| def read_wo_o_obj(res): | |
| f = open(res, 'r') | |
| all_lines = f.readlines() | |
| all_symbols = [] | |
| for i in all_lines: | |
| all_symbols.append(i.split(" ")[2][:-1]) | |
| logging.info("Binary {0} has been read...".format(res)) | |
| return all_symbols | |
| def read_w_o_obj(res): | |
| f = open(res, 'r') | |
| all_lines_in_lib = f.readlines() | |
| all_symbol_in_lib = {} | |
| for i in range(0, len(all_lines_in_lib)): | |
| if len(all_lines_in_lib[i]) > 1: | |
| if len(all_lines_in_lib[i].split(" ")) <= 1: | |
| o_file_name = all_lines_in_lib[i][:-1] | |
| logging.debug(o_file_name) | |
| o_symbol_list = [] | |
| while 1: | |
| i += 1 | |
| if i >= len(all_lines_in_lib): | |
| break | |
| # logging.debug(str(i)+":"+all_lines_in_lib[i]) | |
| if len(all_lines_in_lib[i]) > 1: | |
| o_symbol_list.append(all_lines_in_lib[i].split(" ")[2][:-1]) | |
| else: | |
| i -= 1 | |
| break | |
| all_symbol_in_lib[o_file_name] = o_symbol_list | |
| # for i in all_symbol_in_lib.keys(): | |
| # logging.debug(i+":"+str(len(all_symbol_in_lib[i]))) | |
| logging.info("Binary {0} has been read...".format(res)) | |
| return all_symbol_in_lib | |
| def main(mb, lo): | |
| print(lo) | |
| all_symbol_in_main = read_wo_o_obj(mb) | |
| for i in lo: | |
| all_symbol_in_lib = read_w_o_obj(i) | |
| # print(len(all_symbol_in_main)) | |
| get_all_o_files(all_symbol_in_main, all_symbol_in_lib) | |
| # print(len(all_symbol_in_main)) | |
| # print all_symbol_in_main | |
| if __name__ == "__main__": | |
| logging.basicConfig(level=logging.INFO) | |
| main(sys.argv[1], sys.argv[2:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment