Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Aug 25, 2023
1 parent 8333c67 commit df2696c
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .idea/misc.xml

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

54 changes: 54 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
id('com.android.application')
id('org.jetbrains.kotlin.android')
}

android {
namespace 'com.chrxw.purenga'
compileSdk = 33

buildFeatures {
buildConfig = true
}

defaultConfig {
applicationId = "com.chrxw.purenga"
minSdk = 24
targetSdk = 33
versionCode = 10
versionName = "1.7.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
proguardFiles
}

buildTypes {
release {
minifyEnabled = false
proguardFiles(
getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
buildToolsVersion = '33.0.1'
}

dependencies {
compileOnly('de.robv.android.xposed:api:82')

implementation('androidx.core:core-ktx:1.9.0')
implementation('androidx.appcompat:appcompat:1.6.1')
implementation('com.google.android.material:material:1.8.0')
implementation('androidx.preference:preference:1.2.0')
testImplementation('junit:junit:4.13.2')
androidTestImplementation('androidx.test.ext:junit:1.1.5')
androidTestImplementation('androidx.test.espresso:espresso-core:3.5.1')
}
11 changes: 6 additions & 5 deletions app/build.gradle.kts → app/build.gradle.kts.bak
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ android {

buildTypes {
named("release") {
isShrinkResources = true
isMinifyEnabled = true
proguardFiles("proguard-rules.pro")
isShrinkResources = false
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
Expand All @@ -48,8 +51,6 @@ android {
}

dependencies {
implementation("com.highcapable.yukihookapi:api:1.1.11")
implementation("com.highcapable.yukihookapi:ksp-xposed:1.1.11")
compileOnly("de.robv.android.xposed:api:82")

implementation("androidx.core:core-ktx:1.10.1")
Expand Down
44 changes: 40 additions & 4 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,50 @@
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

## 保留Xposed入口
#-keep class com.chrxw.purenga.XposedInit {*;}
#
## 保留R下面的资源
#-keep class **.R$* {*;}
#
## 抛出异常时保留代码行号
#-keepattributes SourceFile,LineNumberTable
#
## 基本混淆
#-keep class * extends android.app.Activity
#-keepclassmembers enum * {
# public static **[] values();
# public static ** valueOf(java.lang.String);
#}
#
## 保留我们使用的四大组件,自定义的Application等等这些类不被混淆
## 因为这些子类都有可能被外部调用
#-keep public class * extends android.app.Activity
#-keep public class * extends android.preference.Preference
#-keep public class * extends android.view.View
## 保留在Activity中的方法参数是view的方法,
## 这样以来我们在layout中写的onClick就不会被影响
#-keepclassmembers class * extends android.app.Activity{
# public void *(android.view.View);
#}
#
## 保留枚举类不被混淆
#-keepclassmembers enum * {
# public static **[] values();
# public static ** valueOf(java.lang.String);
#}
#
## 对于带有回调函数的onXXEvent、**On*Listener的,不能被混淆
#-keepclassmembers class * {
# void *(**On*Event);
# void *(**On*Listener);
#}
20 changes: 2 additions & 18 deletions app/src/main/java/com/chrxw/purenga/XposedInit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.content.pm.PackageInfo
import android.content.res.Resources
import android.content.res.XModuleResources
import android.widget.Toast
import com.chrxw.purenga.hook.IHook
import com.chrxw.purenga.utils.Helper
import com.chrxw.purenga.utils.Log
import de.robv.android.xposed.IXposedHookLoadPackage
Expand Down Expand Up @@ -55,6 +54,8 @@ class XposedInit : IXposedHookLoadPackage, IXposedHookZygoteInit {

if (Helper.init()) {
Hooks.initHooks(lpparam.classLoader)


if (!Helper.spPlugin.getBoolean(Constant.HIDE_HOOK_INFO, false)) {
Helper.toast("PureNGA 加载成功, 请到【设置】>【PureNGA】开启功能", Toast.LENGTH_LONG)
}
Expand Down Expand Up @@ -92,23 +93,6 @@ class XposedInit : IXposedHookLoadPackage, IXposedHookZygoteInit {
fun getModuleRes(path: String): Resources {
return XModuleResources.createInstance(path, null)
}

fun initHooks(classLoader: ClassLoader, vararg hooks: IHook) {
for (hook in hooks) {
val name = hook.hookName()
try {
Log.i("加载 $name 模块")
hook.init(classLoader)
hook.hook()
} catch (e: NoSuchMethodError) {
Helper.toast("模块 $name 加载失败, 可能不支持当前版本的NGA")
Log.e(e)
} catch (e: Exception) {
Helper.toast("模块 $name 加载遇到未知错误")
Log.e(e)
}
}
}
}
}

Expand Down
17 changes: 8 additions & 9 deletions app/src/main/java/com/chrxw/purenga/hook/PreferencesHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.chrxw.purenga.hook
import android.app.AlertDialog
import android.content.Context
import android.graphics.Color
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
Expand Down Expand Up @@ -42,22 +41,23 @@ class PreferencesHook : IHook {
var btnPureNGASetting: Button? = null

XposedHelpers.findAndHookMethod(clsSettingActivity, "initLayout", object : XC_MethodHook() {
@Throws(Throwable::class)
override fun afterHookedMethod(param: MethodHookParam) {
val viewBinding = XposedHelpers.getObjectField(param.thisObject, "viewBinding")
val root = XposedHelpers.callMethod(viewBinding, "getRoot") as LinearLayout
val scrollView = root.getChildAt(1) as ScrollView
val linearLayout = scrollView.getChildAt(0) as LinearLayout

val context = root.context
val context = param.thisObject as Context

btnPureNGASetting = Button(context).also { btn ->
btn.text = "PureNGA 设置"
btn.setOnClickListener {
val view = generateView(context)
val view = generateView(Helper.context)
// loadSetting(view)
AlertDialog.Builder(view.context).run {
setTitle("PureNGA 设置")
setCancelable(false).setView(view)
setCancelable(false)
setView(view)
setNegativeButton("取消") { _, _ ->
Helper.toast("设置未保存")
}
Expand All @@ -67,7 +67,7 @@ class PreferencesHook : IHook {
}
create().also { dialog ->
val params = dialog.window?.attributes
val metrics = DisplayMetrics()
val metrics = android.util.DisplayMetrics()
dialog.window!!.windowManager.defaultDisplay.getMetrics(metrics)
params?.width = metrics.widthPixels
params?.height = metrics.heightPixels
Expand Down Expand Up @@ -99,16 +99,15 @@ class PreferencesHook : IHook {
* 生成设置界面
*/
fun generateView(context: Context): View {
val view = try {
return try {
throw Exception()
val ctx = context.createPackageContext(BuildConfig.APPLICATION_ID, Context.CONTEXT_IGNORE_SECURITY)
val inflater = LayoutInflater.from(ctx)
inflater.inflate(R.layout.inapp_setting_activity, null)
} catch (e: Throwable) {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
inflater.inflate(XposedInit.moduleRes.getLayout(R.layout.inapp_setting_activity), null)
}
loadSetting(view)
return view
}

private fun loadSetting(view: View) {
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id 'com.android.application' version '8.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
File renamed without changes.
17 changes: 17 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url "https://api.xposed.info/" }
}
}
rootProject.name = "PureNGA"
include ':app'
File renamed without changes.

0 comments on commit df2696c

Please sign in to comment.