Skip to content

Commit

Permalink
AT Command Injection Started, Code Cleanup/Updates, Java 1.7 Language…
Browse files Browse the repository at this point in the history
… Updates

Extension of the Samsung MultiRil to attempt hooking of the OemHookStrings method,
presently I am not 100% certain this will work but the basic framework and extensions
have been made to modify the current implementation to deal with the Strings request
data and responses.

This still requires work and as such is currently disabled until further testing
has been completed as it will cause the socket to disconnect.

Huge code cleanup and updates to a number of areas with optimisations across a large
number of packages, some unused imports removed and code comments added to a variety
of methods.

Addressed a number of possible NPE causes through different parts of the application
which will ultimately provide better stability and an increased user experience,
although in saying that these items were not causing any issues that had been reported
but prevention is better then a cure right?!?! :)

Use of Java 1.7 language rules have further allowed updates to take advantage of
the highler langauge level with removal of explicit types within arrays, lists, maps
etc plus other changes.

Unnecessary compatibility library removed which has resulted in a reduction in size
of the APK.

Reversed the previous change to insert the Cell ID and Lac in Hex format to allow
further time to ensure all methods that utilise these variables to be updated, the
original change was made too quickly and resulted in a number of issues so I have
returned to the standard integer format until I have more time to ensure this
change is implemented correctly.
  • Loading branch information
xLaMbChOpSx committed May 21, 2014
1 parent 90a7402 commit c2b2a45
Show file tree
Hide file tree
Showing 24 changed files with 798 additions and 308 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ android {

dependencies {
compile files('libs/opencsv-2.3.jar')
compile 'com.android.support:appcompat-v7:19.1.+'
compile 'com.google.android.gms:play-services:4.3.23'
compile 'com.google.android.gms:play-services:4.4.52'
compile 'com.android.support:support-v4:19.+'
}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.SecUpwN.AIMSICD"
android:versionCode="15"
android:versionName="0.1.15" >
android:versionCode="16"
android:versionName="0.1.16" >

<uses-feature
android:glEsVersion="0x00020000"
Expand Down
70 changes: 41 additions & 29 deletions app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.SecUpwN.AIMSICD.activities.MapViewer;
import com.SecUpwN.AIMSICD.activities.PrefActivity;
import com.SecUpwN.AIMSICD.fragments.AboutFragment;
import com.SecUpwN.AIMSICD.fragments.AtCommandFragment;
import com.SecUpwN.AIMSICD.fragments.CellInfoFragment;
import com.SecUpwN.AIMSICD.fragments.DbViewerFragment;
import com.SecUpwN.AIMSICD.fragments.DeviceFragment;
Expand All @@ -61,7 +62,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
Expand All @@ -81,9 +81,6 @@ public class AIMSICD extends FragmentActivity {

private final String TAG = "AIMSICD";

private MyFragmentPagerAdapter mMyFragmentPagerAdapter;
private ViewPager mViewPager;

private final Context mContext = this;
private boolean mBound;
private SharedPreferences prefs;
Expand All @@ -110,9 +107,10 @@ public void onCreate(Bundle savedInstanceState) {
startService(intent);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager)findViewById(R.id.viewPager);
mViewPager.setAdapter(mMyFragmentPagerAdapter);
MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter(
getSupportFragmentManager());
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setAdapter(myFragmentPagerAdapter);

prefs = mContext.getSharedPreferences(
AimsicdService.SHARED_PREFERENCES_BASENAME, 0);
Expand Down Expand Up @@ -209,31 +207,45 @@ public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem mTrackFemtocell = menu.findItem(R.id.track_femtocell);

if (mBound && mAimsicdService.isTrackingCell()) {
mTrackCell.setTitle(R.string.untrack_cell);
mTrackCell.setIcon(R.drawable.track_cell);
if (mTrackCell != null) {
mTrackCell.setTitle(R.string.untrack_cell);
mTrackCell.setIcon(R.drawable.track_cell);
}
} else {
mTrackCell.setTitle(R.string.track_cell);
mTrackCell.setIcon(R.drawable.untrack_cell);
if (mTrackCell != null) {
mTrackCell.setTitle(R.string.track_cell);
mTrackCell.setIcon(R.drawable.untrack_cell);
}
}

if (mBound && mAimsicdService.isTrackingLocation()) {
mTrackLocation.setTitle(R.string.untrack_location);
mTrackLocation.setIcon(R.drawable.ic_action_location_found);
if (mTrackLocation != null) {
mTrackLocation.setTitle(R.string.untrack_location);
mTrackLocation.setIcon(R.drawable.ic_action_location_found);
}
} else {
mTrackLocation.setTitle(R.string.track_location);
mTrackLocation.setIcon(R.drawable.ic_action_location_off);
if (mTrackLocation != null) {
mTrackLocation.setTitle(R.string.track_location);
mTrackLocation.setIcon(R.drawable.ic_action_location_off);
}
}

if (mBound && mAimsicdService.getPhoneID() == TelephonyManager.PHONE_TYPE_CDMA) {
if (mBound && mAimsicdService.isTrackingFemtocell()) {
mTrackFemtocell.setTitle(R.string.untrack_femtocell);
mTrackFemtocell.setIcon(R.drawable.ic_action_network_cell);
if (mTrackFemtocell != null) {
mTrackFemtocell.setTitle(R.string.untrack_femtocell);
mTrackFemtocell.setIcon(R.drawable.ic_action_network_cell);
}
} else {
mTrackFemtocell.setTitle(R.string.track_femtocell);
mTrackFemtocell.setIcon(R.drawable.ic_action_network_cell_not_tracked);
if (mTrackFemtocell != null) {
mTrackFemtocell.setTitle(R.string.track_femtocell);
mTrackFemtocell.setIcon(R.drawable.ic_action_network_cell_not_tracked);
}
}
} else {
mTrackFemtocell.setVisible(false);
if (mTrackFemtocell != null) {
mTrackFemtocell.setVisible(false);
}
}

return super.onPrepareOptionsMenu(menu);
Expand Down Expand Up @@ -391,12 +403,12 @@ private Boolean isNetAvailable(Context context) {
NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobileInfo =
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (wifiInfo.isConnected() || mobileInfo.isConnected()) {
return true;
if (wifiInfo != null && mobileInfo != null) {
return wifiInfo.isConnected() || mobileInfo.isConnected();
}
}
catch(Exception e){
e.printStackTrace();
Log.e(TAG, "isNetAvailable " + e);
}
return false;
}
Expand Down Expand Up @@ -463,8 +475,6 @@ protected String doInBackground(String... uri) {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
//TODO Handle problems..
} catch (IOException e) {
//TODO Handle problems..
}
Expand Down Expand Up @@ -506,17 +516,19 @@ protected void onPostExecute(String result) {


class MyFragmentPagerAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
private List<String> titles;
private final List<Fragment> fragments;
private final List<String> titles;

public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
this.fragments = new ArrayList<Fragment>();
titles = new ArrayList<String>();
this.fragments = new ArrayList<>();
titles = new ArrayList<>();
fragments.add(new DeviceFragment());
titles.add(getString(R.string.device_info));
fragments.add(new CellInfoFragment());
titles.add(getString(R.string.cell_info_title));
fragments.add(new AtCommandFragment());
titles.add(getString(R.string.at_command_title));
fragments.add(new DbViewerFragment());
titles.add(getString(R.string.db_viewer));
fragments.add(new AboutFragment());
Expand Down
25 changes: 12 additions & 13 deletions app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ public class MapViewer extends FragmentActivity implements OnSharedPreferenceCha
private final String TAG = "AIMSICD_MapViewer";

private GoogleMap mMap;
private UiSettings mUiSettings;

private AIMSICDDbAdapter mDbHelper;
private Context mContext;
private LatLng loc = null;
private SharedPreferences prefs;
private String mapTypePref;

/**
* Called when the activity is first created.
Expand All @@ -106,7 +105,7 @@ public void onCreate(Bundle savedInstanceState) {
mDbHelper = new AIMSICDDbAdapter(this);
loadEntries();
mContext = this;
mapTypePref = getResources().getString(R.string.pref_map_type_key);
String mapTypePref = getResources().getString(R.string.pref_map_type_key);
prefs = mContext.getSharedPreferences(
AimsicdService.SHARED_PREFERENCES_BASENAME, 0);
if (prefs.contains(mapTypePref)) {
Expand Down Expand Up @@ -157,14 +156,14 @@ private void setUpMapIfNeeded() {
// Check if we were successful in obtaining the map.
if (mMap != null) {
// The Map is verified. It is now safe to manipulate the map.
mUiSettings = mMap.getUiSettings();
mUiSettings.setZoomControlsEnabled(true);
mUiSettings.setCompassEnabled(true);
mUiSettings.setMyLocationButtonEnabled(true);
mUiSettings.setScrollGesturesEnabled(true);
mUiSettings.setZoomGesturesEnabled(true);
mUiSettings.setTiltGesturesEnabled(true);
mUiSettings.setRotateGesturesEnabled(true);
UiSettings uiSettings = mMap.getUiSettings();
uiSettings.setZoomControlsEnabled(true);
uiSettings.setCompassEnabled(true);
uiSettings.setMyLocationButtonEnabled(true);
uiSettings.setScrollGesturesEnabled(true);
uiSettings.setZoomGesturesEnabled(true);
uiSettings.setTiltGesturesEnabled(true);
uiSettings.setRotateGesturesEnabled(true);
mMap.setMyLocationEnabled(true);
} else {
Helpers.sendMsg(this, "Unable to create map!");
Expand Down Expand Up @@ -441,8 +440,8 @@ private Boolean isNetAvailable(Context context) {
NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobileInfo =
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (wifiInfo.isConnected() || mobileInfo.isConnected()) {
return true;
if (wifiInfo != null && mobileInfo != null) {
return wifiInfo.isConnected() || mobileInfo.isConnected();
}
}
catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.SecUpwN.AIMSICD.adapters;

import com.SecUpwN.AIMSICD.R;
import com.SecUpwN.AIMSICD.rilexecutor.HexDump;

import android.app.AlertDialog;
import android.content.ContentValues;
Expand All @@ -19,7 +18,6 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

import au.com.bytecode.opencsv.CSVReader;
Expand All @@ -31,7 +29,7 @@ public class AIMSICDDbAdapter {

private final DbHelper mDbHelper;
private SQLiteDatabase mDb;
private Context mContext;
private final Context mContext;
private static final int DATABASE_VERSION = 4;
private static final String COLUMN_ID = "_id";
private final String LOCATION_TABLE = "locationinfo";
Expand All @@ -55,42 +53,6 @@ public void close() {
mDbHelper.close();
}

/**
* Location Tracking Database
*/
private final String LOC_DATABASE_CREATE = "create table " +
LOCATION_TABLE + " (" + COLUMN_ID +
" integer primary key autoincrement, Lac INTEGER, CellID INTEGER, " +
"Net VARCHAR, Lat VARCHAR, Lng VARCHAR, Signal INTEGER, Connection VARCHAR, " +
"Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);";

/**
* Cell Information Tracking Database
*/
private final String CELL_DATABASE_CREATE = "create table " +
CELL_TABLE + " (" + COLUMN_ID +
" integer primary key autoincrement, Lac INTEGER, CellID INTEGER, " +
"Net VARCHAR, Lat VARCHAR, Lng VARCHAR, Signal INTEGER, Connection VARCHAR, " +
"Country VARCHAR, Operator VARCHAR, OperatorName VARCHAR, " +
"Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);";

/**
* OpenCellID Cell Information Database
*/
private final String OPENCELLID_DATABASE_CREATE = "create table " +
OPENCELLID_TABLE + " (" + COLUMN_ID +
" integer primary key autoincrement, Lat VARCHAR, Lng VARCHAR, Mcc INTEGER, " +
"Mnc INTEGER, Lac INTEGER, CellID INTEGER, AvgSigStr INTEGER, Samples INTEGER, " +
"Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);";

/**
* Default MCC Location Database
*/
private final String DEFAULT_MCC_DATABASE_CREATE = "create table " +
DEFAULT_MCC_TABLE + " (" + COLUMN_ID +
" integer primary key autoincrement, Country VARCHAR, Mcc INTEGER, "
+ "Lat VARCHAR, Lng VARCHAR);";

/**
* Inserts Cell Details into Database
*
Expand All @@ -104,8 +66,8 @@ public long insertCell( int lac, int cellID,
if (cellID != -1) {
//Populate Content Values for Insert or Update
ContentValues cellValues = new ContentValues();
cellValues.put("Lac", HexDump.toHexString(lac));
cellValues.put("CellID", HexDump.toHexString(cellID));
cellValues.put("Lac", lac);
cellValues.put("CellID", cellID);
cellValues.put("Net", netType);
cellValues.put("Lat", latitude);
cellValues.put("Lng", longitude);
Expand Down Expand Up @@ -166,8 +128,8 @@ public long insertLocation(int lac, int cellID,
if (latitude != 0.0 && longitude != 0.0) {
//Populate Content Values for Insert or Update
ContentValues locationValues = new ContentValues();
locationValues.put("Lac", HexDump.toHexString(lac));
locationValues.put("CellID", HexDump.toHexString(cellID));
locationValues.put("Lac", lac);
locationValues.put("CellID", cellID);
locationValues.put("Net", netType);
locationValues.put("Lat", latitude);
locationValues.put("Lng", longitude);
Expand Down Expand Up @@ -224,7 +186,7 @@ public Cursor getDefaultMccLocationData() {
/**
* Checks to see if Location already exists in database
*/
public boolean locationExists(int cellID) {
boolean locationExists(int cellID) {
Cursor cursor = mDb.rawQuery("SELECT * FROM " + LOCATION_TABLE + " WHERE CellID = " +
cellID, null);

Expand All @@ -234,7 +196,7 @@ public boolean locationExists(int cellID) {
/**
* Checks to see if Cell already exists in database
*/
public boolean cellExists(int cellID) {
boolean cellExists(int cellID) {
Cursor cursor = mDb.rawQuery("SELECT * FROM " + CELL_TABLE + " WHERE CellID = " +
cellID, null);

Expand All @@ -244,7 +206,7 @@ public boolean cellExists(int cellID) {
/**
* Checks to see if Cell already exists in OpenCellID database
*/
public boolean openCellExists(int cellID) {
boolean openCellExists(int cellID) {
Cursor cursor = mDb.rawQuery("SELECT * FROM " + OPENCELLID_TABLE + " WHERE CellID = " +
cellID, null);

Expand Down Expand Up @@ -381,10 +343,50 @@ public class DbHelper extends SQLiteOpenHelper {

@Override
public void onCreate(SQLiteDatabase database) {
/*
* Location Tracking Database
*/
String LOC_DATABASE_CREATE = "create table " +
LOCATION_TABLE + " (" + COLUMN_ID +
" integer primary key autoincrement, Lac INTEGER, CellID INTEGER, " +
"Net VARCHAR, Lat VARCHAR, Lng VARCHAR, Signal INTEGER, Connection VARCHAR, " +
"Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);";
database.execSQL(LOC_DATABASE_CREATE);

/*
* Cell Information Tracking Database
*/
String CELL_DATABASE_CREATE = "create table " +
CELL_TABLE + " (" + COLUMN_ID +
" integer primary key autoincrement, Lac INTEGER, CellID INTEGER, " +
"Net VARCHAR, Lat VARCHAR, Lng VARCHAR, Signal INTEGER, Connection VARCHAR, " +
"Country VARCHAR, Operator VARCHAR, OperatorName VARCHAR, " +
"Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);";
database.execSQL(CELL_DATABASE_CREATE);

/*
* OpenCellID Cell Information Database
*/
String OPENCELLID_DATABASE_CREATE = "create table " +
OPENCELLID_TABLE + " (" + COLUMN_ID +
" integer primary key autoincrement, Lat VARCHAR, Lng VARCHAR, Mcc INTEGER, " +
"Mnc INTEGER, Lac INTEGER, CellID INTEGER, AvgSigStr INTEGER, Samples INTEGER, "
+
"Timestamp TIMESTAMP NOT NULL DEFAULT current_timestamp);";
database.execSQL(OPENCELLID_DATABASE_CREATE);

/*
* Default MCC Location Database
*/
String DEFAULT_MCC_DATABASE_CREATE = "create table " +
DEFAULT_MCC_TABLE + " (" + COLUMN_ID +
" integer primary key autoincrement, Country VARCHAR, Mcc INTEGER, "
+ "Lat VARCHAR, Lng VARCHAR);";
database.execSQL(DEFAULT_MCC_DATABASE_CREATE);

/*
* Repopulate the default MCC location table
*/
populateDefaultMCC(database);
}

Expand Down
Loading

0 comments on commit c2b2a45

Please sign in to comment.