MCPcopy Create free account
hub / github.com/APKLab/APKLab / parseReport

Function parseReport

src/tools/quark-engine.ts:58–109  ·  view source on GitHub ↗

* Read and parse the JSON file of quark analysis report. * @param reportPath The path of the `quarkReport.json` file. * @returns return parsed report data.

(reportPath: string)

Source from the content-addressed store, hash-verified

56 * @returns return parsed report data.
57 */
58function parseReport(reportPath: string): QuarkReport {
59 const quarkReportJSON: QuarkRawReport = JSON.parse(
60 fs.readFileSync(reportPath, "utf8"),
61 );
62 const crimes = quarkReportJSON.crimes;
63
64 const report: QuarkReport = {};
65
66 for (let crimeIndex = 0; crimeIndex < crimes.length; crimeIndex++) {
67 const crimeObj = crimes[crimeIndex];
68 const crimeId = `c${crimeIndex}`;
69
70 if (crimeObj.confidence === QUARK_HIGH_CONFIDENCE) {
71 const newFunctionObj: Record<string, QuarkApiCallEntry> = {};
72
73 for (
74 let functionIndex = 0;
75 functionIndex < crimeObj.register.length;
76 functionIndex++
77 ) {
78 const functionObj = crimeObj.register[functionIndex];
79 const [items] = Object.entries(functionObj);
80 const parentFunction: string[] = items[0].split(" ");
81 const apiCalls: QuarkApiCall = items[1];
82
83 const parentClassName = parentFunction[0].replace(";", "");
84 // Use slice instead of delete to properly remove first element
85 const parentMethodName: string = parentFunction
86 .slice(1)
87 .join("");
88 const functionId = `${crimeId}-f${functionIndex}`;
89
90 newFunctionObj[functionId] = {
91 function: {
92 class: parentClassName,
93 method: parentMethodName,
94 },
95 apis: [apiCalls["first"], apiCalls["second"]],
96 };
97 }
98
99 report[crimeId] = {
100 crime: crimeObj.crime,
101 score: crimeObj.score,
102 weight: crimeObj.weight,
103 confidence: crimeObj.confidence,
104 api_call: newFunctionObj,
105 };
106 }
107 }
108 return report;
109}
110
111/**
112 * Convert function name to the path of the source code file.

Callers 1

showSummaryReportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected