MCPcopy Create free account
hub / github.com/CheckPointSW/Karta / analyzeLibrary

Function analyzeLibrary

src/karta_analyze_src.py:70–244  ·  view source on GitHub ↗

Analyze the open source library, file-by-file and merge the results. Args: config_name (str): name of the final JSON config file bin_dirs (list): list of paths to the binary folders containing the compiled *.o files compiled_ars (list): list of paths to the compiled *.ar

(config_name, bin_dirs, compiled_ars, prompter)

Source from the content-addressed store, hash-verified

68 src_func_ctx.unknown_fptrs.clear()
69
70def analyzeLibrary(config_name, bin_dirs, compiled_ars, prompter):
71 """Analyze the open source library, file-by-file and merge the results.
72
73 Args:
74 config_name (str): name of the final JSON config file
75 bin_dirs (list): list of paths to the binary folders containing the compiled *.o files
76 compiled_ars (list): list of paths to the compiled *.ar files
77 prompter (prompter): prompter instance
78 """
79 prompter.info("Starting to analyze the library")
80 prompter.addIndent()
81 ignore_archive = len(compiled_ars) == 0
82 finished_scan = False
83
84 # workaround the enumerate in the next loop
85 if ignore_archive:
86 compiled_ars = range(len(bin_dirs))
87
88 # ida has severe bugs, make sure to warn the user in advance
89 if disas_cmd.name() == ida_cmd_api.IdaCMD.name() and ' ' in SCRIPT_PATH:
90 prompter.error(f"IDA does not support spaces (' ') in the script's path. Please move {LIBRARY_NAME}'s directory accordingly (I feel your pain)")
91 prompter.removeIndent()
92 return
93
94 # We could have 2 iteration rounds here
95 while not finished_scan:
96 # Prepare & load the stats from each file
97 for ind, compiled_ar in enumerate(compiled_ars):
98 # check if this is a windows archive
99 is_windows = isWindows()
100 bin_dir = bin_dirs[ind]
101 bin_suffix = "o" if not is_windows else "obj"
102 if not ignore_archive:
103 prompter.info(f"Analyzing each of the files in the archive - {compiled_ar}")
104 else:
105 prompter.info(f"Analyzing each of the *.{bin_suffix} files in the bin directory")
106 prompter.addIndent()
107 archive_files = list(locateFiles(bin_dir, [x for x in getArchiveFiles(compiled_ar) if x.endswith("." + bin_suffix)] if not ignore_archive else None, bin_suffix))
108 # check if we need a progress bar
109 if len(archive_files) >= PROGRESS_BAR_THRESHOLD and prompter._min_level > logging.DEBUG:
110 progress_bar = ProgressBar("Analyzed %d/%d files - %d%% Completed", len(archive_files), 20, True, time_format="Elapsed %M:%S -")
111 progress_bar.start()
112 else:
113 progress_bar = None
114 # it makes more sense to have a sorted list
115 archive_files.sort()
116 # start the work itself
117 for full_file_path, compiled_file in archive_files:
118 # ida has severe bugs, make sure to warn the user in advance
119 if disas_cmd.name() == "IDA" and ' ' in full_file_path:
120 prompter.error("IDA does not support spaces (' ') in the file's path (in script mode). Please move the binary directory accordingly (I feel your pain)")
121 prompter.removeIndent()
122 return
123 prompter.debug(f"{full_file_path} - {compiled_file}")
124 if progress_bar is None:
125 prompter.info(f"{compiled_file} - {full_file_path}")
126 # analyze the file
127 analyzeFile(full_file_path, is_windows)

Callers 1

mainFunction · 0.85

Calls 14

getArchiveFilesFunction · 0.90
isWindowsFunction · 0.85
locateFilesFunction · 0.85
constructInitLogPathFunction · 0.85
constructLogPathFunction · 0.85
parseFileStatsFunction · 0.85
resolveUnknownsFunction · 0.85
getContextsStatsFunction · 0.85
startMethod · 0.80
serializeMethod · 0.80
analyzeFileFunction · 0.70
nameMethod · 0.45

Tested by

no test coverage detected