Moriba

Android UDF

24 posts in this topic




Maybe you could add a demo script?

2 people like this

Share this post


Link to post
Share on other sites

VERY MUCH THX !!!!!!!!!!!!!!

Really Nice work there  :thumbsup:  :thumbsup:  :thumbsup:

implementation of create Nandroid Backups or Kernel Dump would be some nice Adds there i guess

Share this post


Link to post
Share on other sites

This is easy for beginner,like me to create Android Tools. Thank  :thumbsup:  :bye:

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

someone has got this working? some examples? i cant seem to get it going, just hangs for me :(

 

this works to get it going though, but not the udf version of connect O.o

 

 

 

GUICtrlSetData($Label1, "Connected: " & "Waiting for Device...")
 Runwait(@ComSpec & " /c " & "adb kill-server", @ScriptDir, @SW_SHOW)
 Runwait(@ComSpec & " /c " & "adb start-server", @ScriptDir, @SW_SHOW)
 Runwait(@ComSpec & " /c " & "adb get-state", @ScriptDir, @SW_SHOW)
 GUICtrlSetData($Label1, "Connected: " & _Android_IsOnline())
Edited by damian666

and proud of it!!!

Share this post


Link to post
Share on other sites

为什么不给个例子呢?

Share this post


Link to post
Share on other sites

Thanks for sharing!


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Has anyone tried this out, or test to make sure the files are safe?


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

the script, for what I just seen, is a shell for adb.exe ( http://developer.android.com/tools/help/adb.html )
If you know what you're doing, then this is may be useful, otherwise, its useless.
With the .exe's you save yourself from installing the SDK ( http://forum.xda-developers.com/showthread.php?t=723135 )
So ACTIVATE USB DEBUGGING IN YOUR DEVICE and have fun.

PS: don't come telling me that your phone broke. I won't be able to help you. Again, have fun.

Share this post


Link to post
Share on other sites

Have you done much programming for the Android? If so, do you have any tools that I might start off with, that will not brick my phone?


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

For "bypassing" ADB.EXE you just could start the server thru ADB (so far not found an easy way to only start the adb daemon on the device itsef)

http://forum.xda-developers.com/showthread.php?t=803223

and once started you can communicate with tcp/ip commands of AutoIT

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

and an example to start the shell and just get an ls directory overview.

#include <MsgBoxConstants.au3>
; Assign Local variables the loopback IP Address and the Port.
Local $sIPAddress = "127.0.0.1" ;"localhost" ; "127.0.0.1" ; This IP Address only works for testing on your own computer.
Local $iPort = 5037 ; Port used for the connection.


Example()

Func Example()
    TCPStartup() ; Start the TCP service.

    ; Register OnAutoItExit to be called when the script is closed.
    OnAutoItExitRegister("OnAutoItExit")

    ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified.
    Local $iSocket = TCPConnect($sIPAddress, $iPort)

    ; If an error occurred display the error code and return False.
    If @error Then
        ; The server is probably offline/port is not opened on the server.
        Local $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not connect, Error code: " & $iError)
        Return False
    Else
        Consolewrite("Connection successful" & @CRLF)
    EndIf

    ;Connect over usb
    TCPSend($iSocket, adbData("host:transport-usb"))
    $data=TCPRecv($iSocket,4096,0)
    consolewrite($data & @CRLF)

    ;Connect to the shell
    TCPSend($iSocket, adbData("shell:"))
    $data=TCPRecv($iSocket,4096,0)
    consolewrite($data & @CRLF)

    ;See the shell line
    $data=TCPRecv($iSocket,4096,0)
    consolewrite($data & @CRLF)

    ;Give the LS Command (do not forget CR)
    TCPSend($iSocket, "ls" & @CR)
    sleep(2000)
    $data=TCPRecv($iSocket,4096,0)
    consolewrite($data & @CRLF)


    ; Close the socket.
    TCPCloseSocket($iSocket)
EndFunc   ;==>Example

Func OnAutoItExit()
    TCPShutdown() ; Close the TCP service.
EndFunc   ;==>OnAutoItExit

;Put hexLengthIn front of the data
Func adbData($s)
    return hex(stringlen($s),4) & $s
EndFunc

 

Edited by junkew
2 people like this

Share this post


Link to post
Share on other sites

Fun to play with needs more study

to have this work first run command:  adb start-server

that will start the daemon on the device and the background server program (adb is just besides a client also a hub to start the daemon and the server)

extended example with snapshot of the android device without adb.exe

according to services.txt it should be possible to read framebuffer of device directly

#include <MsgBoxConstants.au3>
#include <string.au3>

;Example to communicate with Android device with the ADB server started but bypassing ADB client.exe
;See links like
; https://github.com/android/platform_system_core/tree/master/adb
; http://www.w3.org/TR/PNG-Structure.html
; https://mogutan.wordpress.com/2014/06/25/ways-to-take-android-screenshot-from-command-line/

; Assign Local variables the loopback IP Address and the Port.
Local $sIPAddress = "127.0.0.1" ;"localhost" ; "127.0.0.1" ; This IP Address only works for testing on your own computer.
Local $iPort = 5037 ; Port used for the connection.

Example()

Func Example()
    TCPStartup() ; Start the TCP service.

    ; Register OnAutoItExit to be called when the script is closed.
    OnAutoItExitRegister("OnAutoItExit")

    ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified.
    Local $iSocket = TCPConnect($sIPAddress, $iPort)

    ; If an error occurred display the error code and return False.
    If @error Then
        ; The server is probably offline/port is not opened on the server.
        Local $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not connect, Error code: " & $iError)
        Return False
    Else
        Consolewrite("Connection successful" & @CRLF)
    EndIf

    ;Connect over usb
    TCPSend($iSocket, adbData("host:transport-usb"))
    $data=TCPRecv($iSocket,4096,0)
    consolewrite($data & @CRLF)

    ;Connect to the shell
    TCPSend($iSocket, adbData("shell:"))
    $data=TCPRecv($iSocket,4096,0)
    consolewrite($data & @CRLF)

    ;See the shell line
    $data=TCPRecv($iSocket,4096,0)
    consolewrite($data & @CRLF)

;~  ExampleLS($iSocket)

    ExamplePNG($iSocket)

    ; Close the socket.
    TCPCloseSocket($iSocket)
EndFunc   ;==>Example
func TCPReadAway($iSocket, $s)
    $data=TCPRecv($iSocket,1)
    while stringinstr($s,$data)=0
    $data=TCPRecv($iSocket,1)
    wend
EndFunc
Func OnAutoItExit()
    TCPShutdown() ; Close the TCP service.
EndFunc   ;==>OnAutoItExit

;Put hexLengthIn front of the data
Func adbData($s)
    return hex(stringlen($s),4) & $s
EndFunc

func ExamplePNG($iSocket)
;Take a screenshot as png
    TCPSend($iSocket, "screencap -p" & @CR)
    sleep(2000)

;~  $data=TCPRecv($iSocket,1024*1024,0)

    ;Just receive a lot of binary data at once to get the whole picture in directly and not in parts    , assume 16 megabytes max
    ;First block contains a start string to much
    $tData=TCPRecv($iSocket,1024*1024*16,1)
    ;89 50 4E is the PNG starting point
    $startAt=stringinstr($tdata,"89504E")
    $data=_hextostring(stringmid($tdata,$startAt))

    while $tData<>""
        $tData=_hextostring(TCPRecv($iSocket,1024*1024*16,1))
        $data=$data & $tData
    WEnd

    $dataLen=consolewrite("Data length: " & (stringlen($data)/1024) & @CRLF)

;~  $data=stringreplace($data,"\x0D\x0A","\x0A")
    $data=stringtobinary(stringreplace($data, @CRLF, @LF))

;Carbage at the end, no need to remove
;49 45 4E 44 AE 42 60 82 is the PNG ending point

    filedelete("screenshot.png")
    filewrite("screenshot.png",$data)
endfunc

func ExampleLS($iSocket)
    ;Give the LS Command (do not forget CR)
    TCPSend($iSocket, "ls" & @CR)
    sleep(2000)
    ;Read the data quick and dirty max 1 megabyte
    $data=TCPRecv($iSocket,1024*1024,0)
    consolewrite($data & @CRLF)
EndFunc

;~ https://mogutan.wordpress.com/2014/06/25/ways-to-take-android-screenshot-from-command-line/

;~ framebuffer:
;~     This service is used to send snapshots of the framebuffer to a client.
;~     It requires sufficient privileges but works as follow:

;~       After the OKAY, the service sends 16-byte binary structure
;~       containing the following fields (little-endian format):

;~             depth:   uint32_t:    framebuffer depth
;~             size:    uint32_t:    framebuffer size in bytes
;~             width:   uint32_t:    framebuffer width in pixels
;~             height:  uint32_t:    framebuffer height in pixels

;~       With the current implementation, depth is always 16, and
;~       size is always width*height*2

;~       Then, each time the client wants a snapshot, it should send
;~       one byte through the channel, which will trigger the service
;~       to send it 'size' bytes of framebuffer data.

;~       If the adbd daemon doesn't have sufficient privileges to open
;~       the framebuffer device, the connection is simply closed immediately.
func readFB($iSocket)
EndFunc

 

Share this post


Link to post
Share on other sites

It looks all possible to directly talk to android phone with ADB daemon/server running (lot of work to extend in udf), easy testable on cmldine with ADB <command> and in previous example shown in code that you can start ADB.EXE / Server/Shell in an interactive way (removing overhead of starting adb over and over again)

XML snapshot to identify elements can be done with

Store an xml dump on the phone

adb shell uiautomator.dump

Get it to your local directory

adb shell pull /storage/sdcard0/window_dump.xml test.xml 

Interpret the xml

TODO ;-)

Sending events

Sending events (key, mouse, tap etc.) to your android phone is based on the linux event model and can be done with 

adb shell sendevent

http://ktnr74.blogspot.nl/2013/06/emulating-touchscreen-interaction-with.html

 

background reading

https://source.android.com/devices/input/overview.html

https://www.kernel.org/doc/Documentation/input/event-codes.txt

https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt

 

1 person likes this

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Question.. how to start an .exe with an Android Device?!?!?! This could probably only work with Windows Phone.. but however nice made but can't be really used because Autoit don't support .apk/Android Application creating or got I something wrong >.<..

 

Edited by RaiNote

  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Share this post


Link to post
Share on other sites

 

The ADB.EXE starts on your windows machine but triggers the remote daemon on your android phone (if android debugging is enabled)

 

Ok first of all to do anything with android from windows you need adb.exe on your local windows machine which can be installed in about 15 seconds.

http://forum.xda-developers.com/showthread.php?t=2588979

after you adb working you can do a lot of nice things from any programming language (including AutoIT)

  • As a starter you can read this

http://wiki.cyanogenmod.org/w/Doc:_adb_intro

And after that you can read a lot on how to do some stuff from AutoIT where OP did make a nice start of wrapping up functions around adb.exe.

ADB consists of https://android.googlesource.com/platform/system/core/+/master/adb/SERVICES.TXT

This can be made a little more efficient by not making adb call each time but just start communicating directly

  • As AutoIT is about sending keys, recognizing controls I started with these

1. Make screenshot:   ADB screencap   makes a RAW screenshot, -p makes it PNG            (making a lot of screenshots probably faster in RAW format)

2. Get the element hierarchy:  ADB shell uiautomator dump <file>

http://www.bdtool.net/third/android-doc/web-docs/tools/help/uiautomator/index.html

3. Get files from your phone to the pc with ADB pull

4. Put files to your phone with ADB push

5. sendevent / keys or getevent / record

http://ktnr74.blogspot.nl/2013/06/emulating-touchscreen-interaction-with.html

 

And with all above combined you can remotely control your android phone

 

  • Technically I see no reason why you cannot maken an APK with help of AutoIT but probably a lot of work and nobody started such a project 

http://en.wikipedia.org/wiki/Android_application_package

2 people like this

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

@junkew

You are right, is a good idea an ADB client implemented in pure AutoIT.

There are some examples in other languages:

I did something similar in the past but for the Android Monkey Tool.

Another approach in order to make AutoIt a "scripting language for mobile automation", is develop an Appium driver on Autoit that implements the Mobile JSON Wire Protocol or try develop an ImperiusGeorge AutoIt driver like this Ruby gem or also a wrapper of Android uiautomator-server testing framework like this Python module.

Best regards.
Henry

Edited by oHenry
1 person likes this

Regards.

Henry

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Hey check this new PureAutoItADB UDF. This project is still in beta. Kindly suggest me to improve. Very thanks :)

<snip>

Edited by Melba23
Link removed - not AutoIt related

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now