Skip to content

Commit

Permalink
C/C++ improvements (#750)
Browse files Browse the repository at this point in the history
Added c reachables example

Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu authored Dec 1, 2023
1 parent ed424be commit c2e5edd
Show file tree
Hide file tree
Showing 11 changed files with 423 additions and 151 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/java-reachables-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ jobs:
with:
repository: 'DependencyTrack/dependency-track'
path: 'repotests/dependency-track'
- uses: actions/checkout@v4
with:
repository: 'drogonframework/drogon'
path: 'repotests/drogon'
- name: compile
run: |
cd repotests/dependency-track
mvn -q clean compile -DskipTests -Dmaven.test.skip=true
- name: repotests
run: |
bin/cdxgen.js -p -t java --profile research -o repotests/dependency-track/bom.json repotests/dependency-track
run: |
node bin/cdxgen.js -p -t java --profile research -o repotests/dependency-track/bom.json repotests/dependency-track
cp -rf repotests/dependency-track/*.json *.slices.json bomresults/
cd repotests/drogon/examples
node ../../../bin/cdxgen.js -p -t c --profile research -o bom.json .
cd ../../..
- uses: actions/upload-artifact@v3
with:
name: bomresults
Expand Down
2 changes: 1 addition & 1 deletion ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ RUN set -e; \
&& python3 -m pip install --user pipenv poetry \
&& curl -s "https://get.sdkman.io" | bash \
&& source "$HOME/.sdkman/bin/sdkman-init.sh" \
&& echo -e "sdkman_auto_answer=true\nsdkman_selfupdate_feature=false\nsdkman_auto_env=true" >> $HOME/.sdkman/etc/config \
&& echo -e "sdkman_auto_answer=true\nsdkman_selfupdate_feature=false\nsdkman_auto_env=true\nsdkman_curl_connect_timeout=20\nsdkman_curl_max_time=0" >> $HOME/.sdkman/etc/config \
&& sdk install java $JAVA_VERSION \
&& sdk install maven $MAVEN_VERSION \
&& sdk install gradle $GRADLE_VERSION \
Expand Down
21 changes: 20 additions & 1 deletion data/frameworks-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,25 @@
"pkg:cargo/nickel",
"pkg:cargo/yew",
"pkg:cargo/azul",
"pkg:cargo/conrod"
"pkg:cargo/conrod",
"pkg:generic/Aws",
"pkg:generic/Azure",
"pkg:generic/google",
"pkg:generic/CivetServer",
"pkg:generic/civetweb",
"pkg:generic/cpprest",
"pkg:generic/QCoreApplication",
"pkg:generic/drogon",
"pkg:generic/wfrest",
"pkg:generic/http",
"pkg:generic/fio",
"pkg:generic/onion",
"pkg:generic/lwan",
"pkg:generic/oatpp",
"pkg:generic/QDjango",
"pkg:generic/userver",
"pkg:generic/Wt/",
"pkg:generic/klone",
"pkg:generic/kcgi"
]
}
66 changes: 35 additions & 31 deletions evinser.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,29 @@ export const analyzeProject = async (dbObjMap, options) => {
// Load any existing purl-location information from the sbom.
// For eg: cdxgen populates this information for javascript projects
let { purlLocationMap, purlImportsMap } = initFromSbom(components);
// Do reachables first so that usages slicing can reuse the atom file
if (options.withReachables) {
if (
options.reachablesSlicesFile &&
fs.existsSync(options.reachablesSlicesFile)
) {
reachablesSlicesFile = options.reachablesSlicesFile;
reachablesSlice = JSON.parse(
fs.readFileSync(options.reachablesSlicesFile, "utf-8")
);
} else {
retMap = createSlice(language, dirPath, "reachables", options);
if (retMap && retMap.slicesFile && fs.existsSync(retMap.slicesFile)) {
reachablesSlicesFile = retMap.slicesFile;
reachablesSlice = JSON.parse(
fs.readFileSync(retMap.slicesFile, "utf-8")
);
}
}
}
if (reachablesSlice && Object.keys(reachablesSlice).length) {
dataFlowFrames = await collectReachableFrames(language, reachablesSlice);
}
// Reuse existing usages slices
if (options.usagesSlicesFile && fs.existsSync(options.usagesSlicesFile)) {
usageSlice = JSON.parse(fs.readFileSync(options.usagesSlicesFile, "utf-8"));
Expand Down Expand Up @@ -374,28 +397,6 @@ export const analyzeProject = async (dbObjMap, options) => {
purlImportsMap
);
}
if (options.withReachables) {
if (
options.reachablesSlicesFile &&
fs.existsSync(options.reachablesSlicesFile)
) {
reachablesSlicesFile = options.reachablesSlicesFile;
reachablesSlice = JSON.parse(
fs.readFileSync(options.reachablesSlicesFile, "utf-8")
);
} else {
retMap = createSlice(language, dirPath, "reachables", options);
if (retMap && retMap.slicesFile && fs.existsSync(retMap.slicesFile)) {
reachablesSlicesFile = retMap.slicesFile;
reachablesSlice = JSON.parse(
fs.readFileSync(retMap.slicesFile, "utf-8")
);
}
}
}
if (reachablesSlice && Object.keys(reachablesSlice).length) {
dataFlowFrames = await collectReachableFrames(language, reachablesSlice);
}
return {
atomFile: retMap.atomFile,
usagesSlicesFile,
Expand Down Expand Up @@ -776,15 +777,19 @@ export const detectServicesFromUDT = (
servicesMap
) => {
if (
["python", "py"].includes(language) &&
["python", "py", "c", "cpp", "c++"].includes(language) &&
userDefinedTypes &&
userDefinedTypes.length
) {
for (const audt of userDefinedTypes) {
if (
audt.name.includes("route") ||
audt.name.includes("path") ||
audt.name.includes("url")
audt.name.toLowerCase().includes("route") ||
audt.name.toLowerCase().includes("path") ||
audt.name.toLowerCase().includes("url") ||
audt.name.toLowerCase().includes("registerhandler") ||
audt.name.toLowerCase().includes("endpoint") ||
audt.name.toLowerCase().includes("api") ||
audt.name.toLowerCase().includes("add_method")
) {
const fields = audt.fields || [];
if (
Expand Down Expand Up @@ -875,14 +880,11 @@ export const extractEndpoints = (language, code) => {
);
}
break;
case "py":
case "python":
default:
endpoints = (code.match(/['"](.*?)['"]/gi) || [])
.map((v) => v.replace(/["']/g, "").replace("\n", ""))
.filter((v) => v.length > 2);
break;
default:
break;
}
return endpoints;
};
Expand Down Expand Up @@ -910,6 +912,7 @@ export const createEvinseFile = (sliceArtefacts, options) => {
const components = bomJson.components || [];
let occEvidencePresent = false;
let csEvidencePresent = false;
let servicesPresent = false;
for (const comp of components) {
if (!comp.purl) {
continue;
Expand Down Expand Up @@ -957,6 +960,7 @@ export const createEvinseFile = (sliceArtefacts, options) => {
}
// Add to existing services
bomJson.services = (bomJson.services || []).concat(services);
servicesPresent = true;
}
if (options.annotate) {
if (!bomJson.annotations) {
Expand Down Expand Up @@ -993,7 +997,7 @@ export const createEvinseFile = (sliceArtefacts, options) => {
bomJson.metadata.timestamp = new Date().toISOString();
delete bomJson.signature;
fs.writeFileSync(evinseOutFile, JSON.stringify(bomJson, null, 2));
if (occEvidencePresent || csEvidencePresent) {
if (occEvidencePresent || csEvidencePresent || servicesPresent) {
console.log(evinseOutFile, "created successfully.");
} else {
console.log(
Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3149,6 +3149,18 @@ export const createCppBom = (path, options) => {
retMap.parentComponent.type = "library";
pkgList.push(retMap.parentComponent);
}
// Retain the dependency tree from cmake
if (retMap.dependenciesList) {
if (dependencies.length) {
dependencies = mergeDependencies(
dependencies,
retMap.dependenciesList,
parentComponent
);
} else {
dependencies = retMap.dependenciesList;
}
}
}
}
// The need for java >= 17 with atom is causing confusions since there could be C projects
Expand Down
Loading

0 comments on commit c2e5edd

Please sign in to comment.