Skip to content

Commit 00ced4f

Browse files
committed
AT Command Injection
First thing you need to do before using this is give a BIG THANK YOU to @E3V3A (E:V:A on xda) for determining how this implementation was possible because without his perseverance this would not be possible! ROOT IS REQUIRED!! Root terminal methods are used to execute the AT Command Injection so this fragment will check for both ROOT (su binary) and BUSYBOX to confirm both are available on your device, if not the execution section of the fragment WILL NOT DISPLAY. If the initial setup works correctly the next step is trying to determine your Ril Serial Device through the system property ril.libargs if this is successful then you are in business and the AT Command Injection system is available for you to test. This will probably NOT WORK on many devices (such as my i9100) but it will provide details of the failure if available and display them to the screen but also write them to the file error.txt in the AIMSICD directory of your external storage. Have fun and try not to break anything.
1 parent abb4ebf commit 00ced4f

File tree

8 files changed

+178
-60
lines changed

8 files changed

+178
-60
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ android {
2323
assets.srcDirs = ['src/main/assets']
2424
}
2525
}
26-
2726
compileOptions {
2827
sourceCompatibility JavaVersion.VERSION_1_7
2928
targetCompatibility JavaVersion.VERSION_1_7
3029
}
31-
30+
productFlavors {
31+
}
3232
}
3333

3434
dependencies {

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.SecUpwN.AIMSICD"
4-
android:versionCode="19"
5-
android:versionName="0.1.19">
4+
android:versionCode="20"
5+
android:versionName="0.1.20">
66

77
<uses-feature
88
android:glEsVersion="0x00020000"

app/src/main/java/com/SecUpwN/AIMSICD/fragments/AtCommandFragment.java

Lines changed: 117 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,68 @@
22

33
import com.SecUpwN.AIMSICD.R;
44
import com.SecUpwN.AIMSICD.service.AimsicdService;
5+
import com.SecUpwN.AIMSICD.utils.CMDProcessor;
6+
import com.SecUpwN.AIMSICD.utils.CommandResult;
57
import com.SecUpwN.AIMSICD.utils.Helpers;
68

79
import android.app.Activity;
10+
import android.app.Fragment;
811
import android.content.ComponentName;
912
import android.content.Context;
1013
import android.content.Intent;
1114
import android.content.ServiceConnection;
1215
import android.os.AsyncTask;
1316
import android.os.Bundle;
1417
import android.os.IBinder;
15-
import android.app.Fragment;
1618
import android.text.TextUtils;
1719
import android.util.Log;
1820
import android.view.LayoutInflater;
1921
import android.view.View;
2022
import android.view.ViewGroup;
2123
import android.widget.Button;
2224
import android.widget.EditText;
25+
import android.widget.RelativeLayout;
2326
import android.widget.TextView;
2427

2528
import java.util.List;
2629

2730
public class AtCommandFragment extends Fragment {
2831

32+
//Return value constants
33+
private final int RIL_INIT_OK = 200;
34+
private final int RIL_INIT_ERROR = 201;
35+
private final int ROOT_UNAVAILABLE = 202;
36+
private final int BUSYBOX_UNAVAILABLE = 203;
37+
38+
//System items
2939
private AimsicdService mAimsicdService;
3040
private boolean mBound;
3141
private Context mContext;
3242
private Activity mActivity;
43+
44+
//Layout items
3345
private View mView;
46+
private RelativeLayout mAtCommandLayout;
47+
private TextView mAtCommandError;
48+
private TextView mRilDeviceDisplay;
3449
private Button mAtCommandExecute;
3550
private TextView mAtResponse;
3651
private EditText mAtCommand;
52+
private String mRilDevice;
3753

3854
@Override
3955
public View onCreateView(LayoutInflater inflater, ViewGroup container,
4056
Bundle savedInstanceState) {
4157
mView = inflater.inflate(R.layout.at_command_fragment, container, false);
4258
if (mView != null) {
59+
mAtCommandLayout = (RelativeLayout) mView.findViewById(R.id.atcommandView);
60+
mAtCommandError = (TextView) mView.findViewById(R.id.at_command_error);
4361
mAtCommandExecute = (Button) mView.findViewById(R.id.execute);
62+
mRilDeviceDisplay = (TextView) mView.findViewById(R.id.ril_device);
63+
mAtResponse = (TextView) mView.findViewById(R.id.response);
64+
mAtCommand = (EditText) mView.findViewById(R.id.at_command);
65+
mAtCommandExecute.setOnClickListener(new btnClick());
4466
}
45-
mAtCommandExecute.setOnClickListener(new btnClick());
46-
mAtResponse = (TextView) mView.findViewById(R.id.response);
47-
mAtCommand = (EditText) mView.findViewById(R.id.at_command);
4867

4968
return mView;
5069
}
@@ -74,6 +93,54 @@ public void onDestroy() {
7493
}
7594
}
7695

96+
@Override
97+
public void onResume() {
98+
super.onResume();
99+
if (!mBound) {
100+
// Bind to LocalService
101+
Intent intent = new Intent(mContext, AimsicdService.class);
102+
mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
103+
}
104+
105+
int rilInit = initialiseRil();
106+
107+
switch (rilInit) {
108+
case RIL_INIT_OK:
109+
mAtCommandLayout.setVisibility(View.VISIBLE);
110+
break;
111+
case ROOT_UNAVAILABLE:
112+
String rootUnavailable = "Unable to acquire ROOT access on your device. \n\n" +
113+
"AT Command Injection requires ROOT Terminal access. \n\n" +
114+
"Please check your device is ROOTED and try again";
115+
mAtCommandError.setText(rootUnavailable);
116+
break;
117+
case BUSYBOX_UNAVAILABLE:
118+
String busyboxUnavailable = "Unable to detect Busybox on your device. \n\n" +
119+
"AT Command Injection requires Busybox components to function correctly. \n\n"
120+
+ "Please check your device has Busybox installed and try again";
121+
mAtCommandError.setText(busyboxUnavailable);
122+
break;
123+
case RIL_INIT_ERROR:
124+
String error =
125+
"An unknown error has occurred trying to acquire the Ril Serial Device.\n\n"
126+
+ "Please check your logcat for any errors and post them to Github "
127+
+ "or XDA, links to both of these locations can be found within the "
128+
+ "About section of the application.";
129+
mAtCommandError.setText(error);
130+
break;
131+
default:
132+
String unknownError =
133+
"An unknown error has occurred trying to initialise the AT Command Injector.\n\n"
134+
+ "Please check your logcat for any errors and post them to Github or "
135+
+ "XDA, links to both of these locations can be found within the "
136+
+ "About section of the application.";
137+
mAtCommandError.setText(unknownError);
138+
break;
139+
}
140+
141+
142+
}
143+
77144
/**
78145
* Service Connection to bind the activity to the service
79146
*/
@@ -92,53 +159,65 @@ public void onServiceDisconnected(ComponentName arg0) {
92159
};
93160

94161
private class btnClick implements View.OnClickListener {
162+
95163
@Override
96164
public void onClick(View v) {
97-
executeAT();
165+
executeAT();
98166
}
99167
}
100168

101-
private void executeAT() {
102-
/* if (mBound && !mView.findViewById(R.id.at_command).toString().isEmpty()) {
103-
//Try SamSung MultiRil Implementation
104-
DetectResult rilStatus = mAimsicdService.getRilExecutorStatus();
105-
if (rilStatus.available) {
106-
new RequestOemInfoTask().execute();
107-
}
108-
}*/
109-
Helpers.sendMsg(mContext, "Coming soon...");
110-
}
169+
private int initialiseRil() {
170+
//Check for root access
171+
boolean root = Helpers.checkSu();
172+
if (!root) {
173+
return ROOT_UNAVAILABLE;
174+
}
111175

112-
private void requestResponse() {
113-
try {
114-
String[] atCommand = new String[]{mAtCommand.getText().toString()};
115-
final List<String> list = mAimsicdService.executeAtCommand(atCommand);
116-
mActivity.runOnUiThread(new Runnable() {
117-
@Override
118-
public void run() {
119-
if (list != null) {
120-
mAtResponse.setText(TextUtils.join("\n", list));
121-
}
122-
}
123-
});
124-
}catch (Exception e) {
125-
Log.e("AIMSICD", "requestResponse " + e);
176+
//Check busybox is installed
177+
boolean busybox = Helpers.checkBusybox();
178+
if (!busybox) {
179+
return BUSYBOX_UNAVAILABLE;
126180
}
181+
182+
//Draw Ril Serial Device details from the System Property
183+
String rilDevice = Helpers.getSystemProp(mContext, "rild.libargs", "UNKNOWN");
184+
mRilDevice = (rilDevice.equals("UNKNOWN") ? rilDevice : rilDevice.substring(3));
185+
mRilDeviceDisplay.setText(mRilDevice);
186+
187+
if (mRilDevice.equals("UNKNOWN"))
188+
return RIL_INIT_ERROR;
189+
190+
return RIL_INIT_OK;
127191
}
128192

193+
private void executeAT() {
194+
if (mAtCommand.getText() != null) {
195+
mAtResponse.setText("");
196+
String cmdSetup = "cat " + mRilDevice + " &";
197+
new ExecuteAtCommand().execute(cmdSetup);
198+
String atCommand = mAtCommand.getText().toString();
199+
new ExecuteAtCommand().execute("echo -e " + atCommand +"\r > " + mRilDevice);
200+
}
201+
}
129202

130-
private class RequestOemInfoTask extends AsyncTask<Void, Void, Void> {
131-
@Override
132-
protected Void doInBackground(Void... string) {
133-
if (!mBound) return null;
134-
requestResponse();
203+
private class ExecuteAtCommand extends AsyncTask<String, Integer, CommandResult> {
135204

136-
return null;
205+
protected CommandResult doInBackground(String... atCommand) {
206+
return CMDProcessor.runSuCommand(atCommand[0]);
137207
}
138208

139-
@Override
140-
protected void onPostExecute(Void aVoid) {
141-
super.onPostExecute(aVoid);
209+
protected void onPostExecute(CommandResult result) {
210+
if (result != null) {
211+
Log.i("AIMSICD_ATCommand", "Stdout: " + result.getStdout() +
212+
" StdErr: " + result.getStderr() + " Exit Value: " + result.getExitValue());
213+
if (!result.getStdout().isEmpty())
214+
mAtResponse.append(result.getStdout());
215+
else if (!result.getStderr().isEmpty())
216+
mAtResponse.append(result.getStderr());
217+
else
218+
mAtResponse.append("No response or error detected...");
219+
}
142220
}
143221
}
222+
144223
}

app/src/main/java/com/SecUpwN/AIMSICD/utils/CommandResult.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
package com.SecUpwN.AIMSICD.utils;
2323

24+
import com.SecUpwN.AIMSICD.adapters.AIMSICDDbAdapter;
25+
2426
import android.os.Environment;
2527
import android.os.Parcel;
2628
import android.os.Parcelable;
@@ -106,8 +108,7 @@ private void checkForErrors() {
106108
FileWriter errorWriter = null;
107109
try {
108110
File errorLogFile = new File(
109-
Environment.getExternalStorageDirectory()
110-
+ "/aokp/error.txt"
111+
AIMSICDDbAdapter.FOLDER + "error.txt"
111112
);
112113
if (!errorLogFile.exists()) {
113114
errorLogFile.createNewFile();
@@ -175,7 +176,6 @@ public CommandResult[] newArray(int size) {
175176
}
176177
};
177178

178-
179179
@Override
180180
public boolean equals(Object o) {
181181
if (this == o) {
@@ -189,8 +189,8 @@ public boolean equals(Object o) {
189189

190190
return (mStartTime == that.mStartTime &&
191191
mExitValue == that.mExitValue &&
192-
mStdout == that.mStdout &&
193-
mStderr == that.mStderr &&
192+
mStdout.equals(that.mStdout) &&
193+
mStderr.equals(that.mStderr) &&
194194
mEndTime == that.mEndTime);
195195
}
196196

app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static Boolean isNetAvailable(Context context) {
125125
* @param lat Latitude of current location
126126
* @param lng Longitude of current location
127127
*/
128-
public static void getOpenCellData(Context context, double lat, double lng, int type) {
128+
public static void getOpenCellData(Context context, double lat, double lng, char type) {
129129
if (Helpers.isNetAvailable(context)) {
130130
double earthRadius = 6371.01;
131131

app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@
2222
import java.net.URL;
2323
import java.net.URLConnection;
2424

25-
public class RequestTask extends AsyncTask<String, String, String> {
25+
public class RequestTask extends AsyncTask<String, Integer, String> {
2626

27-
public static final int OPEN_CELL_ID_REQUEST = 1;
28-
public static final int OPEN_CELL_ID_REQUEST_FROM_MAP = 2;
29-
public static final int BACKUP_DATABASE = 3;
30-
public static final int RESTORE_DATABASE = 4;
27+
public static final char OPEN_CELL_ID_REQUEST = 1;
28+
public static final char OPEN_CELL_ID_REQUEST_FROM_MAP = 2;
29+
public static final char BACKUP_DATABASE = 3;
30+
public static final char RESTORE_DATABASE = 4;
3131

3232
private final AIMSICDDbAdapter mDbAdapter;
3333
private final Context mContext;
34-
private final int mType;
34+
private final char mType;
3535

36-
public RequestTask(Context context, int type) {
36+
public RequestTask(Context context, char type) {
3737
mType = type;
3838
mContext = context;
3939
mDbAdapter = new AIMSICDDbAdapter(mContext);
4040
}
4141

4242
@Override
43-
protected String doInBackground(String... urlString) {
43+
protected String doInBackground(String... commandString) {
4444

4545
switch (mType) {
4646
case OPEN_CELL_ID_REQUEST:
@@ -56,7 +56,7 @@ protected String doInBackground(String... urlString) {
5656
}
5757
File file = new File(dir, "opencellid.csv");
5858

59-
URL url = new URL(urlString[0]);
59+
URL url = new URL(commandString[0]);
6060
URLConnection connection = url.openConnection();
6161
connection.connect();
6262

@@ -78,7 +78,7 @@ protected String doInBackground(String... urlString) {
7878

7979
while ((count = input.read(data)) != -1) {
8080
total += count;
81-
AIMSICD.mProgressBar.setProgress((int) ((total * 100) / lengthOfFile));
81+
publishProgress((int) ((total * 100) / lengthOfFile));
8282

8383
// writing data to file
8484
output.write(data, 0, count);
@@ -118,6 +118,11 @@ protected String doInBackground(String... urlString) {
118118
return null;
119119
}
120120

121+
122+
protected void onProgressUpdate(Integer... values) {
123+
AIMSICD.mProgressBar.setProgress(values[0]);
124+
}
125+
121126
@Override
122127
protected void onPostExecute(String result) {
123128
super.onPostExecute(result);

0 commit comments

Comments
 (0)