-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathoverride-dlopen-paths-preload.js
More file actions
27 lines (22 loc) · 1.07 KB
/
override-dlopen-paths-preload.js
File metadata and controls
27 lines (22 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var fs = require('fs');
var path = require('path');
var substitutionDataFile = path.join(__dirname,'override-dlopen-paths-data.json');
// If the json file exists, override dlopen to load the specified framework paths instead.
if (fs.existsSync(substitutionDataFile)) {
var pathSubstitutionData = JSON.parse(fs.readFileSync(substitutionDataFile, 'utf8'));
var pathSubstitutionDictionary = {};
// Build a dictionary to convert paths at runtime, taking current sandboxed paths into account.
for (let i = 0; i < pathSubstitutionData.length; i++) {
pathSubstitutionDictionary[
path.normalize(path.join.apply(null, [__dirname].concat(pathSubstitutionData[i].originalpath)))
] = path.normalize(path.join.apply(null, [__dirname].concat(pathSubstitutionData[i].newpath)));
}
var old_dlopen = process.dlopen;
// Override process.dlopen
process.dlopen = function(_module, _filename) {
if( pathSubstitutionDictionary[path.normalize(_filename)] ) {
_filename = pathSubstitutionDictionary[path.normalize(_filename)];
}
old_dlopen(_module,_filename);
}
}