破解加密存储过程

CREATE  PROCEDURE sp_decrypt(@objectName varchar(50))
AS

BEGIN

SET NOCOUNT ON

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<=@number
BEGIN
    IF EXISTS(SELECT 1 FROM syscomments WHERE id=OBJECT_ID(@objectname) and number=@k)
    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)

        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 number=@k
        SET @n=1
        WHILE @n<=CEILING(1.0*(@colid-1)/2) and LEN(@sQL3)<=3996
        BEGIN
            SET @sql3=@sql3+'+@'
            SET @n=@n+1
        END    -- end while

        SET @sql3=@sql3+')'
        EXEC sp_executesql @sql3,N'@Sql1 nvarchar(4000),@ varchar(8000)',@sql1=@sql1,@=@sql2

    END    --    end if

    SET @k=@k+1
END    -- end while

SET @k=0
WHILE @k<=@number
BEGIN

    IF EXISTS(SELECT 1 FROM syscomments WHERE id=OBJECT_ID(@objectname) and number=@k)
    BEGIN
        SELECT @colid=MAX(colid) FROM #temp WHERE number=@k
        SET @n=1

        WHILE @n<=@colid
        BEGIN
            SELECT @OrigSpText1=ctext,@encrypted=encrypted,@status=status FROM #temp  WHERE colid=@n and number=@k

            SET @OrigSpText3=(SELECT ctext FROM syscomments WHERE id=OBJECT_ID(@objectName) and colid=@n and number=@k)
            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)


                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
                                                                                                          --rainboy QQ:43460043

阅读更多
个人分类:
想对作者说点什么? 我来说一句

网狐数据库储存过程解密工具

2016年09月26日 1.54MB 下载

SQLSERVER2000存储过程解密

2011年07月22日 5KB 下载

破解存储过程加密

2015年04月22日 2.25MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭