mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 05:48:23 +03:00
Context fixes and typoes
This commit is contained in:
parent
b9c646d64d
commit
a31cf44e3d
9 changed files with 73 additions and 57 deletions
11
.idea/dictionaries/tad.xml
generated
Normal file
11
.idea/dictionaries/tad.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="tad">
|
||||
<words>
|
||||
<w>autostart</w>
|
||||
<w>eicar</w>
|
||||
<w>hypatia</w>
|
||||
<w>malware</w>
|
||||
<w>realtime</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
|
@ -34,7 +34,7 @@ public class DatabaseManager {
|
|||
public static File databasePath = null;
|
||||
public final static HashSet<Signatures.SignatureDatabase> signatureDatabases = new HashSet<>();
|
||||
|
||||
private Context context;
|
||||
private static Context context;
|
||||
|
||||
public DatabaseManager(Context context) {
|
||||
this.context = context;
|
||||
|
@ -50,14 +50,14 @@ public class DatabaseManager {
|
|||
return new File(databasePath + "/" + name).exists();
|
||||
}
|
||||
|
||||
public static void deteleDatabase(String name) {
|
||||
public static void deleteDatabase(String name) {
|
||||
new File(databasePath + "/" + name).delete();
|
||||
}
|
||||
|
||||
public static void loadRemoteDatabases() {
|
||||
try {
|
||||
signatureDatabases.clear();
|
||||
String api = Utils.prefs.getString("database_repo", "https://spotco.us/MalwareScannerSignatures/api.php");
|
||||
String api = Utils.getPrefs(context).getString("database_repo", "https://spotco.us/MalwareScannerSignatures/api.php");
|
||||
HttpURLConnection connection = Utils.getConnection(api);
|
||||
connection.connect();
|
||||
int res = connection.getResponseCode();
|
||||
|
@ -97,7 +97,7 @@ public class DatabaseManager {
|
|||
loadDatabase(dbLocation);
|
||||
}
|
||||
}
|
||||
Signatures.MD5.put("44d88612fea8a8f36de82e1278abb02f".substring(0, Utils.prefs.getInt("database_hash_length", 12)), "Eicar-Test-Signature");
|
||||
Signatures.MD5.put("44d88612fea8a8f36de82e1278abb02f".substring(0, Utils.getPrefs(context).getInt("database_hash_length", 12)), "Eicar-Test-Signature");
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
@ -112,8 +112,8 @@ public class DatabaseManager {
|
|||
reader = new BufferedReader(new FileReader(database));
|
||||
}
|
||||
String line;
|
||||
boolean trim = Utils.prefs.getBoolean("database_trim_variants", false);
|
||||
int maxLength = Utils.prefs.getInt("database_hash_length", 12);
|
||||
boolean trim = Utils.getPrefs(context).getBoolean("database_trim_variants", false);
|
||||
int maxLength = Utils.getPrefs(context).getInt("database_hash_length", 12);
|
||||
|
||||
if (database.getName().contains(".hdb")) {//.hdb format: md5, size, name
|
||||
while ((line = reader.readLine()) != null) {
|
||||
|
|
|
@ -44,7 +44,7 @@ public class MainActivity extends FragmentActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
|
||||
BottomNavigationView navigation = findViewById(R.id.navigation);
|
||||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
||||
navigation.setItemIconTintList(null);
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class MainActivity extends FragmentActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
||||
private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
||||
= new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
*/
|
||||
package us.spotco.malwarescanner;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Environment;
|
||||
import android.os.SystemClock;
|
||||
|
@ -32,16 +33,16 @@ import java.util.Set;
|
|||
|
||||
class MalwareScanner extends AsyncTask<Set<File>, Object, String> {
|
||||
|
||||
private boolean userFacing = false;
|
||||
private boolean userFacing;
|
||||
private long scanTime = 0;
|
||||
private int hashMaxLength = 0;
|
||||
private int hashMaxLength;
|
||||
private final HashMap<String, File> fileHashesMD5 = new HashMap<>();
|
||||
private final HashMap<String, File> fileHashesSHA1 = new HashMap<>();
|
||||
private final HashMap<String, File> fileHashesSHA256 = new HashMap<>();
|
||||
|
||||
public MalwareScanner(boolean userFacing) {
|
||||
public MalwareScanner(Context context, boolean userFacing) {
|
||||
this.userFacing = userFacing;
|
||||
hashMaxLength = Utils.prefs.getInt("database_hash_length", 12);
|
||||
hashMaxLength = Utils.getPrefs(context).getInt("database_hash_length", 12);
|
||||
}
|
||||
|
||||
private void returnResult(String result, boolean userFacingOnly) {
|
||||
|
|
|
@ -49,13 +49,13 @@ public class MalwareScannerService extends Service {
|
|||
|
||||
@Override
|
||||
public final int onStartCommand(Intent intent, int flags, int startId) {
|
||||
maxScanSize = Utils.prefs.getInt("scanner_max_file_size", (1000 * 1000) * 80) * (1000 * 1000);
|
||||
maxScanSize = Utils.getPrefs(getApplicationContext()).getInt("scanner_max_file_size", (1000 * 1000) * 80) * (1000 * 1000);
|
||||
|
||||
malwareMonitors.clear();
|
||||
|
||||
if(Utils.prefs.getBoolean("scanner_realtime_path_external", false)) {
|
||||
if (Utils.getPrefs(getApplicationContext()).getBoolean("scanner_realtime_path_external", false)) {
|
||||
addMalwareMonitor("/storage");
|
||||
} else if(Utils.prefs.getBoolean("scanner_realtime_path_internal", true)) {
|
||||
} else if (Utils.getPrefs(getApplicationContext()).getBoolean("scanner_realtime_path_internal", true)) {
|
||||
addMalwareMonitor(Environment.getExternalStorageDirectory().toString());
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class MalwareScannerService extends Service {
|
|||
if (file.exists() && /*file.length() > 0 &&*/ file.length() <= maxScanSize) {
|
||||
HashSet<File> filesToScan = new HashSet<>();
|
||||
filesToScan.add(file);
|
||||
new MalwareScanner(false).executeOnExecutor(threadPoolExecutor, filesToScan);
|
||||
new MalwareScanner(getApplicationContext(), false).executeOnExecutor(threadPoolExecutor, filesToScan);
|
||||
}
|
||||
updateForegroundNotification();
|
||||
break;
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.content.SharedPreferences;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
|
@ -30,11 +31,6 @@ import android.widget.Toast;
|
|||
*/
|
||||
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.fragment_settings, rootKey);
|
||||
|
@ -43,13 +39,13 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Utils.prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
Utils.prefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
@ -67,10 +63,14 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
|||
if (key.equals("scanner_realtime_enabled")) {
|
||||
if (prefs.getBoolean("scanner_realtime_enabled", false)) {
|
||||
Utils.considerStartService(getContext());
|
||||
Log.d("settings", "scanner true");
|
||||
} else {
|
||||
Intent realtimeScanner = new Intent(getContext(), MalwareScannerService.class);
|
||||
getContext().stopService(realtimeScanner);
|
||||
Log.d("settings", "scanner false");
|
||||
|
||||
}
|
||||
}
|
||||
Log.d("settings", key + " " + System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ public class Signatures {
|
|||
|
||||
public static class SignatureDatabase {
|
||||
|
||||
private String name = null;
|
||||
private String url = null;
|
||||
private boolean available = false;
|
||||
private String name;
|
||||
private String url;
|
||||
private boolean available;
|
||||
|
||||
public SignatureDatabase(String name, String url, boolean available) {
|
||||
this.name = name;
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.HttpURLConnection;
|
||||
|
@ -37,10 +38,14 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||
public class Utils {
|
||||
|
||||
public static int amtFilesScanned = 0;
|
||||
public static SharedPreferences prefs = null;
|
||||
private static Context context = null;
|
||||
|
||||
public Utils(Context context) {
|
||||
prefs = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public static SharedPreferences getPrefs(Context context) {
|
||||
return context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
private static ThreadPoolExecutor threadPoolExecutor = null;
|
||||
|
@ -53,22 +58,21 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static int getMaxThreads() {
|
||||
int maxTheads = Runtime.getRuntime().availableProcessors();
|
||||
if (maxTheads >= 2) {
|
||||
maxTheads /= 2;
|
||||
int maxThreads = Runtime.getRuntime().availableProcessors();
|
||||
if (maxThreads >= 2) {
|
||||
maxThreads /= 2;
|
||||
}
|
||||
return maxTheads;
|
||||
return maxThreads;
|
||||
}
|
||||
|
||||
public static HashSet<File> getFilesRecursive(File root) {
|
||||
int maxScanSize = prefs.getInt("scanner_max_file_size", (1000 * 1000) * 80) * (1000 * 1000);
|
||||
public static HashSet<File> getFilesRecursive(File root, int maxScanSize) {
|
||||
HashSet<File> filesAll = new HashSet<>();
|
||||
|
||||
File[] files = root.listFiles();
|
||||
if (files != null && files.length > 0) {
|
||||
for (File f : files) {
|
||||
if (f.isDirectory()) {
|
||||
HashSet<File> filesTmp = getFilesRecursive(f);
|
||||
HashSet<File> filesTmp = getFilesRecursive(f, maxScanSize);
|
||||
if (filesTmp != null) {
|
||||
filesAll.addAll(filesTmp);
|
||||
}
|
||||
|
@ -96,7 +100,8 @@ public class Utils {
|
|||
|
||||
public static void considerStartService(Context context) {
|
||||
if (!isServiceRunning(MalwareScannerService.class, context)) {
|
||||
boolean autostart = prefs.getBoolean("scanner_realtime_enabled", false);
|
||||
boolean autostart = getPrefs(context).getBoolean("scanner_realtime_enabled", false);
|
||||
Log.d("Utils", autostart + "");
|
||||
if (autostart) {
|
||||
Intent realtimeScanner = new Intent(context, MalwareScannerService.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
@ -143,7 +148,7 @@ public class Utils {
|
|||
if (s != null) {
|
||||
try {
|
||||
s.close();
|
||||
} catch (Exception e1) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,15 +161,14 @@ public class Utils {
|
|||
tries++;
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {
|
||||
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
return listening;
|
||||
}
|
||||
|
||||
public static boolean useTor() {
|
||||
return prefs.getBoolean("network_use_tor", false);
|
||||
return getPrefs(context).getBoolean("network_use_tor", false);
|
||||
}
|
||||
|
||||
public static HttpURLConnection getConnection(String url) {
|
||||
|
|
Loading…
Add table
Reference in a new issue