public void LoadAsBinary() { using (var handle = ModuleMethods.LoadLibrary(GetNativeTestLibraryLocation(), 0)) { handle.IsInvalid.Should().BeFalse(); } }
public void RegisterClass_UnregisterClassName() { WindowClass myClass = new WindowClass { ClassName = "RegisterClass_UnregisterClassName", Style = ClassStyle.HorizontalRedraw, WindowProcedure = CallDefaultProcedure }; Atom atom = WindowMethods.RegisterClass(ref myClass); atom.IsValid.Should().BeTrue(); try { var info = WindowMethods.GetClassInfo(ModuleMethods.GetModuleHandle(null), "RegisterClass_UnregisterClassName"); info.ClassName.Should().Be("RegisterClass_UnregisterClassName"); info.ClassAtom.Should().Be(Atom.Null); info.Style.Should().Be(ClassStyle.HorizontalRedraw); } finally { WindowMethods.UnregisterClass("RegisterClass_UnregisterClassName", null); Action action = () => WindowMethods.GetClassInfo(ModuleMethods.GetModuleHandle(null), "RegisterClass_UnregisterClassName"); action.ShouldThrow <IOException>().And .HResult.Should().Be((int)ErrorMacros.HRESULT_FROM_WIN32(WindowsError.ERROR_CLASS_DOES_NOT_EXIST)); } }
public void LoadAsResource() { using (var handle = ModuleMethods.LoadLibrary(GetNativeTestLibraryLocation(), LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)) { handle.IsInvalid.Should().BeFalse(); } }
public void GetProcessModulePaths() { var modules = ModuleMethods.GetProcessModules(); var moduleNames = (from module in modules select ModuleMethods.GetModuleFileName(module)).ToArray(); moduleNames.Should().NotBeEmpty(); moduleNames.Length.Should().Be(modules.Count()); }
public void GetEntryModuleInfo() { var module = ModuleMethods.GetModuleHandle(null); module.Should().NotBe(ModuleTypes.ModuleInstance.Null); var info = ModuleMethods.GetModuleInfo(module); info.lpBaseOfDll.Should().Be(module.DangerousGetHandle()); }
public void LoadFunctionStandard() { using (var handle = ModuleMethods.LoadLibrary(GetNativeTestLibraryLocation(), LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH)) { handle.IsInvalid.Should().BeFalse(); var doubler = ModuleMethods.GetFunctionDelegate <DoubleDelegateStandard>(handle, "DoubleStdCall"); doubler(2).Should().Be(4); } }
public void LoadString() { using (var handle = ModuleMethods.LoadLibrary(GetNativeTestLibraryLocation(), LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)) { string resource = ResourceMethods.LoadString(handle, 101); resource.Should().Be("Test"); } }
public void GetEntryModuleHandleAndFileName() { var module = ModuleMethods.GetModuleHandle(null); module.Should().NotBe(ModuleTypes.ModuleInstance.Null); string pathByHandle = ModuleMethods.GetModuleFileName(module); pathByHandle.Should().NotBeNullOrWhiteSpace(); string pathByDefault = ModuleMethods.GetModuleFileName(ModuleTypes.ModuleInstance.Null); // Strangely the path is cased differently when getting the module file name through GetModuleFileNameEx, but not GetModuleFileName. pathByHandle.Should().BeEquivalentTo(pathByDefault); }
public async Task Ban(IGuildUser userToBan, [Remainder] string reason = "No reason.") { if (ModuleMethods.IsMod(Context, userToBan)) { throw new Exception("You cannot ban another mod!"); } await ModuleMethods.InformSubjectAsync(Context.User, "Ban", userToBan, reason); await Context.Guild.AddBanAsync(userToBan); await Logger.ModLog(Context, "Ban", new Color(255, 0, 0), reason, userToBan); await ReplyAsync($"{Context.User.Mention} has successfully banned {userToBan.Mention}!"); }
public async Task Kick(IGuildUser userToKick, [Remainder] string reason = "No reason.") { if (ModuleMethods.IsMod(Context, userToKick)) { throw new Exception("You cannot kick another mod!"); } await ModuleMethods.InformSubjectAsync(Context.User, "Kick", userToKick, reason); await userToKick.KickAsync(); await Logger.ModLog(Context, "Kick", new Color(255, 114, 14), reason, userToKick); await ReplyAsync($"{Context.User.Mention} has successfully kicked {userToKick.Mention}!"); }
public void LoadAsBinaryFromLongPath() { using (var cleaner = new TestFileCleaner()) { string longPath = @"\\?\" + PathGenerator.CreatePathOfLength(cleaner.TempFolder, 500); FileHelper.CreateDirectoryRecursive(longPath); string longPathLibrary = Paths.Combine(longPath, "LoadAsBinaryFromLongPath.dll"); FileMethods.CopyFile(GetNativeTestLibraryLocation(), longPathLibrary); using (var handle = ModuleMethods.LoadLibrary(longPathLibrary, LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH)) { handle.IsInvalid.Should().BeFalse(); } } }
public void LoadStringFromLongPath() { using (var cleaner = new TestFileCleaner()) { string longPath = @"\\?\" + PathGenerator.CreatePathOfLength(cleaner.TempFolder, 500); FileHelper.CreateDirectoryRecursive(longPath); string longPathLibrary = Paths.Combine(longPath, "LoadStringFromLongPath.dll"); FileMethods.CopyFile(GetNativeTestLibraryLocation(), longPathLibrary); using (var handle = ModuleMethods.LoadLibrary(longPathLibrary, LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE | LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE)) { string resource = ResourceMethods.LoadString(handle, 101); resource.Should().Be("Test"); } } }
public async Task Unmute(IGuildUser userToUnmute, [Remainder] string reason = "No reason.") { var mutedRoleId = GuildRepository.FetchGuild(Context.Guild.Id).MutedRoleId; if (userToUnmute.RoleIds.All(x => x != mutedRoleId)) { throw new Exception("You cannot unmute a user who isn't muted."); } await ModuleMethods.InformSubjectAsync(Context.User, "Unmute", userToUnmute, reason); await userToUnmute.RemoveRoleAsync(Context.Guild.GetRole(mutedRoleId)); MuteRepository.RemoveMute(userToUnmute.Id, Context.Guild.Id); await Logger.ModLog(Context, "Unmute", new Color(12, 255, 129), reason, userToUnmute); await ReplyAsync($"{Context.User.Mention} has successfully unmuted {userToUnmute.Mention}!"); }
public void LoadFunctionFromLongPath() { using (var cleaner = new TestFileCleaner()) { string longPath = @"\\?\" + PathGenerator.CreatePathOfLength(cleaner.TempFolder, 500); FileHelper.CreateDirectoryRecursive(longPath); string longPathLibrary = Paths.Combine(longPath, "LoadFunctionFromLongPath.dll"); FileMethods.CopyFile(GetNativeTestLibraryLocation(), longPathLibrary); using (var handle = ModuleMethods.LoadLibrary(longPathLibrary, 0)) { handle.IsInvalid.Should().BeFalse(); var doubler = ModuleMethods.GetFunctionDelegate <DoubleDelegate>(handle, "Double"); doubler(2).Should().Be(4); } } }
public void RegisterClass_GetSetClassLong() { // Some docs claim that 40 is the max, but that isn't true (at least in recent OSes) // https://msdn.microsoft.com/en-us/library/windows/desktop/ms633574.aspx WindowClass myClass = new WindowClass { ClassName = "RegisterClass_GetSetClassLong", Style = ClassStyle.HorizontalRedraw, WindowProcedure = CallDefaultProcedure, ClassExtraBytes = 80 }; Atom atom = WindowMethods.RegisterClass(ref myClass); atom.IsValid.Should().BeTrue(); try { WindowHandle window = WindowMethods.CreateWindow(atom, "RegisterClass_GetSetClassLong_Window", WindowStyles.Diabled | WindowStyles.Minimize); window.IsValid.Should().BeTrue(); try { var info = WindowMethods.GetClassInfo(ModuleMethods.GetModuleHandle(null), atom); info.ClassExtraBytes.Should().Be(80); IntPtr result = WindowMethods.SetClassLong(window, (ClassLong)72, (IntPtr)0x0000BEEF); result.Should().Be(IntPtr.Zero); WindowMethods.GetClassLong(window, (ClassLong)72).Should().Be((IntPtr)0x0000BEEF); } finally { WindowMethods.DestroyWindow(window); } } finally { WindowMethods.UnregisterClass(atom, null); } }
public async Task Mute(IGuildUser userToMute, [Remainder] string reason = "No reason.") { var guild = GuildRepository.FetchGuild(Context.Guild.Id); var mutedRole = Context.Guild.GetRole(guild.MutedRoleId); if (mutedRole == null) { throw new Exception($"You may not mute users if the muted role is not valid.\nPlease use the " + $"`{guild.Prefix}SetMutedRole` command to change that."); } if (ModuleMethods.IsMod(Context, userToMute)) { throw new Exception("You cannot mute another mod!"); } await ModuleMethods.InformSubjectAsync(Context.User, "Mute", userToMute, reason); await userToMute.AddRoleAsync(mutedRole); MuteRepository.AddMute(userToMute.Id, Context.Guild.Id, Config.DEFAULT_MUTE_TIME); await Logger.ModLog(Context, "Mute", new Color(255, 114, 14), reason, userToMute, $"\n**Length:** {Config.DEFAULT_MUTE_TIME.TotalHours} hours"); await ReplyAsync($"{Context.User.Mention} has successfully muted {userToMute.Mention}!"); }
public async Task CustomMute(double hours, IGuildUser userToMute, [Remainder] string reason = "No reason.") { if (hours > 168) { throw new Exception("You may not mute a user for more than a week."); } if (hours < 1) { throw new Exception("You may not mute a user for less than 1 hour."); } string time = "hours"; if (hours == 1) { time = "hour"; } var guild = GuildRepository.FetchGuild(Context.Guild.Id); var mutedRole = Context.Guild.GetRole(guild.MutedRoleId); if (mutedRole == null) { throw new Exception($"You may not mute users if the muted role is not valid.\nPlease use the " + $"{guild.Prefix}SetMutedRole command to change that."); } if (ModuleMethods.IsMod(Context, userToMute)) { throw new Exception("You cannot mute another mod!"); } await ModuleMethods.InformSubjectAsync(Context.User, "Mute", userToMute, reason); await userToMute.AddRoleAsync(mutedRole); MuteRepository.AddMute(userToMute.Id, Context.Guild.Id, TimeSpan.FromHours(hours)); await Logger.ModLog(Context, "Mute", new Color(255, 114, 14), reason, userToMute, $"\n**Length:** {hours} {time}"); await ReplyAsync($"{Context.User.Mention} has successfully muted {userToMute.Mention} for {hours} {time}!"); }
public async Task XHalf(double bet) { await ModuleMethods.Gamble(Context, bet, 20.84, 0.2); }
public async Task X2(double bet) { await ModuleMethods.Gamble(Context, bet, 52.5, 1.0); }
public async Task X3dot8(double bet) { await ModuleMethods.Gamble(Context, bet, 75.01, 2.8); }
public async Task X90(double bet) { await ModuleMethods.Gamble(Context, bet, 100.0, 9500.0); }
public void GetEntryModuleFileName() { string path = ModuleMethods.GetModuleFileName(ModuleTypes.ModuleInstance.Null); path.Should().NotBeNullOrWhiteSpace(); }
public void GetProcessModules() { var modules = ModuleMethods.GetProcessModules(); modules.Should().NotBeEmpty(); }
public async Task X2BetterOdds(double bet) { await ModuleMethods.Gamble(Context, bet, 50.0, 1.0); }