internal ExtensionWrapper(int targetProcessId, string dllPath, bool randomiseDllName) { // Ensure the users operating system is supported ValidationHandler.ValidateOperatingSystem(); // Ensure the arguments passed in are valid if (targetProcessId <= 0 || string.IsNullOrWhiteSpace(dllPath)) { throw new ArgumentException("One or more of the arguments provided were invalid"); } if (randomiseDllName) { // Assume the DLL is the newest file in the temporary directory var temporaryDirectoryInfo = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "Bleak")); var newestTemporaryFile = temporaryDirectoryInfo.GetFiles().OrderByDescending(file => file.LastWriteTime).First(); _propertyWrapper = new PropertyWrapper(targetProcessId, newestTemporaryFile.FullName); } else { _propertyWrapper = new PropertyWrapper(targetProcessId, dllPath); } ValidationHandler.ValidateDllArchitecture(_propertyWrapper); }
internal MethodWrapper(int targetProcessId, string dllPath, bool randomiseDllName, bool methodIsManualMap) { // Ensure the users operating system is supported ValidationHandler.ValidateOperatingSystem(); // Ensure the arguments passed in are valid if (targetProcessId <= 0 || string.IsNullOrWhiteSpace(dllPath)) { throw new ArgumentException("One or more of the arguments provided were invalid"); } if (randomiseDllName) { // Create a temporary DLL on disk var temporaryDllName = WrapperTools.GenerateRandomDllName(); var temporaryDllPath = WrapperTools.CreateTemporaryDll(temporaryDllName, File.ReadAllBytes(dllPath)); _propertyWrapper = methodIsManualMap ? new PropertyWrapper(targetProcessId, File.ReadAllBytes(temporaryDllPath)) : new PropertyWrapper(targetProcessId, temporaryDllPath); } else { _propertyWrapper = methodIsManualMap ? new PropertyWrapper(targetProcessId, File.ReadAllBytes(dllPath)) : new PropertyWrapper(targetProcessId, dllPath); } // Ensure the architecture of the DLL is valid ValidationHandler.ValidateDllArchitecture(_propertyWrapper); }
internal MethodWrapper(string targetProcessName, byte[] dllBytes, bool randomiseDllName, bool methodIsManualMap) { // Ensure the users operating system is supported ValidationHandler.ValidateOperatingSystem(); // Ensure the arguments passed in are valid if (string.IsNullOrWhiteSpace(targetProcessName) || dllBytes is null || dllBytes.Length == 0) { throw new ArgumentException("One or more of the arguments provided were invalid"); } if (methodIsManualMap) { _propertyWrapper = new PropertyWrapper(targetProcessName, dllBytes); } else { // Create a temporary DLL on disk var temporaryDllName = randomiseDllName ? WrapperTools.GenerateRandomDllName() : WrapperTools.GenerateDllName(dllBytes); var temporaryDllPath = WrapperTools.CreateTemporaryDll(temporaryDllName, dllBytes); _propertyWrapper = new PropertyWrapper(targetProcessName, temporaryDllPath); } // Ensure the architecture of the DLL is valid ValidationHandler.ValidateDllArchitecture(_propertyWrapper); }
internal ExtensionWrapper(int targetProcessId, byte[] dllBytes, bool randomiseDllName) { // Ensure the users operating system is supported 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 (randomiseDllName) { // Assume the DLL is the newest file in the temporary directory var temporaryDirectoryInfo = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "Bleak")); var newestTemporaryFile = temporaryDirectoryInfo.GetFiles().OrderByDescending(file => file.LastWriteTime).First(); _propertyWrapper = new PropertyWrapper(targetProcessId, newestTemporaryFile.FullName); } else { // Get the file path of the DLL on disk var temporaryDirectory = Path.Combine(Path.GetTempPath(), "Bleak"); var temporaryDllName = WrapperTools.GenerateDllName(dllBytes); var temporaryDllPath = Path.Combine(temporaryDirectory, temporaryDllName); _propertyWrapper = new PropertyWrapper(targetProcessId, temporaryDllPath); } // Ensure the architecture of the DLL is valid ValidationHandler.ValidateDllArchitecture(_propertyWrapper); }