duran 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +11 -0
  3. data/Rakefile +29 -0
  4. data/VERSION +1 -0
  5. data/client_src/dr_include/dr_api.h +102 -0
  6. data/client_src/dr_include/dr_app.h +92 -0
  7. data/client_src/dr_include/dr_config.h +650 -0
  8. data/client_src/dr_include/dr_defines.h +391 -0
  9. data/client_src/dr_include/dr_events.h +1057 -0
  10. data/client_src/dr_include/dr_ir_instr.h +1214 -0
  11. data/client_src/dr_include/dr_ir_instrlist.h +149 -0
  12. data/client_src/dr_include/dr_ir_macros.h +2426 -0
  13. data/client_src/dr_include/dr_ir_opcodes.h +768 -0
  14. data/client_src/dr_include/dr_ir_opnd.h +1170 -0
  15. data/client_src/dr_include/dr_ir_utils.h +708 -0
  16. data/client_src/dr_include/dr_proc.h +327 -0
  17. data/client_src/dr_include/dr_tools.h +1304 -0
  18. data/client_src/duran.c +57 -0
  19. data/client_src/extconf.rb +28 -0
  20. data/lib/duran.rb +18 -0
  21. data/lib/duran/app.rb +8 -0
  22. data/lib/duran/defines.rb +39 -0
  23. data/lib/duran/events.rb +156 -0
  24. data/lib/duran/ir_opcodes.rb +616 -0
  25. data/lib/duran/ir_opnd.rb +329 -0
  26. data/lib/duran/ir_utils.rb +133 -0
  27. data/lib/duran/proc.rb +49 -0
  28. data/lib/duran/structs.rb +20 -0
  29. data/lib/duran/structs/exception.rb +23 -0
  30. data/lib/duran/structs/fault_fragment_info.rb +34 -0
  31. data/lib/duran/structs/instruction.rb +15 -0
  32. data/lib/duran/structs/machine_context.rb +80 -0
  33. data/lib/duran/structs/memory_info.rb +12 -0
  34. data/lib/duran/structs/module_data.rb +61 -0
  35. data/lib/duran/structs/module_names.rb +24 -0
  36. data/lib/duran/structs/operand.rb +15 -0
  37. data/lib/duran/structs/restore_state_info.rb +30 -0
  38. data/lib/duran/structs/signal_info.rb +41 -0
  39. data/lib/duran/structs/tracedump.rb +50 -0
  40. data/lib/duran/tools.rb +214 -0
  41. metadata +104 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Eric Monti
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ = duran
2
+
3
+ Duran is an attempt to embed ruby in the DynamoRIO dynamic binary translation
4
+ framework. Duran also provides FFI bindings for the DynamoRIO C library which
5
+ can be used similarly to the C tool API.
6
+
7
+ For DynamoRIO documentation and downloads, please see http://www.dynamorio.org
8
+
9
+ == Copyright
10
+
11
+ Copyright (c) 2010 Eric Monti. See LICENSE for details.
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "duran"
9
+ gem.summary = %Q{Embedded Ruby client and FFI bindings for the DyanoRIO library.}
10
+ gem.description = %Q{Embedded Ruby client and FFI bindings for the DyanoRIO dynamic binary translation library.}
11
+ gem.email = "esmonti@gmail.com"
12
+ gem.homepage = "http://github.com/emonti/duran"
13
+ gem.authors = ["Eric Monti"]
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/rdoctask'
22
+ Rake::RDocTask.new do |rdoc|
23
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
24
+
25
+ rdoc.rdoc_dir = 'rdoc'
26
+ rdoc.title = "duran #{version}"
27
+ rdoc.rdoc_files.include('README*')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,102 @@
1
+ /* **********************************************************
2
+ * Copyright (c) 2002-2008 VMware, Inc. All rights reserved.
3
+ * **********************************************************/
4
+
5
+ /*
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are met:
8
+ *
9
+ * * Redistributions of source code must retain the above copyright notice,
10
+ * this list of conditions and the following disclaimer.
11
+ *
12
+ * * Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ *
16
+ * * Neither the name of VMware, Inc. nor the names of its contributors may be
17
+ * used to endorse or promote products derived from this software without
18
+ * specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
24
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30
+ * DAMAGE.
31
+ */
32
+
33
+ #ifndef _DR_API_H_
34
+ #define _DR_API_H_ 1
35
+
36
+ /**
37
+ * @file dr_api.h
38
+ * @brief Top-level include file for DynamoRIO API.
39
+ */
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ /* Defines and type definitions */
46
+ #include "dr_defines.h"
47
+
48
+ /* Event registration routines */
49
+ #include "dr_events.h"
50
+
51
+ /* Application start/stop interface */
52
+ #include "dr_app.h"
53
+
54
+ /* opnd_t (instruction operand) routines */
55
+ #include "dr_ir_opnd.h"
56
+
57
+ /* High-level routines: memory allocation, mutex support, file
58
+ * support, printing, thread support, adaptive optimization,
59
+ * custom traces, processor-specific utilities, trace dumping,
60
+ * and module information.
61
+ */
62
+ #include "dr_tools.h"
63
+
64
+ /* Utility routines for identifying features of the processor. */
65
+ #include "dr_proc.h"
66
+
67
+ /* Instruction convenience & decode/disassemble routines */
68
+ #include "dr_ir_utils.h"
69
+
70
+ /* instrlist_t routines */
71
+ #include "dr_ir_instrlist.h"
72
+
73
+ /* instr_t routines */
74
+ #include "dr_ir_instr.h"
75
+
76
+ /* opcode OP_ constants and opcode-only routines */
77
+ #include "dr_ir_opcodes.h"
78
+
79
+ /* CREATE_INSTR_ macros */
80
+ #include "dr_ir_macros.h"
81
+
82
+ /**
83
+ * When registering a process, users must provide a list of paths to
84
+ * client libraries and their associated client-specific options. DR
85
+ * looks up "dr_init" in each client library and calls that function
86
+ * when the process starts. Clients can register to receive callbacks
87
+ * for the various events within dr_init. Note that client paths and
88
+ * options cannot include semicolons. \p client_id is the ID supplied
89
+ * at registration and is used to identify the client for
90
+ * dr_get_options(), dr_get_client_path(), and external nudges.
91
+ */
92
+ DR_EXPORT void dr_init(client_id_t client_id);
93
+
94
+ /* Version checking */
95
+ /* This equals major*100 + minor */
96
+ DR_EXPORT LINK_ONCE int _USES_DR_VERSION_ = 105;
97
+
98
+ #ifdef __cplusplus
99
+ }
100
+ #endif
101
+
102
+ #endif /* _DR_API_H_ */
@@ -0,0 +1,92 @@
1
+ /* **********************************************************
2
+ * Copyright (c) 2002-2008 VMware, Inc. All rights reserved.
3
+ * **********************************************************/
4
+
5
+ /*
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are met:
8
+ *
9
+ * * Redistributions of source code must retain the above copyright notice,
10
+ * this list of conditions and the following disclaimer.
11
+ *
12
+ * * Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ *
16
+ * * Neither the name of VMware, Inc. nor the names of its contributors may be
17
+ * used to endorse or promote products derived from this software without
18
+ * specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
24
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30
+ * DAMAGE.
31
+ */
32
+
33
+ /**
34
+ * @file dr_app.h
35
+ * @brief DR's application interface for running portions
36
+ * of a program under its control.
37
+ */
38
+
39
+ #ifndef _DR_APP_H_
40
+ #define _DR_APP_H_ 1
41
+
42
+ #ifdef WINDOWS
43
+ # ifdef DR_APP_EXPORTS
44
+ # define DR_APP_API __declspec(dllexport)
45
+ # else
46
+ # define DR_APP_API __declspec(dllimport)
47
+ # endif
48
+ #else /* LINUX */
49
+ # if defined(DR_APP_EXPORTS) && defined(USE_VISIBILITY_ATTRIBUTES)
50
+ # define DR_APP_API __attribute__ ((visibility ("default")))
51
+ # else
52
+ # define DR_APP_API
53
+ # endif
54
+ #endif
55
+
56
+ /****************************************************************************
57
+ * DR Application Interface
58
+ */
59
+
60
+ /**
61
+ * Application-wide initialization. Must be called before any other
62
+ * API function, and before the application creates any threads. Returns
63
+ * zero on success.
64
+ */
65
+ DR_APP_API int dr_app_setup(void);
66
+
67
+ /**
68
+ * Application-wide cleanup. Prints statistics. Returns zero on success.
69
+ */
70
+ DR_APP_API int dr_app_cleanup(void);
71
+
72
+ /**
73
+ * Causes application to run under DR control upon return
74
+ * from this call.
75
+ */
76
+ DR_APP_API void dr_app_start(void);
77
+
78
+ /**
79
+ * Causes application to run directly on the machine upon return
80
+ * from this call; no effect if application is not currently
81
+ * running under DR control.
82
+ */
83
+ DR_APP_API void dr_app_stop(void);
84
+
85
+ /**
86
+ * Causes application to run under DR control upon return from
87
+ * this call. DR never releases control. Useful for overriding
88
+ * dr_app_start/dr_app_stop calls in the rest of a program.
89
+ */
90
+ DR_APP_API void dr_app_take_over(void);
91
+
92
+ #endif /* _DR_APP_H_ */
@@ -0,0 +1,650 @@
1
+ /* **********************************************************
2
+ * Copyright (c) 2002-2009 VMware, Inc. All rights reserved.
3
+ * **********************************************************/
4
+
5
+ /*
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are met:
8
+ *
9
+ * * Redistributions of source code must retain the above copyright notice,
10
+ * this list of conditions and the following disclaimer.
11
+ *
12
+ * * Redistributions in binary form must reproduce the above copyright notice,
13
+ * this list of conditions and the following disclaimer in the documentation
14
+ * and/or other materials provided with the distribution.
15
+ *
16
+ * * Neither the name of VMware, Inc. nor the names of its contributors may be
17
+ * used to endorse or promote products derived from this software without
18
+ * specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
24
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30
+ * DAMAGE.
31
+ */
32
+
33
+ #ifndef _DR_CONFIG_H_
34
+ #define _DR_CONFIG_H_ 1
35
+
36
+ #ifdef WINDOWS
37
+ /****************************************************************************
38
+ * Deployment API
39
+ */
40
+ /**
41
+ * @file dr_config.h
42
+ * @brief Deployment API for Windows. Use these functions to register
43
+ * processes to run under DynamoRIO, unregister processes, obtain existing
44
+ * registration information, and nudge running processes.
45
+ * \note The dr_config library is currently not multi-thread safe. Users of
46
+ * the library should ensure that no more then one thread accesses the library
47
+ * at a time. This limitation will be addressed in future releases.
48
+ */
49
+
50
+ /** Maximum length of a registered process's options string */
51
+ #define DR_MAX_OPTIONS_LENGTH 512
52
+
53
+ /** Specifies DynamoRIO's operation mode. */
54
+ typedef enum {
55
+
56
+ /**
57
+ * No mode. Clients should not attempt to register a process in
58
+ * this mode.
59
+ */
60
+ DR_MODE_NONE = 0,
61
+
62
+ /** Run DynamoRIO in Code Manipulation mode. */
63
+ DR_MODE_CODE_MANIPULATION = 1,
64
+
65
+
66
+
67
+ } dr_operation_mode_t;
68
+
69
+ /** Return status codes for process registration, unregistration and nudging. */
70
+ typedef enum {
71
+ /** Operation succeeded. */
72
+ DR_SUCCESS,
73
+
74
+ /** Process registration failed due to an existing registration. */
75
+ DR_PROC_REG_EXISTS,
76
+
77
+ /** Operation failed because the supplied process is not registered. */
78
+ DR_PROC_REG_INVALID,
79
+
80
+ /** Client registration failed due to an invalid priority value. */
81
+ DR_PRIORITY_INVALID,
82
+
83
+ /** Client registration failed due to a conflicting ID. */
84
+ DR_ID_CONFLICTING,
85
+
86
+ /** Client operation failed due to an invalid client ID. */
87
+ DR_ID_INVALID,
88
+
89
+ /** Unknown failure. Check that caller has adequate permissions for this operation. */
90
+ DR_FAILURE,
91
+
92
+ /** Nudge operation failed because the specified process id is not under DR. */
93
+ DR_NUDGE_PID_NOT_INJECTED,
94
+
95
+ /** Nudge operation timed out waiting for target process to finish handling a nudge.*/
96
+ DR_NUDGE_TIMEOUT,
97
+
98
+ } dr_config_status_t;
99
+
100
+ /** Allow targeting both WOW64 and native 64-bit processes separately. */
101
+ typedef enum {
102
+ DR_PLATFORM_DEFAULT, /**< The platform this tool is compiled for. */
103
+ DR_PLATFORM_32BIT, /**< 32-bit settings (for 32-bit or WOW64 processes). */
104
+ DR_PLATFORM_64BIT, /**< 64-bit settings (for native 64-bit processes). */
105
+ } dr_platform_t;
106
+
107
+ /**
108
+ * Register a process to run under DynamoRIO. This requires administrative
109
+ * privileges. Note that this routine only sets the base options to run
110
+ * a process under DynamoRIO. To register one or more clients, call
111
+ * dr_register_client() subsequently.
112
+ *
113
+ * \param[in] process_name A NULL-terminated string specifying the name
114
+ * of the target process. The string should
115
+ * identify the base name of the process, not the
116
+ * full path of the executable (e.g., calc.exe).
117
+ *
118
+ * \param[in] dr_root_dir A NULL-terminated string specifying the full
119
+ * path to a valid DynamoRIO root directory.
120
+ * The string length cannot exceed MAX_PATH.
121
+ *
122
+ * \param[in] dr_mode Specifies the mode under which DynamoRIO should
123
+ * operate. See dr_operation_mode_t.
124
+ *
125
+ * \param[in] debug If true, a DynamoRIO debug build will be used;
126
+ * otherwise, a release build will be used.
127
+ *
128
+ * \param[in] dr_platform Configurations are kept separate on 64-bit Windows
129
+ * for 32-bit (WOW64) processes and 64-bit processes.
130
+ * This parameter allows selecting which of those
131
+ * configurations to set.
132
+ *
133
+ * \param[in] dr_options A NULL-terminated string controlling
134
+ * DynamoRIO's behavior. Most users should
135
+ * not need to specify options. The total
136
+ * string length cannot exceed #DR_MAX_OPTIONS_LENGTH.
137
+ *
138
+ * \return A dr_config_status_t code indicating the result of
139
+ * registration. Note that registration fails if the requested
140
+ * process is already registered. To modify a process's
141
+ * registration, first call dr_unregister_process() to remove an
142
+ * existing registration.
143
+ *
144
+ * \remarks
145
+ * After registration, a process will run under DynamoRIO the next time
146
+ * it launches. Note that some processes may require a system reboot to
147
+ * restart. Process registration persists across reboots until explicitly
148
+ * unregistered.
149
+ *
150
+ * \note On Windows NT, a reboot is required after the initial
151
+ * dr_register_process() in order for DynamoRIO to take control of any
152
+ * application.
153
+ *
154
+ * \note An application that does not link with user32.dll will not be
155
+ * run under control of DynamoRIO unless it's launched by the \c drinject.exe
156
+ * tool (in bin/bin32 or bin/bin64) or the parent process (typically
157
+ * explorer.exe, for manually launched applications) is already under
158
+ * DynamoRIO control (the parent can be in any mode, but 32-bit parent
159
+ * cannot inject into a 64-bit child). Only some small non-graphical
160
+ * applications do not link with user32.dll.
161
+ */
162
+ dr_config_status_t
163
+ dr_register_process(const char *process_name,
164
+ const char *dr_root_dir,
165
+ dr_operation_mode_t dr_mode,
166
+ bool debug,
167
+ dr_platform_t dr_platform,
168
+ const char *dr_options);
169
+
170
+ /**
171
+ * Unregister a process from running under DynamoRIO. This requires administrative
172
+ * privileges.
173
+ *
174
+ * \param[in] process_name A NULL-terminated string specifying the name
175
+ * of the target process. The string should
176
+ * identify the base name of the process, not the
177
+ * full path of the executable (e.g., calc.exe).
178
+ *
179
+ * \param[in] dr_platform Configurations are kept separate on 64-bit Windows
180
+ * for 32-bit (WOW64) processes and 64-bit processes.
181
+ * This parameter allows selecting which of those
182
+ * configurations to unset.
183
+ *
184
+ * \return A dr_config_status_t code indicating the result of
185
+ * unregistration. Note that unregistration fails if the process
186
+ * is not currently registered to run under DynamoRIO.
187
+ */
188
+ dr_config_status_t
189
+ dr_unregister_process(const char *process_name,
190
+ dr_platform_t dr_platform);
191
+
192
+ /**
193
+ * Check if a process is registered to run under DynamoRIO. To obtain client
194
+ * information, use dr_get_client_info().
195
+ *
196
+ * \param[in] process_name A NULL-terminated string specifying the name
197
+ * of the target process. The string should
198
+ * identify the base name of the process, not the
199
+ * full path of the executable (e.g., calc.exe).
200
+ *
201
+ * \param[in] dr_platform Configurations are kept separate on 64-bit Windows
202
+ * for 32-bit (WOW64) processes and 64-bit processes.
203
+ * This parameter allows selecting which of those
204
+ * configurations to check.
205
+ *
206
+ * \param[out] dr_root_dir If the process is registered, the root DynamoRIO
207
+ * directory provided at registration. Callers can
208
+ * pass NULL if this value is not needed. Otherwise,
209
+ * the parameter must be a caller-allocated array of
210
+ * length MAX_PATH.
211
+ *
212
+ * \param[out] dr_mode If the process is registered, the mode provided
213
+ * at registration. Callers can pass NULL if this
214
+ * value is not needed.
215
+ *
216
+ * \param[out] debug If the process is registered, the debug flag
217
+ * provided at registration. Callers can pass NULL
218
+ * if this value is not needed.
219
+ *
220
+ * \param[out] dr_options If the process is registered, the extra DynamoRIO
221
+ * parameters provided at registration. Callers can
222
+ * pass NULL if this value is not needed. Otherwise,
223
+ * the parameter must be a caller-allocated array of
224
+ * length #DR_MAX_OPTIONS_LENGTH.
225
+ *
226
+ * \return true if the process is registered for the given platform.
227
+ */
228
+ bool
229
+ dr_process_is_registered(const char *process_name,
230
+ dr_platform_t dr_platform,
231
+ char *dr_root_dir /* OUT */,
232
+ dr_operation_mode_t *dr_mode /* OUT */,
233
+ bool *debug /* OUT */,
234
+ char *dr_options /* OUT */);
235
+
236
+ typedef struct _dr_registered_process_iterator_t dr_registered_process_iterator_t;
237
+
238
+ /**
239
+ * Creates and starts an iterator for iterating over all processes registered for
240
+ * the given platform.
241
+ *
242
+ * \param[in] dr_platform Configurations are kept separate on 64-bit Windows
243
+ * for 32-bit (WOW64) processes and 64-bit processes.
244
+ * This parameter allows selecting which of those
245
+ * configurations to check.
246
+ *
247
+ * \return iterator for use with dr_registered_process_iterator_hasnext()and
248
+ * dr_registered_process_iterator_next(). Must be freed
249
+ * with dr_registered_process_iterator_stop()
250
+ */
251
+ dr_registered_process_iterator_t *
252
+ dr_registered_process_iterator_start(dr_platform_t dr_platform);
253
+
254
+ /**
255
+ * \param[in] iter A registered process iterator created with
256
+ * dr_registered_process_iterator_start()
257
+ *
258
+ * \return true if there are more registered processes to iterate over
259
+ */
260
+ bool
261
+ dr_registered_process_iterator_hasnext(dr_registered_process_iterator_t *iter);
262
+
263
+ /**
264
+ * Return information about a registered process
265
+ *
266
+ * \param[in] iter A registered process iterator created with
267
+ * dr_registered_process_iterator_start().
268
+ *
269
+ * \param[out] process_name The name of the registered process. Callers can
270
+ * pass NULL if this value is not needed. Otherwise
271
+ * the parameter must be a caller-allocated array
272
+ * of length MAX_PATH.
273
+ *
274
+ * \param[out] dr_root_dir The root DynamoRIO directory provided at registration.
275
+ * Callers can pass NULL if this value is not needed.
276
+ * Otherwise, the parameter must be a caller-allocated
277
+ * array of length MAX_PATH.
278
+ *
279
+ * \param[out] dr_mode If the process is registered, the mode provided
280
+ * at registration. Callers can pass NULL if this
281
+ * value is not needed.
282
+ *
283
+ * \param[out] debug If the process is registered, the debug flag
284
+ * provided at registration. Callers can pass NULL
285
+ * if this value is not needed.
286
+ *
287
+ * \param[out] dr_options If the process is registered, the extra DynamoRIO
288
+ * parameters provided at registration. Callers can
289
+ * pass NULL if this value is not needed. Otherwise,
290
+ * the parameter must be a caller-allocated array of
291
+ * length #DR_MAX_OPTIONS_LENGTH.
292
+ *
293
+ * \return true if the process is registered for the given platform.
294
+ */
295
+ void
296
+ dr_registered_process_iterator_next(dr_registered_process_iterator_t *iter,
297
+ char *process_name /* OUT */,
298
+ char *dr_root_dir /* OUT */,
299
+ dr_operation_mode_t *dr_mode /* OUT */,
300
+ bool *debug /* OUT */,
301
+ char *dr_options /* OUT */);
302
+
303
+ /**
304
+ * Stops and frees a registered process iterator.
305
+ *
306
+ * \param[in] iter A registered process iterator created with
307
+ * dr_registered_process_iterator_start()
308
+ */
309
+ void
310
+ dr_registered_process_iterator_stop(dr_registered_process_iterator_t *iter);
311
+
312
+ /**
313
+ * Register a client for a particular process. Note that the process must
314
+ * first be registered via dr_register_process() before calling this routine.
315
+ *
316
+ * \param[in] process_name A NULL-terminated string specifying the name
317
+ * of the target process. The string should
318
+ * identify the base name of the process, not the
319
+ * full path of the executable (e.g., calc.exe).
320
+ *
321
+ * \param[in] dr_platform Configurations are kept separate on 64-bit Windows
322
+ * for 32-bit (WOW64) processes and 64-bit processes.
323
+ * This parameter allows selecting which of those
324
+ * configurations to unset.
325
+ *
326
+ * \param[in] client_id A client_id_t uniquely identifying the client.
327
+ * DynamoRIO provides the client ID as a parameter
328
+ * to dr_init(). Clients use this ID to retrieve
329
+ * client-specific path and option information.
330
+ * Outside entities also identify the target of
331
+ * a nudge via this ID.
332
+ *
333
+ * \param[in] client_pri The client number, or priority. Client registration
334
+ * includes a value indicating the priority of a client
335
+ * relative to other clients. In multi-client settings,
336
+ * a client's priority influences event callback
337
+ * ordering. That is, higher priority clients can
338
+ * register their callbacks first; DynamoRIO then calls
339
+ * these routines last. Client priorities range
340
+ * consecutively from 0 to N-1, where N is the number
341
+ * of registered clients. Specify priority
342
+ * 0 to register a client with highest priority.
343
+ *
344
+ * \param[in] client_path A NULL-terminated string specifying the full path
345
+ * to a valid client library. The string length
346
+ * cannot exceed MAX_PATH. The client path may not
347
+ * include any semicolons.
348
+ *
349
+ * \param[in] client_options A NULL-terminated string specifying options that
350
+ * are available to the client via dr_get_options().
351
+ * The string length cannot exceed #DR_MAX_OPTIONS_LENGTH.
352
+ * The client options may not include any semicolons.
353
+ *
354
+ * \return A dr_config_status_t code indicating the result of registration.
355
+ */
356
+ dr_config_status_t
357
+ dr_register_client(const char *process_name,
358
+ dr_platform_t dr_platform,
359
+ client_id_t client_id,
360
+ size_t client_pri,
361
+ const char *client_path,
362
+ const char *client_options);
363
+
364
+ /**
365
+ * \param[in] process_name A NULL-terminated string specifying the name
366
+ * of the target process. The string should
367
+ * identify the base name of the process, not the
368
+ * full path of the executable (e.g., calc.exe).
369
+ *
370
+ * \param[in] dr_platform Configurations are kept separate on 64-bit Windows
371
+ * for 32-bit (WOW64) processes and 64-bit processes.
372
+ * This parameter allows selecting which of those
373
+ * configurations to unset.
374
+ *
375
+ * \param[in] client_id The unique client ID provided at client
376
+ * registration.
377
+ *
378
+ * \return A dr_config_status_t code indicating the result of unregistration.
379
+ */
380
+ dr_config_status_t
381
+ dr_unregister_client(const char *process_name,
382
+ dr_platform_t dr_platform,
383
+ client_id_t client_id);
384
+
385
+ /**
386
+ * Retrieve the number of clients registered for a particular process.
387
+ *
388
+ * \param[in] process_name A NULL-terminated string specifying the name
389
+ * of the target process. The string should
390
+ * identify the base name of the process, not the
391
+ * full path of the executable (e.g., calc.exe).
392
+ *
393
+ * \param[in] dr_platform Configurations are kept separate on 64-bit Windows
394
+ * for 32-bit (WOW64) processes and 64-bit processes.
395
+ * This parameter allows selecting which of those
396
+ * configurations to unset.
397
+ *
398
+ * \return The number of clients registered for the given process and platform.
399
+ */
400
+ size_t
401
+ dr_num_registered_clients(const char *process_name,
402
+ dr_platform_t dr_platform);
403
+
404
+ /**
405
+ * Retrieve client registration information for a particular process.
406
+ *
407
+ * \param[in] process_name A NULL-terminated string specifying the name
408
+ * of the target process. The string should
409
+ * identify the base name of the process, not the
410
+ * full path of the executable (e.g., calc.exe).
411
+ *
412
+ * \param[in] dr_platform Configurations are kept separate on 64-bit Windows
413
+ * for 32-bit (WOW64) processes and 64-bit processes.
414
+ * This parameter allows selecting which of those
415
+ * configurations to unset.
416
+ *
417
+ * \param[in] client_id The unique client ID provided at client
418
+ * registration.
419
+ *
420
+ * \param[out] client_pri The client's priority.
421
+ *
422
+ * \param[out] client_path The client's path provided at registration.
423
+ * Callers can pass NULL if this value is not needed.
424
+ * Otherwise, the parameter must be a caller-allocated
425
+ * array of length MAX_PATH.
426
+ *
427
+ * \param[out] client_options The client options provided at registration.
428
+ * Callers can pass NULL if this value is not needed.
429
+ * Otherwise, the parameter must be a caller-allocated
430
+ * array of length #DR_MAX_OPTIONS_LENGTH.
431
+ *
432
+ * \return A dr_config_status_t code indicating the result of the call.
433
+ */
434
+ dr_config_status_t
435
+ dr_get_client_info(const char *process_name,
436
+ dr_platform_t dr_platform,
437
+ client_id_t client_id,
438
+ size_t *client_pri, /* OUT */
439
+ char *client_path, /* OUT */
440
+ char *client_options /* OUT */);
441
+
442
+ typedef struct _dr_client_iterator_t dr_client_iterator_t;
443
+
444
+ /**
445
+ * Creates and starts an iterator for iterating over all clients registered for
446
+ * the given process.
447
+ *
448
+ * \param[in] process_name A NULL-terminated string specifying the name
449
+ * of the target process. The string should
450
+ * identify the base name of the process, not the
451
+ * full path of the executable (e.g., calc.exe).
452
+ *
453
+ * \param[in] dr_platform Configurations are kept separate on 64-bit Windows
454
+ * for 32-bit (WOW64) processes and 64-bit processes.
455
+ * This parameter allows selecting which of those
456
+ * configurations to check.
457
+ *
458
+ * \return iterator for use with dr_client_iterator_hasnext() and
459
+ * dr_client_iterator_next(). Must be freed with
460
+ * dr_client_iterator_stop()
461
+ */
462
+ dr_client_iterator_t *
463
+ dr_client_iterator_start(const char *process_name,
464
+ dr_platform_t dr_platform);
465
+
466
+ /**
467
+ * \param[in] iter A client iterator created with dr_client_iterator_start()
468
+ *
469
+ * \return true if there are more clients to iterate over
470
+ */
471
+ bool
472
+ dr_client_iterator_hasnext(dr_client_iterator_t *iter);
473
+
474
+ /**
475
+ * Return information about a client.
476
+ *
477
+ * \param[in] iter A client iterator created with dr_client_iterator_start()
478
+ *
479
+ * \param[out] client_id The unique client ID provided at client registration.
480
+ *
481
+ * \param[out] client_pri The client's priority.
482
+ *
483
+ * \param[out] client_path The client's path provided at registration.
484
+ * Callers can pass NULL if this value is not needed.
485
+ * Otherwise, the parameter must be a caller-allocated
486
+ * array of length MAX_PATH.
487
+ *
488
+ * \param[out] client_options The client options provided at registration.
489
+ * Callers can pass NULL if this value is not needed.
490
+ * Otherwise, the parameter must be a caller-allocated
491
+ * array of length #DR_MAX_OPTIONS_LENGTH.
492
+ */
493
+ void
494
+ dr_client_iterator_next(dr_client_iterator_t *iter,
495
+ client_id_t *client_id, /* OUT */
496
+ size_t *client_pri, /* OUT */
497
+ char *client_path, /* OUT */
498
+ char *client_options /* OUT */);
499
+
500
+ /**
501
+ * Stops and frees a client iterator.
502
+ *
503
+ * \param[in] iter A client iterator created with dr_client_iterator_start()
504
+ */
505
+ void
506
+ dr_client_iterator_stop(dr_client_iterator_t *iter);
507
+
508
+
509
+ /**
510
+ * Provides a mechanism for an external entity on the guest OS to
511
+ * communicate with a client. Requires administrative privileges. A
512
+ * process 'nudge' causes a client event handler to be invoked (use
513
+ * dr_register_nudge_event() to register the handler function). A
514
+ * nudge is ignored if the process is not running under DynamoRIO,
515
+ * the specified client is not loaded, or if the client does not
516
+ * provide a handler.
517
+ *
518
+ * \param[in] process_name A NULL-terminated string specifying the name
519
+ * of the target process. The string should
520
+ * identify the base name of the process, not the
521
+ * full path of the executable.
522
+ *
523
+ * \param[in] client_id The unique client ID provided at client
524
+ * registration.
525
+ *
526
+ * \param[in] arg An argument passed to the client's nudge
527
+ * handler.
528
+ *
529
+ * \param[in] timeout_ms The number of milliseconds to wait for each
530
+ * nudge to complete before continuing. If INFINITE
531
+ * is supplied then the wait is unbounded. If 0
532
+ * is supplied the no wait is performed. If a
533
+ * wait times out DR_NUDGE_TIMEOUT will be returned.
534
+ *
535
+ * \param[out] nudge_count Returns the number of processes nudged.
536
+ * Client can supply NULL if this value is
537
+ * not needed.
538
+ *
539
+ * \return A dr_config_status_t code indicating the result of the nudge.
540
+ *
541
+ * \remarks
542
+ * If there are multiple processes executing with the same name, all
543
+ * of them are nudged.
544
+ *
545
+ * \remarks
546
+ * A process nudge is a one way asynchronous communication from an
547
+ * external entity to a client. It does not allow a client to
548
+ * return information back to the nudge originator. To communicate
549
+ * from a client to another process, use the channels specified
550
+ * in \ref sec_comm.
551
+ *
552
+ * \note Nudging 64-bit processes is not yet supported.
553
+ */
554
+ dr_config_status_t
555
+ dr_nudge_process(const char *process_name,
556
+ client_id_t client_id,
557
+ uint64 arg,
558
+ uint timeout_ms,
559
+ int *nudge_count /*OUT */);
560
+
561
+ /**
562
+ * Provides a mechanism for an external entity on the guest OS to
563
+ * communicate with a client. Requires administrative privileges. A
564
+ * process 'nudge' causes a client event handler to be invoked (use
565
+ * dr_register_nudge_event() to register the handler function). A
566
+ * nudge is ignored if the process is not running under DynamoRIO,
567
+ * the specified client is not loaded, or if the client does not
568
+ * provide a handler.
569
+ *
570
+ * \param[in] process_id The system id of the process to nudge
571
+ * (see dr_get_process_id())
572
+ *
573
+ * \param[in] client_id The unique client ID provided at client
574
+ * registration.
575
+ *
576
+ * \param[in] arg An argument passed to the client's nudge
577
+ * handler.
578
+ *
579
+ * \param[in] timeout_ms The number of milliseconds to wait for the
580
+ * nudge to complete before returning. If INFINITE
581
+ * is supplied then the wait is unbounded. If 0
582
+ * is supplied the no wait is performed. If the
583
+ * wait times out DR_NUDGE_TIMEOUT will be returned.
584
+ *
585
+ * \return A dr_config_status_t code indicating the result of the nudge.
586
+ *
587
+ * \remarks
588
+ * A process nudge is a one way asynchronous communication from an
589
+ * external entity to a client. It does not allow a client to
590
+ * return information back to the nudge originator. To communicate
591
+ * from a client to another process, use the channels specified
592
+ * in \ref sec_comm.
593
+ *
594
+ * \note Nudging 64-bit processes is not yet supported.
595
+ */
596
+ dr_config_status_t
597
+ dr_nudge_pid(process_id_t process_id,
598
+ client_id_t client_id,
599
+ uint64 arg,
600
+ uint timeout_ms);
601
+
602
+ /**
603
+ * Provides a mechanism for an external entity on the guest OS to
604
+ * communicate with a client. Requires administrative privileges. A
605
+ * process 'nudge' causes a client event handler to be invoked (use
606
+ * dr_register_nudge_event() to register the handler function). A
607
+ * nudge is ignored if the process is not running under DynamoRIO,
608
+ * the specified client is not loaded, or if the client does not
609
+ * provide a handler. Nudges are attempted to all processes running
610
+ * on the system.
611
+ *
612
+ * \param[in] client_id The unique client ID provided at client
613
+ * registration.
614
+ *
615
+ * \param[in] arg An argument passed to the client's nudge
616
+ * handler.
617
+ *
618
+ * \param[in] timeout_ms The number of milliseconds to wait for each
619
+ * nudge to complete before continuing. If INFINITE
620
+ * is supplied then the wait is unbounded. If 0
621
+ * is supplied the no wait is performed. If a
622
+ * wait times out DR_NUDGE_TIMEOUT will be returned.
623
+ *
624
+ * \param[out] nudge_count Returns the number of processes nudged.
625
+ * Client can supply NULL if this value is
626
+ * not needed.
627
+ *
628
+ * \return A dr_config_status_t code indicating the result of the nudge.
629
+ *
630
+ * \remarks
631
+ * A process nudge is a one way asynchronous communication from an
632
+ * external entity to a client. It does not allow a client to
633
+ * return information back to the nudge originator. To communicate
634
+ * from a client to another process, use the channels specified
635
+ * in \ref sec_comm.
636
+ *
637
+ * \note Nudging 64-bit processes is not yet supported.
638
+ */
639
+ dr_config_status_t
640
+ dr_nudge_all(client_id_t client_id,
641
+ uint64 arg,
642
+ uint timeout_ms,
643
+ int *nudge_count /*OUT */);
644
+
645
+ #endif /* WINDOWS */
646
+
647
+
648
+
649
+
650
+ #endif /* _DR_CONFIG_H_ */