"Go" sql2008 Decrypt encrypted stored procedures (pro-Test available)

Source: Internet
Author: User
Tags decrypt

Many of the online can not be decrypted correctly, there is a blank, fortunately there is this, mark down.

CreatePROCEDURE[dbo].[sp_windbidecrypt]  (@proceduresysname = NULL, @revfl int= 1)  AS/***********************************************************原王成辉翻译整理 连接sqlcmd语法:sqlcmd -A -d databasename -o c:\a.txt调用形式为: 先运行cmd 执行 :sqlcmd -A -d gzzywst -o c:\a.txt注意: -A A一定要大写,-d 后面是要进入的数据库  -o 是文件输出路径及文件名。本方法为连接本机SQL2008 远程登录的时候语法更复杂一些,需要服务器IP 登录用户 及密码第二步:输入execsp_windbidecrypt ‘Ts_b_InsertBillDetailDraft‘,0  再输入go 以后回车执行接触会跳行,跳行无错误显示,存储过程即解密成功,可以在输出路径下查看了。
 or New in SQL Manament Studio-Database engine query: admin:192.168.1.0 then execute the statement. 
---------------------------------------------------------------If the second parameter uses 1, some hints for the stored procedure are given. --version 4.0 fix the stored procedure too long decryption is blank problem This version has been completely able to decrypt the stored procedure under sql2008 ********************************************************* /SET NOCOUNT on IF @revfl = 1 BEGIN PRINT ' warning: The stored procedure deletes and rebuilds the original stored procedure. ' PRINT ' ensures that your database has a backup before running the stored procedure. ' PRINT ' The stored procedure should normally run in a non-product environment with a backup of the product environment. ' PRINT ' to run this stored procedure, change the value of the parameter @refl to 0. ' RETURN 0 END DECLARE @intProcSpace bigint, @t bigint, @maxColID smallint, @procNameLength int Select @maxColID = Max ( Subobjid) from sys.sysobjvalues WHERE ObjID = object_id (@procedure)--select @maxColID as ' Rows in Sys.sysobjvalues ' s Elect @procNameLength = datalength (@procedure) + DECLARE @real_01 nvarchar (max) DECLARE @fake_01 nvarchar (max) DECLA RE @fake_encrypt_01 nvarchar (max) DECLARE @real_decrypt_01 nvarchar (max), @real_decrypt_01a nvarchar (max) DECLARE @ ObjType varchar (2), @ParentName nvarchar (max) Select @real_decrypt_01a = "--Extract the object's type as a stored procedure or function, and if it is a trigger, get the name of its parent object Sele Ct@objtype =type, @parentname =object_name (parent_object_id) from sys.objects where [object_id]=object_id (@procedure)-- From Sys.sysobjvalues the encrypted imageval record set @real_01 = (SELECT top 1 imageval from sys.sysobjvalues WHERE ObjID = object_id (@pr ocedure) and Valclass = 1 ORDER by Subobjid)--Creating a temporary table create table #output ([ident] [int] IDENTITY (1, 1) not NULL  , [Real_decrypt] NVARCHAR (MAX))--Start a transaction, roll back the begin TRAN--Change the original stored procedure, replace the If @objtype with a dash = ' P ' SET @fake_01 = ' ALTER PROCEDURE ' + @procedure + ' with encryption as SELECT 1/**//* ' +replicate (CAST (' * ' as nvarchar (max)), Datalength (@real_0 1)/2-@procNameLength) + ' */' else if @objtype = ' FN ' SET @fake_01 = ' ALTER FUNCTION ' + @procedure + ' () RETURNS INT with E  Ncryption as BEGIN RETURN 1/**//* ' +replicate (CAST (' * ' as nvarchar (max)), datalength (@real_01)/2-@procNameLength) + ' * * END ' else if @objtype = ' V ' SET @fake_01 = ' ALTER view ' + @procedure + ' with encryption as select 1 as Col/**//* ' +rep Licate (CAST (' * ' as nvarchar (mAX)), datalength (@real_01)/2-@procNameLength) + ' */' else if @objtype = ' TR ' SET @fake_01 = ' ALTER trigger ' + @procedure + ' on ' [email protected]+ ' with encryption after INSERT as RAISERROR (' N ', 16,10)/**//* ' +replicate (CAST (' * ' as NVA Rchar (max)), datalength (@real_01)/2-@procNameLength) + ' * * ' EXECUTE (@fake_01)-a false SET of encryption from Sys.sysobjvalues @fake_ encrypt_01= (SELECT top 1 imageval from sys.sysobjvalues WHERE ObjID = object_id (@procedure) and Valclass = 1 ORDER by Sub ObjID) If @objtype = ' P ' SET @fake_01 = ' Create PROCEDURE ' + @procedure + ' with encryption as SELECT 1/**//* ' +replica TE (CAST (' * ' as nvarchar (max)), datalength (@real_01)/2-@procNameLength) + ' */' else if @objtype = ' FN ' SET @fake_01 = ' CREA TE FUNCTION ' + @procedure + ' () RETURNS INT with encryption as BEGIN RETURN 1/**//* ' +replicate (CAST (' * ' as nvarchar (max)  ), datalength (@real_01)/2-@procNameLength) + ' */END ' else if @objtype = ' V ' SET @fake_01 = ' Create view ' + @procedure + ' With encryption as SeleCt 1 as Col/**//* ' +replicate (CAST (' * ' as nvarchar (max)), datalength (@real_01)/2-@procNameLength) + ' * * ' else if @objt Ype= ' TR ' SET @fake_01 = ' Create trigger ' + @procedure + ' on ' [email protected]+ ' and encryption after INSERT as Rais ERROR (' N ', 16,10)/**//* ' +replicate (CAST (' * ' as nvarchar (max)), datalength (@real_01)/2-@procNameLength) + ' * * '--start count Number Set @intProcSpace = 1--fills the temporary variable set with a character @real_decrypt_01 = Replicate (cast (' A ' as nvarchar (max)), (Datalength (@real_01) /2))--cycle through each variable, create a real variable--each time a byte set @intProcSpace = 1--and, if necessary, traverse each @real_xx variable and decrypt the while @intProcSpace <= (datalengt H (@real_01)/2) BEGIN--True and false and encrypted false for XOR or processing SET @real_decrypt_01 = Stuff (@real_decrypt_01, @intProcSpace, 1, NCHAR (UNICO DE (substring (@real_01, @intProcSpace, 1)) ^ (Unicode (substring (@fake_01, @intProcSpace, 1)) ^ Unicode (substring (@fake_ Encrypt_01, @intProcSpace, 1)))) SET @[email protected]+1 END-Inserts a variable insert into the table #output by sp_helptext logic #outpu T (real_decrypt) Select @real_decrypt_01--select real_decrypt as ' #output Chek ' from #output--test-----------------------------------------Open   Starting from sp_helptext extract---------------------------------------declare @dbname sysname, @BlankSpaceAdded int, @BasePos int , @CurrentPos int, @TextLength int, @LineId int, @AddOnLen int, @LFCR INT-The length of the carriage return line, @DefinedLength int, @SyscomTe XT nvarchar (max), @Line nvarchar (255) Select @DefinedLength = 255 Select @BlankSpaceAdded = 0-The space at the end of the trace line. Note that the Len function ignores the extra spaces CREATE TABLE #CommentText (LineId int, Text nvarchar (255) collate Database_default)--use #output instead of Sys. Sysobjvalues DECLARE ms_crs_syscom CURSOR LOCAL for SELECT real_decrypt from #output ORDER by ident for READ only-- Get text Select @LFCR = 2 Select @LineId = 1 OPEN ms_crs_syscom FETCH NEXT from ms_crs_syscom to @SyscomText while @@f Etch_status >= 0 BEGIN Select @BasePos = 1 Select @CurrentPos = 1 Select @TextLength = LEN (@SyscomText) while @Cur Rentpos! = 0 BEGIN--Find the end of the line by carriage return SELect @CurrentPos = CHARINDEX (char) +char (Ten), @SyscomText, @BasePos)--If you find a carriage return if @CurrentPos! = 0 BEGIN--if @lines The new value of the length is larger than the setting to insert @lines current content and Continue while (IsNull (LEN (@Line), 0) + @BlankSpaceAdded + @[email protected] + @LFCR) > @De Finedlength BEGIN SELECT @AddOnLen = @DefinedLength-(IsNull (LEN (@Line), 0) + @BlankSpaceAdded) INSERT #CommentText VALU ES (@LineId, IsNull (@Line, n ") + IsNull (SUBSTRING (@SyscomText, @BasePos, @AddOnLen), n")) SELECT @Line = NULL, @Lin EId = @LineId + 1, @BasePos = @BasePos + @AddOnLen, @BlankSpaceAdded = 0 END SELECT @Line = IsNull (@Line, N ") + Isnul L (SUBSTRING (@SyscomText, @BasePos, @[email protected] + @LFCR), N ") SELECT @BasePos = @CurrentPos +2 INSERT #Commen Ttext VALUES (@LineId, @Line) Select @LineId = @LineId + 1 Select @Line = NULL END ELSE--if the carriage return does not find the BEGIN if @BaseP OS <= @TextLength BEGIN--If the new value of @lines length is greater than the defined length while (IsNull (LEN (@Line), 0) + @BlankSpaceAdded + @[email prote cted]+1) > @DefinedLEngth BEGIN SELECT @AddOnLen = @DefinedLength-(IsNull (LEN (@Line), 0) + @BlankSpaceAdded) INSERT #CommentText VALUES  (@LineId, IsNull (@Line, n ") + IsNull (SUBSTRING (@SyscomText, @BasePos, @AddOnLen), n")) Select @Line = NULL, @LineId = @LineId + 1, @BasePos = @BasePos + @AddOnLen, @BlankSpaceAdded = 0 END SELECT @Line = i Snull (@Line, n ") + IsNull (SUBSTRING (@SyscomText, @BasePos, @[email protected]+1), N") if LEN (@Line) < @Define  Dlength and Charindex (", @SyscomText, @TextLength +1) > 0 BEGIN SELECT @Line = @Line +", @BlankSpaceAdded = 1  End End end FETCH NEXT from ms_crs_syscom to @SyscomText END IF @Line is not NULL INSERT #CommentText VALUES ( @LineId, @Line) Select Text from #CommentText order by LineId CLOSE ms_crs_syscom deallocate ms_crs_syscom DROP tabl   E #CommentText-----------------------------------------End extract from sp_helptext--------------------------------------- --delete the stored procedure created with the dash and rebuild the original stored procedure ROLLBACK TRAN DROP tablE #output Go   

"Go" sql2008 Decrypt encrypted stored procedures (pro-test available)

Related Article

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.