1

Answers for this question should be ideally non-rooted.

I am looking at re-writing one of the adb tools, sendevent.c I have found this file online and am confident that i could adapt it for my purposes.

I presume i could push my new file to the device, but what i am not sure about is what directories i can place this file so that it can execute, from my research i have found a few directories but get permission errors when trying to push to them.

There is another question that was asked that related allot to what i want to do. but how to add the new tool was not explained for reference it is here.


edit

Or if anyone knows a way of replicating a complex drag without sacrificing accuracy, on a non-rooted device?

My original idea was to remove every other set of co-ordinate events which works, but is not as accurate and timings need allot of fine-tuning.


compiling note

for anyone else interested in how to do this.

I have just compiled and ran a hello world test, the instructions i found were on this question:

here is a copy of the answer if the link becomes invalid (my test modified the test-libstdc++ sample as it is more lightweight):

Last tested with NDK r8e on Linux and Nexus 4 with adb from SDK Platform-Tools Rev 18 on Windows 7 (latest as of 2013-07-25) without root access.

  1. Go to $NDK_ROOT (The topmost folder of NDK zip when unzipped).
  2. Copy $NDK_ROOT/samples/hello-jni directory as $NDK_ROOT/sources/hello-world.
  3. Go to $NDK_ROOT/sources/hello-world.
  4. Edit AndroidManifest.xml to give the application an appropriate name (This is optional).
  5. Go to $NDK_ROOT/sources/hello-world/jni. This is where the source code is.
  6. Edit hello-jni.c, remove all the code, and put in your hello world code. Mine is:

    include

    int main( int argc, char* argv[]) { printf("Hello, World!"); return 0; }
  7. Edit Android.mk and change the line include $(BUILD_SHARED_LIBRARY) to include $(BUILD_EXECUTABLE). You can also change the LOCAL_MODULE line to the name you want for your executable(default is hello-jni)
  8. Go back to $NDK_ROOT/sources/hello-world
  9. Run ../../ndk-build to create the executable.
  10. Copy it from $NDK_ROOT/sources/hello-jni/libs/armeabi/hello-jni to /data/local/tmp on the Android device and change it's permissions to 755 (rwxr-xr-x). If you changed the LOCAL_MODULE line in $NDK_ROOT/sources/hello-world/jni/Android.mk, the executable name will be the new value of LOCAL_MODULE instead of hello-jni. (All this is done via adb from the Android SDK.)
  11. Execute the binary with full path as /data/local/tmp/hello-jni, or whatever you named it to.

And you're done( and free to start on the documentation in $NDK_ROOT/docs to get a better idea of what to do).

Community
  • 1
  • 1
Michael Kent
  • 383
  • 3
  • 17
  • Just for starters... `sendevent` is not an `adb tool`. Also no "adaptation" of `sendevent` would allow non-root to write to the input devices. – Alex P. Apr 17 '14 at 13:34
  • 1
    @Alex P i know it is not an adb tool, it is on the device and accessed by adb shell, it is a tool for use with adb. And the other question i found had no hint as to whether the device was rooted or not, so i had assumed not. – Michael Kent Apr 17 '14 at 13:43
  • 1
    @AlexP. while sendevent is not part of adbd itself, it is very much a command provided specifically for use with adb. Root is not required, as even on secured devices the adb shell user is in the group which owns the input nodes - an app's process could not write to them, but the adb shell can. – Chris Stratton Apr 17 '14 at 14:46

1 Answers1

3

The way I solved it in the question you referenced was by using adb push local_path remote_path and the remote directory I used is /data/local/tmp/ which requires no root permissions. To push a thing you just need to compile it locally and send push it. You can then run in on the device using adb shell absolute_path_to_script

To recap. If you want to make a custom script from a android/adb C source, you need to:

  • compile it (lets say you get my_script)
  • don't forget to make it an executable with chmod a+x my_script
  • push it to the device adb push my_script /data/local/tmp/my_script
  • run it form the device adb shell /data/local/tmp/my_script

Now to answer your other question about dragging, I ended up making my own custom sendevent script that takes a local file (from the android device), reads events line by line and sends them to the driver.

Here's the script http://pastebin.com/LWWiNA6U

It takes 3 arguments,

  • the file_input,
  • the file_output - this is specific to every device, you need to check and see where do you need to write the raw binary data to emulate touch events. For the devices I used: /dev/input/event5 (for the HTC One M7) and /dev/input/event2 (for the Galaxy Note 8)
  • and the sleep_time - delay between every touch event being sent to the driver

Hope it helps

EDIT: Oh and btw, this is example input. It's standard converted from getevent as far as I remember

0003 0039 4a
0003 0035 1cc
0003 0036 3a2
0000 0000 00000000

0003 0035 250
0003 0036 426
0000 0000 00000000

0003 0035 250
0003 0036 4aa
0000 0000 00000000

0003 0035 149
0003 0036 3a2
0000 0000 00000000

0003 0035 c5
0003 0036 3a2
0000 0000 00000000

0003 0039 ffffffff
0000 0000 00000000
Stefan
  • 3,962
  • 4
  • 34
  • 39
  • Thanks for the response, I will most likely be tackling this on Monday. and may have more questions then if you would be so kind as to help. but for now, how would you go about compiling the tool once its finished. [would this be the correct method](http://courses.cms.caltech.edu/cs11/material/c/mike/misc/compiling_c.html) – Michael Kent Apr 17 '14 at 15:15
  • lab:~/Desktop/monkey$ gcc -c -std=gnu99 sendevents.c sendevents.c: In function ‘main’: sendevents.c:37:9: warning: format ‘%f’ expects argument of type ‘double’, but argument 4 has type ‘int’ [-Wformat=] fprintf(stderr, "use: %s in-file out-file [sleep_time=%f]\n", argv[0], DEFAULT_SLEEP_TIME); ^ I received this error while trying to compile your script. – Michael Kent Apr 17 '14 at 15:43
  • replace %f with %d :) – Stefan Apr 17 '14 at 18:42
  • thanks, I now have the file compiled. but am getting errors trying to execute the file.I tried chmod from computer terminal aswell as shelling in, get the same error. 1|shell@android:/data/local/tmp $ chmod 777 sendevents shell@android:/data/local/tmp $ ./sendevents /system/bin/sh: ./sendevents: not executable: magic 7F45 – Michael Kent Apr 22 '14 at 09:23
  • do a `ls -la` and see if it successfully got the execute permission – Stefan Apr 22 '14 at 13:24
  • output is -rwxrwxrwx shell shell 8144 2014-04-22 08:10 sendevents looks to me like it has all the permissions? – Michael Kent Apr 22 '14 at 13:32
  • hmm. try running it directly from your comment like `adb shell path_to_script` ... idk what to say, it should work. If it doesn't try a simple Hello World script and see if that works – Stefan Apr 22 '14 at 15:14
  • It is producing the same result so i shall try a hello world script, also when compiling i had this error: sendevents.c:73:13: note: use option -std=c99 or -std=gnu99 to compile your code . so I compiled with the -std=c99 option, is that likely to be causing this issue? – Michael Kent Apr 22 '14 at 15:24
  • ah yeah, you need to compile it for ARM. I forgot how to do that but there's a special way to compile stuff to work on android. google around for that – Stefan Apr 22 '14 at 15:27
  • is that using the NDK? – Michael Kent Apr 22 '14 at 15:28
  • again, i don't remember exactly as I did that over half a year ago. you google for how to compile C/C++ for android – Stefan Apr 22 '14 at 15:32
  • 1
    Thanks for the help, if i hadnt have found your question i wouldnt have thought this possible. When i have got it working i shall give you a bounty for this depending on how much rep i have at the time. – Michael Kent Apr 22 '14 at 15:37