Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Driver to hide files in Linux OS

, , 2 Sep 2012
Simple driver for Linux OS that performs hiding of the selected files from the system
DriverToHideFiles.zip
DriverForHideFiles
DriverForHideFiles
Makefile
#include "device_file.h"
#include <linux/fs.h>       /* file stuff */
#include <linux/kernel.h>    /* printk() */
#include <linux/errno.h>     /* error codes */
#include <linux/module.h>    /* THIS_MODULE */
#include <linux/cdev.h>      /* char device stuff */
#include <asm/uaccess.h>     /* strncpy_from_user() */
#define SUCCESS 0

static int g_device_open = 0;

static ssize_t device_file_write ( struct file *file_ptr
                        , const char *buffer
                        , size_t length
                        , loff_t *offset)
{
	char* pFile_Path;

	pFile_Path=(char *)kmalloc(sizeof(char *)*length,GFP_KERNEL);

	if ( strncpy_from_user(pFile_Path,buffer,length)== -EFAULT) 
	{
	
		printk( KERN_NOTICE "Entered in fault get_user state");

		length=-1;
		goto finish;
	}

	if (strstr(pFile_Path,"\n"))
	{
		pFile_Path[length - 1] = 0;

		printk( KERN_NOTICE "Entered in end line filter");
	}
	
	printk( KERN_NOTICE "File path is %s without EOF", pFile_Path);

	if (hook_functions(pFile_Path)==-1) 
	{	
		length=-2;
	}
finish:
	kfree(pFile_Path);

	return length;
}

static int device_file_open(struct inode *inode, struct file *file)
{

   if (g_device_open)

   return -EBUSY;

   g_device_open++;
   try_module_get(THIS_MODULE);

   return SUCCESS;

}

static int device_file_release(struct inode *inode, struct file *file)
{

  g_device_open--;

  module_put(THIS_MODULE);
  return SUCCESS;
}

/*===============================================================================================*/
static struct file_operations hide_driver_fops = 
{
   .owner   = THIS_MODULE,
   .write   = device_file_write,
   .open    = device_file_open,
   .release = device_file_release,
};

static int device_file_major_number = 0;

static const char device_name[] = "Hide_Driver";

/*===============================================================================================*/
int register_device(void)
{
      int result = 0;

      printk( KERN_NOTICE "Hide-driver: register_device() is called." );

      result = register_chrdev( 0, device_name, &hide_driver_fops );
      if( result < 0 )
      {
         printk( KERN_WARNING "Hide-driver:  can\'t register character device with errorcode = %i", result );
         return result;
      }

      device_file_major_number = result;
      printk( KERN_NOTICE "Hide-driver: registered character device with major number = %i and minor numbers 0...255"
                  , device_file_major_number );

      return 0;
}
/*-----------------------------------------------------------------------------------------------*/
void unregister_device(void)
{
   printk( KERN_NOTICE "Hide-driver: unregister_device() is called" );
   if(device_file_major_number != 0)
   {
      unregister_chrdev(device_file_major_number, device_name);
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Authors

Apriorit Inc
Apriorit Inc.
Ukraine Ukraine
ApriorIT is a Software Research and Development company that works in advanced knowledge-intensive scopes.
 
Company offers integrated research&development services for the software projects in such directions as Corporate Security, Remote Control, Mobile Development, Embedded Systems, Virtualization, Drivers and others.
 
Official site http://www.apriorit.com
Group type: Organisation

31 members

Follow on   LinkedIn

Semyon Boyko

Ukraine Ukraine
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 3 Sep 2012
Article Copyright 2012 by Apriorit Inc, Semyon Boyko
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid