/*## (c) SECURITY EXPLORATIONS    2018 poland                                #*/
/*##     http://www.security-explorations.com                                #*/

/* THIS SOFTWARE IS PROTECTED BY DOMESTIC AND INTERNATIONAL COPYRIGHT LAWS    */
/* UNAUTHORISED COPYING OF THIS SOFTWARE IN EITHER SOURCE OR BINARY FORM IS   */
/* EXPRESSLY FORBIDDEN. ANY USE, INCLUDING THE REPRODUCTION, MODIFICATION,    */
/* DISTRIBUTION, TRANSMISSION, RE-PUBLICATION, STORAGE OR DISPLAY OF ANY      */
/* PART OF THE SOFTWARE, FOR COMMERCIAL OR ANY OTHER PURPOSES REQUIRES A      */
/* VALID LICENSE FROM THE COPYRIGHT HOLDER.                                   */

/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS    */
/* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,*/
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    */
/* SECURITY EXPLORATIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  */
/* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE     */
/* SOFTWARE.                                                                  */

import java.lang.*;
import java.lang.reflect.*;

public class Spoof {
 public static class Setter implements DaemonThread.Code {
  public void run(Object args[]) {
   while(true) {
    try {
     set_cardaddr_internal(cardaddr);

     Thread.currentThread().sleep(1000);
    } catch(Throwable t) {}
   }
  }
 }

 static String cardaddr;

 static String mac;
 static String sn;

 public static boolean has_mac() {
  return mac!=null;
 }

 public static boolean has_sn() {
  return sn!=null;
 }

 public static String get_mac() {
  return mac;
 }

 public static String get_sn() {
  return sn;
 }

 public static void set_mac(String macaddr) {
  mac=macaddr;
  STBIsolate.PropsMonitor.start();
 }

 public static void set_sn(String snumber) {
  sn=snumber;
  STBIsolate.PropsMonitor.start();
 }

 public static boolean should_spoof(String prop) {
  if (prop.equals("sn")) {
   return has_sn();
  } else

  if (prop.equals("mac.STB.Eth.Ethernet")) {
   return has_mac();
  }

  return false;
 }

 public static String get_prop(String prop) {
  if (prop.equals("sn")) {
   return sn;
  } else

  if (prop.equals("mac.STB.Eth.Ethernet")) {
   return mac;
  }

  return "";
 }

 public static void set_cardaddr(String addr) {
  try {
   boolean first_time=false;

   if (cardaddr==null) {
    first_time=true;
   }

   cardaddr=addr;

   if (first_time) {
    Setter s=new Setter();
    DaemonThread.start(s,null);
   }
  } catch(Throwable t) {}
 }

 public static void set_cardaddr_internal(String addr) {
  try {
   Class c=Class.forName("a.ej.F");
//   ApiMonitor.log("c "+c);

   Method getInstance=c.getMethod("getInstance",new Class[0]);
   Object f_inst=getInstance.invoke(null,new Object[0]);

//   ApiMonitor.log("f "+f_inst);

   Field f=c.getDeclaredField("aZB");
   f.setAccessible(true);

   f.set(f_inst,addr);
  } catch(Throwable t) {}
 }

 public static String get_ivodurl() {
  String vodurl=null;

  try {
   System.setSecurityManager(null);

   Class c=Class.forName("a.dg.b");
   ApiMonitor.log("class: "+c);

   Object obj=c.newInstance();
   ApiMonitor.log("obj: "+obj);

   Method getvodurl=c.getDeclaredMethod("aJD",new Class[0]);
   getvodurl.setAccessible(true);

   vodurl=(String)getvodurl.invoke(obj,new Object[0]);
  } catch(Throwable t) {}

  return vodurl;
 }

 public static void set_ivodurl(String vodurl) {
  try {
   System.setSecurityManager(null);

   Class c=Class.forName("a.bk.h");
   ApiMonitor.log("class: "+c);

   Method getinst=c.getMethod("getInstance",new Class[0]);

   Object obj=getinst.invoke(null,new Object[0]);
   ApiMonitor.log("obj: "+obj);

   Class ctab[]=new Class[2];
   ctab[0]=Class.forName("java.lang.String");
   ctab[1]=Class.forName("java.lang.String");

   Method setval=c.getMethod("setValue",ctab);

   Object args[]=new Object[2];
   args[0]="internetVodUrlWebkitApolloEnhanced";
   args[1]=vodurl;

   setval.invoke(obj,args);
  } catch(Throwable t) {}
 }
}
