package com.lahm.library;
import
android.content.Context;
import
android.content.Intent;
import
android.content.IntentFilter;
import
android.content.pm.PackageManager.NameNotFoundException;
import
android.content.pm.Signature;
import
android.os.Debug;
import
android.os.Process;
import
java.io.BufferedReader;
import
java.io.
File
;
import
java.io.FileReader;
import
java.io.IOException;
import
java.lang.reflect.Field;
import
java.net.InetAddress;
import
java.net.Socket;
import
java.net.UnknownHostException;
import
java.util.HashSet;
import
java.util.Iterator;
public
class
i {
static
class
b {
private static final i a;
static {
b.a
=
new i(null);
}
}
private static final String a
=
"de.robv.android.xposed.XposedHelpers"
;
private static final String b
=
"de.robv.android.xposed.XposedBridge"
;
private i() {
}
i(com.lahm.library.i.a arg1) {
}
public String getAppMetaData(Context arg1, String arg2) {
return
arg1.getApplicationInfo().metaData.getString(arg2);
}
public boolean isDebuggerConnected() {
/
/
检测调试器是否连接
return
Debug.isDebuggerConnected();
}
public boolean isPortAvailable(
int
arg2) {
/
/
检测端口是否被占用,可用于反调试、反hook
try
{
return
this.isNetAddressAvailable(
"127.0.0.1"
, arg2);
}
catch(Exception unused_ex) {
return
true;
}
}
public boolean isApkDebuggable(Context arg1) {
/
/
检测apk:debuggable属性是否为true
return
(arg1.getApplicationInfo().flags &
2
) !
=
0
;
}
public boolean isLibOrJarLoaded(String arg6) {
/
/
检测加载的jar
/
so库
try
{
HashSet v0
=
new HashSet();
BufferedReader v1
=
new BufferedReader(new FileReader(
"/proc/"
+
Process.myPid()
+
"/maps"
));
while
(true) {
String v2
=
v1.readLine();
if
(v2 !
=
null) {
goto label_34;
}
v1.close();
Iterator v0_1
=
v0.iterator();
while
(true) {
label_24:
if
(!v0_1.hasNext()) {
return
false;
}
Object
v1_1
=
v0_1.
next
();
if
(!((String)v1_1).contains(arg6)) {
goto label_24;
}
return
true;
label_34:
if
(!v2.endsWith(
".so"
) && !v2.endsWith(
".jar"
)) {
break
;
}
v0.add(v2.substring(v2.lastIndexOf(
" "
)
+
1
));
break
;
}
}
}
catch(Exception unused_ex) {
return
false;
}
}
public boolean isNetAddressAvailable(String arg2,
int
arg3) throws UnknownHostException {
InetAddress v2
=
InetAddress.getByName(arg2);
/
/
检测网络地址是否可用
try
{
new Socket(v2, arg3);
return
true;
}
catch(IOException unused_ex) {
return
false;
}
}
public boolean isDeviceRooted() {
/
/
检测设备是否root,里面两个函数的实现在下面
return
this.isDeviceRootedByRoSecure()
=
=
0
? true : this.isDeviceRootedByFile();
}
public boolean isEmulatorByBattery(Context arg4) {
/
/
通过检查电量检测模拟器
Intent v4
=
arg4.registerReceiver(null, new IntentFilter(
"android.intent.action.BATTERY_CHANGED"
));
return
v4
=
=
null ? false : v4.getIntExtra(
"plugged"
,
-
1
)
=
=
2
;
}
public String getPackageSignature(Context arg5) {
/
/
获取签名
try
{
Signature[] v5_1
=
arg5.getPackageManager().getPackageInfo(arg5.getPackageName(),
0x40
).signatures;
StringBuilder v0
=
new StringBuilder();
int
v2;
for
(v2
=
0
; v2 < v5_1.length;
+
+
v2) {
v0.append(v5_1[v2].toCharsString());
}
return
v0.toString();
}
catch(PackageManager.NameNotFoundException v5) {
v5.printStackTrace();
return
"";
}
}
public boolean isXposedExistByStack() {
/
/
通过异常栈检测Xposed框架
try
{
throw new Exception(
"gg"
);
}
catch(Exception v0) {
StackTraceElement[] v0_1
=
v0.getStackTrace();
int
v3;
for
(v3
=
0
; v3 < v0_1.length;
+
+
v3) {
if
(v0_1[v3].getClassName().contains(
"de.robv.android.xposed.XposedBridge"
)) {
return
true;
}
}
return
false;
}
}
@Deprecated
public boolean isXposedExistByClassLoader() {
/
/
通过类加载检测Xposed框架
try
{
ClassLoader.getSystemClassLoader().loadClass(
"de.robv.android.xposed.XposedHelpers"
).newInstance();
}
catch(InstantiationException v0_1) {
v0_1.printStackTrace();
return
true;
}
catch(IllegalAccessException v0) {
v0.printStackTrace();
return
true;
}
catch(ClassNotFoundException v1) {
v1.printStackTrace();
return
false;
}
try
{
ClassLoader.getSystemClassLoader().loadClass(
"de.robv.android.xposed.XposedBridge"
).newInstance();
return
true;
}
catch(InstantiationException v0_3) {
v0_3.printStackTrace();
return
true;
}
catch(IllegalAccessException v0_2) {
v0_2.printStackTrace();
return
true;
}
catch(ClassNotFoundException v1_1) {
v1_1.printStackTrace();
return
false;
}
}
public boolean isDebuggingByTarcePid() {
/
/
通过TracePid检测程序是否出于被调试状态
try
{
BufferedReader v1
=
new BufferedReader(new FileReader(
"/proc/"
+
Process.myPid()
+
"/status"
));
String v2
=
"";
do {
label_17:
String v3
=
v1.readLine();
if
(v3.contains(
"TracerPid"
)) {
v2
=
v3.substring(v3.indexOf(
":"
)
+
1
, v3.length()).trim();
}
else
if
(v3 !
=
null) {
goto label_17;
}
break
;
}
while
(true);
v1.close();
return
!
"0"
.equals(v2);
}
catch(Exception unused_ex) {
return
false;
}
}
public boolean disableXposed() {
/
/
disable xposed
try
{
Field v1_3
=
ClassLoader.getSystemClassLoader().loadClass(
"de.robv.android.xposed.XposedBridge"
).getDeclaredField(
"disableHooks"
);
v1_3.setAccessible(true);
v1_3.
set
(null, Boolean.TRUE);
return
true;
}
catch(NoSuchFieldException v1_2) {
v1_2.printStackTrace();
return
false;
}
catch(ClassNotFoundException v1_1) {
v1_1.printStackTrace();
return
false;
}
catch(IllegalAccessException v1) {
v1.printStackTrace();
return
false;
}
}
public static final i getInstance() {
return
b.a;
}
private
int
isDeviceDebuggable() {
/
/
ro.debuggable为
1
的设备可以调试任何应用,即时应用的debuggable属性为false
String v0
=
c.a().b(
"ro.debuggable"
);
return
v0
=
=
null || !
"0"
.equals(v0) ?
1
:
0
;
}
private
int
isDeviceRootedByRoSecure() {
/
/
检测ro.secure
String v0
=
c.a().b(
"ro.secure"
);
return
v0
=
=
null || !
"0"
.equals(v0) ?
1
:
0
;
}
private boolean isDeviceRootedByFile() {
/
/
通过文件检测设备是否root
String[] v0
=
{
"/sbin/su"
,
"/system/bin/su"
,
"/system/xbin/su"
,
"/data/local/xbin/su"
,
"/data/local/bin/su"
,
"/system/sd/xbin/su"
,
"/system/bin/failsafe/su"
,
"/data/local/su"
};
int
v3;
for
(v3
=
0
; v3 < v0.length;
+
+
v3) {
if
(new
File
(v0[v3]).exists()) {
return
true;
}
}
return
false;
}
}