Updating android app

This commit is contained in:
Michael Wain 2024-12-11 02:37:38 +03:00
parent 89e7d0989f
commit 485c711a3e
13 changed files with 227 additions and 40 deletions

View File

@ -23,6 +23,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@ -52,10 +53,10 @@ task deleteLibs(type: Delete) {
}
}
//preBuild.dependsOn deleteLibs
//preBuild.dependsOn downloadAarch
/*preBuild.dependsOn downloadArmeabi
preBuild.dependsOn downloadx86*/
preBuild.dependsOn deleteLibs
preBuild.dependsOn downloadAarch
preBuild.dependsOn downloadArmeabi
preBuild.dependsOn downloadx86
dependencies {
implementation libs.appcompat

View File

@ -3,28 +3,30 @@
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="internalOnly">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:hardwareAccelerated="true"
android:extractNativeLibs="true"
android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:extractNativeLibs="true"
android:fullBackupContent="@xml/backup_rules"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.FridaApp"
tools:targetApi="34"
tools:replace="android:allowBackup">
tools:replace="android:allowBackup"
tools:targetApi="34">
<activity
android:name=".activity.SingleConfigActivity"
android:exported="false" />
<activity
android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true">
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -33,11 +35,14 @@
</activity>
<service
android:name="com.alterdekim.fridaapp.service.FridaService"
android:name=".service.FridaService"
android:exported="false"
android:permission="android.permission.BIND_VPN_SERVICE"
android:foregroundServiceType="specialUse">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" android:value="vpn" />
android:foregroundServiceType="specialUse"
android:permission="android.permission.BIND_VPN_SERVICE">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="vpn" />
<intent-filter>
<action android:name="android.net.VpnService" />
</intent-filter>

View File

@ -8,7 +8,7 @@ public class FridaLib {
System.loadLibrary("frida");
}
public native int start(String config_hex, int tun_fd, boolean close_fd_on_drop);
public native int start(String config_hex, int tun_fd, boolean close_fd_on_drop, String temp_file);
public native int stop();

View File

@ -0,0 +1,26 @@
package com.alterdekim.fridaapp.activity;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.alterdekim.fridaapp.R;
public class SingleConfigActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_single_config);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}
}

View File

@ -43,7 +43,6 @@ public class MainActivityController implements IController {
}
private void initConfigListGUI() {
Toast.makeText(this.mainActivity, R.string.config_adding_success, Toast.LENGTH_LONG).show();
LayoutInflater inflater = this.mainActivity.getLayoutInflater();
this.db.userDao().getAll()
.subscribeOn(Schedulers.io())

View File

@ -1,19 +1,22 @@
package com.alterdekim.fridaapp.service;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.VpnService;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import com.alterdekim.frida.FridaLib;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Objects;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
public class FridaService extends VpnService {
private static final String TAG = FridaService.class.getSimpleName();
@ -22,16 +25,40 @@ public class FridaService extends VpnService {
private ParcelFileDescriptor vpnInterface = null;
private String logPath;
private Disposable vpnProcess;
private final FridaLib lib = new FridaLib();
@Override
public void onCreate() {
Log.i(TAG, "Created");
setupVPN();
}
private void setupVPN() {
try {
File outputDir = this.getCacheDir(); // context being the Activity pointer
File outputFile = new File(outputDir, "fridalib.log");
if( outputFile.exists() ) { outputFile.delete(); }
outputFile.createNewFile();
this.logPath = outputFile.getAbsolutePath();
Log.i(TAG, logPath);
/*new Thread(() -> {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(outputFile)));
String str = "";
Log.i(TAG, "Reading fd has started");
while (true) {
if((str = br.readLine()) != null) {
Log.i(TAG, str);
}
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}).start();*/
Builder builder = new Builder();
builder.setMtu(1400);
builder.addAddress(VPN_ADDRESS, 24);
@ -51,7 +78,18 @@ public class FridaService extends VpnService {
}
private void turnOff() {
if( this.vpnProcess != null && !this.vpnProcess.isDisposed() ) this.vpnProcess.dispose();
if( this.vpnProcess != null ) {
Log.i(TAG, "DISPOSE");
this.vpnProcess.dispose();
}
}
private void turnOffVpn() {
try {
this.vpnInterface.close();
} catch (IOException e) {
Log.e(TAG, Objects.requireNonNull(e.getMessage()));
}
}
@Override
@ -60,18 +98,17 @@ public class FridaService extends VpnService {
String hex = intent.getExtras().getString("vpn_hex");
int uid = intent.getExtras().getInt("vpn_uid");
boolean state = intent.getExtras().getBoolean("vpn_state");
turnOff();
if(!state) return START_STICKY;
// TODO: different configs
/*this.vpnProcess = Flowable.fromRunnable(new NativeBinaryConnection(vpnInterface.detachFd(), hex))
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe();*/
try {
Thread t = new Thread(new NativeBinaryConnection(vpnInterface.dup().detachFd(), hex));
t.start();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
if(!state) {
this.lib.stop();
return START_STICKY;
}
setupVPN();
// TODO: different configs
this.vpnProcess = Flowable.fromRunnable(new NativeBinaryConnection(vpnInterface.detachFd(), hex, lib, logPath))
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.newThread())
.subscribe();
return START_STICKY;
}
}

View File

@ -12,15 +12,15 @@ public class NativeBinaryConnection implements Runnable {
private final int fd;
private final String hex;
private final FridaLib lib;
private final String tempFile;
@Override
public void run() {
try {
Log.i(TAG, "FD: " + this.fd);
FridaLib lib = new FridaLib();
Log.i(TAG, "Starting Frida client");
Log.i(TAG, "Hex: " + this.hex);
int r = lib.start(this.hex.toLowerCase(), this.fd, false);
int r = lib.start(this.hex.toLowerCase(), this.fd, false, this.tempFile);
Log.i(TAG, "Exit code: " + r);
} catch (Exception e) {
Log.e(TAG, e.getMessage());

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F3F2F8"/>
<stroke android:width="3dp" android:color="#F3F2F8" />
<corners android:radius="20dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#E1E1EB"/>
<stroke android:width="2.5dp" android:color="#75757F" />
<corners android:radius="8dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#75757F"/>
<stroke android:width="2.5dp" android:color="#75757F" />
<corners android:bottomLeftRadius="8dp" android:topLeftRadius="8dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#75757F"/>
<stroke android:width="2.5dp" android:color="#75757F" />
<corners android:bottomRightRadius="8dp" android:topRightRadius="8dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/main"
tools:context=".activity.SingleConfigActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Widget.Material3.AppBarLayout">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/Widget.Material3.AppBarLayout" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_single" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/single_config_act"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="@drawable/layout_bg"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="@drawable/layout_bg"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@drawable/layout_switcher"
android:layout_marginTop="10dp"
android:layout_marginHorizontal="20dp">
<LinearLayout
android:layout_weight="1"
android:background="@drawable/layout_swl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Allowed apps"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<!-- android:background="@drawable/layout_swr" -->
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Disallowed apps"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="#75757F"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>