Search in sources :

Example 6 with Cleanup

use of lombok.Cleanup in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class MapViewerOsmDroid method loadOcidMarkersByNetwork.

private void loadOcidMarkersByNetwork() {
    // Check if OpenCellID data exists and if so load this now
    List<CellTowerMarker> items = new LinkedList<>();
    String networkOperator = tm.getNetworkOperator();
    int currentMmc = 0;
    int currentMnc = 0;
    if (networkOperator != null && networkOperator.length() > 3) {
        currentMmc = Integer.parseInt(networkOperator.substring(0, 3));
        currentMnc = Integer.parseInt(networkOperator.substring(3));
    }
    Drawable cellTowerMarkerIcon = getResources().getDrawable(R.drawable.ic_map_pin_green);
    @Cleanup Realm realm = Realm.getDefaultInstance();
    RealmResults<Import> importRealmResults = mDbHelper.returnOcidBtsByNetwork(realm, currentMmc, currentMnc).findAll();
    for (Import anImport : importRealmResults) {
        // CellID,Lac,Mcc,Mnc,Lat,Lng,AvgSigStr,Samples
        final int cellID = anImport.getCellId();
        final int lac = anImport.getLocationAreaCode();
        final int mcc = anImport.getMobileCountryCode();
        final int mnc = anImport.getMobileNetworkCode();
        final int psc = anImport.getPrimaryScramblingCode();
        final String rat = anImport.getRadioAccessTechnology();
        final double dLat = anImport.getGpsLocation().getLatitude();
        final double dLng = anImport.getGpsLocation().getLongitude();
        final GeoPoint location = new GeoPoint(dLat, dLng);
        //where is c.getString(6)AvgSigStr
        final int samples = anImport.getSamples();
        // Add map marker for CellID
        CellTowerMarker ovm = new CellTowerMarker(this, mMap, "Cell ID: " + cellID, "", location, new MarkerData(getApplicationContext(), String.valueOf(cellID), String.valueOf(location.getLatitude()), String.valueOf(location.getLongitude()), String.valueOf(lac), String.valueOf(mcc), String.valueOf(mnc), String.valueOf(psc), rat, String.valueOf(samples), false));
        ovm.setIcon(cellTowerMarkerIcon);
        items.add(ovm);
    }
    mCellTowerGridMarkerClusterer.addAll(items);
}
Also used : MarkerData(com.secupwn.aimsicd.map.MarkerData) Import(com.secupwn.aimsicd.data.model.Import) CellTowerMarker(com.secupwn.aimsicd.map.CellTowerMarker) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Cleanup(lombok.Cleanup) LinkedList(java.util.LinkedList) GeoPoint(org.osmdroid.util.GeoPoint) GeoPoint(org.osmdroid.util.GeoPoint) Realm(io.realm.Realm)

Example 7 with Cleanup

use of lombok.Cleanup in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class SmsDetector method parseMwiSms.

private void parseMwiSms(String[] logcatLines, Date logcat_timestamp) {
    @Cleanup Realm realm = Realm.getDefaultInstance();
    long count = realm.where(SmsData.class).equalTo("timestamp", logcat_timestamp).count();
    // Only alert if the timestamp is not in the data base
    if (count == 0) {
        realm.beginTransaction();
        SmsData capturedSms = realm.createObject(SmsData.class);
        String smsText = findSmsData(logcatLines, null);
        String num = findSmsNumber(logcatLines, null);
        capturedSms.setSenderNumber(num);
        capturedSms.setMessage(smsText);
        capturedSms.setTimestamp(logcat_timestamp);
        capturedSms.setType("MWI");
        setCurrentLocationData(null, capturedSms);
        realm.commitTransaction();
        mDbAdapter.toEventLog(realm, 4, "Detected MWI SMS");
        startPopUpInfo(SmsType.MWI);
    } else {
        log.debug("Detected Sms already logged");
    }
}
Also used : SmsData(com.secupwn.aimsicd.data.model.SmsData) SmsDetectionString(com.secupwn.aimsicd.data.model.SmsDetectionString) Cleanup(lombok.Cleanup) Realm(io.realm.Realm)

Example 8 with Cleanup

use of lombok.Cleanup in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class SmsDetector method parseTypeZeroSms.

private void parseTypeZeroSms(String[] bufferLines, Date logcat_timestamp) {
    @Cleanup Realm realm = Realm.getDefaultInstance();
    long count = realm.where(SmsData.class).equalTo("timestamp", logcat_timestamp).count();
    // Only alert if the timestamp is not in the data base
    if (count == 0) {
        realm.beginTransaction();
        SmsData capturedSms = realm.createObject(SmsData.class);
        String smsText = findSmsData(bufferLines, null);
        String num = findSmsNumber(bufferLines, null);
        capturedSms.setSenderNumber(num);
        capturedSms.setMessage(smsText);
        capturedSms.setTimestamp(logcat_timestamp);
        capturedSms.setType("TYPE0");
        setCurrentLocationData(realm, capturedSms);
        realm.commitTransaction();
        mDbAdapter.toEventLog(realm, 3, "Detected Type-0 SMS");
        startPopUpInfo(SmsType.SILENT);
    } else {
        log.debug("Detected Sms already logged");
    }
}
Also used : SmsData(com.secupwn.aimsicd.data.model.SmsData) SmsDetectionString(com.secupwn.aimsicd.data.model.SmsDetectionString) Cleanup(lombok.Cleanup) Realm(io.realm.Realm)

Example 9 with Cleanup

use of lombok.Cleanup in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class SmsDetector method parseWapPushSms.

private void parseWapPushSms(String[] logcatLines, String[] postWapMessageLines, Date logcat_timestamp) {
    @Cleanup Realm realm = Realm.getDefaultInstance();
    long count = realm.where(SmsData.class).equalTo("timestamp", logcat_timestamp).count();
    // Only alert if the timestamp is not in the data base
    if (count == 0) {
        realm.beginTransaction();
        SmsData capturedSms = realm.createObject(SmsData.class);
        String smsText = findSmsData(logcatLines, postWapMessageLines);
        String num = findSmsNumber(logcatLines, postWapMessageLines);
        capturedSms.setSenderNumber(num);
        capturedSms.setMessage(smsText);
        capturedSms.setTimestamp(logcat_timestamp);
        capturedSms.setType("WAPPUSH");
        setCurrentLocationData(realm, capturedSms);
        realm.commitTransaction();
        mDbAdapter.toEventLog(realm, 6, "Detected WAPPUSH SMS");
        startPopUpInfo(SmsType.WAP_PUSH);
    } else {
        log.debug("Detected SMS already logged");
    }
}
Also used : SmsData(com.secupwn.aimsicd.data.model.SmsData) SmsDetectionString(com.secupwn.aimsicd.data.model.SmsDetectionString) Cleanup(lombok.Cleanup) Realm(io.realm.Realm)

Example 10 with Cleanup

use of lombok.Cleanup in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class SmsDetector method run.

@Override
public void run() {
    setSmsDetectionState(true);
    BufferedReader mLogcatReader;
    try {
        Thread.sleep(500);
        String MODE = "logcat -v time -b radio -b main\n";
        Runtime r = Runtime.getRuntime();
        Process process = r.exec("su");
        @Cleanup DataOutputStream dos = new DataOutputStream(process.getOutputStream());
        dos.writeBytes(MODE);
        dos.flush();
        mLogcatReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    } catch (InterruptedException | IOException e) {
        log.error("Exception while initializing LogCat (time, radio, main) reader", e);
        return;
    }
    String logcatLine;
    List<String> logcatLines = new ArrayList<>();
    while (getSmsDetectionState()) {
        try {
            logcatLine = mLogcatReader.readLine();
            if (logcatLines.size() <= LOGCAT_BUFFER_MAX_SIZE || logcatLine != null) {
                logcatLines.add(logcatLine);
            } else if (logcatLines.size() == 0) {
                /**
                     * Sleep only when there is no more input, not after going through buffer
                     * to not unnecessary slow down the process
                     * */
                Thread.sleep(1000);
            } else {
                /**
                     * In moment, where there are no data
                     * we check the current buffer and clear it
                     * */
                String[] outLines = new String[logcatLines.size()];
                logcatLines.toArray(outLines);
                for (int counter = 0; counter < logcatLines.size(); counter++) {
                    String bufferedLine = logcatLines.get(counter);
                    switch(checkForSms(bufferedLine)) {
                        case TYPE0:
                            parseTypeZeroSms(outLines, MiscUtils.parseLogcatTimeStamp(bufferedLine));
                            break;
                        case MWI:
                            parseMwiSms(outLines, MiscUtils.parseLogcatTimeStamp(bufferedLine));
                            break;
                        case WAP:
                            int remainingLinesInBuffer = logcatLines.size() - counter - LOGCAT_WAP_EXTRA_LINES;
                            if (remainingLinesInBuffer < 0) {
                                /**
                                     * we need to go forward a few more lines to get data
                                     * and store it in post buffer array
                                     * */
                                String[] wapPostLines = new String[Math.abs(remainingLinesInBuffer)];
                                String extraLine;
                                for (int x = 0; x < Math.abs(remainingLinesInBuffer); x++) {
                                    extraLine = mLogcatReader.readLine();
                                    if (extraLine != null) {
                                        wapPostLines[x] = extraLine;
                                    }
                                }
                                /**
                                     * We'll add the extra lines to logcat buffer, so we don't miss anything
                                     * on detection cycle continue
                                     * */
                                int insertCounter = logcatLines.size();
                                for (String postLine : wapPostLines) {
                                    logcatLines.add(counter + insertCounter, postLine);
                                    insertCounter++;
                                }
                            }
                            /**
                                 * Will readout from LogcatBuffer remaining lines, or next LOGCAT_WAP_EXTRA_LINES lines
                                 * depending on how many are available
                                 * */
                            int availableLines = Math.min(logcatLines.size() - counter - LOGCAT_WAP_EXTRA_LINES, LOGCAT_WAP_EXTRA_LINES);
                            String[] nextAvailableLines = new String[availableLines];
                            for (int nextLine = 0; nextLine < availableLines; nextLine++) {
                                nextAvailableLines[nextLine] = logcatLines.get(counter + nextLine);
                            }
                            parseWapPushSms(outLines, nextAvailableLines, MiscUtils.parseLogcatTimeStamp(bufferedLine));
                            break;
                    }
                    counter++;
                }
                logcatLines.clear();
            }
        } catch (IOException e) {
            log.error("IO Exception", e);
        } catch (InterruptedException e) {
            log.error("Interrupted Exception", e);
        }
    }
    try {
        mLogcatReader.close();
    } catch (IOException ee) {
        log.error("IOE Error closing BufferedReader", ee);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) DataOutputStream(java.io.DataOutputStream) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) SmsDetectionString(com.secupwn.aimsicd.data.model.SmsDetectionString) IOException(java.io.IOException) Cleanup(lombok.Cleanup)

Aggregations

Cleanup (lombok.Cleanup)16 Realm (io.realm.Realm)13 SmsDetectionString (com.secupwn.aimsicd.data.model.SmsDetectionString)4 SmsData (com.secupwn.aimsicd.data.model.SmsData)3 IOException (java.io.IOException)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Drawable (android.graphics.drawable.Drawable)2 CdmaCellLocation (android.telephony.cdma.CdmaCellLocation)2 GsmCellLocation (android.telephony.gsm.GsmCellLocation)2 Import (com.secupwn.aimsicd.data.model.Import)2 CellTowerMarker (com.secupwn.aimsicd.map.CellTowerMarker)2 MarkerData (com.secupwn.aimsicd.map.MarkerData)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 GeoPoint (org.osmdroid.util.GeoPoint)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1