国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

Decrypt encrypted stored procedures

2024-07-21 02:09:11
字體:
供稿:網(wǎng)友

http://searchdatabase.techtarget.com/tip/1,289483,sid13_gci837799,00.html



this sp will decrypt stored procedures, views or triggers that were encrypted using "with encryption". it is adapted from a script by joseph gama and shoeboy. there are two versions: one for sp's only and the other one for sp's, triggers and views. for version 1, the input is object name (stored procedure, view or trigger), and for version 2, the input is object name (stored procedure, view or trigger), object type ('t'-trigger, 'p'-stored procedure or 'v'-view). from planetsourcecode.com.


create procedure sp_decrypt_sp (@objectname varchar(50))asdeclare @origsptext1 nvarchar(4000), @origsptext2 nvarchar(4000) , @origsptext3 nvarchar(4000), @resultsp nvarchar(4000)declare @i int , @t bigint--get encrypted dataset @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 counterset @i=1--fill temporary variableset @resultsp = replicate(n'a', (datalength(@origsptext1) / 2))--loopwhile @i<=datalength(@origsptext1)/2begin--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 @[email protected]+1end--drop original spexecute ('drop procedure '+ @objectname)--remove encryption--preserve caseset @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 enryptionexecute( @resultsp)go



reader feedback


joakim m. writes: i tried this script with mixed results. it works for some encrypted procedures, but for others i get error meassages like:

server: msg 512, level 16, state 1, procedure sp_decrypt_sp, line 7.subquery returned more than 1 value. this is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

karl c writes: i got the same message as joakim m. but upon further investigation i found that this happens only when stored procedures exceed 4000 characters. when this happens, sql server stores the procedure across multiple rows so you get the error 'subquery returne more than 1 row'. to get around that you can change the statement

select ctext from syscomments where id = object_id(@objectnameto select top 1 ctext from syscomments where id = object_id(@objectname order by colid

that will get you the first part of the stored procedure, which can't be created because it is missing the end part and is not a valid syntax but you can print @resultsp out to see it.

for more information

feedback: e-mail the editor with your thoughts about this tip. more tips: hundreds of free sql server tips and scripts. tip contest: have a sql server tip to offer your fellow dbas and developers? the best tips submitted will receive a cool prize -- submit your tip today! best web links: sql server tips, tutorials, scripts, and more. forums: ask your technical sql server questions--or help out your peers by answering them--in our active forums. ask the experts: our sql, database design, oracle, sql server, db2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 余干县| 阿坝县| 舒城县| 博罗县| 新安县| 和平县| 涡阳县| 县级市| 潢川县| 商南县| 民和| 淅川县| 望谟县| 昌吉市| 临颍县| 临清市| 新民市| 德令哈市| 叙永县| 神农架林区| 舞阳县| 鄯善县| 苏州市| 呈贡县| 大石桥市| 余姚市| 沅陵县| 罗平县| 古蔺县| 全州县| 资中县| 金沙县| 合川市| 射阳县| 大庆市| 贺州市| 介休市| 淮南市| 高邮市| 宜兴市| 尚义县|