forked from TanninOne/usvfs
-
Notifications
You must be signed in to change notification settings - Fork 26
/
usvfs.h
205 lines (166 loc) · 7.84 KB
/
usvfs.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
Userspace Virtual Filesystem
Copyright (C) 2015 Sebastian Herbord. All rights reserved.
This file is part of usvfs.
usvfs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
usvfs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with usvfs. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "dllimport.h"
#include "usvfsparameters.h"
/*
* Virtual operations:
* - link file
* - link directory (empty)
* - link directory (static)
* - link directory (dynamic)
* - delete file
* - delete directory
* Maybe:
* - rename/move (= copy + delete)
* - copy-on-write semantics (changes to files are done in a separate copy of the file, the original is kept on disc but hidden)
*/
static const unsigned int LINKFLAG_FAILIFEXISTS = 0x00000001; // if set, linking fails in case of an error
static const unsigned int LINKFLAG_MONITORCHANGES = 0x00000002; // if set, changes to the source directory after the link operation
// will be updated in the virtual fs. only relevant in static
// link directory operations
static const unsigned int LINKFLAG_CREATETARGET = 0x00000004; // if set, file creation (including move or copy) operations to
// destination will be redirected to the source. Only one createtarget
// can be set for a destination folder so this flag will replace
// the previous create target.
// If there different create-target have been set for an element and one of its
// ancestors, the inner-most create-target is used
static const unsigned int LINKFLAG_RECURSIVE = 0x00000008; // if set, directories are linked recursively
extern "C" {
/**
* removes all virtual mappings
*/
DLLEXPORT void WINAPI ClearVirtualMappings();
/**
* link a file virtually
* @note: the directory the destination file resides in has to exist - at least virtually.
*/
DLLEXPORT BOOL WINAPI VirtualLinkFile(LPCWSTR source, LPCWSTR destination, unsigned int flags);
/**
* link a directory virtually. This static variant recursively links all files individually, change notifications
* are used to update the information.
* @param failIfExists if true, this call fails if the destination directory exists (virtually or physically)
*/
DLLEXPORT BOOL WINAPI VirtualLinkDirectoryStatic(LPCWSTR source, LPCWSTR destination, unsigned int flags);
/**
* connect to a virtual filesystem as a controller, without hooking the calling process. Please note that
* you can only be connected to one vfs, so this will silently disconnect from a previous vfs.
*/
[[deprecated("deprecated, use usvfsConnectVFS()")]]
DLLEXPORT BOOL WINAPI ConnectVFS(const USVFSParameters *parameters);
DLLEXPORT BOOL WINAPI usvfsConnectVFS(const usvfsParameters* p);
/**
* @brief create a new VFS. This is similar to ConnectVFS except it guarantees
* the vfs is reset before use.
*/
[[deprecated("deprecated, use usvfsCreateVFS()")]]
DLLEXPORT BOOL WINAPI CreateVFS(const USVFSParameters *parameters);
DLLEXPORT BOOL WINAPI usvfsCreateVFS(const usvfsParameters* p);
/**
* disconnect from a virtual filesystem. This removes hooks if necessary
*/
DLLEXPORT void WINAPI DisconnectVFS();
DLLEXPORT void WINAPI GetCurrentVFSName(char *buffer, size_t size);
/**
* retrieve a list of all processes connected to the vfs
*/
DLLEXPORT BOOL WINAPI GetVFSProcessList(size_t *count, LPDWORD processIDs);
// retrieve a list of all processes connected to the vfs, stores an array
// of `count` elements in `*buffer`
//
// if this returns TRUE and `count` is not 0, the caller must release the buffer
// with `free(*buffer)`
//
// return values:
// - ERROR_INVALID_PARAMETERS: either `count` or `buffer` is NULL
// - ERROR_TOO_MANY_OPEN_FILES: there seems to be way too many usvfs processes
// running, probably some internal error
// - ERROR_NOT_ENOUGH_MEMORY: malloc() failed
//
DLLEXPORT BOOL WINAPI GetVFSProcessList2(size_t* count, DWORD** buffer);
/**
* spawn a new process that can see the virtual file system. The signature is identical to CreateProcess
*/
DLLEXPORT BOOL WINAPI CreateProcessHooked(
LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation);
/**
* retrieve a single log message.
* FIXME There is currently no way to unblock from the caller side
* FIXME retrieves log messages from all instances, the logging queue is not separated
*/
DLLEXPORT bool WINAPI GetLogMessages(LPSTR buffer, size_t size, bool blocking = false);
/**
* retrieves a readable representation of the vfs tree
* @param buffer the buffer to write to. this may be null if you only want to determine the required
* buffer size
* @param size pointer to a variable that contains the buffer. After the call
* this value will have been updated to contain the required size,
* even if this is bigger than the buffer size
*/
DLLEXPORT BOOL WINAPI CreateVFSDump(LPSTR buffer, size_t *size);
/**
* adds an executable to the blacklist so it doesn't get exposed to the virtual
* file system
* @param executableName name of the executable
*/
DLLEXPORT VOID WINAPI BlacklistExecutable(LPWSTR executableName);
/**
* clears the executable blacklist
*/
DLLEXPORT VOID WINAPI ClearExecutableBlacklist();
/**
* adds a library to be force loaded when the given process is injected
* @param
*/
DLLEXPORT VOID WINAPI ForceLoadLibrary(LPWSTR processName, LPWSTR libraryPath);
/**
* clears all previous calls to ForceLoadLibrary
*/
DLLEXPORT VOID WINAPI ClearLibraryForceLoads();
/**
* print debugging info about the vfs. The format is currently not fixed and may
* change between usvfs versions
*/
DLLEXPORT VOID WINAPI PrintDebugInfo();
//#if defined(UNITTEST) || defined(_WINDLL)
DLLEXPORT void WINAPI InitLogging(bool toLocal = false);
//#endif
/**
* used internally to initialize a process at startup-time as a "slave". Don't call directly
*/
DLLEXPORT void __cdecl InitHooks(LPVOID userData, size_t userDataSize);
[[deprecated("deprecated, use usvfsCreateParameters()")]]
DLLEXPORT void WINAPI USVFSInitParameters(USVFSParameters *parameters,
const char *instanceName,
bool debugMode,
LogLevel logLevel,
CrashDumpsType crashDumpsType,
const char *crashDumpsPath);
/**
* @brief Used to change parameters which can be changed in runtime
*/
[[deprecated("deprecated, use usvfsUpdateParameters()")]]
DLLEXPORT void WINAPI USVFSUpdateParams(LogLevel level, CrashDumpsType type);
// the instance and shm names are not updated
//
DLLEXPORT void WINAPI usvfsUpdateParameters(usvfsParameters* p);
DLLEXPORT int WINAPI CreateMiniDump(PEXCEPTION_POINTERS exceptionPtrs, CrashDumpsType type, const wchar_t* dumpPath);
DLLEXPORT const char* WINAPI USVFSVersionString();
}