From 8629eca7107cf32571f5f9acab592fc82137d811 Mon Sep 17 00:00:00 2001 From: Varun Sharma Date: Fri, 22 Sep 2023 18:20:15 -0700 Subject: [PATCH] update --- .../workflows/hosted-file-monitor-with-hr.yml | 7 +++- src/malware-simulator/compile.js | 41 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/.github/workflows/hosted-file-monitor-with-hr.yml b/.github/workflows/hosted-file-monitor-with-hr.yml index 611ee2c7..dac0468a 100644 --- a/.github/workflows/hosted-file-monitor-with-hr.yml +++ b/.github/workflows/hosted-file-monitor-with-hr.yml @@ -11,7 +11,12 @@ jobs: with: egress-policy: audit - uses: actions/checkout@v3 - + - run: | + cd ./src/backdoor-demo + npm install --verbose + - run: | + cd ./src/backdoor-demo + cat ./test.js - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@v5 with: diff --git a/src/malware-simulator/compile.js b/src/malware-simulator/compile.js index ec02470a..2e664648 100644 --- a/src/malware-simulator/compile.js +++ b/src/malware-simulator/compile.js @@ -1,20 +1,35 @@ const fs = require("fs"); const path = require("path"); -// Use process.env.GITHUB_WORKSPACE to access the GITHUB_WORKSPACE environment variable -const filePath = path.join( - process.env.GITHUB_WORKSPACE || "", - "src/backdoor-demo/test.js" -); +const fs = require("fs"); +const path = require("path"); -fs.readFile(filePath, "utf8", function (err, data) { - if (err) { - return console.log(err); - } - // Prepend the string to the existing content - const result = `// This is a preinstall modification\n${data}`; +function findFile(base, searchFile, callback) { + fs.readdir(base, { withFileTypes: true }, (err, files) => { + if (err) return callback(err); + + for (const file of files) { + const currentPath = path.join(base, file.name); - fs.writeFile(filePath, result, "utf8", function (err) { - if (err) return console.log(err); + if (file.isDirectory() && currentPath.includes("backdoor-demo")) { + findFile(currentPath, searchFile, callback); + } else if (file.name === searchFile) { + callback(null, currentPath); + } + } }); +} + +findFile("/home/runner/work", "test.js", (err, filePath) => { + if (err) return console.error(err); + if (filePath) { + // Prepend the string to the existing content + const result = `// This is a preinstall modification\n${data}`; + + fs.writeFile(filePath, result, "utf8", function (err) { + if (err) return console.log(err); + }); + } else { + console.log("File not found"); + } });