createPROCEDUREsp_decrypt(@objectnamevarchar(50))
AS
begin
setnocounton
--CSDN:j9988copyright:.07.15
--V3.2
--破解字节不受限制,适用于SQLSERVER2000存储过程,函数,视图,触发器
--修正上一版"视图触发器"不能正确解密错误
--发现有错,请E_MAIL:CSDNj9988@
begintran
declare@objectname1varchar(100),@orgvarbinvarbinary(8000)
declare@sql1nvarchar(4000),@sql2varchar(8000),@sql3nvarchar(4000),@sql4nvarchar(4000)
DECLARE@OrigSpText1nvarchar(4000),@OrigSpText2nvarchar(4000),@OrigSpText3nvarchar(4000),@resultspnvarchar(4000)
declare@iint,@statusint,@typevarchar(10),@parentidint
declare@colidint,@nint,@qint,@jint,@kint,@encryptedint,@numberint
select@type=xtype,@parentid=parent_objfromsysobjectswhereid=object_id(@objectname)
createtable#temp(numberint,colidint,ctextvarbinary(8000),encryptedint,statusint)
insert#tempSELECTnumber,colid,ctext,encrypted,statusFROMsyscommentsWHEREid=object_id(@objectname)
select@number=max(number)from#temp
set@k=0
while@k<=@number
begin
ifexists(select1fromsyscommentswhereid=object_id(@objectname)andnumber=@k)
begin
if@type='P'
set@sql1=(casewhen@number>1then'ALTERPROCEDURE'+@objectname+';'+rtrim(@k)+'WITHENCRYPTIONAS'
else'ALTERPROCEDURE'+@objectname+'WITHENCRYPTIONAS'
end)
if@type='TR'
begin
declare@parent_objvarchar(255),@tr_parent_xtypevarchar(10)
select@parent_obj=parent_objfromsysobjectswhereid=object_id(@objectname)
select@tr_parent_xtype=xtypefromsysobjectswhereid=@parent_obj
if@tr_parent_xtype='V'
begin
set@sql1='ALTERTRIGGER'+@objectname+'ON'+OBJECT_NAME(@parentid)+'WITHENCRYPTIONINSTERDOFINSERTASPRINT1'
end
else
begin
set@sql1='ALTERTRIGGER'+@objectname+'ON'+OBJECT_NAME(@parentid)+'WITHENCRYPTIONFORINSERTASPRINT1'
end
end
if@type='FN'or@type='TF'or@type='IF'
set@sql1=(case@typewhen'TF'then
'ALTERFUNCTION'+@objectname+'(@achar(1))returns@btable(avarchar(10))withencryptionasbegininsert@bselect@areturnend'
when'FN'then
'ALTERFUNCTION'+@objectname+'(@achar(1))returnschar(1)withencryptionasbeginreturn@aend'
when'IF'then
'ALTERFUNCTION'+@objectname+'(@achar(1))returnstablewithencryptionasreturnselect@aasa'
end)
if@type='V'
set@sql1='ALTERVIEW'+@objectname+'WITHENCRYPTIONASSELECT1asf'
set@q=len(@sql1)
set@sql1=@sql1+REPLICATE('-',4000-@q)
select@sql2=REPLICATE('-',8000)
set@sql3='exec(@sql1'
select@colid=max(colid)from#tempwherenumber=@k
set@n=1
while@n<=CEILING(1.0*(@colid-1)/2)andlen(@sql3)<=3996
begin
set@sql3=@sql3+'+@'
set@n=@n+1
end
set@sql3=@sql3+')'
execsp_executesql@sql3,N'@sql1nvarchar(4000),@varchar(8000)',@sql1=@sql1,@=@sql2
end
set@k=@k+1
end
set@k=0
while@k<=@number
begin
ifexists(select1fromsyscommentswhereid=object_id(@objectname)andnumber=@k)
begin
select@colid=max(colid)from#tempwherenumber=@k
set@n=1
while@n<=@colid
begin
select@OrigSpText1=ctext,@encrypted=encrypted,@status=statusFROM#tempWHEREcolid=@nandnumber=@k
SET@OrigSpText3=(SELECTctextFROMsyscommentsWHEREid=object_id(@objectname)andcolid=@nandnumber=@k)
if@n=1
begin
if@type='P'
SET@OrigSpText2=(casewhen@number>1then'CREATEPROCEDURE'+@objectname+';'+rtrim(@k)+'WITHENCRYPTIONAS'
else'CREATEPROCEDURE'+@objectname+'WITHENCRYPTIONAS'
end)
if@type='FN'or@type='TF'or@type='IF'
SET@OrigSpText2=(case@typewhen'TF'then
'CREATEFUNCTION'+@objectname+'(@achar(1))returns@btable(avarchar(10))withencryptionasbegininsert@bselect@areturnend'
when'FN'then
'CREATEFUNCTION'+@objectname+'(@achar(1))returnschar(1)withencryptionasbeginreturn@aend'
when'IF'then
'CREATEFUNCTION'+@objectname+'(@achar(1))returnstablewithencryptionasreturnselect@aasa'
end)
if@type='TR'
begin
if@tr_parent_xtype='V'
begin
set@OrigSpText2='CREATETRIGGER'+@objectname+'ON'+OBJECT_NAME(@parentid)+'WITHENCRYPTIONINSTEADOFINSERTASPRINT1'
end
else
begin
set@OrigSpText2='CREATETRIGGER'+@objectname+'ON'+OBJECT_NAME(@parentid)+'WITHENCRYPTIONFORINSERTASPRINT1'
end
end
if@type='V'
set@OrigSpText2='CREATEVIEW'+@objectname+'WITHENCRYPTIONASSELECT1asf'
set@q=4000-len(@OrigSpText2)
set@OrigSpText2=@OrigSpText2+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@i=@i+1
END
set@orgvarbin=cast(@OrigSpText1asvarbinary(8000))
set@resultsp=(casewhen@encrypted=1
then@resultsp
elseconvert(nvarchar(4000),casewhen@status&2=2thenuncompress(@orgvarbin)else@orgvarbinend)
end)
print@resultsp
set@n=@n+1
end
end
set@k=@k+1
end
droptable#temp
rollbacktran
end