Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

Windows' Permission 1.5

2.71/5 (6 votes)
17 Oct 2012CPL5 min read 16.8K   1K  
This program protects and locks every window in Windows, and encrypts files without any problem.

Introduction

There are too many security programs that lock, encrypt,... files in different forms, but sometimes working with them is not easy and takes a long time. Also, some of them are heavy and slow.

This always made me think about developing a quick, easy, and powerful program on my own. Therefore I decided to design a program that protects and locks every window in Windows and encrypts any files, even large ones, without any problem. I think my program is quite useful.

Features

  • Takes little space from RAM and hard memory.
  • Does the job quickly, with just a few clicks.
  • Doesn't change the file's data.
  • Has good and suitable security.
  • Locks file in every format.
  • Locks every window that appears.
  • Included with Explorer with a nice environment.
  • It's like a gadget.
  • Encrypts files with non-returnable algorithm.
  • Can run in XP, Vista, and 7.
  • Doesn't need external program or library such as .NET Framework.
  • Runs for all users, even if you add a user later or for a limited user account.
  • Has a very quick installer.

First Main Part - Locking files

This works quickly because when you lock a file, the program keeps the file in open mode and doesn't change the file's data. It's easy and clear and doesn't allow the user to open, delete, move, rename, copy, or cut the file. Nothing can be done unless you unlock the file. It works when the program is opened (system loaded). It's not a system driver.

Second Main Part - Encrypting files

This program includes two encryption algorithms. First one is a common algorithm, and the second a non-returnable algorithm. Even if you're encrypting a large file and cancel it when the program is working, you can decrypt the incomplete file.

Third Main Part - Locking windows

This part is very useful and a new subject in security. Have you ever thought of how you can lock a window if we don't have its executable file, such as "Start menu", "Action Center", "System Properties", "Volume mixer", and other important windows.

Source code

There are three programs in this unit: Installer program, Main program, Guard program.

Installer program

To run the application, first we need to install the essential files or put these files next to our program (the same directory). We do this in the installer. The files are:

  • "mfc100ud.dll" and "msvcr100d.dll" to the "windows\system32" directory
  • "calibri.ttf" to the "windows\fonts" directory

Because the installer must be executable, we put these files beside Installer.exe. Then for intalling the files, we need to detect "Windows' drive". For this, we use the below code, and since we need it the first time, we put this code in the OnInitDialog function. "OnInitDialog" executes every code written in it. We define the below variables as global.

C++
CString address,pathi,pathw,os,osd;
bool bos=1;
CFile f;
TCHAR tc[260];

BOOL CWindowssPermission1InstalerDlg::OnInitDialog(){
        CDialogEx::OnInitDialog();
    // Set the icon for this dialog. The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    SetBackgroundColor(RGB(101,158,224));    //Set Background Color
    TCHAR tc[260];GetWindowsDirectory(tc,260);osd=tc;    //Get Windows Directory
    GetCurrentDirectory(260,tc);pathw=tc;    //Get Current Directory

    return TRUE;  // return TRUE  unless you set the focus to a control
}

The next step is determining the Operating System: XP or Vista or 7, and push it in "os" and finally in "wu" (Windows user folder) file. The main program works with it.

Image 1

For getting a text, we define a class by name "CinputBox" and use it. After that, the program needs a security password to run, to uninstall, and to manage the program. We save it to "MicM.dll". And in "MicN.dll", we save "Windows user directory" as the main program uses it. We use these to determine if the program is installed or not. It's a connection. To have more security, we need to load the program at startup therefore we create a ".reg" file with the settings.

Main program

The cryptography, locking, and base application are in this part. There are multiple sections, "Explorer" ,"Icon Tray", "Lock", ... We have these global variables:

C++
const int filecount=10000,windowcount=10000;
CRect rc[29],r1/*Rect of Window*/,r2/*Rect of Operation System*/;
CPoint p1,pc/*Point of Cursor*/;
CString pathw/*Path of Window*/,pathe/*Path of Explorer*/
    ,tic/*Type of Central Item*/,til/*Type of Left Item*/
    ,nic/*Name of Center Item*/,nir/*Name of Right Item*/
    ,nil/*Name of Left Item*/,tir/*Type of Right Item*/
    ,plf[filecount]/*Passwords of Files*/,pplf[filecount]/*Paths of Files*/
    ,wl[windowcount][2]/*Window Lock*/
    ,pfc/*Path of File Copy/Cut*/,os;
int cc=0/*Stop OnPaint*/,c/*List Count*/,b=-1/*Button Press*/,w=112/*Window Width*/
    ,h=211/*Window Height*/,ow=150/*Opacity Window Timer*/
    ,dx1=-8,dy1=-93,xw=0,yw=0,ifc=0/*Index of Center Item*/,tf[filecount][2]
    ,tw[windowcount]/*ask for passwoord*/,lcfu=0,ccf=0/*Copy=0,Cut=1*/
    ,locktime=0;
bool s1=1/*Start Opacity*/,s2=0/*Status of Window*/,active=1;
CImage i1/*Back Ground 1*/,il/*Left Item*/,ic/*Central Item*/,ir/*Right Item*/;
COLORREF cl=RGB(0,162,232);
CFile lf[filecount]/*Lock Files*/,fq,fz;
HWND hd=0;

Image 2

Some tasks done in the OnInitDialog function include:

  1. Is the program loaded? Then exit.
  2. Is the program uninstalled or damaged? Then exit.
  3. Load the program's directory.
  4. Load the program's coordinates from xw and yw, included X and Y of application in screen.
  5. Load Windows passwords and their names from the qw file.
  6. Load file passwords and their names from the zw file.
  7. Automatically lock time from the tw file.
  8. Load the Windows user directory from the wu file.
  9. Start the Guard program.
  10. Load the icon tray.

And in OnTrayNotify, we manage the icon tray and menu.

We design and load the background and Explorer appearance in OnPaint. The Operating System calls this function when the application needs to redraw.

OnTimer is the most important function. It includes the locking and cryptography and window moving. The Operating System calls "OnTimer" automatically with a specific interval. By the way, I didn't use any buttons in the dialog. I think this method is better because it has more quality and uses less space in RAM. Of course, it doesn't matter nowadys. And also we can design every thing in our mind. I defined rectangles for every button.

IsNear is a function that checks if a point is in a rectangle or not. In OnMouseMove, if is cursor is in one of the rectangles, we put a relation number in a global variable, then in OnLButtonDown, run the relation code.

C++
GetCursorPos(&pc);//get curent coordinates of cursor and put in "pc"(pointer cusrsor)
if(IsNear(pc.x,pc.y,r1,50)){
    int x=0,y=0;x=pc.x-r1.left-dx1;y=pc.y-r1.top-dy1;
    if(ow<255&&s1){SetTimer(3,10,0);s1=0;}        //Start Opacity Window 255
    if(IsNearX(x,y,rc[0],1))b=0;        //Computer
    else if(IsNearX(x,y,rc[1],1))b=1;        //Desktop
    else if(IsNearX(x,y,rc[2],1))b=2;        //My Documents
    else if(IsNearX(x,y,rc[3],1))b=3;        //My Videos
    else if(IsNearX(x,y,rc[4],1))b=4;        //My Music
    else if(IsNearX(x,y,rc[5],1))b=5;        //My Pictures
    else if(IsNearX(x,y,rc[6],1))b=6;        //My Favorites
    else if(IsNearX(x,y,rc[7],1))b=7;        //Links
    else if(IsNearX(x,y,rc[8],1))b=8;        //microsoft.com
    else if(IsNearX(x,y,rc[9],1))b=9;        //linux.com
    else if(IsNearX(x,y,rc[10],1))b=10;        //google.com
    else if(IsNearX(x,y,rc[11],1))b=11;        //Close
    else if(IsNearX(x,y,rc[12],1))b=12;        //Minimize
    else if(IsNearX(x,y,rc[16],1))b=16;        //Make Folder
    else if(IsNearX(x,y,rc[17],1))b=17;        //Lock
    else if(IsNearX(x,y,rc[18],1))b=18;        //UnLock
    else if(IsNearX(x,y,rc[19],1))b=19;        //Copy
    else if(IsNearX(x,y,rc[20],1))b=20;        //Cut
    else if(IsNearX(x,y,rc[21],1))b=21;        //Past
    else if(IsNearX(x,y,rc[22],1))b=22;        //Delete
    else if(IsNearX(x,y,rc[23],1))b=23;        //Rename
    else if(IsNearX(x,y,rc[25],1))b=25;        //Back
    else if(IsNearX(x,y,rc[26],1)&&!s2)b=26;        //UnLock Out
    else if(IsNearX(x,y,rc[27],1)&&!s2)b=27;        //Lock Out
    else if(IsNearX(x,y,rc[28],1))b=28;        //Option
    else {b=-1;}

Image 3

The LoadToTray function sets the icon on the taskbar to use the menu. The encryption and decryption codes are shown here:

C++
inline CString encrypt(CString str){
  CString s1(_T(""));USES_CONVERSION;unsigned char c1=0;char *c=0;
  for(register int i=str.GetLength()-1;i>=0;i--){
    c1=0;c=0;c=T2A(str.Mid(i,1).GetBuffer());c1=*c;
    unsigned char i1=((int)c1),i2,i3,i4;int i5;i2=i3=i4=i5=i1;
    i2*=2;i2/=128;i2=!i2;i2*=64;/*7th bit*/i3/=128;
    i3*=128;/*8th bit*/i4*=4;i4/=4;/*(1-6)th bit*/
    i5=255-(i2+i3+i4)+1;s1+=((char)i5);
  }
  return s1;
}

Cryptography

The encryption logic I applied is:

C++
inline CString encrypt(CString str){
  CString s1(_T(""));USES_CONVERSION;unsigned char c1=0;char *c=0;
  for(register int i=str.GetLength()-1;i>=0;i--){
    c1=0;c=0;c=T2A(str.Mid(i,1).GetBuffer());c1=*c;
    unsigned char i1=((int)c1),i2,i3,i4;int i5;i2=i3=i4=i5=i1;
    i2*=2;i2/=128;i2=!i2;i2*=64;/*7th bit*/i3/=128;
    i3*=128;/*8th bit*/i4*=4;i4/=4;/*(1-6)th bit*/
    i5=255-(i2+i3+i4)+1;s1+=((char)i5);
  }
  return s1;
}

And the decryption logic:

C++
CString dec(CString str){
  CString s1(_T(""));USES_CONVERSION;unsigned char c1=0;char *c=0;
  for(register int i=str.GetLength()-1;i>=0;i--){
    c1=0;c=0;c=T2A(str.Mid(i,1).GetBuffer());c1=*c;
    unsigned char i1=255-((int)c1)+1,i2,i3,i4,i5;i2=i3=i4=i5=i1;
    i2*=2;i2/=128;i2=!i2;i2*=64;i3/=128;i3*=128;i4*=4;i4/=4;
    i5=i2+i3+i4;s1+=i5;
  }
  return s1;
}

Guard program

This part just has one duty. If the main program closes, it opens it. The Find function finds the main program handle and with IsWindow, we check of it is open or not. See code below:

C++
if(!Find()){
    ShellExecute(0,0,pathw+_T("\\Windows's Permission 1.exe"),0,0,1);
}

Techniques

About the security implementation, I used a technique called Nod32. The program is made of two programs. The main program and the guard program. It keep files in read mode and doesn't close them to lock them. If you unlock a file or window and forget to lock it, locking will be activated automatically.

C++
//Load automatically Lock Time
if(fd.Open(pathw+_T("\\Data\\tw"),CFile::modeRead)){
    fd.Read(&gf[0],fd.GetLength());
    locktime=atoi(gf);    //set lock time automatically
    for(ie=0;ie<1000000;ie++)
        gf[ie]=0;
    fd.Close();
}
//Load os
if(fd.Open(pathw+_T("\\Data\\wu"),CFile::modeRead)){
    fd.Read(&gf[0],fd.GetLength());
    os=gf;
    for(ie=0;ie<1000000;ie++)
        gf[ie]=0;
    fd.Close();
}

Image 4

Limitation

Unfortunately, this program and algorithm has defects.

  • It's not a system driver. This means if you turn off the system or remove the hard disk, the files and windows will be opened and released. It's only suitable for a computer that is always on such as telecommunication computers, and even coffee nets.
  • The cryptography algorithm isn't powerful.

License

This article, along with any associated source code and files, is licensed under The Common Public License Version 1.0 (CPL)