forked from cSploit/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChild.java
More file actions
109 lines (91 loc) · 2.46 KB
/
Copy pathChild.java
File metadata and controls
109 lines (91 loc) · 2.46 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package org.csploit.android.core;
import java.io.IOException;
import org.csploit.android.events.Event;
/**
* class to hold info about a spawned child
*/
public class Child {
public int id;
public int exitValue;
public int signal;
public EventReceiver receiver;
public boolean running;
public Child() {
this.id = -1;
this.exitValue = 0;
this.receiver = null;
this.running = false;
this.signal = -1;
}
public static abstract class EventReceiver {
/**
* callback function called whence a child has been successfully started
*
* this method is called before any other in this class,
* and before receiving any event from the associated child.
* @param cmd the command that this child is executing
*/
public void onStart(String cmd) { }
/**
* callback function called whence the child exit
* @param exitValue the child exit value
*/
public void onEnd(int exitValue) { }
/**
* callback function called whence the child get terminated by a signal
* @param signal the signal that killed the child
*/
public void onDeath(int signal) { }
/**
* callback function called whence the child print something on the stderr
* @param line the printed line
*/
public void onStderr(String line) { }
/**
* callback function called whence the child generate an evant
* @param e the generated {@link org.csploit.android.events.Event}
*/
public abstract void onEvent(Event e);
}
/**
* send bytes to this child's stdin
* @param data the bytes to send
*/
public synchronized void send(byte[] data) throws IOException {
if(!Client.SendTo(this.id, data))
throw new IOException("cannot send bytes to child");
}
/**
* send a string to this child's stdin
* @param s the string to send
*/
public void send(String s) throws IOException {
send(s.getBytes());
}
/**
* send a signal to this child
* @param signal the signal to send
*/
public void kill(int signal) {
Client.Kill(this.id, signal);
}
/**
* kill this child by sending a SIGKILL
*/
public void kill() {
Client.Kill(this.id, 9);
}
/**
* join a child by waiting it's termination
*/
public void join() throws InterruptedException {
ChildManager.join(this);
}
public boolean equals(Object o) {
Child c;
if(!(o instanceof Child))
return false;
c = (Child)o;
return c.id == this.id;
}
}