com.panda912.defensor.plugin.utils.Const.kt Maven / Gradle / Ivy
package com.panda912.defensor.plugin.utils
import org.objectweb.asm.Type
import java.io.File
/**
* Created by panda on 2021/8/13 17:25
*/
const val DOT_CLASS = ".class"
const val BOOLEAN_CLASS = "java.lang.Boolean"
const val BYTE_CLASS = "java.lang.Byte"
const val SHORT_CLASS = "java.lang.Short"
const val INTEGER_CLASS = "java.lang.Integer"
const val LONG_CLASS = "java.lang.Long"
const val FLOAT_CLASS = "java.lang.Float"
const val DOUBLE_CLASS = "java.lang.Double"
const val STRING_CLASS = "java.lang.String"
const val CHAR_SEQUENCE_CLASS = "java.lang.CharSequence"
const val LIST_CLASS = "java.util.List"
const val ARRAY_LIST_CLASS = "java.util.ArrayList"
const val LINKED_LIST_CLASS = "java.util.LinkedList"
const val COPY_ON_WRITE_ARRAY_LIST_CLASS = "java.util.concurrent.CopyOnWriteArrayList"
const val MAP_CLASS = "java.util.Map"
const val HASHMAP_CLASS = "java.util.HashMap"
const val ARRAYMAP_CLASS = "java.util.ArrayMap"
const val CONCURRENT_HASHMAP_CLASS = "java.util.concurrent.ConcurrentHashMap"
const val JSONOBJECT_CLASS = "org.json.JSONObject"
const val JSONARRAY_CLASS = "org.json.JSONArray"
const val CONTEXT_CLASS = "android.content.Context"
const val INTENT_CLASS = "android.content.Intent"
const val DIALOG_CLASS = "android.app.Dialog"
const val VIEW_CLASS = "android.view.View"
const val TEXTVIEW_CLASS = "android.widget.TextView"
const val APPCOMPAT_TEXTVIEW_CLASS = "androidx.appcompat.widget.AppCompatTextView"
const val IMAGEVIEW_CLASS = "android.widget.ImageView"
const val APPCOMPAT_IMAGEVIEW_CLASS = "androidx.appcompat.widget.AppCompatImageView"
const val INTENT_DEFENSOR = "com.panda912.defensor.internal.IntentDefensor"
const val COLLECTION_DEFENSOR = "com.panda912.defensor.internal.CollectionDefensor"
const val STRING_DEFENSOR = "com.panda912.defensor.internal.StringDefensor"
const val PRIMITIVE_TYPE_PARSER = "com.panda912.defensor.internal.PrimitiveTypeParser"
const val SAFE_DIALOG = "com.panda912.defensor.internal.SafeDialog"
const val SECURITY_CRASH_HANDLER = "com.panda912.defensor.internal.SecurityCrashHandler"
const val JSON_DEFENSOR = "com.panda912.defensor.internal.JsonDefensor"
const val NULL_POINTER_EXCEPTION_DEFENSOR =
"com.panda912.defensor.internal.NullPointerExceptionDefensor"
const val CAST_EXCEPTION_HANDLER = "com.panda912.defensor.CastExceptionHandler"
const val DEAD_OBJECT_CRASH_HANDLER = "com.panda912.defensor.DeadObjectCrashHandler"
const val ILLEGAL_ARGUMENT_CRASH_HANDLER = "com.panda912.defensor.IllegalArgumentCrashHandler"
const val INDEX_OUT_OF_BOUND_CRASH_HANDLER = "com.panda912.defensor.IndexOutOfBoundCrashHandler"
const val SAFE_COLLECTIONS = "com.panda912.defensor.SafeCollections"
const val RESTRICTED_TELEPHONY_MANAGER = "com.panda912.defensor.RestrictedTelephonyManager"
const val SAFE_UNBOXING_UTILS = "com.panda912.defensor.SafeUnboxingUtils"
const val TELEPHONY_MANAGER_TRANSITION = "com.panda912.defensor.TelephonyManagerTransition"
const val UNSUPPORTED_OPERATION_CRASH_HANDLER =
"com.panda912.defensor.UnsupportedOperationCrashHandler"
val DEFENSOR_CLASS_LIST = listOf(
CAST_EXCEPTION_HANDLER,
DEAD_OBJECT_CRASH_HANDLER,
ILLEGAL_ARGUMENT_CRASH_HANDLER,
INDEX_OUT_OF_BOUND_CRASH_HANDLER,
INTENT_DEFENSOR,
JSON_DEFENSOR,
SAFE_COLLECTIONS,
PRIMITIVE_TYPE_PARSER,
RESTRICTED_TELEPHONY_MANAGER,
SAFE_UNBOXING_UTILS,
SECURITY_CRASH_HANDLER,
TELEPHONY_MANAGER_TRANSITION,
UNSUPPORTED_OPERATION_CRASH_HANDLER
).map {
it.toInternalName().toClass()
}
fun String.toInternalName() = replace('.', '/')
fun String.toClassName() = replace('/', '.')
fun String.toClass() = this + DOT_CLASS
fun File.isDefensorClass() = DEFENSOR_CLASS_LIST.indexOfFirst { this.endsWith(it) } != -1
const val DESCRIPTOR_GET_BOOLEAN = "(Ljava/lang/String;Z)Z"
const val DESCRIPTOR_GET_BYTE = "(Ljava/lang/String;B)B"
const val DESCRIPTOR_GET_CHAR = "(Ljava/lang/String;C)C"
const val DESCRIPTOR_GET_SHORT = "(Ljava/lang/String;S)S"
const val DESCRIPTOR_GET_INT = "(Ljava/lang/String;I)I"
const val DESCRIPTOR_GET_LONG = "(Ljava/lang/String;J)J"
const val DESCRIPTOR_GET_FLOAT = "(Ljava/lang/String;F)F"
const val DESCRIPTOR_GET_DOUBLE = "(Ljava/lang/String;D)D"
const val DESCRIPTOR_GET_STRING = "(Ljava/lang/String;)Ljava/lang/String;"
const val DESCRIPTOR_GET_PARCELABLE = "(Ljava/lang/String;)Ljava/lang/String;"
const val DESCRIPTOR_PUT_EXTRA =
"(Ljava/lang/String;Ljava/io/Serializable;)Landroid/content/Intent;"
fun String.intentDescriptor() =
StringBuilder(this).insert(1, "Landroid/content/Intent;").toString()
fun String.listDescriptor() =
StringBuilder(this).insert(1, Type.getDescriptor(java.util.List::class.java)).toString()
fun String.mapDescriptor() =
StringBuilder(this).insert(1, Type.getDescriptor(java.util.Map::class.java)).toString()
fun String.stringDescriptor() =
StringBuilder(this).insert(1, Type.getDescriptor(java.lang.String::class.java)).toString()
fun String.charSequenceDescriptor() =
StringBuilder(this).insert(1, Type.getDescriptor(java.lang.CharSequence::class.java)).toString()
fun String.convertDescriptor(descriptor: String) =
StringBuilder(this).insert(1, descriptor).toString()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy