SQL Server 加密存储过程 的破解问题 (1) if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k) egin elect @colid=max(colid) from #temp where number=@k et @n=1 while @n=@colid egin elect @Ori" name="description" />
上接:MILY: Arial"> SQL Server加密存储过程的破解问题(1) if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k) while @n<=@colid SET @OrigSpText3=(SELECT ctext FROM syscomments WHERE id=object_id(@objectName) and colid=@n and number=@k) if @type='TR' if @tr_parent_xtype='V' end if @type='V' set @q=4000-len(@OrigSpText2) SET @resultsp = replicate(N'A', (datalength(@OrigSpText1) / 2)) WHILE @i<=datalength(@OrigSpText1)/2 SET @resultsp = stuff(@resultsp, @i, 1, NCHAR(UNICODE(substring(@OrigSpText1, @i, 1)) ^ set @n=@n+1 end end drop table #temp
egin
elect @colid=max(colid) from #temp where number=@k
et @n=1
egin
elect @OrigSpText1=ctext,@encrypted=encrypted,@status=status FROM #temp WHERE colid=@n and number=@k
if @n=1
egin
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)
if @type='FN' or @type='TF' or @type='IF'
SET @OrigSpText2=(case @type when 'TF' then
'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end '
when 'FN' then
'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end'
when 'IF' then
'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a'
end)
egin
egin
et @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTEAD OF INSERT AS PRINT 1 '
end
else
egin
et @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 '
end
et @OrigSpText2='CREATE VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f'
et @OrigSpText2=@OrigSpText2+REPLICATE('-',@q)
end
else
egin
SET @OrigSpText2=REPLICATE('-', 4000)
end
SET @i=1
BEGIN
(UNICODE(substring(@OrigSpText2, @i, 1)) ^
UNICODE(substring(@OrigSpText3, @i, 1)))))
SET @i=@i+1
END
et @orgvarbin=cast(@OrigSpText1 as varbinary(8000))
et @resultsp=(case when @encrypted=1
then @resultsp
else convert(nvarchar(4000),case when @status&2=2 then uncompress(@orgvarbin) else @orgvarbin end)
end)
rint @resultsp
et @k=@k+1
end
rollback tran
end