29 Mayıs 2015 Cuma

Prevent Mobile Apps Hacking In-App Values

Most of users are not smart enough. Most of them using some hacking apps and searchs some values in memory and change.

Using some tricks will be effective for most users.


  • Use fake variables
  • Use temp modified variables

Sample:


 public int[] XValue = new int[200];
 public int CValue = 0;

These variables keep coins. CValue is real variable.

When coins increase use ApplyCoins method.

public void ApplyCoins(int pCoins)
        {
            CValue += pCoins * 8;
            for (int i = 0; i < 200; i++)
                XValue[i] = CValue;
            for (int i = 50; i < 100; i++)
                XValue[i] = CValue / 8;
        }

Get the real coins value.

 public int GetCoins()
        {
            return CValue / 8;
        }

When user search the coins value lots of fake variables will be listed.

This is not best way for prevent hacking but most of user will be eliminated.

Xamarin Android Admob Banners and InterstitialAds

Here is the sample for Admob elements in xamarin android apps.

First, you need Google Play Services

https://components.xamarin.com/view/googleplayservices/

AndroidManifest.xml

<application>....
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
.....
</application>
   Also add INTERNET and ACCESS_NETWORK_STATE permissions.

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

Monogame Activity

[Activity(Label = "Sample Admob App"
          , MainLauncher = true
          , Icon = "@drawable/ic_launcher"
          , Theme = "@style/Theme.Splash"
          , AlwaysRetainTaskState = true
          , LaunchMode = Android.Content.PM.LaunchMode.SingleTop
          , ScreenOrientation = ScreenOrientation.Portrait
          , ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize)]
    public class TestActivity : Microsoft.Xna.Framework.AndroidGameActivity
    {
        private AdView ad;    
        private static InterstitialAd interstitial;
        private string addid = "YOUR ADMOB ID";
        private LinearLayout ll;
        private FrameLayout fl;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            var g = new Engine.GameEngine();
            //Game engine activity variable
            g.activity = this;          
            //Create interstital ad view
            interstitial = AdWrapper.ConstructFullPageAdd(this, addid);
            //Create FrameLayout
            fl = new FrameLayout(this);
            fl.AddView((View)g.Services.GetService(typeof(View)));
            SetContentView(fl);
            g.Run();
         
        }

        public void ShowInterstitialAd()
        {
            RunOnUiThread(() =>
            {
                if (interstitial.AdListener != null)
                    interstitial.AdListener.Dispose();
                interstitial.AdListener = null;
                var intlistener = new AdMob.adlistener();
                intlistener.AdLoaded += () => { if (interstitial.IsLoaded)interstitial.Show(); };
                interstitial.AdListener = intlistener;

                interstitial.CustomBuild();
            });
        }

        public void HideBannerAd()
        {
            if (ll != null)
            {
                fl.RemoveView(ll);
                ll.RemoveView(ad);
                ad.Dispose();
                ad = null;
                ll.Dispose();
                ll = null;
            }
        }
        public void RefreshBannerAd()
        {      
            if (ll == null)
            {
                HideBannerAd();
                ll = new LinearLayout(this);
                ll.Orientation = Orientation.Horizontal;          
                ll.SetGravity(GravityFlags.Bottom | GravityFlags.Center);

                ad = new AdView(this);
                ad.AdSize = AdSize.Banner;
                ad.AdUnitId = addid;
                ll.AddView(ad);
                fl.AddView(ll);
            }
            using (var requestbuilder = new AdRequest.Builder())
            {
                ad.LoadAd(requestbuilder.Build());
            }
        }

    }


AdWrapper


namespace AdMob
{

    public static class AdWrapper
    {
        public static InterstitialAd ConstructFullPageAdd(Context con, string UnitID)
        {
            var ad = new InterstitialAd(con);
            ad.AdUnitId = UnitID;
            return ad;
        }
        public static AdView ConstructStandardBanner(Context con, AdSize adsize, string UnitID)
        {
            var ad = new AdView(con);
            ad.AdSize = adsize;
            ad.AdUnitId = UnitID;
            return ad;
        }

        public static InterstitialAd CustomBuild(this InterstitialAd ad)
        {
         
            var requestbuilder = new AdRequest.Builder();
       
            ad.LoadAd(requestbuilder.Build());
            return ad;
        }
        public static AdView CustomBuild(this AdView ad)
        {
            var requestbuilder = new AdRequest.Builder();
            ad.LoadAd(requestbuilder.Build());
            return ad;
        }
    }
}


AdListener

namespace AdMob
{
    class adlistener : AdListener
    {
        // Declare the delegate (if using non-generic pattern).
        public delegate void AdLoadedEvent();
        public delegate void AdClosedEvent();
        public delegate void AdOpenedEvent();



        // Declare the event.
        public event AdLoadedEvent AdLoaded;
        public event AdClosedEvent AdClosed;
        public event AdOpenedEvent AdOpened;
        public event AdClosedEvent AdFailed;
        public override void OnAdFailedToLoad(int p0)
        {
            if (AdFailed != null) this.AdFailed();
            base.OnAdFailedToLoad(p0);
        }
        public override void OnAdLoaded()
        {
            if (AdLoaded != null) this.AdLoaded();
            base.OnAdLoaded();
        }

        public override void OnAdClosed()
        {
            if (AdClosed != null) this.AdClosed();
            base.OnAdClosed();
        }
        public override void OnAdOpened()
        {
            if (AdOpened != null) this.AdOpened();
            base.OnAdOpened();
        }
    }
}