server| Function | encryption | decryption
Encryption of stored procedures, stored functions: with encryption
<!--[If!supportlinebreaknewline]-->
<!--[endif]-->
CREATE procedure Dbo.sp_xml_main
@table_name nvarchar (260) = ',
@dirname nvarchar (20) = '
With encryption
As
Begin
....................................................
End
Go
The decryption of stored procedures and stored functions (the following is a code written by a very tall person)
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Sp_decrypt] and OBJECTPROPERTY (ID, N ' isprocedure ') = 1)
drop procedure [dbo]. [Sp_decrypt]
Go
/*--cracked functions, procedures, triggers, views. Limited to SQLSERVER2000
--Author: j9988--*/
/*--Call Example
--Decrypt the specified stored procedure
exec sp_decrypt ' appsp_test '
--Decryption of all stored procedures
DECLARE TB cursor FOR
Select name from sysobjects where xtype= ' P ' and status>0 and name<> ' Sp_decrypt '
declare @name sysname
Open TB
FETCH NEXT from TB into @name
While @ @fetch_status =0
Begin
print '/*-------stored procedure [' + @name + ']-----------* *
EXEC sp_decrypt @name
FETCH NEXT from TB into @name
End
Close TB
Deallocate TB
--*/
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Sp_decrypt] and OBJECTPROPERTY (ID, N ' isprocedure ') = 1)
drop procedure [dbo]. [Sp_decrypt]
Go
CREATE PROCEDURE sp_decrypt (@objectName varchar (50))
As
Begin
SET NOCOUNT ON
--csdn:j9988 copyright:2004.04.15
--v3.1
--crack byte unrestricted, apply to SQLSERVER2000 stored procedures, functions, views, triggers
--Fixed previous view triggers do not correctly decrypt errors
--Find fault, please e_mail:csdnj9988@tom.com
BEGIN Tran
DECLARE @objectname1 varchar (@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 (a), @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<= @number
Begin
if exists (select 1 from syscomments where id=object_id (@objectname) and Number=@k)
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 id= @parent_obj
If @tr_parent_xtype = ' V '
Begin
Set @sql1 = ' ALTER TRIGGER ' + @objectname + ' on ' +object_name (@parentid) + ' with encryption Insterd of INSERT as PRINT 1 '
End
Else
Begin
Set @sql1 = ' ALTER TRIGGER ' + @objectname + ' on ' +object_name (@parentid) + ' and 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) 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"
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 ' + @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 (colid) from #temp where number=@k
Set @n=1
While @n<=ceiling (1.0* (@colid-1)/2) and Len (@sQL3) <=3996
Begin
Set @sql3 = @sql3 + ' +@ '
Set @n=@n+1
End
Set @sql3 = @sql3 + ') '
EXEC sp_executesql @sql3, N ' @sql1 nvarchar (4000), @ varchar (8000) ', @sql1 = @sql1, @= @sql2
End
Set @k=@k+1
End
Set @k=0
While @k<= @number
Begin
if exists (select 1 from syscomments where id=object_id (@objectname) and Number=@k)
Begin
Select @colid =max (colid) from #temp where number=@k
Set @n=1
While @n<= @colid
Begin
Select @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=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) 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"
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 ' + @objectname + ' on ' +object_name (@parentid) + ' with encryption INSTEAD of INSERT as PRINT 1 '
End
Else
Begin
Set @OrigSpText2 = ' CREATE TRIGGER ' + @objectname + ' on ' +object_name (@parentid) + ' with encryption for INSERT as PRINT 1 '
End
End
If @type = ' V '
Set @OrigSpText2 = ' CREATE VIEW ' + @objectname + ' with encryption as SELECT 1 as f '
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 (@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 @n=@n+1
End
End
Set @k=@k+1
End
drop table #temp
Rollback Tran
End