View SQL SERVER encrypted stored procedures, functions, triggers, views

Source: Internet
Author: User
Tags rtrim

Original: View SQL SERVER encrypted stored procedures, functions, triggers, views

create  PROCEDURE sp_decrypt (@objectname varchar)
as
begin
SET NOCOUNT on
--csdn:j9988 copyright:2004.07.15
--v3.2
--crack byte unrestricted, applicable to SQLSERVER2000 stored procedures, functions, views, triggers
--fix the previous version of "View Trigger" does not decrypt the error correctly
-- Find fault, please e_mail:[email  Protected]
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 (ten), @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
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 "TF" Then
' ALTER FUNCTION ' + @objectname + ' (@a char (1)) Returns @b table (a varchar) with encryption as begin insert @b Select @a Return End '
When the ' FN ' then
' ALTER FUNCTION ' + @objectname + ' (@a char (1)) returns char (1) with encryption as begin return @a end '
When the ' 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 where @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 "TF" Then
' CREATE FUNCTION ' + @objectname + ' (@a char (1)) Returns @b table (a varchar) with encryption as begin insert @b Select @a Return End '
When the ' FN ' then
' CREATE FUNCTION ' + @objectname + ' (@a char (1)) returns char (1) with encryption as begin return @a end '
When the ' 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 I Nsert as PRINT 1 '
End
Else
Begin
Set @OrigSpText2 = ' CREATE TRIGGER '[email protected]+ ' on ' +object_name (@parentid) + ' with encryption for INSERT A S 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]+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 @encrypted =1
Then @resultsp
else convert (nvarchar (4000), case if @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

View SQL SERVER encrypted stored procedures, functions, triggers, views

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.