Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ru lang to android app, fix disconnect in android app #169

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ The client is an _Android_ project located in [`app/`](app/).

The [`VpnService`] is implemented by [`GnirehtetService`].

We control the application through broadcasts received by
[`GnirehtetControlReceiver`] (we cannot send intents to `GnirehtetService`
directly, read comments in [`GnirehtetControlReceiver`]).
We control the application through intents to [`GnirehtetActivity`].

Some configuration options may be passed as extra parameters, converted to a
[`VpnConfiguration`] instance. Currently, the user can configure the DNS servers
Expand All @@ -158,7 +156,7 @@ of [`IPPacketOutputStream`].

[`VpnService`]: https://developer.android.com/reference/android/net/VpnService.html
[`GnirehtetService`]: app/src/main/java/com/genymobile/gnirehtet/GnirehtetService.java
[`GnirehtetControlReceiver`]: app/src/main/java/com/genymobile/gnirehtet/GnirehtetControlReceiver.java
[`GnirehtetActivity`]: app/src/main/java/com/genymobile/gnirehtet/GnirehtetActivity.java
[`VpnConfiguration`]: app/src/main/java/com/genymobile/gnirehtet/VpnConfiguration.java
[`startActivityForResult`]: https://developer.android.com/reference/android/app/Activity.html#startActivityForResult%28android.content.Intent,%20int%29
[`Activity`]: https://developer.android.com/reference/android/app/Activity.html
Expand Down
65 changes: 46 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Gnirehtet (v2.3)
# Gnirehtet (v2.5)

This project provides **reverse tethering** over `adb` for Android: it
allows devices to use the internet connection of the computer they are plugged
Expand Down Expand Up @@ -64,24 +64,36 @@ Make sure you [enabled adb debugging][enable-adb] on your device(s).
[platform-tools-windows]: https://dl.google.com/android/repository/platform-tools-latest-windows.zip


## Download
## Get the app

### Homebrew

If you use [Homebrew](https://brew.sh/), getting up and running is very quick.
To install the Rust version:

```
brew install gnirehtet
```

### Download

Download the [latest release][latest] in the flavor you want.

[latest]: https://github.com/Genymobile/gnirehtet/releases/latest

### Rust

- **Linux:** [`gnirehtet-rust-linux64-v2.3.zip`][direct-rust-linux64]
(SHA-256: _561d77e94d65ecf2d919053e5da6109b8cceb73bffedea71cd4e51304ccaa3d3_)
- **Windows:** [`gnirehtet-rust-win64-v2.3.zip`][direct-rust-win64]
(SHA-256: _4c4d961f069a663d6b826f24a8795d1752f3e316f121d2bfc296a4cd32c8d4ca_)
#### Rust

- **Linux:** [`gnirehtet-rust-linux64-v2.5.zip`][direct-rust-linux64]
(SHA-256: _2b1ce04540e8de5df5ddbebb64bb01e27c13d556b3a04a8563dcce3786765705_)
- **Windows:** [`gnirehtet-rust-win64-v2.5.zip`][direct-rust-win64]
(SHA-256: _9f6d7700368f45d2fa43923324660eca9f879e837e10fc45d8d975273eae4755_)
- **MacOS:** [`gnirehtet-rust-macos64-v2.2.1.zip`][direct-rust-macos64]
_(previous release)_
_(old release)_
(SHA-256: _902103e6497f995e1e9b92421be212559950cca4a8b557e1f0403769aee06fc8_)

[direct-rust-linux64]: https://github.com/Genymobile/gnirehtet/releases/download/v2.3/gnirehtet-rust-linux64-v2.3.zip
[direct-rust-win64]: https://github.com/Genymobile/gnirehtet/releases/download/v2.3/gnirehtet-rust-win64-v2.3.zip
[direct-rust-linux64]: https://github.com/Genymobile/gnirehtet/releases/download/v2.5/gnirehtet-rust-linux64-v2.5.zip
[direct-rust-win64]: https://github.com/Genymobile/gnirehtet/releases/download/v2.5/gnirehtet-rust-win64-v2.5.zip
[direct-rust-macos64]: https://github.com/Genymobile/gnirehtet/releases/download/v2.2.1/gnirehtet-rust-macos64-v2.2.1.zip

Then extract it.
Expand All @@ -96,12 +108,12 @@ The Windows archive contains:
- `gnirehtet-run.cmd`


### Java
#### Java

- **All platforms:** [`gnirehtet-java-v2.3.zip`][direct-java]
(SHA-256: _93d1d46ee566376596f033832626dd5e89e76c91f2c46d2383735937b7d3b8b0_)
- **All platforms:** [`gnirehtet-java-v2.5.zip`][direct-java]
(SHA-256: _c65fc1a35e6b169ab6aa45e695c043e933f6fd650363aea7c2add0ecb0db27ca_)

[direct-java]: https://github.com/Genymobile/gnirehtet/releases/download/v2.3/gnirehtet-java-v2.3.zip
[direct-java]: https://github.com/Genymobile/gnirehtet/releases/download/v2.5/gnirehtet-java-v2.5.zip

Then extract it. The archive contains:
- `gnirehtet.apk`
Expand Down Expand Up @@ -182,7 +194,7 @@ lower-level commands. You can call them manually instead.

To start the relay server:

java -jar gnirehtet.jar relay
./gnirehtet relay

To install the apk:

Expand All @@ -191,13 +203,28 @@ To install the apk:
To start a client:

adb reverse localabstract:gnirehtet tcp:31416
adb shell am broadcast -a com.genymobile.gnirehtet.START \
-n com.genymobile.gnirehtet/.GnirehtetControlReceiver
adb shell am start -a com.genymobile.gnirehtet.START \
-n com.genymobile.gnirehtet/.GnirehtetActivity

To stop a client:

adb shell am broadcast -a com.genymobile.gnirehtet.STOP \
-n com.genymobile.gnirehtet/.GnirehtetControlReceiver
adb shell am start -a com.genymobile.gnirehtet.STOP \
-n com.genymobile.gnirehtet/.GnirehtetActivity


## Environment variables

`ADB` defines a custom path to the `adb` executable:

```bash
ADB=/path/to/my/adb ./gnirehtet run
```

`GNIREHTET_APK` defines a custom path to `gnirehtet.apk`:

```bash
GNIREHTET_APK=/usr/share/gnirehtet/gnirehtet.apk ./gnirehtet run
```


## Why _gnirehtet_?
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ android {
archivesBaseName = "gnirehtet" // change apk name
applicationId "com.genymobile.gnirehtet"
minSdkVersion 21
targetSdkVersion 28
versionCode 6
versionName "2.3"
targetSdkVersion 29
versionCode 8
versionName "2.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
8 changes: 8 additions & 0 deletions app/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu Jul 01 13:56:53 MSK 2021
sdk.dir=C\:\\Users\\barto\\AppData\\Local\\Android\\Sdk
Binary file added app/release/gnirehtet.apk
Binary file not shown.
1 change: 1 addition & 0 deletions app/release/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":8,"versionName":"2.5","enabled":true,"outputFile":"gnirehtet-release.apk","fullName":"release","baseName":"release"},"path":"gnirehtet-release.apk","properties":{}}]
24 changes: 15 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.genymobile.gnirehtet">
xmlns:tools="http://schemas.android.com/tools"
package="com.genymobile.gnirehtet">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="false"
Expand All @@ -13,13 +14,22 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name="com.genymobile.gnirehtet.GnirehtetActivity"
android:exported="true"
android:permission="android.permission.WRITE_SECURE_SETTINGS"
android:theme="@style/Theme.Transparent">
<intent-filter>
<action android:name="com.genymobile.gnirehtet.START" />
<action android:name="com.genymobile.gnirehtet.STOP" />
</intent-filter>
</activity>
<receiver
android:name="com.genymobile.gnirehtet.GnirehtetControlReceiver"
android:exported="true"
android:permission="android.permission.WRITE_SECURE_SETTINGS">
<intent-filter>
<action android:name="com.genymobile.gnirehtet.START" />
<action android:name="com.genymobile.gnirehtet.STOP" />
<action android:name="android.hardware.usb.action.USB_STATE" />
</intent-filter>
</receiver>
<service
Expand All @@ -31,10 +41,6 @@
<action android:name="android.net.VpnService" />
</intent-filter>
</service>

<activity
android:name="com.genymobile.gnirehtet.AuthorizationActivity"
android:theme="@style/Theme.Transparent" />
</application>

</manifest>

This file was deleted.

19 changes: 13 additions & 6 deletions app/src/main/java/com/genymobile/gnirehtet/Binary.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@SuppressWarnings("checkstyle:MagicNumber")
public final class Binary {

private static final int MAX_STRING_PACKET_SIZE = 20;

private Binary() {
// not instantiable
}
Expand All @@ -35,15 +37,20 @@ public static long unsigned(int value) {
return value & 0xffffffffL;
}

public static String toString(byte[] data, int len) {
public static String buildPacketString(byte[] data, int len) {
int limit = Math.min(MAX_STRING_PACKET_SIZE, len);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < len; ++i) {
if (i % 8 == 0) {
builder.append('\n');
builder.append('[').append(len).append(" bytes] ");
for (int i = 0; i < limit; ++i) {
if (i != 0) {
String sep = i % 4 == 0 ? " " : " ";
builder.append(sep);
}
builder.append(String.format("%02X ", data[i] & 0xff));
builder.append(String.format("%02X", data[i] & 0xff));
}
if (limit < len) {
builder.append(" ... +").append(len - limit).append(" bytes");
}
return builder.toString();
}

}
5 changes: 1 addition & 4 deletions app/src/main/java/com/genymobile/gnirehtet/Forwarder.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Forwarder {

private static final String TAG = Forwarder.class.getSimpleName();

private static final int BUFSIZE = 4096;
private static final int BUFSIZE = 0x10000;

private static final byte[] DUMMY_ADDRESS = {42, 42, 42, 42};
private static final int DUMMY_PORT = 4242;
Expand Down Expand Up @@ -129,9 +129,6 @@ private void forwardTunnelToDevice(Tunnel tunnel) throws IOException {
break;
}
if (w > 0) {
if (GnirehtetService.VERBOSE) {
Log.d(TAG, "WRITING " + w + "..." + Binary.toString(buffer, w));
}
// blocking write
packetOutputStream.write(buffer, 0, w);
} else {
Expand Down