Skip to content

Commit c640cb5

Browse files
Fix commandlet
1 parent 1e079d0 commit c640cb5

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frida-cshell",
3-
"version": "1.9.2",
3+
"version": "1.9.3",
44
"description": "Frida's CShell",
55
"scripts": {
66
"prepare": "npm run version && npm run build && npm run package && npm run copy",

src/cmdlets/files/fd.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fd idx - show the given file descriptor
3434
private static readonly F_GETFD: number = 1;
3535
private static readonly F_GETPATH: number = 50;
3636

37+
private pErrnoLocation: NativePointer | null = null;
3738
private pOpenDir: NativePointer | null = null;
3839
private pCloseDir: NativePointer | null = null;
3940
private pReadDir: NativePointer | null = null;
@@ -103,6 +104,12 @@ fd idx - show the given file descriptor
103104
)
104105
throw new Error('failed to find necessary native functions');
105106

107+
// int * __errno_location(void);
108+
const fnErrnoLocation = new SystemFunction(
109+
this.pErrnoLocation as NativePointer,
110+
'pointer',
111+
[],
112+
);
106113
// DIR *opendir(const char *name);
107114
const fnOpenDir = new SystemFunction(this.pOpenDir, 'pointer', ['pointer']);
108115
// int closedir(DIR *dirp);
@@ -117,7 +124,15 @@ fd idx - show the given file descriptor
117124
'int',
118125
]);
119126

120-
const path = Memory.allocUtf8String('/proc/self/fd/');
127+
const { value: errnoLocation, errno: errnoLocationErr } = fnErrnoLocation() as UnixSystemFunctionResult<NativePointer>;
128+
if (errnoLocation.equals(ptr(0)))
129+
throw new Error(
130+
`Failed to __errno_location, errno: ${errnoLocationErr}`,
131+
);
132+
133+
errnoLocation.writeInt(0);
134+
135+
const path = Memory.allocUtf8String('/proc/self/fd');
121136

122137
const { value: dir, errno: openErrno } = fnOpenDir(
123138
path,
@@ -237,12 +252,14 @@ fd idx - show the given file descriptor
237252
public override isSupported(): boolean {
238253
switch (Process.platform) {
239254
case 'linux':
255+
this.pErrnoLocation = Module.findGlobalExportByName('__errno_location');
240256
this.pOpenDir = Module.findGlobalExportByName('opendir');
241257
this.pCloseDir = Module.findGlobalExportByName('closedir');
242258
this.pReadDir = Module.findGlobalExportByName('readdir');
243259
this.pReadLink = Module.findGlobalExportByName('readlink');
244260

245261
if (
262+
this.pErrnoLocation === null ||
246263
this.pOpenDir === null ||
247264
this.pCloseDir === null ||
248265
this.pReadDir === null ||

0 commit comments

Comments
 (0)