NativeBridge.java 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package de.tudarmstadt.informatik.hostage.system;
  2. import java.io.FileDescriptor;
  3. import java.io.IOException;
  4. import android.net.LocalSocket;
  5. import android.net.LocalSocketAddress;
  6. public class NativeBridge implements Runnable {
  7. private final static NativeBridge INSTANCE = new NativeBridge();
  8. public NativeBridge getInstance() {
  9. return INSTANCE;
  10. }
  11. private final static LocalSocket SOCK = new LocalSocket();
  12. private NativeBridge() {
  13. try {
  14. SOCK.bind(new LocalSocketAddress("hostage"));
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. @Override
  20. public void run() {
  21. try {
  22. Process p = Runtime.getRuntime().exec(
  23. new String[] { "/data/local/p", "21" });
  24. p.waitFor();
  25. } catch (IOException e) {
  26. e.printStackTrace();
  27. } catch (InterruptedException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. public static FileDescriptor getFD(int port) {
  32. new Thread(INSTANCE).start();
  33. try {
  34. FileDescriptor[] fds = SOCK.getAncillaryFileDescriptors();
  35. return fds[0];
  36. } catch (IOException e) {
  37. e.printStackTrace();
  38. }
  39. return null;
  40. }
  41. }