This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdropbox_inj.c
53 lines (43 loc) · 1.5 KB
/
dropbox_inj.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright : (C) 2014 Tristan Konolige
// License : BSD-style (see the file LICENSE)
#include <errno.h>
#include <fcntl.h>
/* #include <sys/stat.h> don't include lstat otherwise the wrong version is hooked */
#include <stdlib.h>
#include "ignore_stub.h"
#include <stdbool.h>
#include <crt_externs.h>
#include <syslog.h>
bool ignore(const char* p) {
return ignore_hs((char*)p);
}
struct stat;
int lstat(const char*, struct stat*);
/* from http://opensource.apple.com/source/dyld/dyld-210.2.3/include/mach-o/dyld-interposing.h*/
#define DYLD_INTERPOSE(_replacement,_replacee) \
__attribute__((used)) static struct{ const void* replacement; const void* replacee; } _interpose_##_replacee \
__attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacement, (const void*)(unsigned long)&_replacee };
int(*lstat_old)(const char*, struct stat*);
int lstat_new(const char* path, struct stat* buf) {
if(ignore(path)) {
errno = ENOENT;
return -1;
}
return lstat(path, buf);
}
DYLD_INTERPOSE(lstat_new, lstat);
int open_new(const char* path, int flag, int mode) {
if(ignore(path)) {
errno = ENOENT;
return -1;
}
return open(path, flag, mode);
}
DYLD_INTERPOSE(open_new, open);
__attribute__((__constructor__)) static void initialize(void) {
unsetenv("DYLD_INSERT_LIBRARIES"); /* only want to hook Dropbox */
hs_init(_NSGetArgc(), _NSGetArgv());
syslog(LOG_NOTICE, "dbignore loaded");
/* TODO: should happen when unloaded */
/* hs_exit(); */
}