-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMalwareItem.tsx
More file actions
161 lines (154 loc) · 4.5 KB
/
Copy pathMalwareItem.tsx
File metadata and controls
161 lines (154 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { Button, HStack } from '@react-native-material/core';
import {
addToWhitelist,
getAppIcon,
type SuspiciousAppInfo,
} from 'freerasp-react-native';
import ArrowUp from '../assets/arrow-up.png';
import ArrowDown from '../assets/arrow-down.png';
import React, { useEffect } from 'react';
import { useState } from 'react';
import { TouchableOpacity, View, Text, Image, StyleSheet } from 'react-native';
import { Colors } from './styles';
export const MalwareItem: React.FC<{ app: SuspiciousAppInfo }> = ({ app }) => {
const [expanded, setExpanded] = useState(false);
useEffect(() => {
(async () => {
// retrieve app icons for detected malware
const appIcon = await getAppIcon(app.packageInfo.packageName);
app.packageInfo.appIcon = appIcon;
})();
}, [app.packageInfo]);
const appUninstall = async () => {
alert('Implement yourself!');
};
const whitelistApp = async (packageName: string) => {
try {
const whitelistResponse = await addToWhitelist(packageName);
console.info(
`Malware Whitelist response for ${app}: ${whitelistResponse}`
);
alert('Restart app for whitelist to take effect');
} catch (error: any) {
console.info('Error while adding app to malware whitelist: ', error);
}
};
return (
<View style={styles.item}>
<TouchableOpacity onPress={() => setExpanded(!expanded)}>
<HStack>
<Image
style={styles.iconSmall}
source={{
uri: `data:image/png;base64,${app.packageInfo.appIcon}`,
}}
/>
<View style={styles.textView}>
<Text numberOfLines={1} style={styles.titleText}>
{app.packageInfo.appName}
</Text>
</View>
<View style={styles.buttonView}>
<Image
source={expanded ? ArrowUp : ArrowDown}
style={styles.expandArrow}
/>
</View>
</HStack>
</TouchableOpacity>
{expanded && (
<>
<View style={styles.spacer} />
<Text style={styles.listItemTitle}>Package name:</Text>
<Text style={styles.listItem}>{app.packageInfo.packageName}</Text>
<Text style={styles.listItemTitle}>App name:</Text>
<Text style={styles.listItem}>
{app.packageInfo.appName ?? 'Not specified'}
</Text>
<Text style={styles.listItemTitle}>App version:</Text>
<Text style={styles.listItem}>
{app.packageInfo.version ?? 'Not specified'}
</Text>
<Text style={styles.listItemTitle}>App Icon:</Text>
{app.packageInfo.appIcon ? (
<Image
style={styles.icon}
source={{
uri: `data:image/png;base64,${app.packageInfo.appIcon}`,
}}
/>
) : (
<Text style={styles.listItem}>Not specified</Text>
)}
<Text style={styles.listItemTitle}>Installer store:</Text>
<Text style={styles.listItem}>
{app.packageInfo.installerStore ?? 'Not specified'}
</Text>
<Text style={styles.listItemTitle}>Detection reasons:</Text>
<Text style={styles.listItem}>{app.reasons.join(', ')}</Text>
<Text style={styles.listItemTitle}>Granted permissions:</Text>
<Text style={styles.listItem}>
{app.permissions?.join(', ') ?? 'Not specified'}
</Text>
<HStack style={styles.buttonGroup}>
<Button
title={'Add to whitelist'}
onPress={() => whitelistApp(app.packageInfo.packageName)}
/>
<Button title={'Uninstall'} onPress={appUninstall} />
</HStack>
</>
)}
</View>
);
};
const styles = StyleSheet.create({
item: {
backgroundColor: '#d4e4ff',
borderRadius: 20,
padding: 20,
marginVertical: 8,
},
listItemTitle: {
fontSize: 20,
fontWeight: 'bold',
},
listItem: {
fontSize: 16,
paddingBottom: 5,
},
titleText: {
fontSize: 20,
},
icon: {
marginTop: 5,
marginBottom: 5,
width: 50,
height: 50,
},
iconSmall: {
width: 40,
height: 40,
},
textView: {
justifyContent: 'center',
flex: 1,
marginLeft: 20,
marginRight: 30,
},
buttonView: {
justifyContent: 'center',
},
spacer: {
height: 15,
},
buttonGroup: {
marginTop: 10,
justifyContent: 'space-between',
},
expandArrow: {
tintColor: Colors.grey,
width: 30,
height: 30,
},
});