L
linuxping
Unregistered / Unconfirmed
GUEST, unregistred user!
DLL代码:
unit Procc;
interface
uses Windows, Messages, SysUtils,StrUtils, Variants, Classes,Dialogs,TLHelp32;
function AdjustProcessPrivilege(ProcessHandle:THandle;Token_Namechar):boolean;stdcall;
function IsFoundProc(ANameChar):Boolean;stdcall;
function FoundProc(ANameChar):THandle;stdcall;
function KillProc(ANameChar):Boolean;stdcall;
implementation
function AdjustProcessPrivilege(ProcessHandle:THandle;Token_Namechar):boolean;stdcall;
var
Token:Cardinal;
TokenPri:_TOKEN_PRIVILEGES;
ProcessDest:int64;
lWORD;
begin
Result:=False;
if OpenProcessToken(ProcessHandle,TOKEN_Adjust_Privileges,Token) then
begin
if LookupPrivilegeValue(nil,Token_Name,ProcessDest) then
begin
TokenPri.PrivilegeCount:=1;
TokenPri.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
TokenPri.Privileges[0].Luid:=ProcessDest;
l:=0;
//更新进程令牌,成功返回TRUE
if AdjustTokenPrivileges(Token,False,TokenPri,sizeof(TokenPri),nil,l) then
Result:=True;
end;
end;
end;
function IsFoundProc(ANameChar):Boolean;stdcall;
begin
Result:=FoundProc(AName)<>0;
end;
function FoundProc(ANameChar):THandle;stdcall;
var
hSnapShot:THandle;
bExist:Boolean;
pProcess PROCESSENTRY32;
sProcNameChar;
begin
Result:=0;
hSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //创建进程快照
If hSnapShot = 0 Then Exit;
GetMem(pProcess,SizeOf(TProcessEntry32));
//FillChar(pProcess,SizeOf(TProcessEntry32),0);
//ShowMessage(IntToStr(SizeOf(TProcessEntry32)));
pProcess^.dwSize := SizeOf(TProcessEntry32);
bExist:=Process32First(hSnapShot, pProcess^);
if (not bExist) then FreeMem(pProcess);
While (bExist) do
begin
sProcName:=pProcess.szExeFile;
if AnsiCompareText(sProcName,AName)=0 then
begin
Result:=pProcess.th32ProcessID;
Exit;
end;
//FillChar(pProcess,SizeOf(TProcessEntry32),0);
pProcess^.dwSize := SizeOf(TProcessEntry32);
bExist:=Process32Next(hSnapShot, pProcess^);
end;
FreeMem(pProcess);
CloseHandle(hSnapShot);
end;
function KillProc(ANameChar):Boolean;stdcall;
var
hProc:THandle;
MyProc:HWND;
begin
Result:=False;
try
hProc:=FoundProc(AName);
if hProc=0 then Exit;
if AdjustProcessPrivilege(GetCurrentProcess,'SeDebugPrivilege') then
begin
MyProc:=OpenProcess(PROCESS_ALL_ACCESS ,False,hProc);
TerminateProcess(MyProc,1);
Result:=True;
end;
except
//abort all Errors~
end;
end;
end.
//////////////////////////////
调用:
type TFound=function(AName:string):Boolean;
TKill=function(AName:string):Boolean;
pFound=^TFound;
pKill=^TKill;
type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
pfd, pkl:TFarProc;
tfd:TFound;
tkl:TKill;
hMd:THandle;
sNameChar;
begin
hMd:=LoadLibrary('Project1.dll');
if hMd=0 then raise Exception.Create('load Error~');
try
pfd:=GetProcAddress(hMd,'IsFoundProc');
if (pfd=nil) then raise Exception.Create('Function1 not found~');
tfd:=TFound(Pfd);
pkl:=GetProcAddress(hMd,'KillProc');
if pkl=nil then raise Exception.Create('Function2 not found~');
tkl:=TKill(pkl);
GetMem(sName,260);
StrCopy(sName,'QQ.EXE');
if tfd(sName) then
tkl(sName);
FreeMem(sName);
finally
FreeLibrary(hMd);
end;
end;
end.
这是帮网友写的东西.可是参数传递却把我给搞得累死了~
>> 单步调试到:
function IsFoundProc(ANameChar):Boolean;stdcall;
begin
Result:=FoundProc(AName)<>0; <------------AName居然是乱码!!!!!!
end;
unit Procc;
interface
uses Windows, Messages, SysUtils,StrUtils, Variants, Classes,Dialogs,TLHelp32;
function AdjustProcessPrivilege(ProcessHandle:THandle;Token_Namechar):boolean;stdcall;
function IsFoundProc(ANameChar):Boolean;stdcall;
function FoundProc(ANameChar):THandle;stdcall;
function KillProc(ANameChar):Boolean;stdcall;
implementation
function AdjustProcessPrivilege(ProcessHandle:THandle;Token_Namechar):boolean;stdcall;
var
Token:Cardinal;
TokenPri:_TOKEN_PRIVILEGES;
ProcessDest:int64;
lWORD;
begin
Result:=False;
if OpenProcessToken(ProcessHandle,TOKEN_Adjust_Privileges,Token) then
begin
if LookupPrivilegeValue(nil,Token_Name,ProcessDest) then
begin
TokenPri.PrivilegeCount:=1;
TokenPri.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
TokenPri.Privileges[0].Luid:=ProcessDest;
l:=0;
//更新进程令牌,成功返回TRUE
if AdjustTokenPrivileges(Token,False,TokenPri,sizeof(TokenPri),nil,l) then
Result:=True;
end;
end;
end;
function IsFoundProc(ANameChar):Boolean;stdcall;
begin
Result:=FoundProc(AName)<>0;
end;
function FoundProc(ANameChar):THandle;stdcall;
var
hSnapShot:THandle;
bExist:Boolean;
pProcess PROCESSENTRY32;
sProcNameChar;
begin
Result:=0;
hSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //创建进程快照
If hSnapShot = 0 Then Exit;
GetMem(pProcess,SizeOf(TProcessEntry32));
//FillChar(pProcess,SizeOf(TProcessEntry32),0);
//ShowMessage(IntToStr(SizeOf(TProcessEntry32)));
pProcess^.dwSize := SizeOf(TProcessEntry32);
bExist:=Process32First(hSnapShot, pProcess^);
if (not bExist) then FreeMem(pProcess);
While (bExist) do
begin
sProcName:=pProcess.szExeFile;
if AnsiCompareText(sProcName,AName)=0 then
begin
Result:=pProcess.th32ProcessID;
Exit;
end;
//FillChar(pProcess,SizeOf(TProcessEntry32),0);
pProcess^.dwSize := SizeOf(TProcessEntry32);
bExist:=Process32Next(hSnapShot, pProcess^);
end;
FreeMem(pProcess);
CloseHandle(hSnapShot);
end;
function KillProc(ANameChar):Boolean;stdcall;
var
hProc:THandle;
MyProc:HWND;
begin
Result:=False;
try
hProc:=FoundProc(AName);
if hProc=0 then Exit;
if AdjustProcessPrivilege(GetCurrentProcess,'SeDebugPrivilege') then
begin
MyProc:=OpenProcess(PROCESS_ALL_ACCESS ,False,hProc);
TerminateProcess(MyProc,1);
Result:=True;
end;
except
//abort all Errors~
end;
end;
end.
//////////////////////////////
调用:
type TFound=function(AName:string):Boolean;
TKill=function(AName:string):Boolean;
pFound=^TFound;
pKill=^TKill;
type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
pfd, pkl:TFarProc;
tfd:TFound;
tkl:TKill;
hMd:THandle;
sNameChar;
begin
hMd:=LoadLibrary('Project1.dll');
if hMd=0 then raise Exception.Create('load Error~');
try
pfd:=GetProcAddress(hMd,'IsFoundProc');
if (pfd=nil) then raise Exception.Create('Function1 not found~');
tfd:=TFound(Pfd);
pkl:=GetProcAddress(hMd,'KillProc');
if pkl=nil then raise Exception.Create('Function2 not found~');
tkl:=TKill(pkl);
GetMem(sName,260);
StrCopy(sName,'QQ.EXE');
if tfd(sName) then
tkl(sName);
FreeMem(sName);
finally
FreeLibrary(hMd);
end;
end;
end.
这是帮网友写的东西.可是参数传递却把我给搞得累死了~
>> 单步调试到:
function IsFoundProc(ANameChar):Boolean;stdcall;
begin
Result:=FoundProc(AName)<>0; <------------AName居然是乱码!!!!!!
end;