diff --git a/build.gradle b/build.gradle index e7a76f1..0d0b16a 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index bda8b94..4a23f48 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -3,28 +3,30 @@ xmlns:tools="http://schemas.android.com/tools" android:installLocation="internalOnly"> - - - - + + + + tools:replace="android:allowBackup" + tools:targetApi="34"> + + android:exported="true" + android:screenOrientation="portrait"> @@ -33,11 +35,14 @@ - + android:foregroundServiceType="specialUse" + android:permission="android.permission.BIND_VPN_SERVICE"> + + diff --git a/src/main/java/com/alterdekim/frida/FridaLib.java b/src/main/java/com/alterdekim/frida/FridaLib.java index f6b97d9..1680007 100644 --- a/src/main/java/com/alterdekim/frida/FridaLib.java +++ b/src/main/java/com/alterdekim/frida/FridaLib.java @@ -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(); diff --git a/src/main/java/com/alterdekim/fridaapp/activity/SingleConfigActivity.java b/src/main/java/com/alterdekim/fridaapp/activity/SingleConfigActivity.java new file mode 100644 index 0000000..78c7123 --- /dev/null +++ b/src/main/java/com/alterdekim/fridaapp/activity/SingleConfigActivity.java @@ -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; + }); + } +} \ No newline at end of file diff --git a/src/main/java/com/alterdekim/fridaapp/controller/MainActivityController.java b/src/main/java/com/alterdekim/fridaapp/controller/MainActivityController.java index 2d7842a..a88b1a7 100644 --- a/src/main/java/com/alterdekim/fridaapp/controller/MainActivityController.java +++ b/src/main/java/com/alterdekim/fridaapp/controller/MainActivityController.java @@ -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()) diff --git a/src/main/java/com/alterdekim/fridaapp/service/FridaService.java b/src/main/java/com/alterdekim/fridaapp/service/FridaService.java index e87ef48..a4a8bc1 100644 --- a/src/main/java/com/alterdekim/fridaapp/service/FridaService.java +++ b/src/main/java/com/alterdekim/fridaapp/service/FridaService.java @@ -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; } } diff --git a/src/main/java/com/alterdekim/fridaapp/service/NativeBinaryConnection.java b/src/main/java/com/alterdekim/fridaapp/service/NativeBinaryConnection.java index 2d57ab5..5ba9ec2 100644 --- a/src/main/java/com/alterdekim/fridaapp/service/NativeBinaryConnection.java +++ b/src/main/java/com/alterdekim/fridaapp/service/NativeBinaryConnection.java @@ -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()); diff --git a/src/main/res/drawable/layout_bg.xml b/src/main/res/drawable/layout_bg.xml new file mode 100644 index 0000000..32d0b6f --- /dev/null +++ b/src/main/res/drawable/layout_bg.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/layout_switcher.xml b/src/main/res/drawable/layout_switcher.xml new file mode 100644 index 0000000..940e922 --- /dev/null +++ b/src/main/res/drawable/layout_switcher.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/layout_swl.xml b/src/main/res/drawable/layout_swl.xml new file mode 100644 index 0000000..8ac978e --- /dev/null +++ b/src/main/res/drawable/layout_swl.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/drawable/layout_swr.xml b/src/main/res/drawable/layout_swr.xml new file mode 100644 index 0000000..8d5331c --- /dev/null +++ b/src/main/res/drawable/layout_swr.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/activity_single_config.xml b/src/main/res/layout/activity_single_config.xml new file mode 100644 index 0000000..f4b04da --- /dev/null +++ b/src/main/res/layout/activity_single_config.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/content_single.xml b/src/main/res/layout/content_single.xml new file mode 100644 index 0000000..c68c3d2 --- /dev/null +++ b/src/main/res/layout/content_single.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file