Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
varunsh-coder committed Sep 23, 2023
1 parent c6db431 commit 8629eca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/hosted-file-monitor-with-hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 28 additions & 13 deletions src/malware-simulator/compile.js
Original file line number Diff line number Diff line change
@@ -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");
}
});

0 comments on commit 8629eca

Please sign in to comment.