/*
执行:
sp_decrypt '你要查看的存储过程'
*/
[separator]
use master
go
if exists(select 1 from sysobjects where xtype='p' and name='sp_decrypt')
drop proc sp_decrypt
go
create procedure sp_decrypt(@objectname varchar(50))
as
begin
set nocount on
--csdn:j9988 copyright:2004.07.15
--v3.2
--破解字节不受限制,适用于sqlserver2000存储过程,函数,视图,触发器
--修正上一版"视图触发器"不能正确解密错误
--发现有错,请e_mail:[email protected]
begin tran
declare @objectname1 varchar(100),@orgvarbin varbinary(8000)
declare @sql1 nvarchar(4000),@sql2 varchar(8000),@sql3 nvarchar(4000),@sql4 nvarchar(4000)
declare @origsptext1 nvarchar(4000), @origsptext2 nvarchar(4000) , @origsptext3 nvarchar(4000), @resultsp nvarchar(4000)
declare @i int,@status int,@type varchar(10),@parentid int
declare @colid int,@n int,@q int,@j int,@k int,@encrypted int,@number int
select @type=xtype,@parentid=parent_obj from sysobjects where id=object_id(@objectname)
create table #temp(number int,colid int,ctext varbinary(8000),encrypted int,status int)
insert #temp select number,colid,ctext,encrypted,status from syscomments where id = object_id(@objectname)
select @number=max(number) from #temp
set @k=0
while @k<[email protected]
begin
if exists(select 1 from syscomments where id=object_id(@objectname) and [email protected])
begin
if @type='p'
set @sql1=(case when @number>1 then 'alter procedure '+ @objectname +';'+rtrim(@k)+' with encryption as '
else 'alter procedure '+ @objectname+' with encryption as '
end)
if @type='tr'
begin
declare @parent_obj varchar(255),@tr_parent_xtype varchar(10)
select @parent_obj=parent_obj from sysobjects where id=object_id(@objectname)
select @tr_parent_xtype=xtype from sysobjects where [email protected]_obj
if @tr_parent_xtype='v'
begin
set @sql1='alter trigger '[email protected]+' on '+object_name(@parentid)+' with encryption insterd of insert as print 1 '
end
else
begin
set @sql1='alter trigger '[email protected]+' on '+object_name(@parentid)+' with encryption for insert as print 1 '
end
end
if @type='fn' or @type='tf' or @type='if'
set @sql1=(case @type when 'tf' then
'alter function '+ @objectname+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end '
when 'fn' then
'alter function '+ @objectname+'(@a char(1)) returns char(1) with encryption as begin return @a end'
when 'if' then
'alter function '+ @objectname+'(@a char(1)) returns table with encryption as return select @a as a'
end)
if @type='v'
set @sql1='alter view '[email protected]+' with encryption as select 1 as f'
set @q=len(@sql1)
set @[email protected]+replicate('-',[email protected])
select @sql2=replicate('-',8000)
set @sql3='exec(@sql1'
select @colid=max(colid) from #temp where [email protected]
set @n=1
while @n<=ceiling(1.0*(@colid-1)/2) and len(@sql3)<=3996
begin
set @[email protected]+'[email protected]'
set @[email protected]+1
end
set @[email protected]+')'
exec sp_executesql @sql3,n'@sql1 nvarchar(4000),@ varchar(8000)',@[email protected],@[email protected]
end
set @[email protected]+1
end
set @k=0
while @k<[email protected]
begin
if exists(select 1 from syscomments where id=object_id(@objectname) and [email protected])
begin
select @colid=max(colid) from #temp where [email protected]
set @n=1
while @n<[email protected]
begin
select @origsptext1=ctext,@encrypted=encrypted,@status=status from #temp where [email protected] and [email protected]
set @origsptext3=(select ctext from syscomments where id=object_id(@objectname) and [email protected] and [email protected])
if @n=1
begin
if @type='p'
set @origsptext2=(case when @number>1 then 'create procedure '+ @objectname +';'+rtrim(@k)+' with encryption as '
else 'create procedure '+ @objectname +' with encryption as '
end)
if @type='fn' or @type='tf' or @type='if'
set @origsptext2=(case @type when 'tf' then
'create function '+ @objectname+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end '
when 'fn' then
'create function '+ @objectname+'(@a char(1)) returns char(1) with encryption as begin return @a end'
when 'if' then
'create function '+ @objectname+'(@a char(1)) returns table with encryption as return select @a as a'
end)
if @type='tr'
begin
if @tr_parent_xtype='v'
begin
set @origsptext2='create trigger '[email protected]+' on '+object_name(@parentid)+' with encryption instead of insert as print 1 '
end
else
begin
set @origsptext2='create trigger '[email protected]+' on '+object_name(@parentid)+' with encryption for insert as print 1 '
end
end
if @type='v'
set @origsptext2='create view '[email protected]+' with encryption as select 1 as f'
set @q=4000-len(@origsptext2)
set @[email protected]gsptext2+replicate('-',@q)
end
else
begin
set @origsptext2=replicate('-', 4000)
end
set @i=1
set @resultsp = replicate(n'a', (datalength(@origsptext1) / 2))
while @i<=datalength(@origsptext1)/2
begin
set @resultsp = stuff(@resultsp, @i, 1, nchar(unicode(substring(@origsptext1, @i, 1)) ^
(unicode(substring(@origsptext2, @i, 1)) ^
unicode(substring(@origsptext3, @i, 1)))))
set @[email protected]+1
end
set @orgvarbin=cast(@origsptext1 as varbinary(8000))
set @resultsp=(case when @encrypted=1
then @resultsp
else convert(nvarchar(4000),case when @status&2=2 then uncompress(@orgvarbin) else @orgvarbin end)
end)
print @resultsp
set @[email protected]+1
end
end
set @[email protected]+1
end
drop table #temp
rollback tran
end
新闻热点
疑难解答