Cordova Plugin for Malwarelytics

Edit on Github Send Feedback 2021.09 - Current Release

How To Install The Plugin

1. Create the malwarelytics.xml file

Create the malwarelytics.xml file inside your app root folder with your Malwarelytics service credentials and credentials for the native plugin repository.

You can visit malwarelytics.xml inside the demo app..

You can also configure the visuals of the SmartProtection feature.

<?xml version='1.0' encoding='utf-8'?>
<malwarelytics>

    <!-- 
        Service configuration 

         username : Username for the Malwarelytics service
         password : Password for the Malwarelytics service
         publicKey : [OPTIONAL] Public key of the service
    -->
    <service 
        username="MY_USERNAME"
        password="MY_PASWORD"
        publicKey="PUBLIC_KEY"
    />

    <!-- 
        Maven repository configuration 

        username : Username for the m2 repo
        password : Password for the m2 repo
             url : [OPTIONAL] Custom URL to the m2 repo
    -->
    <maven 
        username="MY_ARTIFACTORY_USERNAME"
        password="MY_ARTIFACTORY_PASSWORD"
        url="https://wultra.jfrog.io/artifactory/malwarelytics-android/"
    /> 

    <!-- 
        UI configuration [OPTIONAL] 

         resourcesFolder : Folder that will be copied (merged) into the android app resources folder
                   theme : Theme resource path that will be applied to the threat screen
        notificationIcon : Resource icon used in threat notifications
            settingsIcon : Resource icon used in threat screen for settings
              deleteIcon : Resource icon used in threat screen for deleting malware
    -->
    <ui
        resourcesFolder="./malwarelytics_resources"
        theme="R.style.CustomAppTheme"
        notificationIcon="R.mipmap.ic_launcher"
        settingsIcon="R.drawable.custom_av_settings_outline"
        deleteIcon="R.drawable.custom_av_delete_outline"
    />

</malwarelytics>

  • resourcesFolder is a relative path to a folder. Content of this folder will be copied inside the app resource folder (platforms/android/app/src/main/res). This can be used for adding custom theme file or localization files.
  • theme is a resource reference to your theme. For more information on styling see Styling Threat Screen.
  • notificationIcon is a resource reference to an icon that will be displayed in Malwarelytics notififcations. You can use R.mipmap.ic_launcher to reuse your app icon.
  • settingsIcon is a resource reference to a drawable that will be displayed as an uninstall button in Malwarelytics UI. (For example R.drawable.custom_av_settings_outline).
  • deleteIcon is a resource reference to a drawable that will be displayed as a delete button in Malwarelytics UI. (For example R.drawable.custom_av_delete_outline).

2. Install the plugin into your app

For “vanilla” Cordova app

cordova plugin add cordova-plugin-malwarelytics

For Ionic Cordova app

ionic cordova plugin add cordova-plugin-malwarelytics

3. Initialize and use the plugin

In your app js file, you can now access window.plugins.malwarelytics property.

Initialize the plugin:

window.plugins.malwarelytics.initialize({
        enableSilentMode: false
    }, function () {
        console.log("initialized");
    }, function (error) {
        console.log(error);
});

If you want to force the scan use following code. Note that that by default (can be change in the configuration), an initial update is performed and this scan doesn’t need to be called after the initialization.

window.plugins.malwarelytics.triggerSmartProtection(function () {
        console.log("Smart Protection finished...");
    }, function (error) {
        console.log(error.type);
});

If you want to get the list of threats manually, you can use:

window.plugins.malwarelytics.getThreatList((list) => {
    list.items.filter(i => i.threatIndex == "MALWARE" || i.threatIndex == "HIGHLY_DANGEROUS" || i.threatIndex == "DANGEROUS" || i.threatIndex == "POTENTIALLY_UNWANTED_APP").forEach(apk => {
        window.plugins.malwarelytics.getApkInfo(apk.packageName, (apkInfo) => {
            console.log(`App name: ${apkInfo.label}, Threat Index: ${apk.threatIndex}, base64 image: ${apkInfo.icon}`);
        })
    })
})

Typescript support

In case that you’re using TypeScript to build the app, there is a Malwarelytics.d.ts definition file in the package. You can reference it in your file and use it as follow:

/// <reference path="../../plugins/cordova-plugin-malwarelytics/www/MalwarelyticsPlugin.d.ts"/>

declare interface Window {
    plugins: {
        malwarelytics: MalwarelyticsPlugin;
    }
}

// now you can use window.plugins.malwarelytics with autocompletion

Language Configuration

To support different than included languages, you need to provide custom strings. To do that, prepare a resources folder and set it to <resources-folder> tag inside the malwarelytics.xml file. Contents of such resource folder will be copied inside the android project as any other resource.

For an example implementation, you can visit the malwarelytics.xml and custom resources inside the demo application.

You can then set your preferred language both in the initialize method as a property of MalwarelyticsConfig or via changeAppLanguage after the plugin is initialized.

Styling Threat Screen

Threat screen can by styled by setting custom theme for the activity and by changing icons for the image buttons on the screen.

There are two icons. Delete icon and settings icon. Delete icon serves for button requesting app uninstall (for apps that can be uninstalled). Settings icon serves for button opening app’s detail in system settings (for apps that cannot be uninstalled) where user can disable the app.

The theme for the screen should contain standard Android attributes and can contain couple of extra attributes defined by the AV SDK.

We recommend to derive the theme from AppCompat themes. The usage of ActionBar in the screen is derived from the theme. Use NoActionBar version of the theme for design without the ActionBar (contains the app name). Alternatively you can hide the ActionBar by adding

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

to your theme.

Following is an example of such theme.

<resources>
    <style name="CustomAppTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">#FF0000</item>
        <item name="colorPrimaryDark">#222222</item>
        <item name="colorAccent">#FF0000</item>

        <item name="titleTextColor">@android:color/black</item>

        <!-- <item name="android:windowBackground">@drawable/img_bg_app</item> -->

        <!-- <item name="android:fontFamily">@font/font_family_roboto</item>
        <item name="fontFamily">@font/font_family_roboto</item> -->

        <!-- <item name="buttonStyle">@style/CustomAppTheme.Button.Filled</item> -->
        <item name="imageButtonStyle">@style/CustomAppTheme.ImageButton.Borderless</item>

        <item name="wultraThreatTitleTextAppearance">@style/CustomAppTheme.TextAppearance.Title</item>
        <item name="wultraThreatTitleStyle">@style/CustomAppTheme.TextView.Title</item>
        <item name="wultraThreatDescriptionTextAppearance">@style/CustomAppTheme.TextAppearance.Description</item>
        <item name="wultraThreatDescriptionStyle">@style/CustomAppTheme.TextView.Description</item>
        <item name="wultraThreatProtipTextAppearance">@style/CustomAppTheme.TextAppearance.Description</item>
        <item name="wultraThreatProtipStyle">@style/CustomAppTheme.TextView.Description</item>
        <item name="wultraThreatPackageNameTextAppearance">@style/CustomAppTheme.TextAppearance.PackageName</item>
    </style>

    <style name="CustomAppTheme.TextAppearance.Button" parent="TextAppearance.AppCompat.Button">
        <item name="android:textColor">@android:color/black</item>
        <item name="android:textSize">19.2sp</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="CustomAppTheme.Button.Filled" parent="Widget.AppCompat.Button">
        <item name="android:textAppearance">@style/CustomAppTheme.TextAppearance.Button</item>
        <item name="android:textAllCaps">false</item>
        <!-- <item name="android:background">@drawable/bg_button_filled</item> -->
    </style>

    <style name="CustomAppTheme.ImageButton.Borderless" parent="Widget.AppCompat.ImageButton">
        <!-- <item name="android:background">@drawable/bg_button_borderless</item> -->
    </style>

    <style name="CustomAppTheme.TextView"/>

    <style name="CustomAppTheme.TextView.Title">
        <item name="android:gravity">center</item>
    </style>

    <style name="CustomAppTheme.TextAppearance.Title" parent="TextAppearance.AppCompat.Title">
        <item name="android:textColor">#FF0000</item>
    </style>

    <style name="CustomAppTheme.TextView.Description">
        <item name="android:gravity">center</item>
    </style>

    <style name="CustomAppTheme.TextAppearance.Description" parent="TextAppearance.AppCompat.Medium">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textSize">16.8sp</item>
    </style>
    <style name="CustomAppTheme.TextAppearance.PackageName" parent="TextAppearance.AppCompat.Title">
        <item name="android:textSize">@dimen/custom_text_size_small</item>
        <item name="android:textColor">@color/customWhite</item>
        <item name="android:fontFamily">sans-serif</item>
        <item name="fontFamily">sans-serif</item>
    </style>
</resources>

Such custom theme can be set into your malwarelytics.xml configuration file by

<ui
    resourcesFolder="./malwarelytics_resources"
    theme="R.style.CustomAppTheme"
    notificationIcon="R.mipmap.ic_launcher"
    settingsIcon="R.drawable.custom_av_settings_outline"
    deleteIcon="R.drawable.custom_av_delete_outline"
    />

Support and Compatibility

Cordova Library Native Library
2.0.x 0.13.x
1.1.x 0.13.x
1.0.x 0.11.x and 0.12.x
Last updated on Mar 05, 2021 (00:06) Edit on Github Send Feedback
Search

2021.09

Malwarelytics

Malwarelytics cordova plugin