Guest User

Untitled

a guest
May 24th, 2021
553
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.vivo.daemonService.i;
  2.  
  3. import android.content.BroadcastReceiver;
  4. import android.content.ContentResolver;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.IntentFilter;
  8. import android.content.pm.PackageInfo;
  9. import android.content.pm.PackageManager;
  10. import android.database.ContentObserver;
  11. import android.net.Uri;
  12. import android.os.Bundle;
  13. import android.os.Handler;
  14. import android.os.Message;
  15. import android.os.ServiceManager;
  16. import android.os.SystemProperties;
  17. import android.text.TextUtils;
  18. import android.util.Log;
  19. import com.vivo.services.daemon.VivoDmServiceProxy;
  20. import java.io.Closeable;
  21. import java.io.IOException;
  22.  
  23. public class a {
  24.   private static final String a = "iptables -t nat -A OUTPUT -p tcp -d %s --dport 80 -j DNAT --to-destination 127.0.0.1:55555";
  25.  
  26.   private static final String b = "hYQ8mkn8EvqhrZtVsldlKLXGfomUHaQMk6+oJzfK2rymmf40pyVvCUBWm2gsaN/PkVVPh7PTR6ZwDVpuSBXvbrR7lm57OvthiylIJ7pC5698nUpCwJ3k0uqoWDEIqE7K3+AR14Eqiid1iHneN7GAnTlxKEomIH/pFwpD6K8u7vv7PfovvoI1TfQFIQ4lWcIHAAu3vsRmqDKwDvE0bKvYDOknB7+fhQ+0wrx9ghB37F0LBEv5N/pEKjGGkFCdGGcaooL2EWOGnLqz3s93Oh9l0q1cdL/Pro3WywK75Nd/u8FdU87PBB3MhONIiT8aPRSZN7YdbjByF6dCLsiF8Z1wqA==?nat?OUTPUT?tcp?%s?80?DNAT?127.0.0.1:55555";
  27.  
  28.   private static final String c = "iptables -t nat -D OUTPUT -p tcp -d %s --dport 80 -j DNAT --to-destination 127.0.0.1:55555";
  29.  
  30.   private static final String d = "WpBVfAqKAG+KrzryJRP/xH1TRx19JnnqH9mjJXtTKqQyW8I5zdT/Opwjd3Qe/yUvspykJt/m11/1vPA9SM2mjknjxU/yxh6v3SCjH0gK5pheKnsMel3Z07rDCmJCQMaNChywgTi9dJnmcyX+p5Rgeb0kjHpXonVzKQEwoPjG+5DCTe5aMH2dlCkLo9EPFZh9aB7bXAnrwrqn2Has4sq3W4w/O05vQiUo2Nceb1JpJ+olZs/YNElrcgQE8BDfQGUmGEfAK+7hJUp2VXyNOj607z//R4DT4FWVK151w71kMSsnCybecWpcTDJ9lkBYt7Lp35eo8f6m8vX3azcuCkfoqQ==?nat?OUTPUT?tcp?%s?80?DNAT?127.0.0.1:55555";
  31.  
  32.   private static final a i = new a();
  33.  
  34.   private d e;
  35.  
  36.   private VivoDmServiceProxy f = VivoDmServiceProxy.asInterface(ServiceManager.getService("vivo_daemon.service"));
  37.  
  38.   private Context g;
  39.  
  40.   private BroadcastReceiver h;
  41.  
  42.   private Handler j = new Handler(this) {
  43.       public void handleMessage(Message param1Message) {
  44.         super.handleMessage(param1Message);
  45.         if (param1Message.what == 1)
  46.           a.b(this.a);
  47.       }
  48.     };
  49.  
  50.   public static a a() {
  51.     return i;
  52.   }
  53.  
  54.   public static void a(Closeable paramCloseable) {
  55.     if (paramCloseable == null)
  56.       return;
  57.     try {
  58.       paramCloseable.close();
  59.     } catch (IOException iOException) {
  60.       Log.e("Hybrid.InterceptManager", "IO Exception", iOException);
  61.     }
  62.   }
  63.  
  64.   private void b() {
  65.     Log.i("Hybrid.InterceptManager", "prepare url intercept.");
  66.     IntentFilter intentFilter = new IntentFilter();
  67.     intentFilter.addAction("com.vivo.daemonService.action.WEB_INTERCEPT");
  68.     this.h = new BroadcastReceiver(this) {
  69.         public void onReceive(Context param1Context, Intent param1Intent) {
  70.           String str = param1Intent.getAction();
  71.           Log.i("Hybrid.InterceptManager", "receive broadcast");
  72.           if (!TextUtils.isEmpty(str)) {
  73.             if (str.equals("com.vivo.daemonService.action.WEB_INTERCEPT"))
  74.               a.a(this.a).sendEmptyMessage(1);
  75.           } else {
  76.             Log.w("Hybrid.InterceptManager", "Null of action.");
  77.           }
  78.         }
  79.       };
  80.     this.g.registerReceiver(this.h, intentFilter);
  81.   }
  82.  
  83.   private void b(Context paramContext) {
  84.     Uri uri = Uri.parse("content://com.vivo.hybrid.hybridData/datas");
  85.     try {
  86.       ContentResolver contentResolver = paramContext.getContentResolver();
  87.       ContentObserver contentObserver = new ContentObserver() {
  88.           public void onChange(boolean param1Boolean) {
  89.             Bundle bundle = this.a.getContentResolver().call(this.b, "get_web_intercept_url_v2", null, null);
  90.             if (bundle != null) {
  91.               String str = (String)bundle.get("get_web_intercept_url_v2");
  92.               if (!TextUtils.isEmpty(str)) {
  93.                 String[] arrayOfString = str.split("\\|");
  94.                 if (arrayOfString != null && arrayOfString.length == 2) {
  95.                   String str1 = arrayOfString[1];
  96.                   String str2 = a.c(this.c);
  97.                   StringBuilder stringBuilder = new StringBuilder();
  98.                   stringBuilder.append("new ip:");
  99.                   stringBuilder.append(str1);
  100.                   stringBuilder.append(" -- old ip: ");
  101.                   stringBuilder.append(str2);
  102.                   Log.i("Hybrid.InterceptManager", stringBuilder.toString());
  103.                   if (!TextUtils.isEmpty(str1) && !str1.equals(str2)) {
  104.                     SystemProperties.set("persist.vivo.ip_v2", str1);
  105.                     this.c.a(str2);
  106.                     a.b(this.c);
  107.                   } else {
  108.                     Log.e("Hybrid.InterceptManager", "Null of domain.");
  109.                   }
  110.                 } else {
  111.                   Log.e("Hybrid.InterceptManager", "Failed to get domain and ip");
  112.                 }
  113.               } else {
  114.                 Log.e("Hybrid.InterceptManager", "Null of bundle infos.");
  115.               }
  116.             } else {
  117.               Log.e("Hybrid.InterceptManager", "Null of bundle.");
  118.             }
  119.           }
  120.         };
  121.       Handler handler = new Handler();
  122.       this();
  123.       super(this, handler, paramContext, uri);
  124.       contentResolver.registerContentObserver(uri, false, contentObserver);
  125.     } catch (Exception exception) {
  126.       Log.e("Hybrid.InterceptManager", "Failed to get web intercept domain.", exception);
  127.     }
  128.   }
  129.  
  130.   private boolean c() {
  131.     return "yes".equals(SystemProperties.get("ro.vivo.product.overseas", "no"));
  132.   }
  133.  
  134.   private boolean d() {
  135.     return "yes".equals(SystemProperties.get("persist.vivo.web_intercept", "no"));
  136.   }
  137.  
  138.   private void e() {
  139.     if (!h()) {
  140.       Log.e("Hybrid.InterceptManager", "Hybrid app is not installed.");
  141.       return;
  142.     }
  143.     if (this.e != null) {
  144.       Log.e("Hybrid.InterceptManager", "mSocketServerThread already started.");
  145.       return;
  146.     }
  147.     if (this.f != null) {
  148.       try {
  149.         Log.d("Hybrid.InterceptManager", "start intercept.");
  150.         d d1 = new d();
  151.         this(this.g.getApplicationContext());
  152.         this.e = d1;
  153.         this.e.start();
  154.         String str2 = g();
  155.         if (i()) {
  156.           str1 = b;
  157.         } else {
  158.           str1 = a;
  159.         }
  160.         String str1 = String.format(str1, new Object[] { str2 });
  161.         str2 = this.f.runShellWithResult(str1);
  162.         StringBuilder stringBuilder = new StringBuilder();
  163.         this();
  164.         stringBuilder.append("cmd: ");
  165.         stringBuilder.append(str1);
  166.         stringBuilder.append(" -- result: ");
  167.         stringBuilder.append(str2);
  168.         Log.d("Hybrid.InterceptManager", stringBuilder.toString());
  169.       } catch (Exception exception) {
  170.         Log.e("Hybrid.InterceptManager", "Error of run shell iptables cmd.", exception);
  171.       }
  172.     } else {
  173.       Log.e("Hybrid.InterceptManager", "Null of mVivoDmServiceProxy.");
  174.     }
  175.   }
  176.  
  177.   private void f() {
  178.     if (SystemProperties.get("persist.vivo.ip_v2").isEmpty())
  179.       SystemProperties.set("persist.vivo.ip_v2", "52.81.126.7");
  180.   }
  181.  
  182.   private String g() {
  183.     return SystemProperties.get("persist.vivo.ip_v2", "52.81.126.7");
  184.   }
  185.  
  186.   private boolean h() {
  187.     PackageManager packageManager = this.g.getPackageManager();
  188.     if (packageManager != null) {
  189.       try {
  190.         PackageInfo packageInfo = packageManager.getPackageInfo("com.vivo.hybrid", 0);
  191.         if (packageInfo != null && packageInfo.versionCode > 0)
  192.           return true;
  193.         Log.e("Hybrid.InterceptManager", "Failed to get package info.");
  194.       } catch (android.content.pm.PackageManager.NameNotFoundException nameNotFoundException) {
  195.         Log.e("Hybrid.InterceptManager", "Failed to get hybrid package name.", (Throwable)nameNotFoundException);
  196.       }
  197.     } else {
  198.       Log.e("Hybrid.InterceptManager", "Failed to get PM.");
  199.     }
  200.     return false;
  201.   }
  202.  
  203.   private boolean i() {
  204.     try {
  205.       String str = SystemProperties.get("persist.vivo.vivo_daemon");
  206.       if (!str.isEmpty()) {
  207.         String[] arrayOfString = str.split("\\.");
  208.         if (Integer.parseInt(arrayOfString[0]) > 3)
  209.           return true;
  210.         if (arrayOfString.length >= 2 && Integer.parseInt(arrayOfString[0]) == 3 && Integer.parseInt(arrayOfString[1]) > 1)
  211.           return true;
  212.         if (arrayOfString.length >= 3 && Integer.parseInt(arrayOfString[0]) == 3 && Integer.parseInt(arrayOfString[1]) == 1 && Integer.parseInt(arrayOfString[2]) >= 0)
  213.           return true;
  214.       } else {
  215.         Log.d("Hybrid.InterceptManager", "Null of prop daemon.");
  216.       }
  217.     } catch (Exception exception) {
  218.       Log.e("Hybrid.InterceptManager", "Failed to get daemon version", exception);
  219.     }
  220.     return false;
  221.   }
  222.  
  223.   public void a(Context paramContext) {
  224.     if (c()) {
  225.       Log.w("Hybrid.InterceptManager", "Oversea product do not support URL jump function.");
  226.       return;
  227.     }
  228.     f();
  229.     this.g = paramContext;
  230.     b();
  231.     b(this.g);
  232.     if (d()) {
  233.       e();
  234.     } else {
  235.       Log.w("Hybrid.InterceptManager", "can not start intercept.");
  236.     }
  237.   }
  238.  
  239.   public void a(String paramString) {
  240.     try {
  241.       if (this.e != null) {
  242.         this.e.a();
  243.         this.e = null;
  244.       }
  245.     } catch (Exception exception) {
  246.       Log.e("Hybrid.InterceptManager", "Exception of stop server socket.", exception);
  247.     }
  248.     if (this.f != null && !TextUtils.isEmpty(paramString)) {
  249.       try {
  250.         String str1;
  251.         if (i()) {
  252.           str1 = d;
  253.         } else {
  254.           str1 = c;
  255.         }
  256.         String str2 = String.format(str1, new Object[] { paramString });
  257.         paramString = this.f.runShellWithResult(str2);
  258.         StringBuilder stringBuilder = new StringBuilder();
  259.         this();
  260.         stringBuilder.append("drop iptables, cmd: ");
  261.         stringBuilder.append(str2);
  262.         stringBuilder.append(" -- result: ");
  263.         stringBuilder.append(paramString);
  264.         Log.d("Hybrid.InterceptManager", stringBuilder.toString());
  265.       } catch (Exception exception) {
  266.         Log.e("Hybrid.InterceptManager", "Error of drop shell iptables cmd.", exception);
  267.       }
  268.     } else {
  269.       Log.e("Hybrid.InterceptManager", "Null of mVivoDmServiceProxy.");
  270.     }
  271.   }
  272. }
  273.  
RAW Paste Data