internal InjectionManager(int targetProcessId, byte[] dllBytes, bool manualMap, bool isExtension, bool randomiseDllName) { // Ensure the users operating system is valid ValidationHandler.ValidateOperatingSystem(); // Ensure the arguments passed in are valid if (targetProcessId <= 0 || dllBytes is null || dllBytes.Length == 0) { throw new ArgumentException("One or more of the arguments provided were invalid"); } if (manualMap) { _injectionProperties = new InjectionProperties(targetProcessId, dllBytes); } else if (randomiseDllName && isExtension) { // Assume the DLL is the newest file in the directory var directoryInfo = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "Bleak")); var newestFile = directoryInfo.GetFiles().OrderByDescending(file => file.LastWriteTime).First(); _injectionProperties = new InjectionProperties(targetProcessId, newestFile.FullName); } else { // Create a temporary DLL on disk var temporaryDllName = randomiseDllName ? DllTools.GenerateRandomDllName() : DllTools.GenerateDllName(dllBytes); _injectionProperties = new InjectionProperties(targetProcessId, DllTools.CreateTemporaryDll(temporaryDllName, dllBytes)); } // Ensure the architecture of the DLL is valid ValidationHandler.ValidateDllArchitecture(_injectionProperties); }
public Injector(InjectionMethod injectionMethod, string processName, byte[] dllBytes) { // Ensure the users operating system is valid ValidationHandler.ValidateOperatingSystem(); // Ensure the arguments passed in are valid if (string.IsNullOrWhiteSpace(processName) || dllBytes is null || dllBytes.Length == 0) { throw new ArgumentException("One or more of the arguments provided were invalid"); } _injectionContext = injectionMethod == InjectionMethod.ManualMap ? new InjectionContext(injectionMethod, processName, dllBytes) : new InjectionContext(injectionMethod, processName, DllTools.CreateTemporaryDll(DllTools.GenerateDllName(dllBytes), dllBytes)); }