Decrypt stored procedure:
The USE [RYTreasureDB] the GO / * ***** Object:. The StoredProcedure [the dbo] [$ sp__windbi the decrypt] Script a Date: 2019/8/8 10:26:20 ***** * / the SET the ANSI_NULLS the ON the GO the SET the QUOTED_IDENTIFIER ON GO the CREATE PROCEDURE [dbo]. [sp__windbi the decrypt $] ( @procedure SYSNAME = NULL, @revfl INT = 1 ) AS / ** // * Wang Chenghui translation order, please indicate posted by Microsoft BI pioneer www.windbi. com call in the form of: Exec dbo.sp__windbi $ @ the decrypt procedure, 0 if the second argument, then use 1, it will give some hints of the stored procedure. - 4.0 long decryption procedure stored correction is out of the question blank * / the SET the NOCOUNT the ON the IF @revfl = . 1 BEGIN the PRINT ' Warning: This will delete the stored procedure and recreate the original stored procedure. ' The PRINT ' before running the stored procedure to make sure you have a backup of the database. ' The PRINT ' This stored procedure should normally be run in a non-production environment a backup of the production environment. ' The PRINT ' to run the stored procedure, change the value of the parameter is 0 @refl. ' The RETURN 0 the END the DECLARE @intProcSpace BIGINT, @t BIGINT, @maxColID SMALLINT, @procNameLength the INT the SELECT @maxColID = MAX (subobjid) the FROM sys.sysobjvalues the WHERE the objid = the OBJECT_ID (@procedure) - SELECT@maxColID AS ' the Rows in sys.sysobjvalues ' the SELECT @procNameLength = the DATALENGTH (@procedure) + 29 the DECLARE @ real_01 NVARCHAR (MAX) the DECLARE @ fake_01 NVARCHAR (MAX) the DECLARE @ fake_encrypt_01 NVARCHAR (MAX) the DECLARE @ real_decrypt_01 NVARCHAR (MAX), real_decrypt_01a NVARCHAR @ (MAX) the DECLARE @objtype VARCHAR ( 2 ), @ParentName NVARCHAR (MAX) the SELECT @ real_decrypt_01a = '' - extracting an object type stored procedures or functions case, if the trigger, but also to give the parent object name the SELECT @objtype = of the type, @parentname = OBJECT_NAME (parent_object_id) the FROM the sys.objects The WHERE [object_id] =OBJECT_ID (@procedure) - made from sys.sysobjvalues encrypted in imageval record the SET @ real_01 = (the SELECT TOP 1 imageval the FROM sys.sysobjvalues the WHERE objid = OBJECT_ID (@procedure) the AND valclass = 1 the ORDER BY subobjid ) - create a temporary table the CREATE tABLE #output ( [ident] [ int ] the IDENTITY ( . 1 , . 1 ) the NOT NULL, [real_decrypt] NVARCHAR (MAX) ) -------------------- ---------------------------------------- - start a transaction rollback later the bEGIN TRAN - change the original stored procedure and replaced with hyphens the IF @objtype = ' P ' the SET fake_01 @ = ' the ALTER pROCEDURE ' + @ + Procedure ' the WITH SELECT. 1 the ENCRYPTION the AS / * ** // ' + REPLICATE (the CAST ( '*' the AS NVARCHAR (MAX)), the DATALENGTH (@ real_01) / 2 - @procNameLength) + ' * / ' the ELSE the IF @objtype = ' FN ' the SET fake_01 @ = ' the ALTER the 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 = 'ALTER view ' + @procedure + ' WITH ENCRYPTION AS select 1 as col /**//*' + REPLICATE(CAST('*' AS NVARCHAR(MAX)), DATALENGTH(@real_01) / 2 - @procNameLength) + '*/' ELSE IF @objtype = ''TR SET @fake_01 = 'ALTER trigger ' + @procedure + ' ON ' + @parentname + 'WITH ENCRYPTION AFTER INSERT AS RAISERROR (''N'',16,10) /**//*' + REPLICATE(CAST('*' AS NVARCHAR(MAX)), DATALENGTH(@real_01) / 2 - @procNameLength) + '*/' EXECUTE (@fake_01) --从sys.sysobjvalues proposed in encrypted fake imageval1= (the SELECT TOP the SET @ fake_encrypt_01 FROM sys.sysobjvalues WHERE objid = OBJECT_ID(@procedure) AND valclass = 1 ORDER BY subobjid ) IF @objtype = 'P' SET @fake_01 = 'Create PROCEDURE ' + @procedure + ' WITH ENCRYPTION AS select 1 /**//*' + REPLICATE(CAST('*' AS NVARCHAR(MAX)), DATALENGTH(@real_01) / 2 - @procNameLength) + '*/' ELSE IF @objtype = 'FN' SET @fake_01 = 'CREATE 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 @objtype = 'TR' SET @fake_01 = 'Create trigger ' + @procedure + ' ON ' + @parentname + 'WITH ENCRYPTION AFTER INSERT AS RAISERROR (''N'',16,10) /**//*' + REPLICATE(CAST('*' AS NVARCHAR(MAX)), DATALENGTH(@real_01) / 2 - @procNameLength) + '*/' A'= REPLICATE (the CAST ( the SET @ real_decrypt_01use of temporary variables character stuffing -. 1= the SET @intProcSpacecounting-' The AS NVARCHAR (MAX)), (the DATALENGTH (@ real_01) / 2 )) - loop settings for each variable, create a true variable - one byte at the SET @intProcSpace = . 1 - if necessary, through each a variable and decryption @real_xx the WHILE @intProcSpace <= (the DATALENGTH (@ real_01) / 2 ) the BEGIN - true and false false encrypted and XORed the SET @ real_decrypt_01 = STUFF is (@ real_decrypt_01, @intProcSpace, . 1 , NCHAR (UNICODE (SUBSTRING (@ real_01, @intProcSpace, 1 )) ^(The UNICODE (the SUBSTRING (@ fake_01, @intProcSpace, . 1 )) ^ the UNICODE (the SUBSTRING (@ fake_encrypt_01, @intProcSpace, . 1 ))))) the SET @intProcSpace = @intProcSpace + . 1 the END - by the logic table #output in sp_helptext insert variable the iNSERT #output (real_decrypt) the SELECT @ real_decrypt_01 - SELECT real_decrypt the AS ' #output Chek ' from #output - test - --------------------- ---------------- -Began to be extracted from the sp_helptext - ------------------------------------- DECLARE @dbname SYSNAME, @BlankSpaceAdded the INT, @BasePos the INT, @CurrentPos the INT, @TextLength the INT, @LineId the INT, @AddOnLen the INT, @LFCR the INT - the length of the transport line feed , @DefinedLength the INT, @SyscomText NVARCHAR (MAX), @Line NVARCHAR ( 255 ) @DefinedLength the SELECT = 255 the SELECT @BlankSpaceAdded = 0 - end of tracking line spaces. Note Len function ignores the extra spaces the CREATE TABLE #CommentText ( LineID INT, Text NVARCHAR (255) COLLATE database_default ) --使用#output代替sys.sysobjvalues DECLARE ms_crs_syscom CURSOR LOCAL FOR SELECT real_decrypt FROM #output ORDER BY ident FOR READ ONLY --获取文本 SELECT @LFCR = 2 SELECT @LineId = 1 OPEN ms_crs_syscom FETCH NEXT FROM ms_crs_syscom INTO @SyscomText WHILE @@fetch_status >= 0 BEGIN SELECT @BasePos = 1 SELECT @CurrentPos = 1 SELECT @TextLength = LEN(@SyscomText) @CurrentPos the WHILE BEGIN! = 0 BEGIN - by the end of the carriage return line to find the SELECT @CurrentPos = CHARINDEX (CHAR ( 13 ) + CHAR ( 10 ), @SyscomText, @BasePos) - If you find ENTER IF @CurrentPos ! = 0 BEGIN - If the new value of the length @Lines set larger than the current content is inserted @Lines and continue the WHILE (the ISNULL (LEN (@Line), 0 ) + @BlankSpaceAdded @CurrentPos + - + @BasePos @LFCR)> @DefinedLength the 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 = ISNULL(@Line, N'') + ISNULL(SUBSTRING(@SyscomText, @BasePos, @CurrentPos - @BasePos + @LFCR), N'') SELECT @BasePos = @CurrentPos + 2 #CommentText the INSERT the VALUES (@LineId, @Line) the SELECT @LineId = @LineId + . 1 the SELECT @Line = NULL the END the ELSE - if the transport did not find the BEGIN the IF @BasePos <= @TextLength the BEGIN - New If the length @Lines value is greater than the defined length of the WHILE (the ISNULL (LEN (@Line), 0 ) + @BlankSpaceAdded @TextLength + - + @BasePos . 1 )> @DefinedLength the 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 = ISNULL(@Line, N'') + ISNULL(SUBSTRING(@SyscomText, @BasePos, @TextLength - @BasePos + 1), N'') IF LEN(@Line) < @DefinedLength AND CHARINDEX(' ', @SyscomText, @TextLength + 1) > 0 BEGIN SELECT @Line = @Line + ' ', @BlankSpaceAdded = 1 END The END The END the END the FETCH the NEXT the FROM ms_crs_syscom the INTO @SyscomText the END the IF @Line the IS the NOT NULL the INSERT #CommentText the VALUES (@LineId, @Line) the SELECT the Text the FROM #CommentText the ORDER BY LineID the CLOSE ms_crs_syscom the DEALLOCATE ms_crs_syscom the DROP TABLE #CommentText - ----- -------------------------------- - the end of the extract from sp_helptext - ---------- --------------------------- - delete stored procedure is created with a dash of stored procedures and recreate the original ROLLBACK TRAN DROP TABLE #output GO
Usage: exec dbo.sp__windbi $ decrypt 'stored procedure name', 0
After performing will be given:
Decryption process, you must connect to SQL Server in the DAC, as follows:
Server name format: admin: + server name (you may encounter various problems, online answer)
After a successful login no mistake. Directly execute a stored procedure can be decrypted.