程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> Decryptencryptedstoredprocedures

Decryptencryptedstoredprocedures

編輯:關於SqlServer

This SP will decrypt Stored Procedures, Views or Triggers that were encrypted using "with encryption". It is adapted from a script by asp?txtCodeId=505&lngWId=5">Joseph Gama and ShoeBoy. There are two versions: one for SP's only and the other one for SP's, triggers and views. For version 1, the input is object name (stored procedure, view or trigger), and for version 2, the input is object name (stored procedure, view or trigger), object type ('T'-trigger, 'P'-stored procedure or 'V'-vIEw). From ASP?txtCodeId=505&lngWId=5">PlanetSourceCode.com.

create  PROCEDURE sp_decrypt_sp (@objectName varchar(50))



AS



DECLARE  @OrigSpText1 nvarchar(4000),  @OrigSpText2 nvarchar(4000) , @OrigSpText3 nvarchar(4000), @resultsp nvarchar(4000)



declare  @i int , @t bigint







--get encrypted data



SET @OrigSpText1=(SELECT ctext FROM syscomments  WHERE id = object_id(@objectName))



SET @OrigSpText2='ALTER PROCEDURE '+ @objectName +' WITH ENCRYPTION AS '+REPLICATE('-', 3938)



EXECUTE (@OrigSpText2)







SET @OrigSpText3=(SELECT ctext FROM syscomments  WHERE id = object_id(@objectName))



SET @OrigSpText2='CREATE PROCEDURE '+ @objectName +' WITH ENCRYPTION AS '+REPLICATE('-', 4000-62)







--start counter



SET @i=1



--fill temporary variable



SET @resultsp = replicate(N'A', (datalength(@OrigSpText1) / 2))







--loop



WHILE @i<=datalength(@OrigSpText1)/2



BEGIN



--reverse encryption (XOR original+bogus+bogus encrypted)



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



--drop original SP



EXECUTE ('drop PROCEDURE '+ @objectName)



--remove encryption



--preserve case



SET @resultsp=REPLACE((@resultsp),'WITH ENCRYPTION', ')



SET @resultsp=REPLACE((@resultsp),'With Encryption', ')



SET @resultsp=REPLACE((@resultsp),'with encryption', ')



IF CHARINDEX('WITH ENCRYPTION',
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved