Created a new driver, which I found on the phone “/system/vendor/lib/hw/[email protected]”. As I understand it is responsible for the camera video stream. Created via c++ file on android studio. Which creates the same file, again theoretically) But I can not check, since the file does not allow me to replace even with the flag “setenforce 0”.
From the input phone is rooted, the application is accessed by the superuser.
Created a separate method that will check the success of the camera substitution by checking its date:
extern "C" JNIEXPORT jlong JNICALL
Java_com_example_rtmpstreamchanger_MainActivity_checkFileModificationDateNative(JNIEnv* env, jobject thiz, jstring filePath) {
const char *path = env->GetStringUTFChars(filePath, nullptr);
int result = system("su -c 'setenforce 0'");
if (result != 0) {
ALOGE("Failed to set SELinux to permissive mode, result: %d", result);
} else {
ALOGI("SELinux set to permissive mode successfully.");
}
struct stat attrib;
if (stat(path, &attrib) == -1) {
ALOGE("Error accessing file: %s. Error: %s", path, strerror(errno));
env->ReleaseStringUTFChars(filePath, path);
result = system("su -c 'setenforce 0'");
if (result != 0) {
ALOGE("Failed to set SELinux back to enforcing mode, result: %d", result);
} else {
ALOGI("SELinux set back to enforcing mode successfully.");
}
return (jlong)0;
}
ALOGI("File modification time for %s is %ld", path, (long)attrib.st_mtime);
env->ReleaseStringUTFChars(filePath, path);
result = system("su -c 'setenforce 0'");
if (result != 0) {
ALOGE("Failed to set SELinux back to enforcing mode after operation, result: %d", result);
} else {
ALOGI("SELinux restored to enforcing mode after operation successfully.");
}
return (jlong)attrib.st_mtime;
}
Produces logs like this:
2024-06-04 09:22:35.699 6561-6561 native-lib com.example.rtmpstreamchanger I SELinux set to permissive mode successfully.
2024-06-04 09:22:35.699 6561-6561 native-lib com.example.rtmpstreamchanger I File modification time for /system/vendor/lib/hw/[email protected] is 1230768000
2024-06-04 09:22:35.696 6561-6561 mpstreamchanger com.example.rtmpstreamchanger I type=1400 audit(0.0:50863): avc: denied { getattr } for path="/vendor/lib/hw/[email protected]" dev="dm-4" ino=1202 scontext=u:r:untrusted_app:s0:c23,c257,c512,c768 tcontext=u:object_r:vendor_file:s0 tclass=file permissive=1 app=com.example.rtmpstreamchanger
2024-06-04 09:22:35.809 6561-6561 native-lib com.example.rtmpstreamchanger I SELinux restored to enforcing mode after operation successfully.
2024-06-04 09:22:35.838 6561-6561 CameraLibPath com.example.rtmpstreamchanger I Last modified file date /system/vendor/lib/hw/[email protected]: Thu Jan 01 03:00:00 GMT+03:00 2009
That is, I see the flag of insufficient access denied { getattr }
And I also see the date, apparently by default.
I’ve tried so many things. I don’t understand why it doesn’t work.
I tried many options. For example, change this file via java or change it via ndk (c++)
Alexander Shevkunov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.