Advertisement
RyokoN

Untitled

Sep 15th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.54 KB | None | 0 0
  1. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  2. // Jad home page: http://www.kpdus.com/jad.html
  3. // Decompiler options: packimports(3)
  4.  
  5. package com.android.commands.input;
  6.  
  7. import android.hardware.input.InputManager;
  8. import android.os.SystemClock;
  9. import android.util.Log;
  10. import android.view.*;
  11. import java.io.PrintStream;
  12. import java.util.*;
  13.  
  14. public class Input
  15. {
  16.  
  17. public Input()
  18. {
  19. }
  20.  
  21. private int getInputDeviceId(int i)
  22. {
  23. int ai[] = InputDevice.getDeviceIds();
  24. int j = ai.length;
  25. for(int k = 0; k < j; k++)
  26. {
  27. int l = ai[k];
  28. if(InputDevice.getDevice(l).supportsSource(i))
  29. return l;
  30. }
  31.  
  32. return 0;
  33. }
  34.  
  35. private static final int getSource(int i, int j)
  36. {
  37. if(i == 0)
  38. i = j;
  39. return i;
  40. }
  41.  
  42. private void injectKeyEvent(KeyEvent keyevent)
  43. {
  44. Log.i("Input", (new StringBuilder()).append("injectKeyEvent: ").append(keyevent).toString());
  45. InputManager.getInstance().injectInputEvent(keyevent, 2);
  46. }
  47.  
  48. private void injectMotionEvent(int i, int j, long l, float f, float f1, float f2)
  49. {
  50. MotionEvent motionevent = MotionEvent.obtain(l, l, j, f, f1, f2, 1.0F, 0, 1.0F, 1.0F, getInputDeviceId(i), 0);
  51. motionevent.setSource(i);
  52. Log.i("Input", (new StringBuilder()).append("injectMotionEvent: ").append(motionevent).toString());
  53. InputManager.getInstance().injectInputEvent(motionevent, 2);
  54. }
  55.  
  56. private static final float lerp(float f, float f1, float f2)
  57. {
  58. return (f1 - f) * f2 + f;
  59. }
  60.  
  61. public static void main(String args[])
  62. {
  63. (new Input()).run(args);
  64. }
  65.  
  66. private void run(String as[])
  67. {
  68. int i;
  69. int j;
  70. String s1;
  71. int k;
  72. if(as.length < 1)
  73. {
  74. showUsage();
  75. return;
  76. }
  77. i = 0;
  78. String s = as[0];
  79. j = 0;
  80. s1 = s;
  81. if(SOURCES.containsKey(s))
  82. {
  83. j = ((Integer)SOURCES.get(s)).intValue();
  84. i = 1;
  85. s1 = as[1];
  86. }
  87. k = as.length - i;
  88. if(!s1.equals("text")) goto _L2; else goto _L1
  89. _L1:
  90. boolean flag;
  91. int l;
  92. int i1;
  93. if(k == 2)
  94. try
  95. {
  96. sendText(getSource(j, 257), as[i + 1]);
  97. return;
  98. }
  99. // Misplaced declaration of an exception variable
  100. catch(String as[]) { }
  101. goto _L3
  102. _L2:
  103. if(!s1.equals("keyevent")) goto _L5; else goto _L4
  104. _L4:
  105. if(k < 2) goto _L3; else goto _L6
  106. _L6:
  107. flag = "--longpress".equals(as[i + 1]);
  108. if(flag)
  109. i += 2;
  110. else
  111. i++;
  112. l = getSource(j, 257);
  113. if(k <= i) goto _L3; else goto _L7
  114. _L7:
  115. if(i >= k)
  116. break; /* Loop/switch isn't completed */
  117. i1 = KeyEvent.keyCodeFromString(as[i]);
  118. j = i1;
  119. if(i1 != 0)
  120. break MISSING_BLOCK_LABEL_202;
  121. StringBuilder stringbuilder = JVM INSTR new #47 <Class StringBuilder>;
  122. stringbuilder.StringBuilder();
  123. j = KeyEvent.keyCodeFromString(stringbuilder.append("KEYCODE_").append(as[i]).toString());
  124. sendKeyEvent(l, j, flag);
  125. i++;
  126. if(true) goto _L7; else goto _L8
  127. _L8:
  128. return;
  129. _L5:
  130. if(!s1.equals("tap")) goto _L10; else goto _L9
  131. _L9:
  132. if(k != 3) goto _L3; else goto _L11
  133. _L11:
  134. sendTap(getSource(j, 4098), Float.parseFloat(as[i + 1]), Float.parseFloat(as[i + 2]));
  135. return;
  136. _L10:
  137. if(!s1.equals("swipe")) goto _L13; else goto _L12
  138. _L12:
  139. i1 = -1;
  140. l = getSource(j, 4098);
  141. j = i1;
  142. k;
  143. JVM INSTR tableswitch 5 6: default 320
  144. // 5 361
  145. // 6 351;
  146. goto _L3 _L14 _L15
  147. _L3:
  148. System.err.println((new StringBuilder()).append("Error: Invalid arguments for command: ").append(s1).toString());
  149. showUsage();
  150. return;
  151. _L15:
  152. j = Integer.parseInt(as[i + 5]);
  153. _L14:
  154. sendSwipe(l, Float.parseFloat(as[i + 1]), Float.parseFloat(as[i + 2]), Float.parseFloat(as[i + 3]), Float.parseFloat(as[i + 4]), j);
  155. return;
  156. _L13:
  157. if(!s1.equals("draganddrop")) goto _L17; else goto _L16
  158. _L16:
  159. i1 = -1;
  160. l = getSource(j, 4098);
  161. j = i1;
  162. k;
  163. JVM INSTR tableswitch 5 6: default 452
  164. // 5 455
  165. // 6 496;
  166. goto _L3 _L18 _L19
  167. _L18:
  168. sendDragAndDrop(l, Float.parseFloat(as[i + 1]), Float.parseFloat(as[i + 2]), Float.parseFloat(as[i + 3]), Float.parseFloat(as[i + 4]), j);
  169. return;
  170. _L19:
  171. j = Integer.parseInt(as[i + 5]);
  172. if(true) goto _L18; else goto _L17
  173. _L17:
  174. if(!s1.equals("press")) goto _L21; else goto _L20
  175. _L20:
  176. i = getSource(j, 0x10004);
  177. if(k != 1) goto _L3; else goto _L22
  178. _L22:
  179. sendTap(i, 0.0F, 0.0F);
  180. return;
  181. _L21:
  182. if(!s1.equals("roll")) goto _L24; else goto _L23
  183. _L23:
  184. j = getSource(j, 0x10004);
  185. if(k != 3) goto _L3; else goto _L25
  186. _L25:
  187. sendMove(j, Float.parseFloat(as[i + 1]), Float.parseFloat(as[i + 2]));
  188. return;
  189. _L24:
  190. if(!s1.equals("tmode")) goto _L27; else goto _L26
  191. _L26:
  192. if(as.length <= 1) goto _L29; else goto _L28
  193. _L28:
  194. as = as[1];
  195. if(!as.equals("glove_off")) goto _L31; else goto _L30
  196. _L30:
  197. InputManager.getInstance().switchTouchSensitiveMode(false);
  198. System.err.println("glove off!\n");
  199. _L29:
  200. return;
  201. _L31:
  202. if(!as.equals("glove_on")) goto _L33; else goto _L32
  203. _L32:
  204. InputManager.getInstance().switchTouchSensitiveMode(true);
  205. System.err.println("glove on!\n");
  206. goto _L29
  207. _L33:
  208. if(!as.equals("stylus_off")) goto _L35; else goto _L34
  209. _L34:
  210. InputManager.getInstance().switchTouchStylusMode(false);
  211. System.err.println("stylus off!\n");
  212. goto _L29
  213. _L35:
  214. if(!as.equals("stylus_on")) goto _L37; else goto _L36
  215. _L36:
  216. InputManager.getInstance().switchTouchStylusMode(true);
  217. System.err.println("stylus on!\n");
  218. goto _L29
  219. _L37:
  220. if(!as.equals("wakeup_off")) goto _L39; else goto _L38
  221. _L38:
  222. InputManager.getInstance().switchTouchWakeupMode(false);
  223. System.err.println("wakeup gesture off!\n");
  224. goto _L29
  225. _L39:
  226. if(!as.equals("wakeup_on")) goto _L41; else goto _L40
  227. _L40:
  228. InputManager.getInstance().switchTouchWakeupMode(true);
  229. System.err.println("wakeup gesture on!\n");
  230. goto _L29
  231. _L41:
  232. if(!as.equals("cover_off")) goto _L43; else goto _L42
  233. _L42:
  234. InputManager.getInstance().switchTouchCoverMode(false);
  235. System.err.println("cover gesture off!\n");
  236. goto _L29
  237. _L43:
  238. if(!as.equals("cover_on")) goto _L29; else goto _L44
  239. _L44:
  240. InputManager.getInstance().switchTouchCoverMode(true);
  241. System.err.println("cover gesture on!\n");
  242. goto _L29
  243. _L27:
  244. as = System.err;
  245. StringBuilder stringbuilder1 = JVM INSTR new #47 <Class StringBuilder>;
  246. stringbuilder1.StringBuilder();
  247. as.println(stringbuilder1.append("Error: Unknown command: ").append(s1).toString());
  248. showUsage();
  249. return;
  250. }
  251.  
  252. private void sendDragAndDrop(int i, float f, float f1, float f2, float f3, int j)
  253. {
  254. int k = j;
  255. if(j < 0)
  256. k = 300;
  257. injectMotionEvent(i, 0, SystemClock.uptimeMillis(), f, f1, 1.0F);
  258. long l;
  259. long l1;
  260. long l2;
  261. try
  262. {
  263. Thread.sleep(ViewConfiguration.getLongPressTimeout());
  264. }
  265. catch(InterruptedException interruptedexception)
  266. {
  267. throw new RuntimeException(interruptedexception);
  268. }
  269. l = SystemClock.uptimeMillis();
  270. l1 = k;
  271. for(l2 = l; l2 < l + l1; l2 = SystemClock.uptimeMillis())
  272. {
  273. float f4 = (float)(l2 - l) / (float)k;
  274. injectMotionEvent(i, 2, l2, lerp(f, f2, f4), lerp(f1, f3, f4), 1.0F);
  275. }
  276.  
  277. injectMotionEvent(i, 1, l2, f2, f3, 0.0F);
  278. }
  279.  
  280. private void sendKeyEvent(int i, int j, boolean flag)
  281. {
  282. long l = SystemClock.uptimeMillis();
  283. injectKeyEvent(new KeyEvent(l, l, 0, j, 0, 0, -1, 0, 0, i));
  284. if(flag)
  285. injectKeyEvent(new KeyEvent(l, l, 0, j, 1, 0, -1, 0, 128, i));
  286. injectKeyEvent(new KeyEvent(l, l, 1, j, 0, 0, -1, 0, 0, i));
  287. }
  288.  
  289. private void sendMove(int i, float f, float f1)
  290. {
  291. injectMotionEvent(i, 2, SystemClock.uptimeMillis(), f, f1, 0.0F);
  292. }
  293.  
  294. private void sendSwipe(int i, float f, float f1, float f2, float f3, int j)
  295. {
  296. int k = j;
  297. if(j < 0)
  298. k = 300;
  299. long l = SystemClock.uptimeMillis();
  300. injectMotionEvent(i, 0, l, f, f1, 1.0F);
  301. long l1 = k;
  302. long l2;
  303. for(l2 = l; l2 < l + l1; l2 = SystemClock.uptimeMillis())
  304. {
  305. float f4 = (float)(l2 - l) / (float)k;
  306. injectMotionEvent(i, 2, l2, lerp(f, f2, f4), lerp(f1, f3, f4), 1.0F);
  307. }
  308.  
  309. injectMotionEvent(i, 1, l2, f2, f3, 0.0F);
  310. }
  311.  
  312. private void sendTap(int i, float f, float f1)
  313. {
  314. long l = SystemClock.uptimeMillis();
  315. injectMotionEvent(i, 0, l, f, f1, 1.0F);
  316. injectMotionEvent(i, 1, l, f, f1, 0.0F);
  317. }
  318.  
  319. private void sendText(int i, String s)
  320. {
  321. s = new StringBuffer(s);
  322. boolean flag = false;
  323. int l;
  324. for(int j = 0; j < s.length(); j = l + 1)
  325. {
  326. boolean flag1 = flag;
  327. l = j;
  328. if(flag)
  329. {
  330. flag = false;
  331. flag1 = flag;
  332. l = j;
  333. if(s.charAt(j) == 's')
  334. {
  335. s.setCharAt(j, ' ');
  336. l = j - 1;
  337. s.deleteCharAt(l);
  338. flag1 = flag;
  339. }
  340. }
  341. flag = flag1;
  342. if(s.charAt(l) == '%')
  343. flag = true;
  344. }
  345.  
  346. s = s.toString().toCharArray();
  347. s = KeyCharacterMap.load(-1).getEvents(s);
  348. for(int k = 0; k < s.length; k++)
  349. {
  350. KeyEvent keyevent = s[k];
  351. if(i != keyevent.getSource())
  352. keyevent.setSource(i);
  353. injectKeyEvent(keyevent);
  354. }
  355.  
  356. }
  357.  
  358. private void showUsage()
  359. {
  360. System.err.println("Usage: input [<source>] <command> [<arg>...]");
  361. System.err.println();
  362. System.err.println("The sources are: ");
  363. String s;
  364. for(Iterator iterator = SOURCES.keySet().iterator(); iterator.hasNext(); System.err.println((new StringBuilder()).append(" ").append(s).toString()))
  365. s = (String)iterator.next();
  366.  
  367. System.err.println();
  368. System.err.println("The commands and default sources are:");
  369. System.err.println(" text <string> (Default: touchscreen)");
  370. System.err.println(" keyevent [--longpress] <key code number or name> ... (Default: keyboard)");
  371. System.err.println(" tap <x> <y> (Default: touchscreen)");
  372. System.err.println(" swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)");
  373. System.err.println(" draganddrop <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)");
  374. System.err.println(" press (Default: trackball)");
  375. System.err.println(" roll <dx> <dy> (Default: trackball)");
  376. System.err.println(" tmode <tmode>");
  377. }
  378.  
  379. private static final String INVALID_ARGUMENTS = "Error: Invalid arguments for command: ";
  380. private static final Map SOURCES = new HashMap() {
  381.  
  382.  
  383. {
  384. put("keyboard", Integer.valueOf(257));
  385. put("dpad", Integer.valueOf(513));
  386. put("gamepad", Integer.valueOf(1025));
  387. put("touchscreen", Integer.valueOf(4098));
  388. put("mouse", Integer.valueOf(8194));
  389. put("stylus", Integer.valueOf(16386));
  390. put("trackball", Integer.valueOf(0x10004));
  391. put("touchpad", Integer.valueOf(0x100008));
  392. put("touchnavigation", Integer.valueOf(0x200000));
  393. put("joystick", Integer.valueOf(0x1000010));
  394. }
  395. }
  396. ;
  397. private static final String TAG = "Input";
  398.  
  399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement