| 1 | + | using System; |
| 2 | + | using System.Configuration.Assemblies; |
| 3 | + | using System.Globalization; |
| 4 | + | using System.Reflection; |
| 5 | + | using System.Runtime.CompilerServices; |
| 6 | + | using System.Runtime.Remoting; |
| 7 | + | using System.Security.Policy; |
| 8 | + | using DotDumper.Hooks; |
| 9 | + | |
| 10 | + | namespace DotDumper.HookHandlers |
| 11 | + | { |
| 12 | + | class ActivatorHooks |
| 13 | + | { |
| 14 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 15 | + | public static ObjectHandle CreateComInstanceFromHookStringStringByteArrayAssemblyHashAlgorithm(string assemblyName, string typeName, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) |
| 16 | + | { |
| 17 | + | //Declare the local variable to store the object in |
| 18 | + | ObjectHandle result; |
| 19 | + | |
| 20 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 21 | + | lock (GenericHookHelper.SyncLock) |
| 22 | + | { |
| 23 | + | //Sets the title for the log |
| 24 | + | string functionName = "Activator.CreateComInstanceFrom(string assemblyName, string typeName, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)"; |
| 25 | + | |
| 26 | + | HookManager.UnHookByHookName("CreateComInstanceFromHookStringStringByteArrayAssemblyHashAlgorithm"); |
| 27 | + | //Call the original function |
| 28 | + | result = Activator.CreateComInstanceFrom(assemblyName, typeName, hashValue, hashAlgorithm); |
| 29 | + | HookManager.HookByHookName("CreateComInstanceFromHookStringStringByteArrayAssemblyHashAlgorithm"); |
| 30 | + | |
| 31 | + | //Write the aggregated data to the log and the console |
| 32 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateComInstanceFromStringStringByteArrayAssemblyHashAlgorithm(), new object[] { assemblyName, typeName, hashValue, hashAlgorithm }, result); |
| 33 | + | } |
| 34 | + | |
| 35 | + | //Return the process object to the caller |
| 36 | + | return result; |
| 37 | + | } |
| 38 | + | |
| 39 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 40 | + | public static ObjectHandle CreateComInstanceFromHookStringString(string assemblyName, string typeName) |
| 41 | + | { |
| 42 | + | //Declare the local variable to store the object in |
| 43 | + | ObjectHandle result; |
| 44 | + | |
| 45 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 46 | + | lock (GenericHookHelper.SyncLock) |
| 47 | + | { |
| 48 | + | //Within the DotNet framework, another CreateComInstance function is used, which is also hooked. To avoid duplicate entries in the logging, both are unhooked and rehooked |
| 49 | + | HookManager.UnHookByHookName("CreateComInstanceFromHookStringString"); |
| 50 | + | HookManager.UnHookByHookName("CreateComInstanceFromHookStringStringByteArrayAssemblyHashAlgorithm"); |
| 51 | + | //Call the original function |
| 52 | + | result = Activator.CreateComInstanceFrom(assemblyName, typeName); |
| 53 | + | HookManager.HookByHookName("CreateComInstanceFromHookStringString"); |
| 54 | + | HookManager.HookByHookName("CreateComInstanceFromHookStringStringByteArrayAssemblyHashAlgorithm"); |
| 55 | + | |
| 56 | + | //Write the aggregated data to the log and the console |
| 57 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateComInstanceFromStringString(), new object[] { assemblyName, typeName }, result); |
| 58 | + | } |
| 59 | + | |
| 60 | + | //Return the process object to the caller |
| 61 | + | return result; |
| 62 | + | } |
| 63 | + | |
| 64 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 65 | + | public static object CreateInstanceHookType(Type type) |
| 66 | + | { |
| 67 | + | //Declare the local variable to store the object in |
| 68 | + | object result; |
| 69 | + | |
| 70 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 71 | + | lock (GenericHookHelper.SyncLock) |
| 72 | + | { |
| 73 | + | //Double unhook due to DotNet internal wrappers, thereby avoiding double logging |
| 74 | + | HookManager.UnHookByHookName("CreateInstanceHookType"); |
| 75 | + | HookManager.UnHookByHookName("CreateInstanceHookTypeBool"); |
| 76 | + | //Call the original function |
| 77 | + | result = Activator.CreateInstance(type); |
| 78 | + | HookManager.HookByHookName("CreateInstanceHookType"); |
| 79 | + | HookManager.HookByHookName("CreateInstanceHookTypeBool"); |
| 80 | + | |
| 81 | + | //Write the aggregated data to the log and the console |
| 82 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceTypeBool(), new object[] { type }, result); |
| 83 | + | } |
| 84 | + | |
| 85 | + | //Return the process object to the caller |
| 86 | + | return result; |
| 87 | + | } |
| 88 | + | |
| 89 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 90 | + | public static object CreateInstanceHookTypeBool(Type type, bool nonPublic) |
| 91 | + | { |
| 92 | + | //Declare the local variable to store the object in |
| 93 | + | object result; |
| 94 | + | |
| 95 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 96 | + | lock (GenericHookHelper.SyncLock) |
| 97 | + | { |
| 98 | + | //Sets the title for the log |
| 99 | + | string functionName = "Activator.CreateInstance(Type type, bool nonPublic)"; |
| 100 | + | //Process the given data via the helper class |
| 101 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 102 | + | HookManager.UnHookByHookName("CreateInstanceHookTypeBool"); |
| 103 | + | //Call the original function |
| 104 | + | result = Activator.CreateInstance(type, nonPublic); |
| 105 | + | HookManager.HookByHookName("CreateInstanceHookTypeBool"); |
| 106 | + | |
| 107 | + | //Write the aggregated data to the log and the console |
| 108 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceTypeBool(), new object[] { type, nonPublic }, result); |
| 109 | + | } |
| 110 | + | |
| 111 | + | //Return the process object to the caller |
| 112 | + | return result; |
| 113 | + | } |
| 114 | + | |
| 115 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 116 | + | public static ObjectHandle CreateInstanceHookActivationContext(ActivationContext activationContext) |
| 117 | + | { |
| 118 | + | //Declare the local variable to store the object in |
| 119 | + | ObjectHandle result; |
| 120 | + | |
| 121 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 122 | + | lock (GenericHookHelper.SyncLock) |
| 123 | + | { |
| 124 | + | //Sets the title for the log |
| 125 | + | string functionName = "Activator.CreateInstance(ActivationContext activationContext)"; |
| 126 | + | //Process the given data via the helper class |
| 127 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 128 | + | HookManager.UnHookByHookName("CreateInstanceHookActivationContext"); |
| 129 | + | //Call the original function |
| 130 | + | result = Activator.CreateInstance(activationContext); |
| 131 | + | HookManager.HookByHookName("CreateInstanceHookActivationContext"); |
| 132 | + | |
| 133 | + | //Write the aggregated data to the log and the console |
| 134 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceActivationContext(), new object[] { activationContext }, result); |
| 135 | + | } |
| 136 | + | |
| 137 | + | //Return the process object to the caller |
| 138 | + | return result; |
| 139 | + | } |
| 140 | + | |
| 141 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 142 | + | public static object CreateInstanceHookTypeObjectArray(Type type, params object[] args) |
| 143 | + | { |
| 144 | + | //Declare the local variable to store the object in |
| 145 | + | object result; |
| 146 | + | |
| 147 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 148 | + | lock (GenericHookHelper.SyncLock) |
| 149 | + | { |
| 150 | + | //Double unhook due to |
| 151 | + | HookManager.UnHookByHookName("CreateInstanceHookTypeObjectArray"); |
| 152 | + | HookManager.UnHookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 153 | + | //Call the original function |
| 154 | + | result = Activator.CreateInstance(type, args); |
| 155 | + | HookManager.HookByHookName("CreateInstanceHookTypeObjectArray"); |
| 156 | + | HookManager.HookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 157 | + | |
| 158 | + | //Write the aggregated data to the log and the console |
| 159 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceActivationContext(), new object[] { type, args }, result); |
| 160 | + | } |
| 161 | + | |
| 162 | + | //Return the process object to the caller |
| 163 | + | return result; |
| 164 | + | } |
| 165 | + | |
| 166 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 167 | + | public static object CreateInstanceHookStringString(string assemblyName, string typeName) |
| 168 | + | { |
| 169 | + | //Declare the local variable to store the object in |
| 170 | + | object result; |
| 171 | + | |
| 172 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 173 | + | lock (GenericHookHelper.SyncLock) |
| 174 | + | { |
| 175 | + | //Sets the title for the log |
| 176 | + | string functionName = "Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)"; |
| 177 | + | //Process the given data via the helper class |
| 178 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 179 | + | HookManager.UnHookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 180 | + | //Call the original function |
| 181 | + | result = Activator.CreateInstance(assemblyName, typeName); |
| 182 | + | HookManager.HookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 183 | + | |
| 184 | + | //Write the aggregated data to the log and the console |
| 185 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceStringString(), new object[] { assemblyName, typeName }, result); |
| 186 | + | } |
| 187 | + | |
| 188 | + | //Return the process object to the caller |
| 189 | + | return result; |
| 190 | + | } |
| 191 | + | |
| 192 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 193 | + | public static object CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfo(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture) |
| 194 | + | { |
| 195 | + | //Declare the local variable to store the object in |
| 196 | + | object result; |
| 197 | + | |
| 198 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 199 | + | lock (GenericHookHelper.SyncLock) |
| 200 | + | { |
| 201 | + | //Double unhook due to an internal wrapper within the DotNet framework |
| 202 | + | HookManager.UnHookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfo"); |
| 203 | + | HookManager.UnHookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 204 | + | //Call the original function |
| 205 | + | result = Activator.CreateInstance(type, bindingAttr, binder, args, culture); |
| 206 | + | HookManager.HookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfo"); |
| 207 | + | HookManager.HookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 208 | + | |
| 209 | + | //Write the aggregated data to the log and the console |
| 210 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceActivationContext(), new object[] { type, bindingAttr, binder, args, culture }, result); |
| 211 | + | } |
| 212 | + | |
| 213 | + | //Return the process object to the caller |
| 214 | + | return result; |
| 215 | + | } |
| 216 | + | |
| 217 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 218 | + | public static object CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfoObjectArray(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes) |
| 219 | + | { |
| 220 | + | //Declare the local variable to store the object in |
| 221 | + | object result; |
| 222 | + | |
| 223 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 224 | + | lock (GenericHookHelper.SyncLock) |
| 225 | + | { |
| 226 | + | //Sets the title for the log |
| 227 | + | string functionName = "Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)"; |
| 228 | + | //Process the given data via the helper class |
| 229 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 230 | + | HookManager.UnHookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 231 | + | //Call the original function |
| 232 | + | result = Activator.CreateInstance(type, bindingAttr, binder, args, culture, activationAttributes); |
| 233 | + | HookManager.HookByHookName("CreateInstanceHookTypeBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 234 | + | |
| 235 | + | //Write the aggregated data to the log and the console |
| 236 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceActivationContext(), new object[] { type, bindingAttr, binder, args, culture, activationAttributes }, result); |
| 237 | + | } |
| 238 | + | |
| 239 | + | //Return the process object to the caller |
| 240 | + | return result; |
| 241 | + | } |
| 242 | + | |
| 243 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 244 | + | public static ObjectHandle CreateInstanceHookStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes) |
| 245 | + | { |
| 246 | + | //Declare the local variable to store the object in |
| 247 | + | ObjectHandle result; |
| 248 | + | |
| 249 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 250 | + | lock (GenericHookHelper.SyncLock) |
| 251 | + | { |
| 252 | + | //Sets the title for the log |
| 253 | + | string functionName = "Activator.CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)"; |
| 254 | + | //Process the given data via the helper class |
| 255 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 256 | + | HookManager.UnHookByHookName("CreateInstanceHookStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 257 | + | //Call the original function |
| 258 | + | result = Activator.CreateInstance(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes); |
| 259 | + | HookManager.HookByHookName("CreateInstanceHookStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 260 | + | |
| 261 | + | //Write the aggregated data to the log and the console |
| 262 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray(), new object[] { assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes }, result); |
| 263 | + | } |
| 264 | + | |
| 265 | + | //Return the process object to the caller |
| 266 | + | return result; |
| 267 | + | } |
| 268 | + | |
| 269 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 270 | + | public static ObjectHandle CreateInstanceHookActivationContextStringArray(ActivationContext activationContext, string[] activationCustomData) |
| 271 | + | { |
| 272 | + | //Declare the local variable to store the object in |
| 273 | + | ObjectHandle result; |
| 274 | + | |
| 275 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 276 | + | lock (GenericHookHelper.SyncLock) |
| 277 | + | { |
| 278 | + | //Sets the title for the log |
| 279 | + | string functionName = "Activator.CreateInstance(ActivationContext activationContext, string[] activationCustomData)"; |
| 280 | + | //Process the given data via the helper class |
| 281 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 282 | + | HookManager.UnHookByHookName("CreateInstanceHookActivationContextStringArray"); |
| 283 | + | //Call the original function |
| 284 | + | result = Activator.CreateInstance(activationContext, activationCustomData); |
| 285 | + | HookManager.HookByHookName("CreateInstanceHookActivationContextStringArray"); |
| 286 | + | |
| 287 | + | //Write the aggregated data to the log and the console |
| 288 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceActivationContextStringArray(), new object[] { activationContext, activationCustomData }, result); |
| 289 | + | } |
| 290 | + | |
| 291 | + | //Return the process object to the caller |
| 292 | + | return result; |
| 293 | + | } |
| 294 | + | |
| 295 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 296 | + | public static ObjectHandle CreateInstanceHookStringStringObjectArray(string assemblyName, string typeName, object[] activationAttributes) |
| 297 | + | { |
| 298 | + | //Declare the local variable to store the object in |
| 299 | + | ObjectHandle result; |
| 300 | + | |
| 301 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 302 | + | lock (GenericHookHelper.SyncLock) |
| 303 | + | { |
| 304 | + | //Sets the title for the log |
| 305 | + | string functionName = "Activator.CreateInstance(string assemblyName, string typeName, object[] activationAttributes)"; |
| 306 | + | //Process the given data via the helper class |
| 307 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 308 | + | HookManager.UnHookByHookName("CreateInstanceHookStringStringObjectArray"); |
| 309 | + | //Call the original function |
| 310 | + | result = Activator.CreateInstance(assemblyName, typeName, activationAttributes); |
| 311 | + | HookManager.HookByHookName("CreateInstanceHookStringStringObjectArray"); |
| 312 | + | |
| 313 | + | //Write the aggregated data to the log and the console |
| 314 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceStringStringObjectArray(), new object[] { assemblyName, typeName, activationAttributes }, result); |
| 315 | + | } |
| 316 | + | |
| 317 | + | //Return the process object to the caller |
| 318 | + | return result; |
| 319 | + | } |
| 320 | + | |
| 321 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 322 | + | public static ObjectHandle CreateInstanceHookAppDomainStringString(AppDomain domain, string assemblyName, string typeName) |
| 323 | + | { |
| 324 | + | //Declare the local variable to store the object in |
| 325 | + | ObjectHandle result; |
| 326 | + | |
| 327 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 328 | + | lock (GenericHookHelper.SyncLock) |
| 329 | + | { |
| 330 | + | //Sets the title for the log |
| 331 | + | string functionName = "Activator.CreateInstance(AppDomain domain, string assemblyName, string typeName)"; |
| 332 | + | //Process the given data via the helper class |
| 333 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 334 | + | HookManager.UnHookByHookName("CreateInstanceHookAppDomainStringString"); |
| 335 | + | //Call the original function |
| 336 | + | result = Activator.CreateInstance(domain, assemblyName, typeName); |
| 337 | + | HookManager.HookByHookName("CreateInstanceHookAppDomainStringString"); |
| 338 | + | |
| 339 | + | //Write the aggregated data to the log and the console |
| 340 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceAppDomainStringString(), new object[] { domain, assemblyName, typeName }, result); |
| 341 | + | } |
| 342 | + | |
| 343 | + | //Return the process object to the caller |
| 344 | + | return result; |
| 345 | + | } |
| 346 | + | |
| 347 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 348 | + | public static ObjectHandle CreateInstanceHookStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityInfo) |
| 349 | + | { |
| 350 | + | //Declare the local variable to store the object in |
| 351 | + | ObjectHandle result; |
| 352 | + | |
| 353 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 354 | + | lock (GenericHookHelper.SyncLock) |
| 355 | + | { |
| 356 | + | //Sets the title for the log |
| 357 | + | string functionName = "Activator.CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityInfo)"; |
| 358 | + | //Process the given data via the helper class |
| 359 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 360 | + | HookManager.UnHookByHookName("CreateInstanceHookStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence"); |
| 361 | + | //Call the original function |
| 362 | + | result = Activator.CreateInstance(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityInfo); |
| 363 | + | HookManager.HookByHookName("CreateInstanceHookStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence"); |
| 364 | + | |
| 365 | + | //Write the aggregated data to the log and the console |
| 366 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(), new object[] { assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityInfo }, result); |
| 367 | + | } |
| 368 | + | |
| 369 | + | //Return the process object to the caller |
| 370 | + | return result; |
| 371 | + | } |
| 372 | + | |
| 373 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 374 | + | public static ObjectHandle CreateInstanceHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray(AppDomain domain, string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes) |
| 375 | + | { |
| 376 | + | //Declare the local variable to store the object in |
| 377 | + | ObjectHandle result; |
| 378 | + | |
| 379 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 380 | + | lock (GenericHookHelper.SyncLock) |
| 381 | + | { |
| 382 | + | //Sets the title for the log |
| 383 | + | string functionName = "Activator.CreateInstance(AppDomain domain, string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)"; |
| 384 | + | //Process the given data via the helper class |
| 385 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 386 | + | HookManager.UnHookByHookName("CreateInstanceHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 387 | + | //Call the original function |
| 388 | + | result = Activator.CreateInstance(domain, assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes); |
| 389 | + | HookManager.HookByHookName("CreateInstanceHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 390 | + | |
| 391 | + | //Write the aggregated data to the log and the console |
| 392 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray(), new object[] { domain, assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes }, result); |
| 393 | + | } |
| 394 | + | |
| 395 | + | //Return the process object to the caller |
| 396 | + | return result; |
| 397 | + | } |
| 398 | + | |
| 399 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 400 | + | public static ObjectHandle CreateInstanceHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(AppDomain domain, string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes) |
| 401 | + | { |
| 402 | + | //Declare the local variable to store the object in |
| 403 | + | ObjectHandle result; |
| 404 | + | |
| 405 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 406 | + | lock (GenericHookHelper.SyncLock) |
| 407 | + | { |
| 408 | + | //Sets the title for the log |
| 409 | + | string functionName = "Activator.CreateInstance(AppDomain domain, string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)"; |
| 410 | + | //Process the given data via the helper class |
| 411 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 412 | + | HookManager.UnHookByHookName("CreateInstanceHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence"); |
| 413 | + | //Call the original function |
| 414 | + | result = Activator.CreateInstance(domain, assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes); |
| 415 | + | HookManager.HookByHookName("CreateInstanceHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence"); |
| 416 | + | |
| 417 | + | //Write the aggregated data to the log and the console |
| 418 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(), new object[] { domain, assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes }, result); |
| 419 | + | } |
| 420 | + | |
| 421 | + | //Return the process object to the caller |
| 422 | + | return result; |
| 423 | + | } |
| 424 | + | |
| 425 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 426 | + | public static ObjectHandle CreateInstanceFromHookAppDomainStringString(AppDomain domain, string assemblyFile, string typeName) |
| 427 | + | { |
| 428 | + | //Declare the local variable to store the object in |
| 429 | + | ObjectHandle result; |
| 430 | + | |
| 431 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 432 | + | lock (GenericHookHelper.SyncLock) |
| 433 | + | { |
| 434 | + | //Sets the title for the log |
| 435 | + | string functionName = "Activator.CreateInstanceFrom(AppDomain domain, string assemblyName, string typeName)"; |
| 436 | + | //Process the given data via the helper class |
| 437 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 438 | + | HookManager.UnHookByHookName("CreateInstanceFromHookAppDomainStringString"); |
| 439 | + | //Call the original function |
| 440 | + | result = Activator.CreateInstanceFrom(domain, assemblyFile, typeName); |
| 441 | + | HookManager.HookByHookName("CreateInstanceFromHookAppDomainStringString"); |
| 442 | + | |
| 443 | + | //Write the aggregated data to the log and the console |
| 444 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceFromAppDomainStringString(), new object[] { domain, assemblyFile, typeName }, result); |
| 445 | + | } |
| 446 | + | |
| 447 | + | //Return the process object to the caller |
| 448 | + | return result; |
| 449 | + | } |
| 450 | + | |
| 451 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 452 | + | public static ObjectHandle CreateInstanceFromHookStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityInfo) |
| 453 | + | { |
| 454 | + | //Declare the local variable to store the object in |
| 455 | + | ObjectHandle result; |
| 456 | + | |
| 457 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 458 | + | lock (GenericHookHelper.SyncLock) |
| 459 | + | { |
| 460 | + | //Sets the title for the log |
| 461 | + | string functionName = "Activator.CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityInfo)"; |
| 462 | + | //Process the given data via the helper class |
| 463 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 464 | + | HookManager.UnHookByHookName("CreateInstanceFromHookStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence"); |
| 465 | + | //Call the original function |
| 466 | + | result = Activator.CreateInstanceFrom(assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityInfo); |
| 467 | + | HookManager.HookByHookName("CreateInstanceFromHookStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence"); |
| 468 | + | |
| 469 | + | //Write the aggregated data to the log and the console |
| 470 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceFromStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(), new object[] { assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityInfo }, result); |
| 471 | + | } |
| 472 | + | |
| 473 | + | //Return the process object to the caller |
| 474 | + | return result; |
| 475 | + | } |
| 476 | + | |
| 477 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 478 | + | public static ObjectHandle CreateInstanceFromHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray(AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes) |
| 479 | + | { |
| 480 | + | //Declare the local variable to store the object in |
| 481 | + | ObjectHandle result; |
| 482 | + | |
| 483 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 484 | + | lock (GenericHookHelper.SyncLock) |
| 485 | + | { |
| 486 | + | //Sets the title for the log |
| 487 | + | string functionName = "Activator.CreateInstanceFrom(AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)"; |
| 488 | + | //Process the given data via the helper class |
| 489 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 490 | + | HookManager.UnHookByHookName("CreateInstanceFromHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 491 | + | //Call the original function |
| 492 | + | result = Activator.CreateInstanceFrom(domain, assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes); |
| 493 | + | HookManager.HookByHookName("CreateInstanceFromHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 494 | + | |
| 495 | + | //Write the aggregated data to the log and the console |
| 496 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceFromAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArray(), new object[] { domain, assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes }, result); |
| 497 | + | } |
| 498 | + | |
| 499 | + | //Return the process object to the caller |
| 500 | + | return result; |
| 501 | + | } |
| 502 | + | |
| 503 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 504 | + | public static ObjectHandle CreateInstanceFromHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes) |
| 505 | + | { |
| 506 | + | //Declare the local variable to store the object in |
| 507 | + | ObjectHandle result; |
| 508 | + | |
| 509 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 510 | + | lock (GenericHookHelper.SyncLock) |
| 511 | + | { |
| 512 | + | //Sets the title for the log |
| 513 | + | string functionName = "Activator.CreateInstanceFrom(AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)"; |
| 514 | + | //Process the given data via the helper class |
| 515 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 516 | + | HookManager.UnHookByHookName("CreateInstanceFromHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence"); |
| 517 | + | //Call the original function |
| 518 | + | result = Activator.CreateInstanceFrom(domain, assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes); |
| 519 | + | HookManager.HookByHookName("CreateInstanceFromHookAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence"); |
| 520 | + | |
| 521 | + | //Write the aggregated data to the log and the console |
| 522 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceFromAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(), new object[] { domain, assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes }, result); |
| 523 | + | } |
| 524 | + | |
| 525 | + | //Return the process object to the caller |
| 526 | + | return result; |
| 527 | + | } |
| 528 | + | |
| 529 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 530 | + | public static ObjectHandle CreateInstanceFromHookStringString(string assemblyFile, string typeName) |
| 531 | + | { |
| 532 | + | //Declare the local variable to store the object in |
| 533 | + | ObjectHandle result; |
| 534 | + | |
| 535 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 536 | + | lock (GenericHookHelper.SyncLock) |
| 537 | + | { |
| 538 | + | //Multi unhooking due to DotNet wrapper calls |
| 539 | + | HookManager.UnHookByHookName("CreateInstanceFromHookStringString"); |
| 540 | + | HookManager.UnHookByHookName("CreateInstanceFromHookStringStringObjectArray"); |
| 541 | + | HookManager.UnHookByHookName("CreateInstanceFromHookStringStringBoolBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 542 | + | //Call the original function |
| 543 | + | result = Activator.CreateInstanceFrom(assemblyFile, typeName); |
| 544 | + | HookManager.HookByHookName("CreateInstanceFromHookStringString"); |
| 545 | + | HookManager.HookByHookName("CreateInstanceFromHookStringStringObjectArray"); |
| 546 | + | HookManager.HookByHookName("CreateInstanceFromHookStringStringBoolBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 547 | + | |
| 548 | + | //Write the aggregated data to the log and the console |
| 549 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceFromStringString(), new object[] { assemblyFile, typeName }, result); |
| 550 | + | } |
| 551 | + | |
| 552 | + | //Return the process object to the caller |
| 553 | + | return result; |
| 554 | + | } |
| 555 | + | |
| 556 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 557 | + | public static ObjectHandle CreateInstanceFromHookStringStringObjectArray(string assemblyFile, string typeName, object[] activationAttributes) |
| 558 | + | { |
| 559 | + | //Declare the local variable to store the object in |
| 560 | + | ObjectHandle result; |
| 561 | + | |
| 562 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 563 | + | lock (GenericHookHelper.SyncLock) |
| 564 | + | { |
| 565 | + | //Sets the title for the log |
| 566 | + | string functionName = "Activator.CreateInstanceFrom(AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)"; |
| 567 | + | //Process the given data via the helper class |
| 568 | + | //MethodBaseHooksHelper.Invoke(methodBase, functionName, parameters); |
| 569 | + | HookManager.UnHookByHookName("CreateInstanceFromHookStringStringObjectArray"); |
| 570 | + | HookManager.UnHookByHookName("CreateInstanceFromHookStringStringBoolBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 571 | + | //Call the original function |
| 572 | + | result = Activator.CreateInstanceFrom(assemblyFile, typeName, activationAttributes); |
| 573 | + | HookManager.HookByHookName("CreateInstanceFromHookStringStringObjectArray"); |
| 574 | + | HookManager.HookByHookName("CreateInstanceFromHookStringStringBoolBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 575 | + | |
| 576 | + | //Write the aggregated data to the log and the console |
| 577 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceFromAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(), new object[] { assemblyFile, typeName, activationAttributes }, result); |
| 578 | + | } |
| 579 | + | |
| 580 | + | //Return the process object to the caller |
| 581 | + | return result; |
| 582 | + | } |
| 583 | + | |
| 584 | + | [MethodImpl(MethodImplOptions.NoInlining)] |
| 585 | + | public static ObjectHandle CreateInstanceFromHookStringStringBoolBindingFlagsBinderObjectArrayCultureInfoObjectArray(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes) |
| 586 | + | { |
| 587 | + | //Declare the local variable to store the object in |
| 588 | + | ObjectHandle result; |
| 589 | + | |
| 590 | + | //Enable the thread safe lock, as a launched program can be multi-threaded |
| 591 | + | lock (GenericHookHelper.SyncLock) |
| 592 | + | { |
| 593 | + | //Multi unhook due to internal wrappers in the DotNet framework |
| 594 | + | HookManager.UnHookByHookName("CreateInstanceFromHookStringStringBoolBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 595 | + | //Call the original function |
| 596 | + | result = Activator.CreateInstanceFrom(assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes); |
| 597 | + | HookManager.HookByHookName("CreateInstanceFromHookStringStringBoolBindingFlagsBinderObjectArrayCultureInfoObjectArray"); |
| 598 | + | |
| 599 | + | //Write the aggregated data to the log and the console |
| 600 | + | GenericHookHelper._Logger.LogSampleCall(1, OriginalManagedFunctions.ActivatorCreateInstanceFromAppDomainStringStringBooleanBindingFlagsBinderObjectArrayCultureInfoObjectArrayEvidence(), new object[] { assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes }, result); |
| 601 | + | } |
| 602 | + | |
| 603 | + | //Return the process object to the caller |
| 604 | + | return result; |
| 605 | + | } |
| 606 | + | } |
| 607 | + | } |
| 608 | + | |