1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package de.tudarmstadt.informatik.hostage.system;
- import java.io.FileDescriptor;
- import android.net.LocalServerSocket;
- import android.net.LocalSocket;
- /**
- * Port loaded with porthack with root rights
- * @author Mihai Plasoianu
- */
- public class PrivilegedPort implements Runnable {
- /**
- * Path for UDS in abstract namespace.
- */
- private final static String NAME = "hostage";
- /**
- * Port to bind.
- */
- private int port;
- public PrivilegedPort(int port) {
- this.port = port;
- }
- /**
- * Run porthack in separate Thread.
- */
-
- public void run() {
- Process p;
- try {
- String command = String.format("/data/local/p %d", port);
- p = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
- p.waitFor();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Start porthack, wait for connection through UDS and receive a file
- * descriptor for bound port.
- */
- public FileDescriptor bindAndGetFD() {
- FileDescriptor fd = null;
- try {
- new Thread(this).start();
- LocalServerSocket lss = new LocalServerSocket(NAME);
- LocalSocket ls = lss.accept();
- while (ls.getInputStream().read() != -1)
- ;
- FileDescriptor[] fdarr;
- fdarr = ls.getAncillaryFileDescriptors();
- if (fdarr != null) {
- fd = fdarr[0];
- }
- ls.close();
- lss.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return fd;
- }
- }
|