Skip to content

Instantly share code, notes, and snippets.

@0x4E69676874466F78
Created May 20, 2014 12:49
Show Gist options
  • Save 0x4E69676874466F78/f37c22cbdfecc2510b1e to your computer and use it in GitHub Desktop.
Save 0x4E69676874466F78/f37c22cbdfecc2510b1e to your computer and use it in GitHub Desktop.
; ╔╦═════════════════════════════════╦╗
; ╟╪─ Набыдлокодено NightFox © 2014 ─╪╢
; ╚╩═════════════════════════════════╩╝
; добавить режим автоматического завершения DO.
; добавить больше проверок (права доступа)
; переписать функции удаления веток реестра и добавить проверки
; почистить код от мусора
; добавить ключ получения исходника из EXE
; добавить полоску прогресса
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <String.au3>
;#include <WinAPI.au3>
#include <WinAPIShPath.au3>
;#include <Debug.au3>
;#include <EditConstants.au3>
;#include <Constants.au3>
#include <WinAPIFiles.au3>
#include <WinAPIProc.au3>
_WinAPI_Wow64EnableWow64FsRedirection(False) ; чтобы получить не только SysWOW64, но и System32
;#RequireAdmin
Opt("GUIOnEventMode", 1)
;╔════════════════════════════════╗
OnAutoItExitRegister("ExitApp") ; ╬═─ ПРИ ОТЛАДКЕ ЗАКОМЕНТИРОВАТЬ!!!
;╚════════════════════════════════╝
Opt('TrayIconDebug', 1)
; Языки
If (@MUILang = 0419) _
Or (@OSLang = 0419) _
Then ; Русский
$tProcessed = "Обработано: "
$tDeleted = "Убрано мусора: "
$tClear = "Ничего не найдено."
$tStart = "Начать"
$tRepeat = "Повторить"
$tClear = "Ничего не найдено."
$tCleanupf = "Найдено файлов:"
$tCleanupr = "Найдено ключей:"
$tInform = "Сведения"
$tYouconfirm = "Вы уверены?"
$tStop = "Работа будет завершена преждевременно."
$tPause = " сейчас приостановлен."
$tContinue = "Нажмите OK чтобы продолжить."
$tComplete = "Завершено!"
$tQck = "Быстрый"
$tDpt = "Глубокий"
$tAlready = "Уже запущено."
$tError_delete = "Произошла ошибка при удалении"
$tError_read = "Произошла ошибка при чтении"
$tError_create = "Произошла ошибка при создании"
$tError = "Ошибка"
$tAppName = "чистильщик"
$tAppVer = " в"
$tCMD_help_auto = "запуск в режиме скрытой очистки (без GUI)."
$tCMD_help_com = "Все ключи могут применены через «-» (помимо «/») и сокращены до одной буквы" & _
@CRLF & @TAB & "(за исключением «/help» она в сокращённой форме «/?» или «-?»)."
$tCMD_help = "Справка:"
$tCMD_wrong = "Неверный ключ"
$tCMD_help_desc = "эта справка."
$tShowCon = "Показать консоль"
$tHideCon = "Скрыть консоль"
$tTryAdmin = "Попробуйте выполнить с правами администратора."
$tShutdown = "Аварийное завершение"
$tWrongSize = "Файл имеет неправильный размер, удаление может быть небезопасно. Проверьте и удалите вручную"
$tCMD_helpLegacy_desc = "также почистить данные касаемые старых систем."
$tCMD_helpDepth_desc = "запуск более глубокого поиска (найти остатки dopuslib)."
Else ; English
$tProcessed = 'Processed: '
$tDeleted = 'Removed trash: '
$tStart = 'Start'
$tRepeat = 'Repeat'
$tClear = 'Nothing has been found.'
$tCleanupf = 'Found files:'
$tCleanupr = 'Found keys:'
$tInform = 'Information'
$tYouconfirm = 'Are you sure?'
$tStop = 'Work will be terminated prematurely.'
$tPause = 'is now suspended.'
$tContinue = 'Click OK to continue.'
$tComplete = 'Completed!'
$tQck = 'Quick'
$tDpt = 'Depth'
$tAlready = 'Is already running.'
$tError_delete = 'An error occurred whilst deleting'
$tError_read = 'An error occurred when reading'
$tError_create = 'An error occurred when creating'
$tError = 'Error'
$tAppName = 'Cleaner'
$tAppVer = ' v'
$tCMD_help_auto = 'run into with unattended cleaning (without GUI).'
$tCMD_help_com = 'All keys can be use through "-" (other than "/") and reduced to a single letter' & _
@CRLF & @TAB & '(except "/ help" it in shortened form "/?" or "-?").'
$tCMD_help = 'Help:'
$tCMD_wrong = 'Wrong command'
$tCMD_help_desc = 'this help.'
$tShowCon = 'Show console'
$tHideCon = 'Hide console'
$tTryAdmin = 'Try running with administrator privileges.'
$tShutdown = 'Emergency shutdown'
$tWrongSize = 'The file has the wrong size, removal may be unsafe. Check and remove manually'
$tCMD_helpLegacy_desc = 'also clear the data of the old systems.'
$tCMD_helpDepth_desc = 'start the deepest search (find remnants dopuslib).'
EndIf
; Название и версия программы
$sAppNameOnly = "Directory Opus " & $tAppName
$sAppVer = "0.3"
$sAppName = $sAppNameOnly & $tAppVer & $sAppVer
$sDOpusPathInReg = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\DOpus.exe"
$sIcon = RegRead($sDOpusPathInReg, "")
;TraySetIcon($sIcon, 0)
; Определяем разрядность ОС для ключей реестра
$sOSARC = "64"
If @OSArch = "X86" Then
$sOSARC = ""
EndIf
$bOSARC = 1
If @OSArch = "X86" Then
$bOSARC = 0
EndIf
Global $bRunINCMD = 0
$sParentProcessID = _WinAPI_GetParentProcess()
$sParentProcessName = _WinAPI_GetProcessName($sParentProcessID)
If ($sParentProcessName = "cmd.exe") Then $bRunINCMD = 1
; Определяем режим работы
Global $bLegacy = 0
If (@OSBuild <= 3790) Then $bLegacy = 1
; Пути для очистки
Global Const $sProgramData = @AppDataCommonDir
Global Const $sAppData = @AppDataDir
Global Const $sDOpusDir = RegRead($sDOpusPathInReg, "Path")
Global Const $mDOpusFiles[4] = [ _
$sProgramData & "\sdpsenv.dat", _
$sProgramData & "\GPSoftware\Directory Opus\dopus.cert", _
$sAppData & "\GPSoftware\Directory Opus\dopus.dat", _
$sDOpusDir & "\dopus.dat" _
]
; для XP спец. режим. // первое число означает файл это или папка
Global Const $mDOpusFilesLegacy[5][2] = [ _
[0, @WindowsDir & "\xpcc*.log"], _
[0, @WindowsDir & "\System32\argtmp*.dll"], _
[0, @WindowsDir & "\SysWOW64\argtmp*.dll"], _
[1, @WindowsDir & "\System32\inf32"], _
[1, @WindowsDir & "\SysWOW64\inf32"] _
]
Global Const $mDOC_regs[5] = [ _
"HKCU\Control Panel\International\Time", _
"HKCU\Software\Microsoft\Metro\AppCompat", _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\DlgInfo", _
"HKCU\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Disallowed", _
"HKCU\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Handlers" _
]
Global Const $mDOC_regsLegacy[2] = [ _
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DesktopInterfaceMethod", _
"HKLM\SOFTWARE\GPSoftware\Directory Opus" _
]
; "HKLM\SOFTWARE\GPSoftware\Directory Opus\Config" _
Global Const $sDO_regs_ua = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist"
;Global Const $sDO_regs_cl = "HKCR" & $sOSARC & "\CLSID"
Global $dTotal = 0
Global $dTotal_deleted = 0
Global $bWork = 0
Global $mRegQuery[1]
Global $mRegQuery2[1]
Global $sPersmPathRAW = @ScriptDir & "\" & StringReplace(@ScriptName, ".exe", "") & ".regini"
Global $sPersmPath = StringReplace($sPersmPathRAW, "\\", "\")
Global $fPersm
Global $bDO_legacy = 0
; Подключаем если есть консолька
;http://www.autoitscript.com/forum/topic/63647-output-to-console/#entry486037
Global $hConsole
If Not _WinAPI_AttachConsole() Then
;DllCall("Kernel32.dll", "long", "AllocConsole")
EndIf
$hConsole = _WinAPI_GetStdHandle(1)
; Не даём запускаться копиям программы
If WinExists(@ScriptName) Then
_CMDWrite($tAlready)
_WinAPI_CloseHandle($hConsole)
Exit
EndIf
$sCMD_help_auto = "/hide /silent /unattended"
$sCMD_helpDepth = "/full /depth /advanced"
$sCMD_helpClose = "/close /kill /terminate /Shutdown"
$sCMD_helpLegacy = "/ForceLegacy"
$sCMD_help = "/help"
;Отладка
Func _M($x)
Return MsgBox(0, $sAppName & ": " & "Проверка", $x)
EndFunc;==>_M
; Ключи запуска // переписать
Global $mCMD_auto[12] = [ _
"-s", "/s", "/silent", "-silent", _
"-h", "/h", "/hide", "-hide", _
"-u", "/u", "/unattended", "-unattended" _
]
Global $mCMD_help[4] = [ _
"-?", "/?", "/help", "-help" _
]
Global $mCMD_adv[12] = [ _
"-f", "/f", "/full", "-full", _
"-d", "/d", "/depth", "-depth", _
"-a", "/a", "/advanced", "-advanced" _
]
Global $mCMD_close[16] = [ _ ; ещё не сделано
"-S", "/S", "/Shutdown", "-Shutdown", _
"-c", "/c", "/close", "-close", _
"-k", "/k", "/kill", "-kill", _
"-t", "/t", "/terminate", "-terminate" _
]
Global $mCMD_legacy[6] = [ _
"-F", "/F", "/ForceLegacy", "-ForceLegacy", "/L", "-L" _
]
Global $mCMD_all[0]
_ArrayConcatenate($mCMD_all, $mCMD_auto)
_ArrayConcatenate($mCMD_all, $mCMD_help)
_ArrayConcatenate($mCMD_all, $mCMD_adv)
_ArrayConcatenate($mCMD_all, $mCMD_legacy)
;_ArrayDisplay($mCMD_all)
$sCMD_title = @ScriptDir & "\" & @ScriptName
$sCMD_title = StringReplace($sCMD_title, "\\", "\")
$hCMD = WinGetHandle($sCMD_title)
If (WinGetTitle($hCMD) = $sCMD_title) Then
WinSetState($hCMD, "", @SW_MINIMIZE)
WinSetState($hCMD, "", @SW_HIDE)
EndIf
; Проверяем командную строку и если найдены ключевые слова включаем автоматический режим
$bDO_auto = 0
Global $sCMD = _WinAPI_CommandLineToArgv($CmdLineRaw)
Global $bAutoitAU3 = 0
Global $bAutoitDebug = 0
If Not ($sCMD[0] = 0) Then
If ($sCMD[1] = $sCMD_title) Then $bAutoitAU3 = 1 ; если запуск через autoit3
If ($sCMD[1] = "/ErrorStdOut") Then $bAutoitDebug = 1 ; пока так
EndIf
If ($sCMD[0] = $bAutoitAU3) Then
_CMD_help()
Else
Global $bCMD_wrong = 1
If ($sCMD[0] >= 1 + $bAutoitAU3) And ($bAutoitDebug = 0) Then
_DOC_ForKeys($mCMD_all, 1, "bCMD_wrong", 0)
If $bCMD_wrong = 1 Then
_CMDWrite(@CRLF & $tCMD_wrong & @CRLF)
_CMD_help(1)
Exit
EndIf
_DOC_ForKeys($mCMD_auto, 1, "bDO_auto", 1)
_DOC_ForKeys($mCMD_adv, 1, "bDO_auto", 2)
_DOC_ForKeys($mCMD_legacy, 1, "bDO_legacy", 1)
_DOC_ForKeys($mCMD_help, 0, "_CMD_help", "Exit")
; добавить обработку второго ряда команд
If ($sCMD[0] = 2 + $bAutoitAU3) Then _M($sCMD[2 + $bAutoitAU3])
EndIf
EndIf
Func _DOC_ForKeys($m, $b, $v, $e = "") ; переписать говнокодецо
For $i = 0 To UBound($m)-1
If $sCMD[1 + $bAutoitAU3] = $m[$i] Then
If $b = 1 Then
;$v = $e ; не работает :(
Assign($v, $e)
Else
Call($v)
If ($e = "Exit") Then Exit
EndIf
EndIf
Next
EndFunc;==>_DOC_ForKeys
Func _CMD_help($s = 0)
If ($s = 1) Then
_CMDWrite($tCMD_help)
Else
_CMDWrite($sAppName & @CRLF & $tCMD_help)
EndIf
_CMDWrite($sCMD_help_auto & " — " & $tCMD_help_auto)
_CMDWrite($sCMD_helpDepth & " — " & $tCMD_helpDepth_desc)
If ($bLegacy = 0) Then
_CMDWrite($sCMD_helpLegacy & " — " & $tCMD_helpLegacy_desc)
EndIf
_CMDWrite($sCMD_help & " — " & $tCMD_help_desc)
_CMDWrite("")
_CMDWrite($tCMD_help_com)
_CMDWrite("")
If ($bAutoitAU3 = 1) Then Send("{Enter}") ; Не нужно при сборке с ключом /console
EndFunc;==>_CMD_help
Func _CMDWrite($x)
_WinAPI_WriteConsole($hConsole, $x & @CRLF)
EndFunc;==>_CMDWrite
;FileInstall(@ScriptDir & "\DirectoryOpus.au3", @ScriptDir & "\DirectoryOpusCleanerSource.au3")
;Окошки информации и выхода
Func _INF($x)
Return MsgBox(64, $sAppName & ": " & $tInform, $x)
EndFunc;==>_INF
Func _QUE($x)
Return MsgBox(32 + 4, $sAppName & ": " & $tYouconfirm, $x)
EndFunc;==>_QUE
Func _DOC_ShowHide_Console()
If BitAND(WinGetState($hCMD), 2) = 0 Then
WinSetState($hCMD, "", @SW_SHOW)
WinSetState($hCMD, "", @SW_RESTORE)
GUICtrlSetData($hCon, $tHideCon)
Else
WinSetState($hCMD, "", @SW_MINIMIZE)
WinSetState($hCMD, "", @SW_HIDE)
GUICtrlSetData($hCon, $tShowCon)
EndIf
EndFunc
; Морда
If ($bDO_auto = 0) Then
Local $hGUI = GUICreate($sAppName, 500, 278, -1, -1, $WS_OVERLAPPEDWINDOW, $WS_EX_COMPOSITED)
GUISetOnEvent($GUI_EVENT_CLOSE, "_DOC_Exit")
GUISetIcon($sIcon, 5, $hGUI)
$hProcessed = GUICtrlCreateLabel($tProcessed & "0", 10, 10, 200, 16)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT + $GUI_DOCKTOP + $GUI_DOCKLEFT)
$hDeleted = GUICtrlCreateLabel($tDeleted & "0", 10, 240, 200, 16)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT)
$hLog = GUICtrlCreateEdit("", 10, 32, 480, 197, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY)
GUICtrlSetResizing(-1, $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKRIGHT)
$hOK = GUICtrlCreateButton($tStart, 406, 243, 85, 25, "0x0001")
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetOnEvent($hOK, "_DOC_Start")
$hAdv = GUICtrlCreateCombo($tQck, 256, 245, 150, 25, $CBS_DROPDOWNLIST)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetData(-1, $tDpt)
If Not $bRunINCMD Then
$hCon = GUICtrlCreateLabel($tShowCon, 10, 258, 200)
GUICtrlSetColor($hCon, 0xff)
GUICtrlSetOnEvent($hCon, "_DOC_ShowHide_Console")
GUICtrlSetResizing($hCon, $GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
EndIf
ControlDisable($hGUI, "", $hProcessed)
ControlDisable($hGUI, "", $hDeleted)
ControlDisable($hGUI, "", $hLog)
ControlFocus($hGUI, "", $hOK)
GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_GETMINMAXINFO, "MY_WM_GETMINMAXINFO")
Else
_DOC_Start()
EndIf
;http://www.autoitscript.com/forum/topic/43962-set-minimum-of-resizing/#entry328186
Func MY_WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
$minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
;DllStructSetData($minmaxinfo,7,330) ; min X
DllStructSetData($minmaxinfo, 7, 470) ; min X
DllStructSetData($minmaxinfo, 8, 250) ; min Y
;DllStructSetData($minmaxinfo,9,600) ; max X
;DllStructSetData($minmaxinfo,10,700) ; max Y
Return 0
EndFunc;==>MY_WM_GETMINMAXINFO
; Клавиши приостановки и выхода
Func _Pause()
_INF($sAppName & $tPause & @CRLF & $tContinue)
EndFunc;==>_Pause
Func _DOC_Key($x) ; иначе клавиши не будут доступны другим приложениям
If ($x = "ESC") Then
Send("{ESC}")
_DOC_Exit()
EndIf
If ($x = "ALTF4") Then
Send("!{F4}")
_DOC_Exit()
EndIf
EndFunc;==>_DOC_Key
If ($bDO_auto = 0) Then
HotKeySet("{Pause}", "_Pause")
HotKeySet("{ESC}", "_DOC_Key('ESC')")
HotKeySet("!{F4}", "_DOC_Key('ALTF4')")
EndIf
Func _DOC_Exit()
If ($bDO_auto = 0) Then
If WinActive($hGUI) Then
If $bWork = 1 Then
If _QUE($tStop) = 6 Then
Exit
EndIf
Else
Exit
EndIf
EndIf
EndIf
EndFunc;==>_DOC_Exit
Func _DOC_Output($x, $y = 0) ; Вывод событий в список
If ($bDO_auto = 0) Then
If $x = "#cls" Then
ControlSetText($hGUI, "", $hLog, "")
Else
$sPrevious = ControlGetText($hGUI, "", $hLog)
ControlSetText($hGUI, "", $hLog, $sPrevious & $x & @CRLF)
_GUICtrlEdit_LineScroll($hLog, 0, 10000)
_CMDWrite($x)
EndIf
Else
If Not ($x = "#cls") Then _CMDWrite($x & @CRLF)
EndIf
EndFunc;==>_DOC_Output
While 1
Sleep(100)
WEnd
Func _DOC_UpdateStatus($x = 0) ; обновить число найденых ключей
If ($bDO_auto = 0) Then
GUICtrlSetData($hProcessed, $tProcessed & $dTotal)
If ($x = 1) Then
GUICtrlSetData($hDeleted, $tDeleted & $dTotal_deleted)
EndIf
EndIf
EndFunc;==>_DOC_UpdateStatus
; Запуск
Func _DOC_Start()
_CMDWrite(@CRLF & $sAppName)
_CMDWrite(@CRLF & _StringRepeat("*", 80))
$bWork = 1
$dTotal = 0
$dTotal_deleted = 0
ReDim $mRegQuery[1], $mRegQuery2[1]
$mRegQuery[0] = 0
$mRegQuery2[0] = 0
_DOC_UpdateStatus(1)
If ($bDO_auto = 0) Then
ControlEnable($hGUI, "", $hProcessed)
ControlEnable($hGUI, "", $hDeleted)
ControlEnable($hGUI, "", $hLog)
ControlDisable($hGUI, "", $hOK)
EndIf
_DOC_Output("#cls")
If ($bDO_auto = 0) Then
If (GUICtrlRead($hAdv) = $tQck) Then _DOC_Quick()
If (GUICtrlRead($hAdv) = $tDpt) Then _DOC_Advance()
Else
If ($bDO_auto = 1) Then _DOC_Quick()
If ($bDO_auto = 2) Then _DOC_Advance()
EndIf
If Not ($mRegQuery2[0] = 0) Then
For $i = 1 To $mRegQuery2[0]
_RegDelete($mRegQuery2[$i])
Next
EndIf
;If Not ($mRegQuery2[0] = 0) Then _RegDelete($mRegQuery2)
If FileExists($sPersmPath) Then FileClose($fPersm)
_DOC_UpdateStatus(1)
If ($bDO_auto = 0) Then
ControlEnable($hGUI, "", $hOK)
ControlSetText($hGUI, "", $hOK, $tRepeat)
EndIf
$bWork = 0
_DOC_Output($tComplete)
If ($bDO_auto >= 1) Then Exit
EndFunc;==>_DOC_Start
Func _DOC_Quick()
_DOC_Output($tCleanupf)
_DOC_FileClear()
If $dTotal_deleted = 0 Then _DOC_Output(@TAB & $tClear)
_DOC_Output(@CR)
_DOC_Output($tCleanupr)
_DOC_RegClear()
;_DOC_RegDate()
If $dTotal_deleted = 0 Then _DOC_Output(@TAB & $tClear)
_DOC_Output(@CR)
EndFunc;==>_DOC_Quick
Func _DOC_Advance()
_DOC_Quick()
_DOC_AdvancedScan("HKCU")
_DOC_AdvancedScan("HKLM")
EndFunc;==>_DOC_Advance
Func _DOC_FileClear() ; Уничтожаем мусорные файлы
For $i = 0 To UBound($mDOpusFiles)-1
$dTotal += $mDOpusFiles[0]
If FileExists($mDOpusFiles[$i]) Then
FileSetAttrib($mDOpusFiles[$i], "-RS")
Local $fDelete = FileDelete($mDOpusFiles[$i])
If Not $fDelete Then
MsgBox(48, $sAppName, $tError_delete & ": " & $mDOpusFiles[$i] & @CRLF & @CRLF & $tTryAdmin)
Else
_DOC_Output(@TAB & $mDOpusFiles[$i])
$dTotal_deleted += 1
_DOC_UpdateStatus(1)
EndIf
EndIf
Next
EndFunc;==>_DOC_FileClear
Func _DOC_FileClearLegacy() ; для XP/2003 посложнее
For $i = 0 To UBound($mDOpusFilesLegacy, 1)-1
Local $sObject = $mDOpusFilesLegacy[$i][1]
If $mDOpusFilesLegacy[$i][0] Then ; папка
If _FolderExists($sObject) Then
FileSetAttrib($sObject, "-RS")
Local $fDelete = DirRemove($sObject, 1)
If Not $fDelete Then
MsgBox(48, $sAppName, $tError_delete & ": " & $sObject & @CRLF & @CRLF & $tTryAdmin)
EndIf
EndIf
Else ; файлы
$hSearchTrashFiles = FileFindFirstFile($sObject)
If Not ($hSearchTrashFiles = -1) Then
Local $sFileName = FileFindNextFile($hSearchTrashFiles)
If FileGetSize($sObject) = 80 Then
Local $fDelete = FileDelete($sObject)
If Not $fDelete Then
MsgBox(48, $sAppName, $tError_delete & ": " & $sFileName & @CRLF & @CRLF & $tTryAdmin)
Else
_DOC_Output(@TAB & $mDOpusFilesLegacy[$i])
$dTotal_deleted += 1
_DOC_UpdateStatus(1)
EndIf
Else
MsgBox(48, $sAppName, $tWrongSize & ": " & $sFileName)
EndIf
FileClose($hSearchTrashFiles)
EndIf
EndIf
Next
EndFunc;==>_DOC_FileClearLegacy
Func _RegDelete($x)
If $bOSARC = 1 Then
RunWait("REG DELETE " & '"' & $x & '"' & " /f /reg:64", "", @SW_SHOW)
;RegDelete( $x, "")
Else
RunWait("REG DELETE " & '"' & $x & '"' & " /f", "", @SW_SHOW)
EndIf
$dTotal_deleted += 1
_DOC_UpdateStatus(1)
EndFunc;==>_RegDelete
#CS ; доперереботать // узнать максимальную длину комстроки и разбить по ней; а вообще переделать под RegDelete
Func _RegDelete($x)
Global $sDOC_RegQuery3 = "echo"
$sDOC_Reg1 = "REG DELETE " & '"'
If $bOSARC = 1 Then
$sDOC_Reg2 = " /f /reg:64"
Else
$sDOC_Reg2 = " /f"
EndIf
For $i = 1 To $mRegQuery2[0]
;$sDOC_RegQuery3_temp = $sDOC_Reg1 & $mRegQuery2[$i] & $sDOC_Reg2
;If Not ($i = 1) Then
;$sDOC_RegQuery3_temp = "|" & $sDOC_RegQuery3_temp
;EndIf
$sDOC_RegQuery3_temp = "|" & $sDOC_Reg1 & $mRegQuery2[$i] & $sDOC_Reg2
$sDOC_RegQuery3 = _StringInsert($sDOC_RegQuery3, $sDOC_RegQuery3_temp, 4)
Next
;_M($sDOC_RegQuery3)
$sDOC_RegQuery3 = StringReplace($sDOC_RegQuery3, "echo", "")
RunWait(@ComSpec & " /c " & $sDOC_RegQuery3, "", @SW_SHOW)
;RunWait($sDOC_RegQuery3, "", @SW_SHOW)
$dTotal_deleted += 1
_DOC_UpdateStatus(1)
EndFunc;==>_RegDelete
#CE
Func _RegPersmWrite($x) ; пишем файл для изменения прав нужных разделов реестра
; Костыль для XP
$x = StringReplace($x, "HKCU", "HKEY_CURRENT_USER")
$x = StringReplace($x, "HKLM", "HKEY_LOCAL_MACHINE")
If Not FileExists($sPersmPath) Then
Global $fPersm = FileOpen($sPersmPath, $FO_APPEND)
If $fPersm = -1 Then
MsgBox(16, $sAppName, $tError_create & ": " & $sPersmPath & @CRLF & @CRLF & $tTryAdmin & @CRLF & $tShutdown)
Exit
EndIf
EndIf
FileWrite($fPersm, $x & " [1 5 7 11 14 17 21]" & @CRLF)
EndFunc;==>_RegPersmWrite
; собираем список ключей на удаление // сделать общую функцию
Func _DOC_RegQuery($x)
; по мотивам http://autoit-script.ru/index.php?topic=7258.msg84703#msg84703
$mRegQuery[0] += 1 ; обновляем число ключей в массиве
ReDim $mRegQuery[UBound($mRegQuery) + 1] ; меняем размер массива на 1
$mRegQuery[UBound($mRegQuery) - 1] = $x ; записываем число в новую ячейку
EndFunc;==>_DOC_RegQuery
Func _DOC_RegQuery2($x)
$mRegQuery2[0] += 1 ; обновляем число ключей в массиве
ReDim $mRegQuery2[UBound($mRegQuery2) + 1] ; меняем размер массива на 1
$mRegQuery2[UBound($mRegQuery2) - 1] = $x ; записываем число в новую ячейку
EndFunc;==>_DOC_RegQuery2
Func _DOC_RegClear() ; Уничтожаем мусорные записи реестра
; Чистим файл прав доступа
If FileExists($sPersmPath) Then FileDelete($sPersmPath)
; Вычищаем общий мусор
For $i = 0 To UBound($mDOC_regs)-1
$dTotal += $mDOC_regs[0]
RegRead($mDOC_regs[$i], "")
If Not (@error = 1) Then
_RegPersmWrite($mDOC_regs[$i])
_DOC_RegQuery2($mDOC_regs[$i])
_DOC_Output(@TAB & $mDOC_regs[$i])
$dTotal_deleted += 1
_DOC_UpdateStatus()
EndIf
Next
; С UserAssist будем более осторожны
$sSearchKey = $sDO_regs_ua
$sSearchString = "*"
Local $mResults = _RegSearch($sSearchKey, $sSearchString, 7, 1, 1)
For $i = 1 To $mResults[0]
$dRegPos = StringInStr($mResults[$i], "\", 0, -2)
$sRegKey = StringMid($mResults[$i], $dRegPos + 1)
If Not (StringLen($sRegKey) = 39) Then ; находим инородный раздел
$dRegPos = StringInStr($mResults[$i], "\", 0, -1)
$sRegKey = StringLeft($mResults[$i], $dRegPos - 1)
_RegPersmWrite($sRegKey)
_DOC_RegQuery2($sRegKey)
;ConsoleWrite($mResults[$i] & @CRLF)
_DOC_Output(@TAB & $mResults[$i])
$dTotal_deleted += 1
_DOC_UpdateStatus()
EndIf
Next
; Уничтожаем записи dopuslib
; Собираем ключики
$mRegGetKeys = _RegSearch("HKCU\Control Panel\International\Time", "*", 7, 1, 1)
If ($mRegGetKeys[0] = 0) Then $mRegGetKeys = _RegSearch("HKCU\Software\Microsoft\Metro\AppCompat", "*", 7, 1, 1)
If ($mRegGetKeys[0] = 0) Then $mRegGetKeys = _RegSearch("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\DlgInfo", "*", 7, 1, 1)
If ($mRegGetKeys[0] = 0) Then $mRegGetKeys = _RegSearch("HKCU\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Disallowed", "*", 7, 1, 1)
If ($mRegGetKeys[0] = 0) Then $mRegGetKeys = _RegSearch("HKCU\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Handlers", "*", 7, 1, 1)
For $i = 1 To $mRegGetKeys[0]
$dRegPos = StringInStr($mRegGetKeys[$i], " = ")
$sRegKey = StringLeft($mRegGetKeys[$i], $dRegPos - 1)
;$dRegPos = StringInStr($sRegKey, "\", 0, 4)
$dRegPos = StringInStr($sRegKey, "{", 0, 1)
;$sRegKey = StringMid($sRegKey, $dRegPos+1)
$sRegKey = StringMid($sRegKey, $dRegPos)
If Not ($sRegKey = "") Then
;ConsoleWrite($sRegKey & @CRLF)
_DOC_RegQuery($sRegKey)
EndIf
Next
; Вычищаем их
;_DOC_Reg_delete("HKCR", "CLSID", $mRegQuery, $bOSARC)
_DOC_Reg_delete("HKCU", "SOFTWARE\Classes\CLSID", $mRegQuery, $bOSARC)
_DOC_Reg_delete("HKLM", "SOFTWARE\Classes\CLSID", $mRegQuery, $bOSARC)
If ($bLegacy = 1) OR ($bDO_legacy = 1) Then
_DOC_RegClearLegacy()
EndIf
If FileExists($sPersmPath) Then RunWait("regini " & '"' & $sPersmPathRAW & '"', "", @SW_HIDE)
EndFunc;==>_DOC_RegClear
Func _DOC_RegClearLegacy()
For $i = 0 To UBound($mDOC_regsLegacy)-1
$dTotal += $mDOC_regsLegacy[0]
RegRead($mDOC_regsLegacy[$i], "")
If Not (@error = 1) Then
_RegPersmWrite($mDOC_regsLegacy[$i])
_DOC_RegQuery2($mDOC_regsLegacy[$i])
$dTotal_deleted += 1
_DOC_Output(@TAB & $mDOC_regsLegacy[$i])
_DOC_UpdateStatus()
Local $mResults = _RegSearch($mDOC_regsLegacy[$i], "*", 1, 1, 0, 1)
;_ArrayDisplay($mResults)
If $mResults[0] Then
For $i = 0 To UBound($mResults)-1
_RegPersmWrite($mResults[$i])
_DOC_RegQuery2($mResults[$i])
$dTotal_deleted += 1
_DOC_Output(@TAB & $mResults[$i])
_DOC_UpdateStatus()
Next
EndIf
EndIf
Next
EndFunc;==>_DOC_RegClearLegacy
Func _DOC_AdvancedScan($x)
$sSearchKey = $x & $sOSARC & "\Software\Classes\CLSID"
$sSearchString = "dopuslib"
Local $mResults = _RegSearch($sSearchKey, $sSearchString, 7, 1)
For $i = 1 To $mResults[0]
$dRegPos = StringInStr($mResults[$i], " = ")
$sRegKey = StringLeft($mResults[$i], $dRegPos - 1)
If Not (StringInStr($sRegKey, "InprocServer32") = 0) Then ; небольшая перестраховка
$dRegPos = StringInStr($sRegKey, "\", 0, -2)
$sRegKey = StringLeft($sRegKey, $dRegPos - 1)
;_M($sRegKey)
$sRegKeyFix = StringReplace($sRegKey, "HKCU64", "HKCU")
$sRegKeyFix = StringReplace($sRegKeyFix, "HKLM64", "HKLM")
;_M($sRegKeyFix)
_RegPersmWrite($sRegKeyFix)
_DOC_RegQuery2($sRegKeyFix)
;ConsoleWrite($sRegKey & @CRLF)
_DOC_Output(@TAB & $sRegKey)
$dTotal_deleted += 1
_DOC_UpdateStatus(1)
EndIf
Next
EndFunc;==>_DOC_AdvancedScan
; http://www.autoitscript.com/forum/topic/9588-searchreg-example/#entry811325
; Немного изменённое
;*****************************************************
; Function: _RegSearch
;
; Purpose: Performs a recursive search of the registry starting at $sStartKey, looking for $sSearchVal
;
; Syntax: _RegSearch($sStartKey, $sSearchVal, $iType = 0x07, $fArray = False, $norecurce = False, $nocount = False)
;
; Where: $sStartKey = Reg path at which to begin search
; $sSearchVal = The string to search for, or RegExp pattern to use if $iType bit 3 is set
; $iType = Matching types to return:
; 1 = Key names
; 2 = Value names
; 4 = Value data
; 8 = $sSearchVal is a RegExp pattern (default is StringInStr)
; Add bits together for multiple match types, default is 7 (all types, StringInStr matching)
; $fArray = Return an array of results vice the string ([0] = count)
;
; Return value: On success, returns a string containing a @LF delimited list of matching key names and values:
; Where a key name matches, it is listed as a reg path with trailing backslash:
; i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\
; Where a value name matches, it is listed as a reg path without trailing backslash:
; i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WallPaperDir
; Where the data matches, the format is path = data:
; i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WallPaperDir = %SystemRoot%\Web\Wallpaper
; On failure, returns 0 and sets @error.
;
; Notes: No matches is not an error, returns "" or an array with [0] = 0 depending on $fArray
; Default StringInStr() matches are not case sensitive.
;*****************************************************
; Change Log:
; v1.0.0.0 | 03/17/05 | Original SearchReg() by Holger
; v2.0.0.0 | 08/10/06 | Native AutoIt version by PsaltyDS
; v2.0.0.1 | 08/16/06 | Fixed bug reported by markloman
; v2.0.1.0 | 07/30/08 | Added $iType and $fArray parameters
; v2.0.2.0 | 11/12/08 | Fixed bug returning array [0] = 1 vice 0 for none found
; v2.0.3.0 | 06/22/10 | Fixed bug appending some result strings together reported by squid808
; v2.1.0.0 | 06/23/10 | Added $iType option for RegExp patterns, and pseudo wildcard "*"
; v2.1.0.1 | 01.05.14 | Добавлен параметр отключения рекурсии.
; v2.1.0.2 | 20.05.14 | Добавлен параметр отключения количества в массиве.
;*****************************************************
Func _RegSearch($sStartKey, $sSearchVal, $iType = 0x07, $fArray = False, $norecurce = False, $nocount = False)
Local $v, $sVal, $k, $sKey, $sFound = "", $sFoundSub = "", $avFound[1] = [0]
; Trim trailing backslash, if present
If StringRight($sStartKey, 1) = "\" Then $sStartKey = StringTrimRight($sStartKey, 1)
; Generate type flags
If Not BitAND($iType, 0x07) Then Return SetError(1, 0, 0); No returns selected
Local $fKeys = BitAND($iType, 0x1), $fValue = BitAND($iType, 0x2), $fData = BitAND($iType, 0x4), $fRegExp = BitAND($iType, 0x8)
; Check for wildcard
If (Not $fRegExp) And ($sSearchVal == "*") Then
; Use RegExp pattern "." to match anything
$iType += 0x8
$fRegExp = 0x8
$sSearchVal = "."
EndIf
; This checks values and data in the current key
If ($fValue Or $fData) Then
$v = 1
While 1
$sVal = RegEnumVal($sStartKey, $v)
If @error = 0 Then
; Valid value - test its name
If $fValue Then
If $fRegExp Then
If StringRegExp($sVal, $sSearchVal, 0) Then $sFound &= $sStartKey & "\" & $sVal & @LF
Else
If StringInStr($sVal, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sVal & @LF
EndIf
EndIf
; test its data
If $fData Then
$readval = RegRead($sStartKey, $sVal)
If $fRegExp Then
If StringRegExp($readval, $sSearchVal, 0) Then $sFound &= $sStartKey & "\" & $sVal & " = " & $readval & @LF
Else
If StringInStr($readval, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sVal & " = " & $readval & @LF
EndIf
EndIf
$v += 1
$dTotal += $v
Else
; No more values here
ExitLoop
EndIf
WEnd
EndIf
; This loop checks subkeys
$k = 1
While 1
$sKey = RegEnumKey($sStartKey, $k)
If @error = 0 Then
; Valid key - test it's name
If $fKeys Then
If $fRegExp Then
If StringRegExp($sKey, $sSearchVal, 0) Then $sFound &= $sStartKey & "\" & $sKey & "\" & @LF
Else
If StringInStr($sKey, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sKey & "\" & @LF
EndIf
EndIf
; Now search it
If ($norecurce = False) Then
$sFoundSub = _RegSearch($sStartKey & "\" & $sKey, $sSearchVal, $iType, False) ; use string mode to test sub keys
EndIf
If $sFoundSub <> "" Then $sFound &= $sFoundSub & @LF
$dTotal += 1
Else
; No more keys here
ExitLoop
EndIf
$k += 1
WEnd
; Return results
If StringRight($sFound, 1) = @LF Then $sFound = StringTrimRight($sFound, 1)
If $fArray Then
If StringStripWS($sFound, 8) <> "" Then
If $nocount Then
$avFound = StringSplit($sFound, @LF, 2)
Else
$avFound = StringSplit($sFound, @LF)
EndIf
EndIf
Return $avFound
Else
Return $sFound
EndIf
EndFunc;==>_RegSearch
; по мотивам http://autoit-script.ru/index.php?topic=822.msg5819#msg5819
Func _DOC_Reg_delete($sRegRoot, $sRegSection, $sRegKeys, $bReg64 = 0, $dDataSize = 1024)
Local $Ret, $tData, $pData, $hKey, $Count = 0
Const $HKEY_CLASSES_ROOT = 0x80000000
Const $HKEY_CURRENT_USER = 0x80000001
Const $HKEY_LOCAL_MACHINE = 0x80000002
Const $HKEY_USERS = 0x80000003
Const $HKEY_PERFORMANCE_DATA = 0x80000004
Const $HKEY_CURRENT_CONFIG = 0x80000005
Const $HKEY_DYN_DATA = 0x80000006
Const $KEY_WOW64_64KEY = 0x0100
Const $KEY_WOW64_32KEY = 0x0200
Const $KEY_WOW64_RES = 0x0300
Const $KEY_QUERY_VALUE = 0x0001
Const $KEY_READ = 0x20019
Const $KEY_WRITE = 0x20006
Const $KEY_CREATE_LINK = 0x0020
Const $KEY_ALL_ACCESS = 0xF003F
Const $REG_OPTION_NON_VOLATILE = 0x00000000
$sRegRootText = $sRegRoot
Select
Case $sRegRoot = "HKEY_CLASSES_ROOT" Or $sRegRoot = "HKCR"
$dRegRoot = $HKEY_CLASSES_ROOT
Case $sRegRoot = "HKEY_CURRENT_USER" Or $sRegRoot = "HKCU"
$dRegRoot = $HKEY_CURRENT_USER
Case $sRegRoot = "HKEY_LOCAL_MACHINE" Or $sRegRoot = "HKLM"
$dRegRoot = $HKEY_LOCAL_MACHINE
Case $sRegRoot = "HKEY_USERS" Or $sRegRoot = "HKU"
$dRegRoot = $HKEY_USERS
EndSelect
If $bReg64 = 1 Then
$regArch = $KEY_ALL_ACCESS + $KEY_WOW64_64KEY
Else
$regArch = $KEY_ALL_ACCESS
EndIf
$Ret = DllCall('advapi32.dll', 'long', 'RegOpenKeyExW', 'ulong_ptr', $dRegRoot, 'wstr', $sRegSection, 'dword', 0, 'dword', $regArch, 'ulong_ptr*', 0)
If (@error) Or ($Ret[0]) Then
Return SetError(1, 0, 0)
EndIf
$hKey = $Ret[5]
;$dDataSize = 1024 ; 256
$tData = DllStructCreate('wchar[' & $dDataSize & ']')
$pData = DllStructGetPtr($tData)
While 1
$Ret = DllCall('advapi32.dll', 'long', 'RegEnumKeyW', 'ulong_ptr', $hKey, 'dword', $Count, 'ptr', $pData, 'dword', $dDataSize)
;$Ret = DllCall('advapi32.dll', 'long', 'RegEnumKeyExW', 'ulong_ptr', $hKey, 'dword', $Count, 'ptr', $pData, 'dword*', $dDataSize, 'dword', 0, 'ptr', 0, 'ptr', 0, 'ptr', 0)
If (@error) Or ($Ret[0]) Then
ExitLoop
EndIf
For $i = 1 To $sRegKeys[0]
If DllStructGetData($tData, 1) = $sRegKeys[$i] Then
$sRegKey_Name = DllStructGetData($tData, 1)
;$sRegKeyPre = $sRegRootText & $sOSARC & "\" & $sRegSection & "\" & $sRegKey_Name
$sRegKeyPre = $sRegRootText & "\" & $sRegSection & "\" & $sRegKey_Name
;If $sRegRootText = "HKEY_CLASSES_ROOT" OR $sRegRootText = "HKCR" Then
; $sRegKeyPrePersm = "HKCU\Software\Classes" & "\" & $sRegSection & "\" & $sRegKey_Name
;Else
; $sRegKeyPrePersm = $sRegRootText & "\" & $sRegSection & "\" & $sRegKey_Name
;EndIf
$sRegKeyFull = $sRegKeyPre & "\InprocServer32"
$sRegKeyFull = RegRead($sRegKeyFull, "")
If Not (StringInStr($sRegKeyFull, "dopuslib") = 0) Then ; небольшая перестраховка
;DllCall('advapi32.dll', 'long', 'RegDeleteKeyW', 'ulong_ptr', $hKey, 'wstr', DllStructGetData($tData, 1))
_RegPersmWrite($sRegKeyPre)
_DOC_RegQuery2($sRegKeyPre)
;ConsoleWrite($sRegKeyPre & @CRLF)
_DOC_Output(@TAB & $sRegKeyPre)
;ConsoleWrite($sRegKeyFull & @CRLF)
;_DOC_Output(@TAB & $sRegKeyFull)
$dTotal_deleted += 1
_DOC_UpdateStatus()
EndIf
EndIf
Next
$Count += 1
WEnd
DllCall('advapi32.dll', 'long', 'RegCloseKey', 'ulong_ptr', $hKey)
$tData = 0
EndFunc;==>_DOC_Reg_delete
Func ExitApp()
_WinAPI_CloseHandle($hConsole)
If FileExists($sPersmPath) Then
FileClose($fPersm)
FileDelete($sPersmPath)
EndIf
EndFunc;==>ExitApp
;http://autoit-script.ru/index.php?topic=5153.msg46190#msg46190
Func _FolderExists($folder)
$fso = ObjCreate("Scripting.Filesystemobject") ; Подключаем объект файловой системы
If $fso.folderexists($folder) = True Then ; если аргумент-папка
Return True ; вернуть: "истина"
Else ; иначе
Return False ; вернуть "ложь"
Endif
EndFunc;==>_FolderExists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment