frida-fs 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +44 -37
- package/package.json +2 -5
package/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {Buffer} from 'buffer';
|
|
2
2
|
import process from 'process';
|
|
3
|
-
import
|
|
4
|
-
import {Writable} from 'readable-stream/lib/writable.js';
|
|
3
|
+
import stream from 'stream';
|
|
5
4
|
|
|
6
5
|
const {platform, pointerSize} = Process;
|
|
7
6
|
|
|
@@ -90,7 +89,7 @@ const SEEK_END = 2;
|
|
|
90
89
|
|
|
91
90
|
const EINTR = 4;
|
|
92
91
|
|
|
93
|
-
class ReadStream extends Readable {
|
|
92
|
+
class ReadStream extends stream.Readable {
|
|
94
93
|
constructor(path) {
|
|
95
94
|
super({
|
|
96
95
|
highWaterMark: 4 * 1024 * 1024
|
|
@@ -103,8 +102,7 @@ class ReadStream extends Readable {
|
|
|
103
102
|
const fd = getApi().open(pathStr, constants.O_RDONLY, 0);
|
|
104
103
|
if (fd.value === -1) {
|
|
105
104
|
process.nextTick(() => {
|
|
106
|
-
this.
|
|
107
|
-
this.push(null);
|
|
105
|
+
this.destroy(new Error(getErrorString(fd.errno)));
|
|
108
106
|
});
|
|
109
107
|
return;
|
|
110
108
|
}
|
|
@@ -112,6 +110,15 @@ class ReadStream extends Readable {
|
|
|
112
110
|
this._input = new UnixInputStream(fd.value, { autoClose: true });
|
|
113
111
|
}
|
|
114
112
|
|
|
113
|
+
_destroy(err, callback) {
|
|
114
|
+
if (this._input !== null) {
|
|
115
|
+
this._input.close();
|
|
116
|
+
this._input = null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
callback(err);
|
|
120
|
+
}
|
|
121
|
+
|
|
115
122
|
_read(size) {
|
|
116
123
|
if (this._readRequest !== null)
|
|
117
124
|
return;
|
|
@@ -121,7 +128,6 @@ class ReadStream extends Readable {
|
|
|
121
128
|
this._readRequest = null;
|
|
122
129
|
|
|
123
130
|
if (buffer.byteLength === 0) {
|
|
124
|
-
this._closeInput();
|
|
125
131
|
this.push(null);
|
|
126
132
|
return;
|
|
127
133
|
}
|
|
@@ -131,21 +137,12 @@ class ReadStream extends Readable {
|
|
|
131
137
|
})
|
|
132
138
|
.catch(error => {
|
|
133
139
|
this._readRequest = null;
|
|
134
|
-
this.
|
|
135
|
-
this.emit('error', error);
|
|
136
|
-
this.push(null);
|
|
140
|
+
this.destroy(error);
|
|
137
141
|
});
|
|
138
142
|
}
|
|
139
|
-
|
|
140
|
-
_closeInput() {
|
|
141
|
-
if (this._input !== null) {
|
|
142
|
-
this._input.close();
|
|
143
|
-
this._input = null;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
143
|
}
|
|
147
144
|
|
|
148
|
-
class WriteStream extends Writable {
|
|
145
|
+
class WriteStream extends stream.Writable {
|
|
149
146
|
constructor(path) {
|
|
150
147
|
super({
|
|
151
148
|
highWaterMark: 4 * 1024 * 1024
|
|
@@ -160,15 +157,21 @@ class WriteStream extends Writable {
|
|
|
160
157
|
const fd = getApi().open(pathStr, flags, mode);
|
|
161
158
|
if (fd.value === -1) {
|
|
162
159
|
process.nextTick(() => {
|
|
163
|
-
this.
|
|
164
|
-
this.push(null);
|
|
160
|
+
this.destroy(new Error(getErrorString(fd.errno)));
|
|
165
161
|
});
|
|
166
162
|
return;
|
|
167
163
|
}
|
|
168
164
|
|
|
169
165
|
this._output = new UnixOutputStream(fd.value, { autoClose: true });
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
_destroy(err, callback) {
|
|
169
|
+
if (this._output !== null) {
|
|
170
|
+
this._output.close();
|
|
171
|
+
this._output = null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
callback(err);
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
_write(chunk, encoding, callback) {
|
|
@@ -187,13 +190,6 @@ class WriteStream extends Writable {
|
|
|
187
190
|
callback(error);
|
|
188
191
|
});
|
|
189
192
|
}
|
|
190
|
-
|
|
191
|
-
_closeOutput() {
|
|
192
|
-
if (this._output !== null) {
|
|
193
|
-
this._output.close();
|
|
194
|
-
this._output = null;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
193
|
}
|
|
198
194
|
|
|
199
195
|
const direntSpecs = {
|
|
@@ -246,7 +242,7 @@ function enumerateDirectoryEntries(path, callback) {
|
|
|
246
242
|
const dir = opendirImpl(Memory.allocUtf8String(path));
|
|
247
243
|
const dirHandle = dir.value;
|
|
248
244
|
if (dirHandle.isNull())
|
|
249
|
-
throw new Error(
|
|
245
|
+
throw new Error(getErrorString(dir.errno));
|
|
250
246
|
|
|
251
247
|
try {
|
|
252
248
|
let entry;
|
|
@@ -281,7 +277,7 @@ function readFileSync(path, options = {}) {
|
|
|
281
277
|
const openResult = open(pathStr, constants.O_RDONLY, 0);
|
|
282
278
|
const fd = openResult.value;
|
|
283
279
|
if (fd === -1)
|
|
284
|
-
throw new Error(
|
|
280
|
+
throw new Error(getErrorString(openResult.errno));
|
|
285
281
|
|
|
286
282
|
try {
|
|
287
283
|
const fileSize = lseek(fd, 0, SEEK_END).valueOf();
|
|
@@ -297,7 +293,7 @@ function readFileSync(path, options = {}) {
|
|
|
297
293
|
} while (readFailed && readResult.errno === EINTR);
|
|
298
294
|
|
|
299
295
|
if (readFailed)
|
|
300
|
-
throw new Error(
|
|
296
|
+
throw new Error(getErrorString(readResult.errno));
|
|
301
297
|
|
|
302
298
|
if (n !== fileSize.valueOf())
|
|
303
299
|
throw new Error('Short read');
|
|
@@ -328,19 +324,25 @@ function readlinkSync(path) {
|
|
|
328
324
|
const result = api.readlink(pathStr, buf, linkSize);
|
|
329
325
|
const n = result.value.valueOf();
|
|
330
326
|
if (n === -1)
|
|
331
|
-
throw new Error(
|
|
327
|
+
throw new Error(getErrorString(result.errno));
|
|
332
328
|
|
|
333
329
|
return buf.readUtf8String(n);
|
|
334
330
|
}
|
|
335
331
|
|
|
336
|
-
function
|
|
337
|
-
const
|
|
332
|
+
function rmdirSync(path) {
|
|
333
|
+
const pathStr = Memory.allocUtf8String(path);
|
|
338
334
|
|
|
335
|
+
const result = getApi().rmdir(pathStr);
|
|
336
|
+
if (result.value === -1)
|
|
337
|
+
throw new Error(getErrorString(result.errno));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function unlinkSync(path) {
|
|
339
341
|
const pathStr = Memory.allocUtf8String(path);
|
|
340
342
|
|
|
341
|
-
const result = unlink(pathStr);
|
|
343
|
+
const result = getApi().unlink(pathStr);
|
|
342
344
|
if (result.value === -1)
|
|
343
|
-
throw new Error(
|
|
345
|
+
throw new Error(getErrorString(result.errno));
|
|
344
346
|
}
|
|
345
347
|
|
|
346
348
|
const statFields = new Set([
|
|
@@ -527,7 +529,7 @@ function performStat(impl, path) {
|
|
|
527
529
|
const buf = Memory.alloc(statBufSize);
|
|
528
530
|
const result = impl(Memory.allocUtf8String(path), buf);
|
|
529
531
|
if (result.value !== 0)
|
|
530
|
-
throw new Error(
|
|
532
|
+
throw new Error(getErrorString(result.errno));
|
|
531
533
|
|
|
532
534
|
return new Proxy(new Stats(), {
|
|
533
535
|
has(target, property) {
|
|
@@ -653,6 +655,7 @@ const apiSpec = [
|
|
|
653
655
|
['readdir', NF, 'pointer', ['pointer']],
|
|
654
656
|
['readdir$INODE64', NF, 'pointer', ['pointer']],
|
|
655
657
|
['readlink', SF, ssizeType, ['pointer', 'pointer', sizeType]],
|
|
658
|
+
['rmdir', SF, 'int', ['pointer']],
|
|
656
659
|
['unlink', SF, 'int', ['pointer']],
|
|
657
660
|
['stat', SF, 'int', ['pointer', 'pointer']],
|
|
658
661
|
['stat64', SF, 'int', ['pointer', 'pointer']],
|
|
@@ -713,6 +716,7 @@ export function createWriteStream(path) {
|
|
|
713
716
|
export const readdir = callbackify(readdirSync);
|
|
714
717
|
export const readFile = callbackify(readFileSync);
|
|
715
718
|
export const readlink = callbackify(readlinkSync);
|
|
719
|
+
export const rmdir = callbackify(rmdirSync);
|
|
716
720
|
export const unlink = callbackify(unlinkSync);
|
|
717
721
|
export const stat = callbackify(statSync);
|
|
718
722
|
export const lstat = callbackify(lstatSync);
|
|
@@ -723,6 +727,7 @@ export {
|
|
|
723
727
|
list,
|
|
724
728
|
readFileSync,
|
|
725
729
|
readlinkSync,
|
|
730
|
+
rmdirSync,
|
|
726
731
|
unlinkSync,
|
|
727
732
|
statSync,
|
|
728
733
|
lstatSync,
|
|
@@ -740,6 +745,8 @@ export default {
|
|
|
740
745
|
readFileSync,
|
|
741
746
|
readlink,
|
|
742
747
|
readlinkSync,
|
|
748
|
+
rmdir,
|
|
749
|
+
rmdirSync,
|
|
743
750
|
unlink,
|
|
744
751
|
unlinkSync,
|
|
745
752
|
stat,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frida-fs",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Create a stream from a filesystem resource",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,8 +15,5 @@
|
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/nowsecure/frida-fs/issues"
|
|
17
17
|
},
|
|
18
|
-
"homepage": "https://github.com/nowsecure/frida-fs#readme"
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"readable-stream": "^4.0.0"
|
|
21
|
-
}
|
|
18
|
+
"homepage": "https://github.com/nowsecure/frida-fs#readme"
|
|
22
19
|
}
|