package com.kuaishou.weapon.p0; import android.content.Context; import android.os.Build; import android.os.Process; import android.text.TextUtils; import com.mbridge.msdk.playercommon.exoplayer2.extractor.ogg.DefaultOggSeeker; import java.io.BufferedReader; import java.io.File; import java.io.FileDescriptor; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.lang.reflect.Field; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Collection; import java.util.HashSet; import java.util.Map; import org.json.JSONArray; public class d0 { private String a(int i, int i2) { StringBuilder sb; String str; if (i2 < 26) { return "u:r:untrusted_app"; } if (i >= i2) { sb = new StringBuilder(); } else { if (i < 26) { sb = new StringBuilder(); sb.append("u:r:untrusted_app"); str = "_25:s0"; } else { if (i2 != 27) { if (i2 == 28 || i2 == 29) { if (i >= 26) { sb = new StringBuilder(); } } else if (i2 == 30) { if (i >= 29) { sb = new StringBuilder(); sb.append("u:r:untrusted_app"); str = "_29:s0"; } else { sb = new StringBuilder(); } } sb.append("u:r:untrusted_app"); sb.append("_27:s0"); return sb.toString(); } else if (i >= 26) { sb = new StringBuilder(); } return "u:r:untrusted_app"; } sb.append(str); return sb.toString(); } sb.append("u:r:untrusted_app"); sb.append(":s0"); return sb.toString(); } /* JADX WARNING: Code restructure failed: missing block: B:47:0x00b1, code lost: if (r3 == null) goto L_0x00b7; */ public JSONArray a(Context context) { BufferedReader bufferedReader; String substring; try { bufferedReader = new BufferedReader(new FileReader("/proc/self/maps")); try { HashSet hashSet = new HashSet(); String packageName = context.getPackageName(); while (true) { String readLine = bufferedReader.readLine(); if (readLine != null) { if (!readLine.contains("@Hw") && !readLine.contains(".apk@classes.dex") && !readLine.contains("WebViewGoogle") && !readLine.contains("FeatureFramework") && !readLine.contains("framework@oppo") && !readLine.contains("framework@mediatek")) { if (hashSet.size() > 15) { break; } if (!readLine.contains(packageName) && readLine.contains("/data/") && readLine.contains(".so")) { substring = readLine.substring(readLine.indexOf("/data/"), readLine.indexOf(".so") + 3); } else if (!readLine.contains(packageName) && readLine.contains("/data/") && readLine.contains(".dex")) { substring = readLine.substring(readLine.indexOf("/data/"), readLine.indexOf(".dex") + 4); } hashSet.add(substring); } } else { break; } } if (hashSet.size() > 0) { JSONArray jSONArray = new JSONArray((Collection) hashSet); try { bufferedReader.close(); } catch (IOException unused) { } return jSONArray; } } catch (Throwable unused2) { } } catch (Throwable unused3) { bufferedReader = null; } try { bufferedReader.close(); } catch (IOException unused4) { } return null; } public boolean a() { return Process.myUid() / DefaultOggSeeker.MATCH_BYTE_RANGE != 0; } public String b(Context context) { try { Object invoke = Class.forName("android.app.ActivityThread").getMethod("currentActivityThread", new Class[0]).invoke(null, new Object[0]); Field declaredField = invoke.getClass().getDeclaredField("mPackages"); declaredField.setAccessible(true); Map map = (Map) declaredField.get(invoke); if (map != null && map.size() > 0) { for (Object obj : map.keySet()) { if (obj.toString().length() > 1 && !obj.toString().equals(context.getPackageName())) { File file = new File("/data/data" + File.separator + obj.toString()); if (file.exists() && file.canWrite()) { return obj.toString(); } } } } } catch (Throwable unused) { } return null; } public String c(Context context) { try { return context.getFilesDir().getParentFile().getAbsolutePath(); } catch (Throwable unused) { return ""; } } public boolean d(Context context) { try { String absolutePath = context.getFilesDir().getParentFile().getAbsolutePath(); return new File(absolutePath + File.separator + "..").canRead(); } catch (Throwable unused) { return false; } } public boolean e(Context context) { try { int i = context.getApplicationInfo().targetSdkVersion; Class<?> cls = Class.forName("android.os.SELinux"); String str = (String) cls.getDeclaredMethod("getContext", new Class[0]).invoke(cls, new Object[0]); return !TextUtils.isEmpty(str) && !str.startsWith(a(i, Build.VERSION.SDK_INT)); } catch (Exception unused) { return false; } } /* JADX WARNING: Removed duplicated region for block: B:31:0x00d7 A[SYNTHETIC, Splitter:B:31:0x00d7] */ public int f(Context context) { FileOutputStream fileOutputStream; try { if (Build.VERSION.SDK_INT < 26) { return d(context) ? 1 : 0; } String str = "fk_w_" + System.currentTimeMillis(); fileOutputStream = new FileOutputStream(context.getFilesDir().getParentFile().getAbsolutePath() + File.separator + str); try { FileDescriptor fd = fileOutputStream.getFD(); Field declaredField = fd.getClass().getDeclaredField("descriptor"); declaredField.setAccessible(true); declaredField.get(fd); String absolutePath = Files.readSymbolicLink(Paths.get(String.format("/proc/self/fd/%d", Integer.valueOf(((Integer) declaredField.get(fd)).intValue())), new String[0])).toFile().getAbsolutePath(); if (!absolutePath.substring(absolutePath.lastIndexOf(File.separator)).equals(File.separator + str)) { try { fileOutputStream.close(); } catch (Exception unused) { } return 1; } boolean canRead = new File(absolutePath.replace(str, "")).getParentFile().canRead(); File file = new File(absolutePath); if (file.exists()) { file.delete(); } if (canRead) { try { fileOutputStream.close(); } catch (Exception unused2) { } return 1; } try { fileOutputStream.close(); } catch (Exception unused3) { } return 0; } catch (Throwable unused4) { if (fileOutputStream != null) { } return 0; } } catch (Throwable unused5) { fileOutputStream = null; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (Exception unused6) { } } return 0; } } }