Office中国论坛/Access中国论坛

标题: 【练习】工作表密码破解 [打印本页]

作者: faunus    时间: 2014-2-25 12:19
标题: 【练习】工作表密码破解
本帖最后由 faunus 于 2014-2-26 11:02 编辑

【工作表密码破解】

以下代码粘在RIBBON中按钮的事件里
  1. //工作表密码破解

  2. //app
  3. Excel.Application app;
  4. app = Globals.ThisAddIn.Application;//在RIBBON中,只能这样调用。

  5. //book|sh
  6. Excel.Workbook book = app.ActiveWorkbook;
  7. Excel.Worksheet sh = book.ActiveSheet;

  8. //开始撸
  9. sh.Protect(
  10.     DrawingObjects: Office.MsoTriState.msoTrue,
  11.     Contents: Office.MsoTriState.msoTrue,
  12.     Scenarios: Office.MsoTriState.msoTrue,
  13.     AllowFiltering: Office.MsoTriState.msoTrue,
  14.     AllowUsingPivotTables: Office.MsoTriState.msoTrue);

  15. sh.Protect(
  16.     DrawingObjects: Office.MsoTriState.msoTrue,
  17.     Contents: Office.MsoTriState.msoTrue, Scenarios:
  18.     Office.MsoTriState.msoTrue,
  19.     AllowFiltering: Office.MsoTriState.msoTrue,
  20.     AllowUsingPivotTables: Office.MsoTriState.msoTrue);

  21. sh.Protect(
  22.     DrawingObjects: Office.MsoTriState.msoTrue,
  23.     Contents: Office.MsoTriState.msoTrue,
  24.     Scenarios: Office.MsoTriState.msoTrue,
  25.     AllowFiltering: Office.MsoTriState.msoTrue,
  26.     AllowUsingPivotTables: Office.MsoTriState.msoTrue);

  27. sh.Protect(
  28.     DrawingObjects: Office.MsoTriState.msoTrue,
  29.     Contents: Office.MsoTriState.msoTrue,
  30.     Scenarios: Office.MsoTriState.msoTrue,
  31.     AllowFiltering: Office.MsoTriState.msoTrue,
  32.     AllowUsingPivotTables: Office.MsoTriState.msoTrue);

  33. sh.Unprotect();
复制代码

还需要加上引用:
  1. //
  2. using Excel = Microsoft.Office.Interop.Excel;
  3. using Office = Microsoft.Office.Core;
复制代码




作者: 寒雨772    时间: 2014-2-25 12:30
开始
作者: microfaint    时间: 2014-2-25 13:45
标记一下,回家撸。
作者: 醉酒狂生    时间: 2014-2-25 14:25
您瞧好了,开撸
作者: 闻启学    时间: 2014-2-25 14:25
继续学习 加油
作者: tianping    时间: 2014-2-25 17:41
本帖最后由 tianping 于 2014-2-25 17:50 编辑

报告老师,撸完。不够完善,需要再对保护状态有更明确的显示。
[attach]53174[/attach]
[attach]53175[/attach]

作者: /kuk心如止水    时间: 2014-2-26 14:46
Sub RemoveShProtect()
      Dim i1 As Integer, i2 As Integer, i3 As Integer
      Dim i4 As Integer, i5 As Integer, i6 As Integer
      Dim i7 As Integer, i8 As Integer, i9 As Integer
      Dim i10 As Integer, i11 As Integer, i12 As Integer
      On Error Resume Next
      If ActiveSheet.ProtectContents = False Then
          MsgBox "该工作表没有保护密码!"
          Exit Sub
      End If
      For i1 = 65 To 66: For i2 = 65 To 66: For i3 = 65 To 66
      For i4 = 65 To 66: For i5 = 65 To 66: For i6 = 65 To 66
      For i7 = 65 To 66: For i8 = 65 To 66: For i9 = 65 To 66
      For i10 = 65 To 66: For i11 = 65 To 66: For i12 = 32 To 126
          ActiveSheet.Unprotect Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) _
          & Chr(i6) & Chr(i7) & Chr(i8) & Chr(i9) & Chr(i10) & Chr(i11) & Chr(i12)
          If ActiveSheet.ProtectContents = False Then
              MsgBox "已经解除了工作表保护!"
              Exit Sub
          End If
      Next: Next: Next: Next: Next: Next
      Next: Next: Next: Next: Next: Next
  End Sub

Sub RemoveBkProtect()
      Dim i1 As Integer, i2 As Integer, i3 As Integer
      Dim i4 As Integer, i5 As Integer, i6 As Integer
      Dim i7 As Integer, i8 As Integer, i9 As Integer
      Dim i10 As Integer, i11 As Integer, i12 As Integer
      On Error Resume Next
      If ActiveWorkbook.ProtectStructure = False And ActiveWorkbook.ProtectWindows = False Then
          MsgBox "该工作簿没有保护密码!"
         
          Exit Sub
      End If
      For i1 = 65 To 66: For i2 = 65 To 66: For i3 = 65 To 66
      For i4 = 65 To 66: For i5 = 65 To 66: For i6 = 65 To 66
      For i7 = 65 To 66: For i8 = 65 To 66: For i9 = 65 To 66
      For i10 = 65 To 66: For i11 = 65 To 66: For i12 = 32 To 126
          ActiveWorkbook.Unprotect Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) _
          & Chr(i6) & Chr(i7) & Chr(i8) & Chr(i9) & Chr(i10) & Chr(i11) & Chr(i12)
          If ActiveWorkbook.ProtectStructure = False And ActiveWorkbook.ProtectWindows = False Then
              MsgBox "已经解除了工作簿保护!"
              Exit Sub
          End If
      Next: Next: Next: Next: Next: Next
      Next: Next: Next: Next: Next: Next
  End Sub
作者: /kuk心如止水    时间: 2014-2-26 14:47
看看这个能用不
作者: 伊邪那美    时间: 2014-2-27 10:36
可以,这个代码可以得到密码。不过多个密文密匙相通,不一定是原始密匙
作者: 刘苏    时间: 2014-3-11 20:25
真厉害~~  秒杀
作者: yjjcm    时间: 2014-3-26 20:56
没试过,运行一下实施




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3