Script Android from TCP socket

Related tags

App NetInterpreter
Overview

What is this?

This is an Android application that will execute commands received over TCP port 9988, which includes automatic introspection to call any Anddroid java API over telnet. Also, it includes exploration tooling, and a nano-language to be able to do small stuff.

Sounds gibberish. What can this be used f or?

The goal is to be able to do simple Android things from "Linux" environments. This application is launched Android-side, and then everything can be scripted Linux-side. The Android APIs are non-trivial, so several examples are provided.

What can we do with this?

Since all Android API are accessible it can do anything, but here are some examples that you can do from the comfort of a shell or a python script:

  • Install Android application
  • Setup WiFi SSID/PSK
  • Take a picture on the camera
  • Put phone in airplane mode
  • Launch apps
  • Play music file

There are some limitations though, because the protocol is text-based. For instance, you can't transmit audio over this socket.

What is the protocol

It's stack based, plus support storing global variables. Commands are split on space except """

  • STACK command dumps the content of the stack
  • DUP duplicates the top of the stack
  • INV inverts the two elements at the top of the stack
  • DISPLAY displays the toString of the top of the stack
  • INSPECT lists all constructor methods and fields of top of the stack's class
  • NULL adds null on stack
  • EXIT closes socket
  • DROP removes top of stack
  • ~ consumes top of stack and put it into variable
  • = loads variable at top of stack
  • . loads field from top of stack
  • : assuming there is exactly one matching function, call the function with arguments on the stack, and add return to stack
  • :1 Same but run the function on UI thread, except result doesn't to go stack
  • "xxxx puts the string xxxx on top of the stack
  • """ if a line starts with """, everything after """ until new-line is added at the top of stack
  • +(zz) creates an object of type (MUST BE a Class<>, created with 1xxx for instance) with parameters matching (zz)
  • ! will set field of to and consume both
  • 0dyyy add decimal number yyy on top of stack
  • 0xyyy add hexadecimal number yyy on top of stack
  • 1 loads class name
  • [<number> does <top of stack>[number] array access drops top of stack and pushes the result on top of stack
  • 90 implements an abstract class (used to implement listener)
  • 91. clears passed called to this function, and declare interest in waiting for that method
  • 92. waits for an implemented abstract class to have its methodName called, then puts the arguments of that callback on top of stack
  • NEW_BYTE_ARRAY create a byte array of size (must be int)

Variables are global across TCP connections. Stack is reset at every TCP connection.

Check adb logcat -s NetInterpreter to understand unexpected behavior (and source code of course).

Listeners

Android APIs relies A LOT on listeners, so we need to be able to deal with it. It is still unclear as of now what is the best route to handle them, so it is highly likely to change.

Sample usage from computer

Even though the primary target is for GNU/Linux on-smartphone to communicate with Android, samples can be developed from computer for more comfort.

bash build.sh
adb install -r app.apk && adb shell am start me.phh.netinterpreter/.MainActivity
adb forward tcp:9988 tcp:9988
bash examples/battery.sh
You might also like...
 🍲Foodium is a sample food blog Android application 📱 built to demonstrate the use of Modern Android development tools - (Kotlin, Coroutines, Flow, Dagger 2/Hilt, Architecture Components, MVVM, Room, Retrofit, Moshi, Material Components). A simple app to showcase Androids Material Design and some of the cool new cool stuff in Android Lollipop. RecyclerView, CardView, ActionBarDrawerToggle, DrawerLayout, Animations, Android Compat Design, Toolbar
A simple app to showcase Androids Material Design and some of the cool new cool stuff in Android Lollipop. RecyclerView, CardView, ActionBarDrawerToggle, DrawerLayout, Animations, Android Compat Design, Toolbar

#Android-LollipopShowcase This is a simple showcase to show off Android's all new Material Design and some other cool new stuff which is (new) in Andr

The Android startup used to schedule tasks, jobs while launching Android App.

Android Startup, schedule your startup jobs Introduction AndroidStartup is an open source project used to refine your Andriod App startup. Compared wi

Android playground project with modularization by feature (android libraries), unit tests, MVVM & MVI.
Android playground project with modularization by feature (android libraries), unit tests, MVVM & MVI.

Movies Movies is a simple project to study and play with some android components, architecture and tools for Android development. Tech Stack This proj

🌄 Photo editor using native modules for iOS and Android. Inherit from 2 available libraries, Brightroom (iOS) and PhotoEditor (Android)
🌄 Photo editor using native modules for iOS and Android. Inherit from 2 available libraries, Brightroom (iOS) and PhotoEditor (Android)

React Native Photo Editor (RNPE) 🌄 Image editor using native modules for iOS and Android. Inherit from 2 available libraries, Brightroom (iOS) and Ph

Ride-Sharing Uber Lyft Android App - Learn to build a ride-sharing Android Taxi Clone App like Uber, Lyft - Open-Source Project By MindOrks
Ride-Sharing Uber Lyft Android App - Learn to build a ride-sharing Android Taxi Clone App like Uber, Lyft - Open-Source Project By MindOrks

Ride-Sharing Uber Lyft Android App - Learn to build a ride-sharing Android Taxi Clone App like Uber, Lyft - Open-Source Project By MindOrks

A simple Android app to demonstrate the use of Hover SDK for M-PESA Send Money while offline. This SDK does not require an internet connection, it automates USSD sessions in the background of an android application.

HoverSDKDemo Hover SDK is an Android SDK that lets mobile developers to add money features to the applications. This SDK does not require an internet

Source code of JekyllEx Android App which can manage your Jekyll blog directly from your Android device!
Source code of JekyllEx Android App which can manage your Jekyll blog directly from your Android device!

JekyllEx Android App Built with ❤︎ by Gourav Khunger 🚀 Introduction JekyllEx is an Android App that allows you to manage a Jekyll Blog directly from

A Simple and Minimal Quotes Android Application to demonstrate the Modern Android Development tools
A Simple and Minimal Quotes Android Application to demonstrate the Modern Android Development tools

Quotee Android 📑 A Simple and Minimal Quotes Android Application to demonstrate the Modern Android Development tools. Developed with ❤️ by Aminullah

Owner
Pierre-Hugues HUSSON
Pierre-Hugues HUSSON
Create Android Demo with TCP/IP Protocol.

DEMO说明文档 本demo为Java 编写的给Android手机或平板使用TCP方式控制Dobot协作机器人CR(以下简称CR)的DEMO DEMO系统要求 Android 4.3版本以上即可 工程文件说明 工程文件需要使用Android Studio打开,请使用4.0版本的Android Stu

Dobot 1 Aug 16, 2022
A simple chat demo for socket.io and Android

socket.io-android-chat This is a simple chat demo for socket.io and Android. You can connect to https://socket-io-chat.now.sh using this app. Installa

Naoyuki Kanezawa 1.9k Dec 30, 2022
vBulletin 2FA BruteForce Example Kotlin Script on bruteforcing 2FA for vBulletin 4.x

vBulletin 2FA BruteForce Example Kotlin Script on bruteforcing 2FA for vBulletin 4.x

Kai o((>ω< ))o 1 May 14, 2022
android-delicious Delicious Android is an Android app which helps you access and save bookmarks via Delicious. It's available over at Google Play.

Delicious Android Delicious Android is an Android app which helps you access and save bookmarks via Delicious. It's available over at Google Play. Fea

Alexander Blom 137 Nov 20, 2022
Android cutout screen support Android P. Android O support huawei, xiaomi, oppo and vivo.

CutoutScreenSupport Android cutout screen support Android P. Android O support huawei, xiaomi, oppo and vivo. Usage whether the mobile phone is cutout

hacket 5 Nov 3, 2022
FoldingNavigationDrawer-Android This is a sample project present how to use Folding-Android to add Folding Efect to Navigation Drawer.

FoldingNavigationDrawer-Android Sample (Play Store Demo) This is a sample project present how to use Folding-Android to add Folding Efect to Navigatio

null 242 Nov 25, 2022
Twidere-Android Twidere is a powerful twitter client for Android 1.6+ 1 , which gives you a full Holo experience and nearly full Twitter's feature.

Twidere for Android Material Design ready and feature rich Twitter/Mastodon/Fanfou app for Android 4.1+. Enjoy Fediverse now! Twidere-Android is maint

Twidere Project 2.7k Jan 2, 2023
:movie_camera: Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.

Popular Movies Stage 1 + Stage 2 Discover the most popular and top rated movies playing. Movies data fetched using themoviedb.org API. ✨ Screenshots M

Yassin AJDI 189 Nov 26, 2022
Extensible Android mobile voice framework: wakeword, ASR, NLU, and TTS. Easily add voice to any Android app!

Spokestack is an all-in-one solution for mobile voice interfaces on Android. It provides every piece of the speech processing puzzle, including voice

Spokestack 57 Nov 20, 2022
Aggregated Android news, articles, podcasts and conferences about Android Development

DroidFeed Curated news feed for Android Developers! Stay up to date with the latest Android Development news. Built for the Android developer communit

Dogan Gulcan 183 Dec 2, 2022