android4.4 (kitkat), how to make APP can directly write SMS messages

The modification of the following code is developed for the android platform. In addition, if there is no system source code, it can also be done by reverse modifying the corresponding files in the ROM.

The reason for this requirement is that if it is your own ROM, you need to grant SMS write permission to one of your own APPs. You can modify the OTHERSMS_PACKAGE_NAME in the following code and replace it with the package name of your own APP.

If it is an application like QQ address book, can it be done with the permission to obtain ROOT? I think it can be achieved. You can inject relevant code fragments into the memory, try to analyze the QQ address book, and find it. After obtaining ROOT, there is an injection operation, but it does not implement the following functions. The current version of QQ address book is on Android 4.4 (KitKat), and there are still problems.

Not much to say, go directly to the code and study it yourself~

diff --git a/src/java/com/android/internal/telephony/SmsApplication.java b/src/java/com/android/internal/telephony/SmsApplication.java
index 0582df8..39dee4c 100644
--- a/src/java/com/android/internal/telephony/SmsApplication.java
+++ b/src/java/com/android/internal/telephony/SmsApplication.java
@@ -49,6 +49,7 @@ public final class SmsApplication {
static final String LOG_TAG = "SmsApplication";
private static final String PHONE_PACKAGE_NAME = "com.android.phone";
private static final String BLUETOOTH_PACKAGE_NAME = "com.android.bluetooth";
+    private static final String OTHERSMS_PACKAGE_NAME = "com.example.demo";
 
private static final String SCHEME_SMS = "sms";
private static final String SCHEME_SMSTO = "smsto";
@@ -357,6 +358,20 @@ public final class SmsApplication {
// No BT app on this device
Rlog.e(LOG_TAG, "Bluetooth package not found: " + BLUETOOTH_PACKAGE_NAME);
}
+
+                try {
+                    PackageInfo info = packageManager.getPackageInfo(OTHERSMS_PACKAGE_NAME, 0);
+                    int mode = appOps.checkOp(AppOpsManager.OP_WRITE_SMS, info.applicationInfo.uid,
+                            OTHERSMS_PACKAGE_NAME);
+                    if (mode != AppOpsManager.MODE_ALLOWED) {
+                        Rlog.e(LOG_TAG, OTHERSMS_PACKAGE_NAME + " lost OP_WRITE_SMS:  (fixing)");
+                        appOps.setMode(AppOpsManager.OP_WRITE_SMS, info.applicationInfo.uid,
+                                OTHERSMS_PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
+                    }
+                } catch (NameNotFoundException e) {
+                    // No BT app on this device
+                    Rlog.e(LOG_TAG, "3rd sms package not found: " + OTHERSMS_PACKAGE_NAME);
+                }
}
}
return applicationData;

 

Welcome to reprint: http://www.yinqisen.cn/blog-310.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326601680&siteId=291194637