马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
<p>CREATE  ROCEDURE sp_decrypt(@objectName varchar(50))<br/>AS<br/>begin<br/>set nocount on<br/>--CSDN:j9988 copyright:2004.04.15 <br/>--V3.1 <br/>--破解字节不受限制,适用于SQLSERVER2000存储过程,函数,视图,触发器<br/>--修正上一版视图触发器不能正确解密错误<br/>--发现有错,请E_MAIL:CSDNj9988@tom.com<br/>begin tran<br/>declare @objectname1 varchar(100),@orgvarbin varbinary(8000)<br/>declare @sql1 nvarchar(4000),@sql2 varchar(8000),@sql3 nvarchar(4000),@sql4 nvarchar(4000)<br/>DECLARE @OrigSpText1 nvarchar(4000), @OrigSpText2 nvarchar(4000) , @OrigSpText3 nvarchar(4000), @resultsp nvarchar(4000)<br/>declare @i int,@status int,@type varchar(10),@parentid int<br/>declare @colid int,@n int,@q int,@j int,@k int,@encrypted int,@number int<br/>select @type=xtype,@parentid=parent_obj from sysobjects where id=object_id(@ObjectName)</p><p>create table #temp(number int,colid int,ctext varbinary(8000),encrypted int,status int)<br/>insert #temp SELECT number,colid,ctext,encrypted,status FROM syscomments WHERE id = object_id(@objectName)<br/>select @number=max(number) from #temp<br/>set @k=0</p><p>while @k<=@number <br/>begin<br/>if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)<br/>begin<br/>if @type='P'<br/>set @sql1=(case when @number>1 then 'ALTER PROCEDURE '+ @objectName +';'+rtrim(@k)+' WITH ENCRYPTION AS '<br/> else 'ALTER PROCEDURE '+ @objectName+' WITH ENCRYPTION AS '<br/> end)</p><p>if @type='TR'<br/>begin<br/>declare @parent_obj varchar(255),@tr_parent_xtype varchar(10)<br/>select @parent_obj=parent_obj from sysobjects where id=object_id(@objectName)<br/>select @tr_parent_xtype=xtype from sysobjects where id=@parent_obj<br/>if @tr_parent_xtype='V'<br/>begin<br/>set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTERD OF INSERT AS PRINT 1 '<br/>end<br/>else<br/>begin<br/>set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 '<br/>end</p><p>end<br/>if @type='FN' or @type='TF' or @type='IF'<br/>set @sql1=(case @type when 'TF' then <br/>'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end '<br/>when 'FN' then<br/>'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end'<br/>when 'IF' then<br/>'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a'<br/>end)</p><p>if @type='V'<br/>set @sql1='ALTER VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f'</p><p>set @q=len(@sql1)<br/>set @sql1=@sql1+REPLICATE('-',4000-@q)<br/>select @sql2=REPLICATE('-',8000)<br/>set @sql3='exec(@sql1'<br/>select @colid=max(colid) from #temp where number=@k <br/>set @n=1<br/>while @n<=CEILING(1.0*(@colid-1)/2) and len(@sQL3)<=3996<br/>begin <br/>set @sql3=@sql3+'+@'<br/>set @n=@n+1<br/>end<br/>set @sql3=@sql3+')'<br/>exec sp_executesql @sql3,N'@Sql1 nvarchar(4000),@ varchar(8000)',@sql1=@sql1,@=@sql2</p><p>end<br/>set @k=@k+1<br/>end</p><p>set @k=0<br/>while @k<=@number <br/>begin</p><p>if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)<br/>begin<br/>select @colid=max(colid) from #temp where number=@k <br/>set @n=1</p><p>while @n<=@colid<br/>begin<br/>select @OrigSpText1=ctext,@encrypted=encrypted,@status=status FROM #temp WHERE colid=@n and number=@k</p><p>SET @OrigSpText3=(SELECT ctext FROM syscomments WHERE id=object_id(@objectName) and colid=@n and number=@k)<br/>if @n=1<br/>begin<br/>if @type='P'<br/>SET @OrigSpText2=(case when @number>1 then 'CREATE PROCEDURE '+ @objectName +';'+rtrim(@k)+' WITH ENCRYPTION AS '<br/> else 'CREATE PROCEDURE '+ @objectName +' WITH ENCRYPTION AS '<br/> end)</p><p><br/>if @type='FN' or @type='TF' or @type='IF'<br/>SET @OrigSpText2=(case @type when 'TF' then <br/>'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end '<br/>when 'FN' then<br/>'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end'<br/>when 'IF' then<br/>'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a'<br/>end)</p><p>if @type='TR' <br/>begin</p><p>if @tr_parent_xtype='V'<br/>begin<br/>set @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTEAD OF INSERT AS PRINT 1 '<br/>end<br/>else<br/>begin<br/>set @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 '<br/>end</p><p>end</p><p>if @type='V'<br/>set @OrigSpText2='CREATE VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f'</p><p>set @q=4000-len(@OrigSpText2)<br/>set @OrigSpText2=@OrigSpText2+REPLICATE('-',@q)<br/>end<br/>else<br/>begin<br/>SET @OrigSpText2=REPLICATE('-', 4000)<br/>end<br/>SET @i=1</p><p>SET @resultsp = replicate(N'A', (datalength(@OrigSpText1) / 2))</p><p>WHILE @i<=datalength(@OrigSpText1)/2<br/>BEGIN</p><p>SET @resultsp = stuff(@resultsp, @i, 1, NCHAR(UNICODE(substring(@OrigSpText1, @i, 1)) ^<br/> (UNICODE(substring(@OrigSpText2, @i, 1)) ^<br/> UNICODE(substring(@OrigSpText3, @i, 1)))))<br/>SET @i=@i+1<br/>END<br/>set @orgvarbin=cast(@OrigSpText1 as varbinary(8000))<br/>set @resultsp=(case when @encrypted=1 <br/> then @resultsp <br/> else convert(nvarchar(4000),case when @status&2=2 then uncompress(@orgvarbin) else @orgvarbin end)<br/> end)<br/>print @resultsp</p><p>set @n=@n+1</p><p>end</p><p>end<br/>set @k=@k+1<br/>end</p><p>drop table #temp<br/>rollback tran<br/>end</p>
[此贴子已经被作者于2007-7-11 16:17:03编辑过]
|