Skip to content

Commit

Permalink
feat:对无网络功能的情况在日志中提示
Browse files Browse the repository at this point in the history
  • Loading branch information
pengboli committed Jun 23, 2021
1 parent a541e01 commit b5862f0
Showing 1 changed file with 33 additions and 42 deletions.
75 changes: 33 additions & 42 deletions app/src/main/java/leon/qujing/XposedEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ public void initZygote(StartupParam startupParam) throws Throwable {
}
}

private boolean isNeedHook(){
try {
HttpURLConnection connection = null;
BufferedReader reader = null;
URL url = new URL("http://127.0.0.1:61000/querytargetapp");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(1000);
connection.setReadTimeout(1000);
InputStream in = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(in));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
String TargetAppsStr = result.toString();
return TargetAppsStr.contains(XposedEntry.packageName + ";");
}
catch (Exception e){
XposedBridge.log("isNeedHook Exception:"+e.getMessage());
XposedBridge.log("被注入应用如果没有网络权限,曲境将无法运行");
return false;
}
}

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if(loadPackageParam.packageName.equals(StartupAPP))
Expand All @@ -68,60 +94,25 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam)
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {

Context context = (Context) param.args[0];

classLoader = context.getClassLoader();
new Thread(new Runnable() {
@Override
public void run() {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL("http://127.0.0.1:61000/querytargetapp");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(1000);
connection.setReadTimeout(1000);
InputStream in = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(in));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
String TargetAppsStr = result.toString();
if (TargetAppsStr.contains(XposedEntry.packageName + ";"))
{
int pid = Process.myPid();
new QuJingServer(pid);
XposedBridge.log("QuJingServer Listening @:"+ pid +" packageName: "+XposedEntry.packageName);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (connection != null) {//关闭连接
connection.disconnect();
}
boolean isHook = isNeedHook();
XposedBridge.log(XposedEntry.packageName + " isHook: "+isHook);
if (isHook) {
int pid = Process.myPid();
new QuJingServer(pid);
XposedBridge.log("QuJingServer Listening @:"+ pid +" packageName: "+XposedEntry.packageName);
}
}
}).start();
XposedBridge.log("Thread start");
}
});
}


private void gatherInfo(XC_LoadPackage.LoadPackageParam loadPackageParam) {
packageName = loadPackageParam.packageName;
isFirstApplication = loadPackageParam.isFirstApplication;
Expand Down

0 comments on commit b5862f0

Please sign in to comment.