C# WPF 加密EXCEL文件字典破解
By
jerryxjr1220
at 2023-10-16 • 0人收藏 • 327人看过
<hc:GlowWindow x:Class="WPFProgressBar.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:model="clr-namespace:WPFProgressBar.Models" xmlns:vm="clr-namespace:WPFProgressBar.ViewModels" xmlns:view="clr-namespace:WPFProgressBar.Views" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:local="clr-namespace:WPFProgressBar" xmlns:hc="https://handyorg.github.io/handycontrol" d:DataContext="{d:DesignInstance Type=vm:MainViewModel}" mc:Ignorable="d" Title="MainWindow" Height="360" Width="720" FontFamily="JetBrains Mono" FontSize="{StaticResource TextFontSize}" Background="GhostWhite"> <Window.Resources> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> </Window.Resources> <hc:SimplePanel> <ScrollViewer x:Name="scrollViewer" VerticalScrollBarVisibility="Auto"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="*"/> <RowDefinition Height="4*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock Grid.Row="0" Grid.Column="0" Text="Excel to Crack" FontSize="14" Style="{StaticResource TextBlockDefaultPrimary}" HorizontalAlignment="Right" VerticalAlignment="Center"/> <TextBox Grid.Row="0" Grid.Column="1" hc:InfoElement.Placeholder="Excel File Path..." Text="{Binding ExcelFilePath}" Style="{StaticResource TextBoxExtend}" VerticalAlignment="Center" Margin="20,0"/> <Button Grid.Row="0" Grid.Column="2" HorizontalAlignment="Left" Style="{StaticResource ButtonDashedPrimary}" hc:IconElement.Geometry="{StaticResource DownloadGeometry}" Command="{Binding ChooseExcelFileCommand}"/> <TextBlock Grid.Row="1" Grid.Column="0" Text="Password Book" FontSize="14" Style="{StaticResource TextBlockDefaultPrimary}" HorizontalAlignment="Right" VerticalAlignment="Center"/> <TextBox Grid.Row="1" Grid.Column="1" hc:InfoElement.Placeholder="Password Book File Path..." Text="{Binding PasswordBookFilePath}" Style="{StaticResource TextBoxExtend}" VerticalAlignment="Center" Margin="20,0"/> <Button Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left" Style="{StaticResource ButtonDashedPrimary}" hc:IconElement.Geometry="{StaticResource DownloadGeometry}" Command="{Binding ChoosePasswordBookFileCommand}"/> <StackPanel Grid.Row="2" Grid.Column="0"> <TextBlock Text="Cracking Progress" FontSize="14" Style="{StaticResource TextBlockDefaultPrimary}" HorizontalAlignment="Right" VerticalAlignment="Top" /> <Button Style="{StaticResource ButtonPrimary}" Margin="20" Content="Crack" Command="{Binding CrackingCommand}"/> </StackPanel> <Border Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" BorderBrush="LightGray" BorderThickness="1" CornerRadius="10" Margin="10"> <hc:WaveProgressBar Width="180" Minimum="0" Maximum="1" Value="{Binding ProgressValue}" Text="{Binding ProgressText}"/> </Border> </Grid> </ScrollViewer> </hc:SimplePanel> </hc:GlowWindow>
using System; using System.IO; using System.Threading; using System.Threading.Tasks; using System.Windows.Threading; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.Mvvm.Messaging.Messages; using Microsoft.Win32; using WPFProgressBar.Models; using Microsoft.Office.Interop.Excel; namespace WPFProgressBar.ViewModels; public partial class MainViewModel : ObservableObject { [ObservableProperty] private string _excelFilePath; [ObservableProperty] private string _passwordBookFilePath; [ObservableProperty] private double _progressValue; [ObservableProperty] private string _progressText; public MainViewModel() { ExcelFilePath = ""; PasswordBookFilePath = ""; ProgressValue = 0; ProgressText = "Not Ready"; } [RelayCommand] public void ChooseExcelFile() { FileDialog fd = new OpenFileDialog(); fd.Filter = "Excel Files|*.xlsx"; fd.Title = "Choose Excel File to crack..."; var fdResult = fd.ShowDialog(); if (fdResult == true) { ExcelFilePath = fd.FileName; } } [RelayCommand] public void ChoosePasswordBookFile() { FileDialog fd = new OpenFileDialog(); fd.Filter = "TXT Files|*.txt"; fd.Title = "Choose Password Book File..."; var fdResult = fd.ShowDialog(); if (fdResult == true) { PasswordBookFilePath = fd.FileName; } } [RelayCommand] public void Cracking() { if(ExcelFilePath.Length<1 || PasswordBookFilePath.Length<1) return; var passowrds = File.ReadAllLines(PasswordBookFilePath); //Application excelApp = new Application(); //Workbook workbook = null; bool cracked = false; Task.Run(() => { for (var index = 0; index < passowrds.Length; index++) { var pwd = passowrds[index]; ProgressValue = (double)index / passowrds.Length; ProgressText = $"{(ProgressValue * 100):F1} %"; try { Thread.Sleep(1000); if (index == passowrds.Length - 1) { ProgressText = $"Password: {pwd}"; cracked = true; } // workbook = excelApp.Workbooks.Open(ExcelFilePath, Password: pwd); // ProgressText = $"Password: {pwd}"; // cracked = true; // break; } catch (Exception) { cracked = false; } } }); if (cracked) { ProgressValue = 1; } else { ProgressValue = 1; ProgressText = "Excel File not cracked!"; } //workbook?.Close(); //excelApp.Quit(); } }
登录后方可回帖