Create Procedure SP_Decrypt (@Objectname VARCHAR (50)) ASBEGINSET NOCOUNT ON - 9CBS: J9988 Copyright: 2004.07.15 --v3.2 - Crack bytes Unrestricted, suitable for SQLServer2000 stored procedures, functions, views, triggers - Correct the previous version "View Trigger" does not decrypt the error correctly - Discover a wrong, please e_mail: 9cbsj9988@tom.combegin treage @ 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 var, @ @ @ n int, @ Q int, @ j int, @ K Int, @ encrypted int, @ Number Intselect @ type = @ @ type @ 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 #Tempset @ K = 0
while @k <= @ number beginif exists (select 1 from syscomments where id = object_id (@objectname) and number = @ k) beginif @ 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'begindeclare @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 id = @ parent_objif @tr_parent_xtype = 'V'beginset @ sql1 =' ALTER TRIGGER ' @ objectname ' ON ' OBJECT_NAME (@parentid) ' WITH ENCRYPTION INSTERD OF INSERT AS PRINT 1 'endelsebeginset @ sql1 =' ALTER TRIGGER ' @ objectname ' ON ' Object_name (@parentid) 'with encryption for insert as print 1' endndif@ 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' @objectname '(@ a char (1)) Returns Table with Encryption AS Return SELECT @a as aeend
IF @ type = 'V'SET @ SQL1 =' Alter View ' @ Objectname ' with Encryption As SELECT 1 AS F '
Set @ q = len (@ SQL1) set @ SQL1 = @ SQL1 Replicate ('-', 4000- @ q) SELECT @ SQL2 = Replicate ('-', 8000) set @ SQL3 = 'Exec (@ SQL1'Select @ colid = max (color) from #temp where number = @ K set @ n = 1WHILE @n <= ceiling (@ colid-1) / 2) And len (@ SQL3) <= 3996begin set @ SQL3 = @ SQL3 ' @' set @ n = @ n 1ndset @ SQL3 = @ SQL3 ')' EXEC SP_EXECUTESQL @ SQL3, N '@ SQL1 NVARCHAR (4000), @ sql1 = @ SQL1, @ = @ SQL2ENDSET @ K = @ K 1END
Set @ K = 0WHILE @K <= @ Number Begin
IF exists (SELECT 1 from syscomments where id = Object_id (@Objectname) and number = @ K) Beginselect @ colid = max (colid) from #temp where number = @ K set @ n = 1
While @n <= @ colorbeginselect @ OrigspText1 = ctext, @ encrypted = encrypted, @ status = status from #temp where colid = @ n and number = @ K
SET @ OrigSpText3 = (SELECT ctext FROM syscomments WHERE id = object_id (@objectname) and colid = @ n and number = @ k) if @ n = 1beginif @ 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 'TEN' CREATE FUNCTION ' @ObjectName ' (@ a char (1)) Returns @B Table (a varchar (10)) with encryption as begin insert @B select @a return end 'when' fn 'dam @Objectname ' (@ a char (1)) Returns char (1) WITH ENCRYPTION AS BEGIN RTURN @a end'when 'f' 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'beginset @ OrigSpText2 =' CREATE TRIGGER ' @ objectname ' ON ' OBJECT_NAME (@parentid) ' WITH ENCRYPTION INSTEAD OF INSERT AS PRINT 1 'endelsebeginset @ OrigSpText2 =' CREATE TRIGGER ' @ objectname ' ON ' Object_name (@parentid) ' with Encryption for Insert Asprint 1 'End
end
IF @ type = 'V'Set @ igsptext2 =' create view ' @ ObjectName ' with encryption as select 1 as f '
SET @ q = 4000-len (@ OrigsPText2) set @ origsptext2 = @ igigsptext2 replicate ('-', @ q) endelsebeginset @ igigsptext2 = replicate ('-', 4000) endset @ = 1
Set @Resultsp = Replicate (N'A ', (DatalesPtext1) / 2)))
While @i <= datalength (@ ptext1) / 2begin
Set @Resultsp = stuff (@Resultsp, @i, 1, nchar (unicode (@ ptext1, @i, 1)) ^ (unicode (@ ptext2, @i, 1)) ^ unicode (@ @ 1 OrigspText3, @i, 1)))))) SET @ i = @ i 1ndset @ orgvarbin = CAST (@ ptext1 as varbinary (8000)) set @ resultsp = (casten @ Encrypted = 1 Then @Resultsp Else Convert (nvarchar (4000), Case When @ status & 2 = 2 THEN UNCOMPRESS (@orgvarbin) Else @orgvarbin end) @Rint @Resultspset @ n = @ n 1
end
Endset @ k = @ K 1END
Drop Table #TemProllback Tranend