Skip to content

Commit 6932b20

Browse files
committed
#1833 Changed the openDatabase() function to expect the content of a database instead of the path
This is what the lurker expects. A temp file is created to the reading of the database easier Signed-off-by: Ilyes Ben Dlala <ilyes.bendlala@iteratec.com>
1 parent ff053e3 commit 6932b20

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎scanners/amass/parser/parser.js‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
const sqlite3 = require('sqlite3').verbose();
6-
6+
const fs = require('fs');
7+
const path = require('path');
8+
const os = require('os');
79

810
async function checkifTableExists(db){
911
const query = `select count(*) from sqlite_master m where m.name="assets" OR m.name="relations"`
@@ -20,10 +22,13 @@ async function checkifTableExists(db){
2022

2123
}
2224

23-
async function openDatabase(databasePath) {
24-
25+
async function openDatabase(fileContent) {
26+
const tempFilePath = path.join(os.tmpdir(), 'temp-sqlite' + '.sqlite');
27+
// Write the content to a temporary file
28+
await fs.promises.writeFile(tempFilePath, fileContent);
29+
2530
return new Promise((resolve, reject) => {
26-
const db = new sqlite3.Database(databasePath, sqlite3.OPEN_READONLY, (err) => {
31+
const db = new sqlite3.Database(tempFilePath, sqlite3.OPEN_READONLY, (err) => {
2732
if (err) {
2833
reject(err.message);
2934
return;
@@ -33,8 +38,8 @@ async function openDatabase(databasePath) {
3338
});
3439
}
3540

36-
async function parse(databasePath) {
37-
const db = await openDatabase(databasePath);
41+
async function parse(fileContent) {
42+
const db = await openDatabase(fileContent);
3843
const tableExists = await checkifTableExists(db);
3944
if(!tableExists) return [];
4045

0 commit comments

Comments
 (0)