TransWikia.com

Block any Screen Recorder from recording desktop in Ubuntu

Unix & Linux Asked on November 21, 2021

I am using Ubuntu 18.04
I want to make a program that can block screen recording.
I have tried 2 ways to achieve this

1. Using mandatory file lock in c++

#include<bits/stdc++.h>
#include<unistd.h>
#include<fcntl.h>
#include <sys/file.h>
using namespace std;
int main(int argc,char **argv)
{
    int fd = open(argv[1], O_RDWR);
    static struct flock lock;
    lock.l_type = F_WRLCK;  //F_WRLCK   F_RDLCK
    lock.l_start = 0;
    lock.l_whence = SEEK_SET;
    lock.l_len = 0;
    lock.l_pid = getpid();
    
    cout<< fcntl(fd, F_SETLKW, &lock)<<'n';
   
    while (1) {      }  // to run this application so lock didn't release
    //will add release lock function here

    return 0;
} 

I will lock the device file /dev/video0 which is used for the camera. In the same way I will lock the file which is used to record screen (currently I don’t know which device file used for screen recording).
This will keep the file locked so no other application can read from it.

2. Changing file permission
If i run
sudo chmod 002 /dev/snd (snd is responsible for audio)
It will change file permission to group write so no application can read data due to no permission.It will not play any audio and even videos which have audio.

Problem in both methods what i am facing

In 1st method
Somestimes files didn’t get locked and when it gets locked application can still read data from that.

In 2nd method
When I revert permission back to chmod 772 then the application is not able to read that change means they are not able to play any audio, to make that effect I have to reboot the system.

What needed to solve problem

In 1st method
After the file being got locked no process can read that device file.

In 2nd method
When I revert permission to 772, I don’t have to reboot for an application can read that effect. I should restart that audio process instead of PC.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP