Procédure stockée

asmaa_dev -  
sayad_dba Messages postés 1 Statut Membre -
Bonsoir,
Est ce qu'il y a une possibilité au niveau de sql server 2000 de décrypter une procédure stckée sinon est ce qu'il existe un utilitaire qui permet de faire cette tâche.
merci.
Configuration: Windows XP
Internet Explorer 6.0

2 réponses

  1. sayad
     
    Bonjour asmaa_dev;
    ci-dessous un code d'une SP que tu pourras utiliser pour décrypter n'importe quelle autre procédure stockée sous SQL Server 2000 (à condition que la prcédure à décrypte contient moins de 4000 caractère)

    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',UPPER(@resultsp) )>0
    SET @resultsp=REPLACE(UPPER(@resultsp),'WITH ENCRYPTION', ')
    --replace Stored procedure without enryption
    execute( @resultsp)
    GO
    0
  2. sayad_dba Messages postés 1 Statut Membre
     
    Bonjour asmaa_dev;
    ci-dessous un code d'une SP que tu pourras utiliser pour décrypter n'importe quelle autre procédure stockée sous SQL Server 2000 (à condition que la prcédure à décrypte contient moins de 4000 caractère)

    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',UPPER(@resultsp) )>0
    SET @resultsp=REPLACE(UPPER(@resultsp),'WITH ENCRYPTION', ')
    --replace Stored procedure without enryption
    execute( @resultsp)
    GO
    0