Skip to content

Commit 36e917f

Browse files
author
Your Name
committed
More corpse improvements
1 parent eaae28f commit 36e917f

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
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.7.5",
3+
"version": "1.7.6",
44
"description": "Frida's CShell",
55
"scripts": {
66
"prepare": "npm run build && npm run version && npm run package && npm run copy",

src/cmdlets/misc/corpse/clone.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
export class Clone {
2-
private static readonly SIGCHLD: number = 17;
3-
private static readonly CLONE_CLEAR_SIGHAND: number = 0x100000000;
2+
private static readonly SIGCHLD: UInt64 = uint64(17);
3+
private static readonly CLONE_CLEAR_SIGHAND: UInt64 = uint64(0x100000000);
44
private fnSyscall: SystemFunction<
55
number,
6-
[number | UInt64, number, NativePointer, NativePointer]
6+
[number | UInt64, number | UInt64, NativePointer, NativePointer]
77
>;
88
public constructor() {
99
const pSyscall = Module.findExportByName(null, 'syscall');
1010
if (pSyscall === null) throw new Error('failed to find syscall');
1111

1212
this.fnSyscall = new SystemFunction(pSyscall, 'int', [
1313
'size_t',
14-
'int',
14+
'size_t',
1515
'pointer',
1616
'pointer',
1717
]);
@@ -22,7 +22,7 @@ export class Clone {
2222
childCallback: () => void,
2323
): number {
2424
const syscallNumber = Clone.getCloneSyscallNumber();
25-
const flags = Clone.SIGCHLD | Clone.CLONE_CLEAR_SIGHAND;
25+
const flags = Clone.SIGCHLD.or(Clone.CLONE_CLEAR_SIGHAND);
2626
const ret = this.fnSyscall(
2727
syscallNumber,
2828
flags,

src/cmdlets/misc/corpse/corpse.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export class CorpseCmdLet extends CmdLetBase {
2222
corpse - create a corpse file`;
2323

2424
private static readonly CHILD_SLEEP_DURATION: number = 0.1;
25-
private static readonly CHILD_WAIT_DURATION: number = 10;
25+
private static readonly PARENT_SLEEP_DURATION: number = 0.5;
26+
private static readonly WAIT_DURATION: number = 20;
27+
private static readonly PARENT_DELAY_DURATION: number = 2;
2628
private static readonly ELF_MAGIC: number = 0x7f454c46;
2729

2830
private rlimit: Rlimit | null = null;
@@ -158,15 +160,30 @@ corpse - create a corpse file`;
158160
this.debug(`Running parent, pid: ${Process.id}, child pid: ${childPid}`);
159161

160162
const proc = this.proc as Proc;
161-
for (let i = 0; i < 10; i++) {
163+
164+
this.debug(`Delaying: ${CorpseCmdLet.PARENT_DELAY_DURATION}s`);
165+
Thread.sleep(CorpseCmdLet.PARENT_DELAY_DURATION);
166+
167+
const limit =
168+
CorpseCmdLet.WAIT_DURATION / CorpseCmdLet.PARENT_SLEEP_DURATION;
169+
170+
this.debug(`Parent limit: ${limit}`);
171+
this.debug(`Delay between signals: ${CorpseCmdLet.PARENT_SLEEP_DURATION}s`);
172+
for (let i = 0; i < limit; i++) {
162173
proc.kill(childPid, Proc.SIGABRT);
163174

164175
const status = proc.waitpid(childPid);
165-
this.debug(`status - exitStatus: ${status.exitStatus},
166-
termSignal: ${status.termSignal}, stopped: ${status.stopped}`);
176+
this.debug(
177+
[
178+
`index: ${i},`,
179+
`exitStatus: ${status.exitStatus},`,
180+
`termSignal: ${status.termSignal},`,
181+
`stopped: ${status.stopped}`,
182+
].join(' '),
183+
);
167184

168185
if (status.stopped) return;
169-
Thread.sleep(0.5);
186+
Thread.sleep(CorpseCmdLet.PARENT_SLEEP_DURATION);
170187
}
171188
this.status(`Child not stopped, pid: ${childPid}`);
172189
proc.kill(childPid, Proc.SIGKILL);
@@ -181,10 +198,13 @@ corpse - create a corpse file`;
181198

182199
try {
183200
const limit =
184-
CorpseCmdLet.CHILD_WAIT_DURATION / CorpseCmdLet.CHILD_SLEEP_DURATION;
201+
CorpseCmdLet.WAIT_DURATION / CorpseCmdLet.CHILD_SLEEP_DURATION;
202+
debug(`Child limit: ${limit}`);
203+
debug(`Delay between sleeps: ${CorpseCmdLet.CHILD_SLEEP_DURATION}s`);
185204
for (let i = 0; i < limit; i++) {
186205
Thread.sleep(CorpseCmdLet.CHILD_SLEEP_DURATION);
187206
}
207+
debug(`Child limit exceeded`);
188208
} catch (error) {
189209
if (error instanceof Error) {
190210
debug(`ERROR: ${error.message}`);

0 commit comments

Comments
 (0)