解密SQL SERVER儲存過程
--可以檢視加密的儲存過程
--exec sp_decrypt 'procName'
create PROCEDURE sp_decrypt(@objectname varchar(50))
AS
begin
set nocount on
--CSDN:j9988 copyright:2004.07.15
--V3.2
--破解位元組不受限制,適用於SQLSERVER2000儲存過程,函式,檢視,觸發器
--修正上一版"檢視觸發器"不能正確解密錯誤
--發現有錯,請E_MAIL:
begin tran
declare @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 varchar(10),@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<
begin
if exists(select 1 from syscomments where id=object_id(@objectname) and )
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
if @tr_parent_xtype='V'
begin
set @sql1='Alter TRIGGER ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTERD OF Insert AS PRINT 1 '
end
else
begin
set @sql1='Alter TRIGGER 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 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 '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 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
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<
begin
if exists(select 1 from syscomments where id=object_id(@objectname) and )
begin
select @colid=max(colid) from #temp where
set @n=1
while @n<
begin
select @OrigSpText1=ctext,@encrypted=encrypted,@status=status FROM #temp Where and
SET @OrigSpText3=(Select ctext FROM syscomments Where id=object_id(@objectname) and and )
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(10)) 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 end'
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 ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTEAD OF Insert AS PRINT 1 '
end
else
begin
set @OrigSpText2='Create TRIGGER ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR Insert AS PRINT 1 '
end
end
if @type='V'
set @OrigSpText2='Create VIEW 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
go
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14490/viewspace-917489/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【fosoyo】SQL Server儲存過程/函式加/解密SQLServer儲存過程函式解密
- SQL Server 儲存過程SQLServer儲存過程
- 【SQL Server】--儲存過程SQLServer儲存過程
- MS SQL Server儲存過程SQLServer儲存過程
- Sql Server系列:儲存過程SQLServer儲存過程
- SQL Server基礎:儲存過程SQLServer儲存過程
- sql server儲存過程語法SQLServer儲存過程
- SQL server儲存過程函式SQLServer儲存過程函式
- SQL Server 儲存過程的運用SQLServer儲存過程
- SQL Server基礎之儲存過程SQLServer儲存過程
- (SQL Server)分頁的儲存過程SQLServer儲存過程
- 解密encrypt的儲存過程解密儲存過程
- SQL Server 禁用擴充套件儲存過程SQLServer套件儲存過程
- SQL Server 資料備份儲存過程SQLServer儲存過程
- ms sql server儲存過程目前使用模板SQLServer儲存過程
- SQL Server儲存過程中raiserror的使用SQLServer儲存過程AIError
- SQL Server儲存過程的優缺點SQLServer儲存過程
- 【SQL Server】常見系統儲存過程SQLServer儲存過程
- SER SERVER儲存過程Server儲存過程
- SQL SERVER儲存過程AS和GO的含義SQLServer儲存過程Go
- Java呼叫SQL Server的儲存過程詳解JavaSQLServer儲存過程
- 幾個實用SQL Server取儲存過程SQLServer儲存過程
- SQL SERVER 2005分頁儲存過程SQLServer儲存過程
- SQL儲存過程示例SQL儲存過程
- SQL Server 資料訪問策略:儲存過程QCSQLServer儲存過程
- 儲存過程 與 SQL Server語句大比拼儲存過程SQLServer
- SQL Server系統儲存過程和引數示例SQLServer儲存過程
- 【stswordman】SQL Server 2005: 儲存過程簽名SQLServer儲存過程
- 編寫和優化SQL Server的儲存過程優化SQLServer儲存過程
- SQL Server 儲存過程的經典分頁(轉)SQLServer儲存過程
- SQL 儲存過程裡呼叫另一個儲存過程SQL儲存過程
- SQL Server 2005/2008 對With Encryption選項建立的儲存過程解密SQLServer儲存過程解密
- 一個SQL Server Sa密碼破解的儲存過程SQLServer密碼儲存過程
- SQL Server系統儲存過程和引數總結SQLServer儲存過程
- 小寫轉大寫金額儲存過程[SQL SERVER]儲存過程SQLServer
- SQL Server中建立儲存過程時,with recompoile的作用SQLServer儲存過程
- 在 SQL Server 的儲存過程中呼叫 Com 元件 (轉)SQLServer儲存過程元件
- SQL Server實戰五:儲存過程與觸發器SQLServer儲存過程觸發器