Пример #1
0
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
{
	void *p;

	log("mmap for %p of length %zu prot %d flags %d fd %d offset %lld\n", 
			addr, length, prot, flags, fd, offset);

	if (libc_mmap == NULL)
		SAVE_LIBC_FUNC(libc_mmap, "mmap");

	p = libc_mmap(addr, length, prot, flags, fd, offset);
	return p;
}
Пример #2
0
void *mmap (void *__addr, size_t __len, int __prot, int __flags, int __fd, __off_t __offset)
{
  static void* (*libc_mmap)
             (void *__addr, size_t __len, int __prot, int __flags, int __fd, __off_t __offset) = NULL;
  void *handle;
  void* mmap_buffer;
  char *error;

  if (!libc_mmap) {
    handle = dlopen("/lib/libc.so.6",
                    RTLD_LAZY);
    if (!handle) {
      fputs(dlerror(), stderr);
      exit(1);
    }
    libc_mmap = dlsym(handle, "mmap");
    if ((error = dlerror()) != NULL) {
      fprintf(stderr, "%s\n", error);
      exit(1);
    }
  }
  
  // custom implementation

  printf("AR.Pwn hooked mmap(%d, %d, %d, %d, %d, %d)\n", __addr, __len, __prot, __flags, __fd, __offset);
  mmap_buffer = libc_mmap(__addr, __len, __prot, __flags, __fd, __offset);
  printf("AR.Pwn mmap() returned %d\n", mmap_buffer);
  
  if(hook_handle_video0 != -1 && __fd == hook_handle_video0)
  {
    int index;
	int found = 0;
	
	for(index = 0; index < 8; index++)
	{
		if(__offset == hook_buffer_offsets_video0[index])
		{
			found = 1;
			break;
		}
	}
	
	if(found)
	{
		printf("AR.Pwn Detected mmap of video0 index %d; saving buffer.\n", index);
		hook_buffers_video0[index] = mmap_buffer;
	}
  }
  else if(hook_handle_video1 != -1 && __fd == hook_handle_video1)
  {
    int index;
	int found = 0;
	
	for(index = 0; index < 8; index++)
	{
		if(__offset == hook_buffer_offsets_video1[index])
		{
			found = 1;
			break;
		}
	}
	
	if(found)
	{
		printf("AR.Pwn Detected mmap of video1 index %d; saving buffer.\n", index);
		hook_buffers_video1[index] = mmap_buffer;
	}
  }
  
  return mmap_buffer;
}