Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasKypta committed Apr 24, 2024
2 parents de8a30a + ddeba6b commit 3303513
Show file tree
Hide file tree
Showing 37 changed files with 1,524 additions and 368 deletions.
10 changes: 5 additions & 5 deletions demoapp/config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.wultra.android.cordova.malwarelytics.demo" version="5.0.2-dev" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="com.wultra.android.cordova.malwarelytics.demo" version="5.1.1-dev" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>MalwarelyticsPluginTest</name>
<description>
A sample Apache Cordova application integrating Malwarelytics for Cordova.
Expand All @@ -15,7 +15,7 @@
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android" kotlin="1.8.20">
<platform name="android" kotlin="1.8.22">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
Expand All @@ -25,9 +25,9 @@
<preference name="GradleVersion" value="7.6.2" />
<preference name="GradlePluginKotlinEnabled" value="false" />
<preference name="GradlePluginKotlinCodeStyle" value="official" />
<preference name="GradlePluginKotlinVersion" value="1.8.20" />
<preference name="GradlePluginKotlinVersion" value="1.8.22" />
<preference name="AndroidGradlePluginVersion" value="7.4.2" />
<preference name="AndroidXEnabled" value="true" />
<preference name="android-targetSdkVersion" value="33" />
<preference name="android-compileSdkVersion" value="33" />
<preference name="android-targetSdkVersion" value="34" />
<preference name="android-compileSdkVersion" value="34" />
</widget>
6 changes: 3 additions & 3 deletions demoapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions demoapp/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.wultra.android.cordova.malwarelytics.demo",
"displayName": "Malwarelytics Cordova Demo",
"version": "5.0.2-dev",
"version": "5.1.1-dev",
"description": "Example Wultra Malwarelytics integration into Cordova app",
"main": "index.js",
"scripts": {
Expand All @@ -24,7 +24,7 @@
"prepareAndRunOnDevice": "npm i && npm run prepareAndroid && npm run reinstallPlugin && npm run rebuildAndroid && npm run startDevice",
"prepareAndRunOnEmulator": "npm i && npm run prepareAndroid && npm run reinstallPlugin && npm run rebuildAndroid && npm run startEmulator",
"prepareAndRunAndroid": "npm i && npm run prepareAndroid && npm run reinstallAndPreparePlugin && npm run rebuildAndroid && cordova run android",
"addIos": "cordova platform add ios@7.0.1",
"addIos": "cordova platform add ios@7.1.0",
"removeIos": "cordova platform rm ios",
"prepareIos": "npm run addIos || ( npm run removeIos && npm run addIos )",
"startDeviceIos": "cordova run ios --device",
Expand Down Expand Up @@ -60,4 +60,4 @@
},
"platforms": []
}
}
}
13 changes: 10 additions & 3 deletions demoapp/www/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,17 @@ h1 {
padding:2px 0px;
background-color:orange;
}

#smart-protection-button, #set-user-id-button, #set-device-id-button {
#customer-identification, #av-features {
display: none;
}
.app-button {
margin-top: 12px;
background: #0088ff;
padding: 12px;
border: 0;
color: #fff;
border-radius: 4px;
display: none;
display: inline-block;
}
#smart-protection-result {
padding: 4px;
Expand Down Expand Up @@ -175,6 +177,11 @@ h1 {
grid-column: 2;
grid-row: 2;
}
.threat-flags {
font-size: 8px;
grid-column: 2;
grid-row: 3;
}
.threat-malware {
color: #ac0b2a;
}
Expand Down
9 changes: 6 additions & 3 deletions demoapp/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ <h1>MALWARELYTICS</h1>
<p class="event failed">Failed to Initialize</p>
</div>
<div id="customer-identification">
<button id="set-user-id-button">Set Client ID</button>
<button id="set-device-id-button">Set Device ID</button>
<button class="app-button" id="set-user-id-button">Set Client ID</button>
<button class="app-button" id="set-device-id-button">Set Device ID</button>
</div>
<div id="android-controls">
<h2>Android demo</h2>
<div id="androidready" class="blink">
<p class="androidstate" id="temp_offline">Temporary offline mode</p>
<p class="androidstate" id="perm_offline">Permanent offline mode</p>
</div>
<button id="smart-protection-button">Run Smart Protection</button><br />
<div id="av-features">
<button class="app-button" id="smart-protection-button">Run Smart Protection</button>
<button class="app-button" id="last-update-info-button">Last Update Info</button>
</div>
<div id="smart-protection-result"></div>
<h3>Language</h3>
<select id="lang-select">
Expand Down
53 changes: 40 additions & 13 deletions demoapp/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var demoApp = {
},
onDeviceReady: function () {
return __awaiter(this, void 0, void 0, function () {
var knownApps, e_1, userIdButton, deviceIdButton;
var knownApps, e_1, customerIdentification;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Expand Down Expand Up @@ -117,12 +117,10 @@ var demoApp = {
return [2];
case 5:
this.setAppState(AppState.READY);
userIdButton = document.getElementById("set-user-id-button");
userIdButton.setAttribute('style', 'display:inline-block');
userIdButton.addEventListener("click", this.onChangeClientId);
deviceIdButton = document.getElementById("set-device-id-button");
deviceIdButton.setAttribute('style', 'display:inline-block');
deviceIdButton.addEventListener("click", this.onChangeDeviceId);
customerIdentification = document.getElementById("customer-identification");
customerIdentification.setAttribute('style', 'display:inline-block');
this.setButtonClick("set-user-id-button", this.onChangeClientId);
this.setButtonClick("set-device-id-button", this.onChangeDeviceId);
if (device.platform == "Android") {
this.configureAndroid();
}
Expand Down Expand Up @@ -340,7 +338,7 @@ var demoApp = {
},
configureAndroid: function () {
return __awaiter(this, void 0, void 0, function () {
var result, button, langSelect, isInitialized, list, itemPromises, enrichedItems, e_2, observer;
var result, avFeatures, updateObserver, langSelect, isInitialized, list, itemPromises, enrichedItems, e_2, observer;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
Expand All @@ -350,9 +348,32 @@ var demoApp = {
case 1:
result = _a.sent();
this.setAndroidState(result);
button = document.getElementById("smart-protection-button");
button.setAttribute('style', 'display:inline-block');
button.addEventListener("click", this.onRunSmartProtection);
avFeatures = document.getElementById("av-features");
avFeatures.setAttribute('style', 'display:inline-block');
this.setButtonClick("smart-protection-button", this.onRunSmartProtection);
this.setButtonClick("last-update-info-button", function () { return __awaiter(_this, void 0, void 0, function () {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
_a = alert;
_b = "last update info: ";
_d = (_c = JSON).stringify;
return [4, window.plugins.malwarelytics.android.antivirus.getLastUpdateInfo()];
case 1:
_a.apply(void 0, [_b + _d.apply(_c, [_e.sent()])]);
return [2];
}
});
}); });
updateObserver = {
onSuggestionUpdated: function (observedUpdateInfo) {
var filter = observedUpdateInfo.updateType === "FULL" ? ['updateResult', 'updateType', 'failureReason'] : ['updateResult', 'updateType', 'failureReason', 'checkedApps'];
var filteredUpdateInfo = JSON.stringify(observedUpdateInfo, filter);
console.log("Update observer: " + filteredUpdateInfo);
}
};
window.plugins.malwarelytics.android.antivirus.setUpdateObserver(updateObserver);
this.setButtonClick("is-rooted-button", function () { return __awaiter(_this, void 0, void 0, function () {
var _a, _b;
return __generator(this, function (_c) {
Expand Down Expand Up @@ -759,6 +780,11 @@ var demoApp = {
else {
icon = "<img src=\"../img/icon-placeholder.svg\" />";
}
var flagsDiv = "";
if (apk.flags.length > 0) {
var flStr = apk.flags.map(function (fl) { return fl.type + ": " + fl.name; });
flagsDiv = "<div class=\"threat-flags\">".concat(flStr.join('; '), "</div>");
}
var threatCls = "";
switch (apk.threatIndex) {
case "MALWARE":
Expand All @@ -771,7 +797,7 @@ var demoApp = {
threatCls = "threat-dangerous";
break;
}
node.innerHTML = "<div class=\"threat\">".concat(icon, "<div class=\"appname\">").concat(apkInfo.label || apk.packageName, "</div><div class=\"threatindex ").concat(threatCls, "\">").concat(apk.threatIndex, "</div></div>");
node.innerHTML = "<div class=\"threat\">".concat(icon, "<div class=\"appname\">").concat(apkInfo.label || apk.packageName, "</div><div class=\"threatindex ").concat(threatCls, "\">").concat(apk.threatIndex, "</div>").concat(flagsDiv, "</div>");
appList.appendChild(node);
});
return [3, 7];
Expand All @@ -785,7 +811,8 @@ var demoApp = {
emulatorDetected: function (emulatorDetection) { console.log("RASP EMULATOR DETECTED " + JSON.stringify(emulatorDetection)); },
repackagingDetected: function (repackagingResult) { console.log("RASP REPACKAGING DETECTED " + JSON.stringify(repackagingResult)); },
rootDetected: function (rootDetection) { console.log("RASP ROOT DETECTED " + JSON.stringify(rootDetection)); },
screenSharingDetected: function (screenSharingDetected) { console.log("RASP SCREEN SHARING DETECTED " + screenSharingDetected); },
screenSharingDetected: function (screenSharingDetection) { console.log("RASP SCREEN SHARING DETECTED " + JSON.stringify(screenSharingDetection)); },
screenReaderDetected: function (screenReaderDetection) { console.log("RASP SCREEN READER DETECTED " + JSON.stringify(screenReaderDetection)); },
tapjackingDetected: function (tapjackingDetection) { console.log("RASP TAPJACKING DETECTED " + JSON.stringify(tapjackingDetection)); },
httpProxyDetected: function (httpProxyDetection) { console.log("RASP HTTP PROXY DETECTED " + JSON.stringify(httpProxyDetection)); },
vpnDetected: function (vpnEnabled) { console.log("RASP VPN DETECTED " + vpnEnabled); },
Expand Down
40 changes: 28 additions & 12 deletions demoapp/www/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ var demoApp = {

this.setAppState(AppState.READY);

let userIdButton = document.getElementById("set-user-id-button");
userIdButton.setAttribute('style', 'display:inline-block');
userIdButton.addEventListener("click", this.onChangeClientId);
let deviceIdButton = document.getElementById("set-device-id-button");
deviceIdButton.setAttribute('style', 'display:inline-block');
deviceIdButton.addEventListener("click", this.onChangeDeviceId);
let customerIdentification = document.getElementById("customer-identification");
customerIdentification.setAttribute('style', 'display:inline-block');
this.setButtonClick("set-user-id-button", this.onChangeClientId);
this.setButtonClick("set-device-id-button", this.onChangeDeviceId);

if (device.platform == "Android") {
this.configureAndroid();
Expand Down Expand Up @@ -162,10 +160,22 @@ var demoApp = {
let result = await window.plugins.malwarelytics.android.getInitializationResult();
this.setAndroidState(result);

let button = document.getElementById("smart-protection-button");

button.setAttribute('style', 'display:inline-block');
button.addEventListener("click", this.onRunSmartProtection);
let avFeatures = document.getElementById("av-features");
avFeatures.setAttribute('style', 'display:inline-block');
this.setButtonClick("smart-protection-button", this.onRunSmartProtection);

this.setButtonClick("last-update-info-button", async () => {
alert("last update info: " + JSON.stringify(await window.plugins.malwarelytics.android.antivirus.getLastUpdateInfo()));
});

let updateObserver: MalwarelyticsAndroidUpdateObserver = {
onSuggestionUpdated(observedUpdateInfo: ObservedUpdateInfo) {
const filter = observedUpdateInfo.updateType === "FULL" ? ['updateResult', 'updateType', 'failureReason'] : ['updateResult', 'updateType', 'failureReason', 'checkedApps'];
const filteredUpdateInfo = JSON.stringify(observedUpdateInfo, filter)
console.log("Update observer: " + filteredUpdateInfo);
}
};
window.plugins.malwarelytics.android.antivirus.setUpdateObserver(updateObserver);

// observable features

Expand Down Expand Up @@ -314,6 +324,11 @@ var demoApp = {
} else {
icon = `<img src="../img/icon-placeholder.svg" />`
}
var flagsDiv = "";
if (apk.flags.length > 0) {
let flStr = apk.flags.map(fl => fl.type + ": " + fl.name)
flagsDiv = `<div class="threat-flags">${flStr.join('; ')}</div>`
}
var threatCls = ""
switch (apk.threatIndex) {
case "MALWARE":
Expand All @@ -326,7 +341,7 @@ var demoApp = {
threatCls = "threat-dangerous";
break;
}
node.innerHTML = `<div class="threat">${icon}<div class="appname">${apkInfo.label || apk.packageName}</div><div class="threatindex ${threatCls}">${apk.threatIndex}</div></div>`;
node.innerHTML = `<div class="threat">${icon}<div class="appname">${apkInfo.label || apk.packageName}</div><div class="threatindex ${threatCls}">${apk.threatIndex}</div>${flagsDiv}</div>`;
appList.appendChild(node);
});
} catch(e) {
Expand All @@ -338,7 +353,8 @@ var demoApp = {
emulatorDetected(emulatorDetection: EmulatorDetection) { console.log("RASP EMULATOR DETECTED " + JSON.stringify(emulatorDetection)); },
repackagingDetected(repackagingResult: RepackagingResult) {console.log("RASP REPACKAGING DETECTED " + JSON.stringify(repackagingResult)); },
rootDetected(rootDetection: RootDetection) { console.log("RASP ROOT DETECTED " + JSON.stringify(rootDetection)); },
screenSharingDetected(screenSharingDetected: boolean){ console.log("RASP SCREEN SHARING DETECTED " + screenSharingDetected); },
screenSharingDetected(screenSharingDetection: ScreenSharingDetection) { console.log("RASP SCREEN SHARING DETECTED " + JSON.stringify(screenSharingDetection)); },
screenReaderDetected(screenReaderDetection: ScreenReaderDetection) { console.log("RASP SCREEN READER DETECTED " + JSON.stringify(screenReaderDetection)); },
tapjackingDetected(tapjackingDetection: TapjackingDetection) { console.log("RASP TAPJACKING DETECTED " + JSON.stringify(tapjackingDetection)); },
httpProxyDetected(httpProxyDetection: HttpProxyDetection) { console.log("RASP HTTP PROXY DETECTED " + JSON.stringify(httpProxyDetection)); },
vpnDetected(vpnEnabled: boolean) { console.log("RASP VPN DETECTED " + vpnEnabled); },
Expand Down
40 changes: 40 additions & 0 deletions docs/Android-Anti-Malware-Feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,46 @@ list.items.filter(i => i.threatIndex == "MALWARE" || i.threatIndex == "HIGHLY_DA
Threat mitigation UI of the smart protection can be [customized](./Android-Anti-Malware-UI-Configuration.md)
in the `malwarelytics.xml`.
## Getting Info About Updates
There are two ways to obtain an info about data updates:
- Getting the last update info
- Using an update observer to be notified about performed updates
These update info data are useful primarily for troubleshooting.
### Getting Last Update Info
Last update info can be obtained via:
```js
const lastUpdateInfo = await window.plugins.malwarelytics.android.antivirus.getLastUpdateInfo()
```
The returned object contains info about successful and unsuccessful updates for each type of update (`UpdateType.FULL` and `UpdateType.PARTIAL`).
### Using Update Observer
Update observer can be set via:
```js
let updateObserver: MalwarelyticsAndroidUpdateObserver = {
onSuggestionUpdated(observedUpdateInfo: ObservedUpdateInfo) {
console.log("Update observer data: " + JSON.stringify(observedUpdateInfo));
}
}
window.plugins.malwarelytics.android.antivirus.setUpdateObserver(updateObserver);
```
The `ObservedUpdateInfo` contains information about the result, type of update, list of apps that were checked, list of apps that received update data, and failure reason.
When the updates are no longer desired, the observer can be cleared with:
```js
window.plugins.malwarelytics.android.antivirus.clearUpdateObserver();
```
## Read Next
- [Configuration of the Anti-Malware UI](./Android-Anti-Malware-UI-Configuration.md)
Loading

0 comments on commit 3303513

Please sign in to comment.