无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 2660|回复: 5
打印 上一主题 下一主题

自制的关闭SFC的小工具

[复制链接]
跳转到指定楼层
1#
发表于 2011-10-4 09:50:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
自制的关闭SFC的小工具
用Delphi编译的
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon 右侧窗格中的SFCDisable值,其设置为0,即重新启动后不扫描受保护的文件。
这种方法不行!!! 不知道哪个家伙乱宣传的。
通过注册表修改键值不能达到目的

找资料顺便就找到了一个挺不错的Delphi的源代码,使用了之后还真有效,编译好了给大家分享(由于涉及一些内核级的操作,杀软可能报毒,请允许)

在Vista和7下请用管理员模式运行





下载地址:
关闭SFC.rar (157.58 KB, 下载次数: 515)

源码:
Unit1.pas:

  1. unit Unit1;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, Unit3, Unit2;
  6. type
  7.   TForm1 = class(TForm)
  8.     Button1: TButton;
  9.     Label2: TLabel;
  10.     Label1: TLabel;
  11.     procedure Button1Click(Sender: TObject);
  12.   private
  13.     { Private declarations }
  14.   public
  15.     { Public declarations }
  16. end;
  17. var
  18.   Form1: TForm1;
  19. implementation

  20. {$R *.dfm}
  21. procedure TForm1.Button1Click(Sender: TObject);
  22. begin
  23.    CloseSFC();
  24.    Application.MessageBox( '关闭SFC成功!感谢您的使用!', '关闭SFC');
  25. end;

  26. end.
复制代码
Unit2.pas:
  1. unit Unit2;
  2. interface
  3. uses
  4. Windows, SysUtils, Unit3;
  5. Function CloseSFC():Integer;
  6. implementation
  7. procedure Root(VOID : Pointer); stdcall; forward;
  8. procedure EndRoot(); forward;
  9. function FixedPChar(const Value : PChar) : PChar;forward;
  10. type
  11. TLoadLibraryA = function(lpLibFileName : PAnsiChar) : HMODULE; stdcall;
  12. TGetProcAddress = function(hModule : HMODULE; lpProcName : LPCSTR) : FARPROC; stdcall;
  13. type
  14. TFuncs = record
  15.     LoadLibraryA : TLoadLibraryA;
  16.     GetProcAddress : TGetProcAddress;
  17. end;
  18. function Init() : TFuncs; forward;
  19. //远线程代码开始处
  20. procedure Root(VOID : Pointer); stdcall;
  21. var
  22. Funcs                                 : TFuncs;
  23. hSFC                                  : Cardinal;
  24. __closeSFC                            : procedure(); stdcall;
  25. begin
  26. Funcs := Init();
  27. hSFC := Funcs.LoadLibraryA(FixedPChar('sfc.dll'));
  28. @__closeSFC := Funcs.GetProcAddress(hSFC, PChar($2));
  29. __closeSFC();
  30. end;
  31. //修正指针常量在内存中的偏移
  32. function FixedPointer(const Value : Pointer) : Pointer;
  33. label
  34. sign;
  35. var
  36. V, K                                  : Cardinal;
  37. begin
  38. //下面是一段汇编代码,希望不由看着头大..
  39. asm
  40.           call   @next                //
  41. sign:
  42. @next:    pop    eax                  //把EIP弹出到P
  43.           mov    K, eax
  44.           mov    V, offset @next
  45. end;
  46. Result := Pointer(K - V + Cardinal(Value));
  47. end;
  48. //修正PChar常量在内存中的偏移
  49. {
  50. Delphi编译的程序有个特点.字符串常量例如 a:='abc' 中的'abc'存储在代码段中.
  51. 紧跟在实现它的函数体的后面.由于引用的绝对地址.而我们的代码地址不确定,
  52. 我们必须把它的绝对地址进行修正.
  53. Delphi的这个特性,可以说Delphi是在编写扫描代码中最方便的工具了.
  54. }
  55. function FixedPChar(const Value : PChar) : PChar;
  56. begin
  57. Result := FixedPointer(Value);
  58. end;
  59. //获得Kernal32.DLL的地址.利用了PEB的结构
  60. //下面是一段汇编代码,希望不由看着头大..
  61. function GetK32Addr : Cardinal;
  62. asm
  63. mov eax,fs:$30
  64. mov eax,[eax + $0c]
  65. mov esi,[eax + $1c]
  66. lodsd
  67. mov eax,[eax+$08]                //这个时候eax中保存的就是k32的基址了
  68. end;
  69. //比较字符串是否相等.这个时候什么API都没有定位.只能自己实现.
  70. function StrSame(A, B : PChar) : Boolean;
  71. begin
  72. Result := True;
  73. if Integer(A) = Integer(B) then
  74. begin
  75.     Exit;
  76. end;
  77. while True do
  78. begin
  79.     if (A^ <> B^) then
  80.     begin
  81.       break;
  82.     end;
  83.     if (A^ = #0) then
  84.       Exit;
  85.     Inc(A);
  86.     Inc(B);
  87. end;
  88. Result := False;
  89. end;
  90. //填充内存块
  91. procedure MemFill(Dest : Pointer; count : Integer; Value : Char);
  92. var
  93. I                                     : Integer;
  94. P                                     : PChar;
  95. begin
  96. P := PChar(Dest);
  97. for I := count - 1 downto 0 do
  98.     P[I] := Value;
  99. end;
  100. //拷贝内存块
  101. procedure MemCopy(Source, Dest : Pointer; count : Integer);
  102. var
  103. S, D                                  : PChar;
  104. I                                     : Integer;
  105. begin
  106. S := PChar(Source);
  107. D := PChar(Dest);
  108. if S = D then Exit;
  109. if Cardinal(D) > Cardinal(S) then
  110.     for I := count - 1 downto 0 do
  111.       D[I] := S[I]
  112. else
  113.     for I := 0 to count - 1 do
  114.       D[I] := S[I];
  115. end;
  116. //获得函数地址GetProcAddress的实现.
  117. function __GetProcAddress(Module : Cardinal; ProcessName : PChar) : Pointer;
  118. var
  119. ExportName                            : pChar;
  120. Address                               : Cardinal;
  121. J                                     : Cardinal;
  122. ImageDosHeader                        : PImageDosHeader;
  123. ImageNTHeaders                        : PImageNTHeaders;
  124. ImageExportDirectory                  : PImageExportDirectory;
  125. begin
  126. ImageDosHeader := Pointer(Module);
  127. ImageNTHeaders := Pointer(Module + ImageDosHeader._lfanew);
  128. ImageExportDirectory := Pointer(ImageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress + Module);
  129. J := 0;
  130. Address := 0;
  131. repeat
  132.     ExportName := Pointer(Cardinal(Pointer(Cardinal(ImageExportDirectory.AddressOfNames) + Module + J * 4)^) + Module);
  133.     if StrSame(ProcessName, ExportName) then
  134.       Address := Cardinal(Pointer(Word(Pointer(J shl 1 + Cardinal(
  135.         ImageExportDirectory.AddressOfNameOrdinals) + Module)^) and
  136.         $0000FFFF shl 2 + Cardinal(ImageExportDirectory.AddressOfFunctions)
  137.         + Module)^) + Module;
  138.     Inc(J);
  139. until (Address <> 0) or (J = ImageExportDirectory.NumberOfNames);
  140. Result := Pointer(Address);
  141. end;
  142. //获得函数地址
  143. function Init() : TFuncs;
  144. var
  145. hK32                                  : HMODULE;
  146. hU32                                  : HMODULE;
  147. begin
  148. hK32 := GetK32Addr;
  149. Result.GetProcAddress := __GetProcAddress(hK32, FixedPChar('GetProcAddress'));
  150. Result.LoadLibraryA := Result.GetProcAddress(hK32, FixedPChar('LoadLibraryA'));
  151. //Result. := __GetProcAddress(hK32,FixedPChar(''));
  152. end;
  153. //远线程代码结束处.这个函数仅仅就是个插桩,标识
  154. procedure EndRoot();
  155. begin
  156. end;
  157. Function CloseSFC():Integer;
  158. //提升获得调试权限
  159. procedure Right;
  160. var
  161.     stmp                                : string;
  162.     htmp, hToken                        : Thandle;
  163.     tkp                                 : TOKEN_PRIVILEGES;
  164.     tkpOld                              : TOKEN_PRIVILEGES;
  165. begin
  166.     OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);
  167.     LookupPrivilegeValue(nil, 'SeDebugPrivilege', tkp.Privileges[0].Luid);
  168.     tkp.PrivilegeCount := 1;
  169.     tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
  170.     AdjustTokenPrivileges(hToken, false, tkp, sizeof(tkpOld), tkpOld, htmp);
  171. end;
  172. var
  173. wpid                                  : Cardinal;
  174. hWinLogon                             : Cardinal;
  175. Mem                                   : Pointer;
  176. hThread                               : Cardinal;
  177. r                                     : DWORD;
  178. Size:DWORD;
  179. begin
  180. Result := 0;
  181. Right();
  182. wpid := GetWinLogonPID();
  183. hWinLogon := OpenProcess(PROCESS_ALL_ACCESS, FALSE, wpid);
  184. //拷贝的代码长度是EndRoot的地址和Root地址的差
  185. Size := (DWORD(@EndRoot) - DWORD(@Root));
  186. mem := VirtualAllocEx(hWinLogon,
  187.     nil,
  188.     Size,
  189.     MEM_COMMIT,
  190.     PAGE_READWRITE);
  191. if Mem = nil then
  192. begin
  193.     Result := GetLastError();
  194.     Exit;
  195. end;
  196. if not WriteProcessMemory(hWinLogon,
  197.     mem,
  198.     @Root,
  199.     Size,
  200.     r) then
  201.     Exit;
  202. hThread := CreateRemoteThread(hWinLogon,
  203.     nil,
  204.     0,
  205.     mem,
  206.     nil,
  207.     0,
  208.     r);
  209. WaitForSingleObject(hThread, 10000);
  210. VirtualFreeEx(hWinLogon, mem, 0, MEM_FREE);
  211. CloseHandle(hThread);
  212. CloseHandle(hWinLogon);
  213. end;
  214. end.
复制代码
Unit3.pas:
  1. unit Unit3;
  2. interface
  3. uses
  4. Windows, SysUtils;
  5. const
  6. ntdll                                 = 'ntdll.dll';
  7. type
  8. PVOID = Pointer;
  9. PQuad = ^TQuad;
  10. _QUAD = record
  11.     DoNotUseThisField : Double;
  12. end;
  13. QUAD = _QUAD;
  14. TQuad = _QUAD;
  15. USHORT = Word;
  16. UQUAD = QUAD;
  17. PWSTR = LPWSTR;
  18. LONG = Longint;
  19. NTSTATUS = LONG;
  20. ULONG_PTR = Longword;
  21. SIZE_T = ULONG_PTR;
  22. ULONGLONG = Int64;
  23. type
  24. PUNICODE_STRING = ^UNICODE_STRING;
  25. _UNICODE_STRING = record
  26.     Length : USHORT;
  27.     MaximumLength : USHORT;
  28.     Buffer : PWSTR;
  29. end;
  30. UNICODE_STRING = _UNICODE_STRING;
  31. PCUNICODE_STRING = ^UNICODE_STRING;
  32. _ANSI_STRING = record
  33.     Length : USHORT;
  34.     MaximumLength : USHORT;
  35.     Buffer : PCHAR;
  36. end;
  37. ANSI_STRING = _ANSI_STRING;
  38. PANSI_STRING = ^ANSI_STRING;
  39. type
  40. _SYSTEM_INFORMATION_CLASS = (
  41.     SystemBasicInformation,
  42.     SystemProcessorInformation,
  43.     SystemPerformanceInformation,
  44.     SystemTimeOfDayInformation,
  45.     SystemPathInformation,              /// Obsolete: Use KUSER_SHARED_DATA
  46.     SystemProcessInformation,
  47.     SystemCallCountInformation,
  48.     SystemDeviceInformation,
  49.     SystemProcessorPerformanceInformation,
  50.     SystemFlagsInformation,
  51.     SystemCallTimeInformation,
  52.     SystemModuleInformation,
  53.     SystemLocksInformation,
  54.     SystemStackTraceInformation,
  55.     SystemPagedPoolInformation,
  56.     SystemNonPagedPoolInformation,
  57.     SystemHandleInformation,
  58.     SystemObjectInformation,
  59.     SystemPageFileInformation,
  60.     SystemVdmInstemulInformation,
  61.     SystemVdmBopInformation,
  62.     SystemFileCacheInformation,
  63.     SystemPoolTagInformation,
  64.     SystemInterruptInformation,
  65.     SystemDpcBehaviorInformation,
  66.     SystemFullMemoryInformation,
  67.     SystemLoadGdiDriverInformation,
  68.     SystemUnloadGdiDriverInformation,
  69.     SystemTimeAdjustmentInformation,
  70.     SystemSummaryMemoryInformation,
  71.     SystemNextEventIdInformation,
  72.     SystemEventIdsInformation,
  73.     SystemCrashDumpInformation,
  74.     SystemExceptionInformation,
  75.     SystemCrashDumpStateInformation,
  76.     SystemKernelDebuggerInformation,
  77.     SystemContextSwitchInformation,
  78.     SystemRegistryQuotaInformation,
  79.     SystemExtendServiceTableInformation,
  80.     SystemPrioritySeperation,
  81.     SystemPlugPlayBusInformation,
  82.     SystemDockInformation,
  83.     SystemPowerInformationNative,
  84.     SystemProcessorSpeedInformation,
  85.     SystemCurrentTimeZoneInformation,
  86.     SystemLookasideInformation,
  87.     SystemTimeSlipNotification,
  88.     SystemSessionCreate,
  89.     SystemSessionDetach,
  90.     SystemSessionInformation,
  91.     SystemRangeStartInformation,
  92.     SystemVerifierInformation,
  93.     SystemAddVerifier,
  94.     SystemSessionProcessesInformation,
  95.     SystemInformationClassMax);
  96. SYSTEM_INFORMATION_CLASS = _SYSTEM_INFORMATION_CLASS;
  97. TSystemInformationClass = SYSTEM_INFORMATION_CLASS;
  98. _CLIENT_ID = record
  99.     UniqueProcess : THandle;
  100.     UniqueThread : THandle;
  101. end;
  102. CLIENT_ID = _CLIENT_ID;
  103. PCLIENT_ID = ^CLIENT_ID;
  104. _SYSTEM_THREAD_INFORMATION = record
  105.     KernelTime : FILETIME;
  106.     UserTime : FILETIME;
  107.     CreateTime : FILETIME;
  108.     WaitTime : ULONG;
  109.     StartAddress : DWORD;
  110.     ClientId : CLIENT_ID;
  111.     Priority : DWORD;
  112.     BasePriority : LONG;
  113.     ContextSwitches : ULONG;
  114.     ThreadState : ULONG;
  115.     WaitReason : ULONG;
  116. end;
  117. SYSTEM_THREAD_INFORMATION = _SYSTEM_THREAD_INFORMATION;
  118. PSYSTEM_THREAD_INFORMATION = ^SYSTEM_THREAD_INFORMATION;
  119. _IO_COUNTERS = record
  120.     ReadOperationCount : LARGE_INTEGER;
  121.     WriteOperationCount : LARGE_INTEGER;
  122.     OtherOperationCount : LARGE_INTEGER;
  123.     ReadTransferCount : LARGE_INTEGER;
  124.     WriteTransferCount : LARGE_INTEGER;
  125.     OtherTransferCount : LARGE_INTEGER;
  126. end;
  127. IO_COUNTERS = _IO_COUNTERS;
  128. PIO_COUNTERS = ^IO_COUNTERS;
  129. _VM_COUNTERS = record
  130.     PeakVirtualSize : SIZE_T;
  131.     VirtualSize : SIZE_T;
  132.     PageFaultCount : ULONG;
  133.     PeakWorkingSetSize : SIZE_T;
  134.     WorkingSetSize : SIZE_T;
  135.     QuotaPeakPagedPoolUsage : SIZE_T;
  136.     QuotaPagedPoolUsage : SIZE_T;
  137.     QuotaPeakNonPagedPoolUsage : SIZE_T;
  138.     QuotaNonPagedPoolUsage : SIZE_T;
  139.     PagefileUsage : SIZE_T;
  140.     PeakPagefileUsage : SIZE_T;
  141. end;
  142. VM_COUNTERS = _VM_COUNTERS;
  143. PVM_COUNTERS = ^VM_COUNTERS;
  144. _SYSTEM_PROCESS_INFORMATION = record
  145.     NextEntryOffset : ULONG;
  146.     NumberOfThreads : ULONG;
  147.     dwUnknown1 : array[0..5] of DWORD;
  148.     CreationTime : FILETIME;
  149.     UserTime : FILETIME;
  150.     KernelTime : FILETIME;
  151.     ImageName : UNICODE_STRING;
  152.     BasePriority : LONG;
  153.     UniqueProcessId : THandle;
  154.     InheritedFromUniqueProcessId : THandle;
  155.     HandleCount : ULONG;
  156.     SessionId : ULONG;
  157.     PageDirectoryFrame : ULONG;
  158.     vmCounters : VM_COUNTERS;
  159.     PrivatePageCount : ULONG;
  160.     ioCounters : IO_COUNTERS;
  161.     Threads : array[0..0] of SYSTEM_THREAD_INFORMATION;
  162. end;
  163. SYSTEM_PROCESS_INFORMATION = _SYSTEM_PROCESS_INFORMATION;
  164. PSYSTEM_PROCESS_INFORMATION = ^SYSTEM_PROCESS_INFORMATION;
  165. //一个native API
  166. function NtQuerySystemInformation(
  167. SystemInformationClass : SYSTEM_INFORMATION_CLASS;
  168. SystemInformation : PVOID;
  169. SystemInformationLength : ULONG;
  170. ReturnLength : PULONG
  171. ) : NTSTATUS; stdcall; external ntdll;
  172. function NT_SUCCESS(Status : NTSTATUS) : BOOL;
  173. //遍历所有进程查找WINLOGON
  174. function GetWinLogonPID() : Cardinal;
  175. implementation
  176. function NT_SUCCESS(Status : NTSTATUS) : BOOL;
  177. begin
  178. Result := Status >= 0;
  179. end;
  180. //获得WinLogon进程的ID
  181. function GetWinLogonPID() : Cardinal;
  182. const
  183. nSize                                 = $2048 * sizeof(SYSTEM_PROCESS_INFORMATION);
  184. var
  185. ProcessInfo, P                        : PSYSTEM_PROCESS_INFORMATION;
  186. rL                                    : ULONG;
  187. states                                : NTSTATUS;
  188. offset                                : Integer;
  189. S                                     : string;
  190. Dt                                    : TDateTime;
  191. DDt                                   : DWORD;
  192. LDt                                   : TFileTime;
  193. WinLogon                              : WideString;
  194. begin
  195. Result := 0;
  196. GetMem(P, nSize);
  197. ProcessInfo := P;
  198. states := NtQuerySystemInformation(SystemProcessInformation,
  199.     ProcessInfo,
  200.     nSize,
  201.     @rL);
  202. if (not NT_SUCCESS(states)) then
  203. begin
  204.     FreeMem(ProcessInfo);
  205.     Exit;
  206. end;
  207. Offset := 0;
  208. repeat
  209.     ProcessInfo := PSYSTEM_PROCESS_INFORMATION(DWORD(ProcessInfo) + Offset);
  210.     WinLogon := ProcessInfo.ImageName.Buffer;
  211.     if UpperCase(WinLogon) = 'WINLOGON.EXE' then
  212.     begin
  213.       Result := ProcessInfo.UniqueProcessId;
  214.       break;
  215.     end;
  216.     Offset := ProcessInfo.NextEntryOffset;
  217. until (Offset = 0);
  218. FreeMem(P);
  219. end;
  220. end.
复制代码

[ 本帖最后由 2011czmxbb52 于 2011-10-4 11:19 编辑 ]
2#
发表于 2011-10-4 12:45:35 | 只看该作者
楼主的原创作品啊,我来支持一下了。
回复

使用道具 举报

3#
 楼主| 发表于 2011-10-4 15:04:20 | 只看该作者
有谁能帮忙测试一下Vista/7的兼容性?(我这边没条件测试)谢谢了!
回复

使用道具 举报

4#
发表于 2011-10-4 19:05:41 | 只看该作者
關閉是0xffffff9d 吧
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v "SfcDisable" /t REG_DWORD /d 0xffffff9d
回复

使用道具 举报

5#
发表于 2011-10-4 22:03:32 | 只看该作者
原帖由 2011czmxbb52 于 2011-10-4 09:50 发表
自制的关闭SFC的小工具
用Delphi编译的
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon 右侧窗格中的SFCDisable值,其设置为0,即重新启动后不扫描受保护的文件。
这种方法不行 ...

还要修改windows中sfc.dll文件就可以了
回复

使用道具 举报

6#
发表于 2011-10-5 01:42:36 | 只看该作者
关闭后还能恢复吗??
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2025-12-14 15:41

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表