SkillAgentSearch skills...

PiracyChecker

An Android library that prevents your app from being pirated / cracked using Google Play Licensing (LVL), APK signature protection and more. API 14+ required.

Install / Use

/learn @javiersantos/PiracyChecker
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<h1 align="center">PiracyChecker <a href="https://github.com/javiersantos/PiracyChecker#how-to-include"><img src="https://jitpack.io/v/javiersantos/PiracyChecker.svg"></a></h1> <h4 align="center">Android Library</h4> <p align="center"> <a target="_blank" href="https://android-arsenal.com/api?level=14"><img src="https://img.shields.io/badge/API-14%2B-orange.svg"></a> <a target="_blank" href="https://travis-ci.org/javiersantos/PiracyChecker"><img src="https://travis-ci.org/javiersantos/PiracyChecker.svg?branch=master"></a> <a target="_blank" href="http://android-arsenal.com/details/1/3641"><img src="https://img.shields.io/badge/Android%20Arsenal-PiracyChecker-blue.svg"></a> </p> <p align="center">An Android library that prevents your app from being pirated / cracked using Google Play Licensing (LVL), APK signature protection and more.</p>

<i><p align="center"> Owner & Author: <a target="_blank" href="https://github.com/javiersantos">Javier Santos</a><br> Co-Author: <a target="_blank" href="https://jahirfiquitiva.com/">Jahir Fiquitiva</a>

</p></i>

Disclaimer

This library applies some techniques to help protect your app's users and attempt to thwart reverse engineers and attackers. BUT, this isn't guaranteed to stop your app from getting pirated. There is no such thing as 100% security, and a determined and skilled attacker with enough time, could remove these checks from the code. The real objective here is to raise the bar out of reach of opportunist and automatic attackers.

Some of the techniques included in this library can be found here.

How to include

Add the repository to your project build.gradle:

allprojects {
    repositories {
        maven {
            url "https://jitpack.io"
        }
    }
}

And add the library to your module build.gradle:

AndroidX

dependencies {
    implementation 'com.github.javiersantos:PiracyChecker:1.2.8'
}

Pre AndroidX (no longer supported)

dependencies {
    implementation 'com.github.javiersantos:PiracyChecker:1.2.4'
}

Recommendations

  • Always enable ProGuard in your production release. Always, without exceptions.
  • PiracyChecker should be included in your onCreate method in order to check for a valid license as soon as possible.
  • It's recommended to show a new Activity instead of a Dialog when the license is not valid. This way you make sure that the main activity of the app is finished. See "Display results in a Dialog or a new Activity".
  • Don't forget to enable ProGuard ;)

Usage

Verify Google Play Licensing (LVL)

Google Play offers a licensing service that lets you enforce licensing policies for applications that you publish on Google Play. With Google Play Licensing, your application can query Google Play to obtain the licensing status for the current user.

Any application that you publish through Google Play can use the Google Play Licensing service. No special account or registration is needed.

For more information check out the Google Developers page.

piracyChecker {
	enableGooglePlayLicensing("BASE_64_LICENSE_KEY")
	...
}.start()
<details><summary><b>Java Sample</b></summary>
new PiracyChecker(this)
	.enableGooglePlayLicensing("BASE_64_LICENSE_KEY")
	...
	.start();
</details><br>

In order to retrieve your BASE64 license key your app must be uploaded to the Google Play Developer Console. Then access to your app -> Services and APIs.

When using Google Play Licensing your should call .destroy() in the onDestroy() method of your Activity to avoid multiple instances of the service running. Have a look to the Wiki for a sample Activity with destroy().

Verify your app's signing certificates (signatures)

In a nutshell, developers must sign applications with their private key/certificate (contained in a .keystore file) before the app can be installed on user devices. The signing certificate must stay consistent throughout the life of the app, and typically have an expiry date of 25 years in the future.

The app signatures will be broken if the .apk is altered in any way — unsigned apps cannot typically be installed. We can imagine an attacker removing license-checking code to enable full app features without paying, for instance. A more dangerous example would be altering the .apk to include malware in a legitimate app to harvest sensitive user data. In order for the altered .apk to be installed, the attacker must resign it.

piracyChecker {
	enableSigningCertificates("478yYkKAQF+KST8y4ATKvHkYibo=") // The original APK signature for the PRODUCTION version
	...
}.start()
<details><summary><b>Java Sample</b></summary>
new PiracyChecker(this)
	.enableSigningCertificates("478yYkKAQF+KST8y4ATKvHkYibo=") // The original APK signature for the PRODUCTION version
	...
	.start();
</details><br>

Don't use this method when using Google Play App Signing since Google removes the original signature and add another one, so this method will fail.

BE CAREFUL!! Your app signature can be retrieved using a PiracyCheckerUtils method. Make sure that you have signed your APK using your PRODUCTION keystore (not using the DEBUG one) and installed the version that you plan to distribute. Then copy the signature returned by this method on the console and paste in enableSigningCertificate("YOUR_APK_SIGNATURE")

// This method will print your app signatures in the console
apkSignatures.forEach { Log.e("SIGNATURE", it) }
<details><summary><b>Java Sample</b></summary>
// This method will print your app signatures in the console
for (String signature : LibraryUtilsKt.getApkSignatures(this)) {
    Log.e("SIGNATURE", signature);
}
</details><br>

Verify the installer

If you only plan to distribute the app on a particular store this technique will block from installing the app using any another store.

Supported stores: Google Play, Amazon App Store and Samsung Galaxy Apps.

piracyChecker {
	enableInstallerId(InstallerID.GOOGLE_PLAY, InstallerID.AMAZON_APP_STORE, InstallerID.GALAXY_APPS)
	...
}.start()
<details><summary><b>Java Sample</b></summary>
new PiracyChecker(this)
	.enableInstallerId(InstallerID.GOOGLE_PLAY, InstallerID.AMAZON_APP_STORE, InstallerID.GALAXY_APPS)
	...
	.start();
</details><br>

BE CAREFUL!! This is a really restrictive technique since it will block your app from being installed using another market or directly installing the .apk on the device. It isn't recommended for most cases.

Verify the use of pirate apps

If you want to check if user has pirate apps installed, you can use this code.

It will check for: Lucky Patcher, Uret Patcher, Freedom, CreeHack and HappyMod.

piracyChecker {
	enableUnauthorizedAppsCheck()
	...
}.start()
<details><summary><b>Java Sample</b></summary>
new PiracyChecker(this)
	.enableUnauthorizedAppsCheck()
	...
	.start();
</details><br>

Add custom apps to check

Since version 1.2.2 you can add additional apps to be checked using this code:

val app = PirateApp("Lucky Patcher", "the.package.name")
piracyChecker {
	addAppToCheck(app)
	...
}.start()
<details><summary><b>Java Sample</b></summary>
PirateApp app = new PirateApp("Lucky Patcher", "the.package.name");
new PiracyChecker(this)
	.addAppToCheck(app)
	...
	.start();
</details><br>

You can block the app even when this pirate apps has been uninstalled. This prevents the app from being patched and then uninstall the pirate app in order to continue using your app. The library will save a SharedPreference value to know when a pirate app has been detected.

There are two ways to do this:

Define the SharedPreferences and the name of the preference where you want to save the result.

piracyChecker {
	enableUnauthorizedAppsCheck()
	blockIfUnauthorizedAppUninstalled(preferences, "app_unauthorized") // Change "app_unauthorized" with your own value
	...
}.start()
<details><summary><b>Java Sample</b></summary>
new PiracyChecker(this)
	.enableUnauthorizedAppsCheck()
	.blockIfUnauthorizedAppUninstalled(preferences, "app_unauthorized") // Change "app_unauthorized" with your own value
	...
	.start();
</details><br>

Define the SharedPreferences name and the name of the preference where you want to save the result.

piracyChecker {
	enableUnauthorizedAppsCheck()
	blockIfUnauthorizedAppUninstalled("license_preferences", "app_unauthorized") // Change "license_preferences" and "app_unauthorized" with your own value
	...
}.start()
<details><summary><b>Java Sample</b></summary>
new PiracyChecker(this)
	.enableUnauthorizedAppsCheck()
	.blockIfUnauthorizedAppUninstalled("license_preferences", "app_unauthorized") // Change "license_preferences" and "app_unauthorized" with your own value
	...
	.start();
</details><br>

Verify the use of third-party store apps

If you want to check if user has third-party store apps installed, you can use this code.

It will check for: Aptoide, BlackMart, Mobogenie, 1Mobile, GetApk, GetJar, SlideMe and ACMarket.

piracyChecker {
	enableStoresCheck()
	...
}.start()
<details><summary><b>Java Sample</b></summary>
new PiracyChecker(this)
	.enableStoresCheck()
	...
	.start();
</details><br>

Enable deep pirate and third-party store apps check

If you want to check if these kind of apps left some files that could make you

View on GitHub
GitHub Stars1.6k
CategoryDevelopment
Updated6d ago
Forks170

Languages

Java

Security Score

100/100

Audited on Mar 26, 2026

No findings