Skip to content

Commit

Permalink
Add proxy and frida feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bongtrop committed Aug 3, 2023
1 parent df93162 commit dc910cb
Show file tree
Hide file tree
Showing 57 changed files with 2,434 additions and 251 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android {
}
buildFeatures {
viewBinding = true
dataBinding = true
}
}

Expand All @@ -50,6 +51,13 @@ dependencies {
implementation("androidx.navigation:navigation-ui-ktx:2.6.0")
implementation("androidx.preference:preference:1.2.0")
implementation("androidx.preference:preference-ktx:1.2.0")
implementation("com.github.topjohnwu.libsu:core:5.2.0")
implementation("com.github.topjohnwu.libsu:service:5.2.0")
implementation("com.github.topjohnwu.libsu:nio:5.2.0")
implementation("com.github.ixuea:android-downloader:3.0.1")
implementation("com.squareup.okhttp3:okhttp:4.11.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("org.tukaani:xz:1.9")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
Expand Down
31 changes: 22 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"

<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand All @@ -15,19 +20,27 @@
android:theme="@style/Theme.EZHZ"
tools:targetApi="31">
<activity
android:name=".ui.appselect.AppSelectActivity"
android:exported="false"
android:label="@string/title_activity_app_select" />
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name">
android:name=".SplashActivity"
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".core.appselect.AppSelectActivity"
android:exported="false"
android:label="@string/title_activity_app_select" />
<activity
android:name=".MainActivity"
android:exported="false" />
<service
android:name=".module.proxy.ProxyService"
android:exported="false" />
<service
android:name=".module.frida.FridaService"
android:exported="false" />
</application>

</manifest>
Binary file added app/src/main/assets/armeabi-v7a/gost
Binary file not shown.
Binary file added app/src/main/assets/x86/gost
Binary file not shown.
36 changes: 32 additions & 4 deletions app/src/main/java/cc/ggez/ezhz/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
package cc.ggez.ezhz

import android.content.Intent
import android.os.Bundle
import com.google.android.material.bottomnavigation.BottomNavigationView
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import cc.ggez.ezhz.databinding.ActivityMainBinding
import com.google.android.material.bottomnavigation.BottomNavigationView

class MainActivity : AppCompatActivity() {

val TAG = "MainActivity"
private lateinit var binding: ActivityMainBinding
private lateinit var navController: NavController

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

val menu = intent?.getStringExtra("menu")
Log.d(TAG, "onCreate: ${menu}")
if (menu.equals("proxy")) {
navController.navigate(R.id.navigation_frida)
} else if (menu.equals("shared_pref")) {
navController.navigate(R.id.navigation_shared_pref)
} else if (menu.equals("frida")) {
navController.navigate(R.id.navigation_proxy)
}

val navView: BottomNavigationView = binding.navView

val navController = binding.navHostFragmentActivityMain.getFragment<NavHostFragment>().navController
navController = binding.navHostFragmentActivityMain.getFragment<NavHostFragment>().navController
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
val appBarConfiguration = AppBarConfiguration(
Expand All @@ -32,5 +45,20 @@ class MainActivity : AppCompatActivity() {
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)


}

override fun onNewIntent(intent: Intent?) {
val menu = intent?.getStringExtra("menu")
Log.d(TAG, "onActivityReenter: ${intent.toString()}")
if (menu.equals("proxy")) {
navController.navigate(R.id.navigation_frida)
} else if (menu.equals("shared_pref")) {
navController.navigate(R.id.navigation_shared_pref)
} else if (menu.equals("frida")) {
navController.navigate(R.id.navigation_proxy)
}
super.onNewIntent(intent)
}
}
116 changes: 116 additions & 0 deletions app/src/main/java/cc/ggez/ezhz/SplashActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package cc.ggez.ezhz

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.topjohnwu.superuser.Shell
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream


class SplashActivity : AppCompatActivity() {
companion object {
init {
Shell.enableVerboseLogging = true
}
}

private lateinit var requestPermissionLauncher: ActivityResultLauncher<String>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) {
if (it) {
startMain()
} else {
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder.setTitle("Notification Permission Required")
builder.setMessage("For foreground service, notification permission is required.")
builder.setPositiveButton("OK") { _, _ ->
startMain()
}

val dialog: AlertDialog = builder.create()
dialog.show()
}
}
if (ContextCompat.checkSelfPermission(
this,
Manifest.permission.POST_NOTIFICATIONS,
) != PackageManager.PERMISSION_GRANTED && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
) {
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
} else {
startMain()
}

}

private fun startMain() {
Shell.getShell { shell ->
if (!shell.isRoot) {
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder.setTitle("Root Required")
builder.setMessage("Please root your device and grant su permission first.")
builder.setPositiveButton("Exit") { _, _ ->
finish()
}

val dialog: AlertDialog = builder.create()
dialog.show()
return@getShell
}

copyAssets()

val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}
}

@Throws(IOException::class)
private fun copyFile(`in`: InputStream, out: OutputStream) {
val buffer = ByteArray(1024)
var read: Int
while (`in`.read(buffer).also { read = it } != -1) {
out.write(buffer, 0, read)
}
}

private fun copyAssets() {
val assetManager = assets
var files: Array<String>? = null
val abi = Build.SUPPORTED_ABIS[0]
val arch = if (abi.matches("armeabi-v7a|arm64-v8a".toRegex())) "armeabi-v7a" else "x86"

files = assetManager.list(arch)

if (files != null) {
for (file in files) {
try {
val inFile = assetManager.open("${arch}/$file")
val outFile = FileOutputStream("${filesDir.absolutePath}/${file}")
copyFile(inFile, outFile)
inFile.close()
outFile.flush()
outFile.close()
} catch (e: IOException) {
Log.e("tag", "Failed to copy asset file: $file", e)
}
}
}
}
}
Loading

0 comments on commit dc910cb

Please sign in to comment.