1if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_decrypt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
2drop procedure [dbo].[sp_decrypt]
3GO
4
5/*--破解函数,过程,触发器,视图.仅限于SQLSERVER2000
6
7--作者:J9988--*/
8/*--调用示例
9
10 --解密指定存储过程
11 exec sp_decrypt 'AppSP_test'
12
13 --对所有的存储过程解密
14 declare tb cursor for
15 select name from sysobjects where xtype='P' and status>0 and name<>'sp_decrypt'
16
17 declare @name sysname
18 open tb
19 fetch next from tb into @name
20 while @@fetch_status=0
21 begin
22 print '/*-------存储过程 ['+@name+'] -----------*/'
23 exec sp_decrypt @name
24 fetch next from tb into @name
25 end
26 close tb
27 deallocate tb
28--*/
29
30if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SP_DECRYPT]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
31 drop procedure [dbo].[SP_DECRYPT]
32GO
33
34CREATE PROCEDURE sp_decrypt(@objectName varchar(50))
35AS
36begin
37set nocount on
38--CSDN:j9988 copyright:2004.04.15
39--V3.1
40--破解字节不受限制,适用于SQLSERVER2000存储过程,函数,视图,触发器
41--修正上一版视图触发器不能正确解密错误
42--发现有错,请E_MAIL:CSDNj9988@tom.com
43begin tran
44declare @objectname1 varchar(100),@orgvarbin varbinary(8000)
45declare @sql1 nvarchar(4000),@sql2 varchar(8000),@sql3 nvarchar(4000),@sql4 nvarchar(4000)
46DECLARE @OrigSpText1 nvarchar(4000), @OrigSpText2 nvarchar(4000) , @OrigSpText3 nvarchar(4000), @resultsp nvarchar(4000)
47declare @i int,@status int,@type varchar(10),@parentid int
48declare @colid int,@n int,@q int,@j int,@k int,@encrypted int,@number int
49select @type=xtype,@parentid=parent_obj from sysobjects where id=object_id(@ObjectName)
50
51create table #temp(number int,colid int,ctext varbinary(8000),encrypted int,status int)
52insert #temp SELECT number,colid,ctext,encrypted,status FROM syscomments WHERE id = object_id(@objectName)
53select @number=max(number) from #temp
54set @k=0
55
56while @k<=@number
57begin
58if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)
59begin
60if @type='P'
61set @sql1=(case when @number>1 then 'ALTER PROCEDURE '+ @objectName +';'+rtrim(@k)+' WITH ENCRYPTION AS '
62 else 'ALTER PROCEDURE '+ @objectName+' WITH ENCRYPTION AS '
63 end)
64
65if @type='TR'
66begin
67declare @parent_obj varchar(255),@tr_parent_xtype varchar(10)
68select @parent_obj=parent_obj from sysobjects where id=object_id(@objectName)
69select @tr_parent_xtype=xtype from sysobjects where id=@parent_obj
70if @tr_parent_xtype='V'
71begin
72set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTERD OF INSERT AS PRINT 1 '
73end
74else
75begin
76set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 '
77end
78
79end
80if @type='FN' or @type='TF' or @type='IF'
81set @sql1=(case @type when 'TF' then
82'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end '
83when 'FN' then
84'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end'
85when 'IF' then
86'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a'
87end)
88
89if @type='V'
90set @sql1='ALTER VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f'
91
92set @q=len(@sql1)
93set @sql1=@sql1+REPLICATE('-',4000-@q)
94select @sql2=REPLICATE('-',8000)
95set @sql3='exec(@sql1'
96select @colid=max(colid) from #temp where number=@k
97set @n=1
98while @n<=CEILING(1.0*(@colid-1)/2) and len(@sQL3)<=3996
99begin
100set @sql3=@sql3+'+@'
101set @n=@n+1
102end
103set @sql3=@sql3+')'
104exec sp_executesql @sql3,N'@sql1 nvarchar(4000),@ varchar(8000)',@sql1=@sql1,@=@sql2
105
106end
107set @k=@k+1
108end
109
110set @k=0
111while @k<=@number
112begin
113
114if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)
115begin
116select @colid=max(colid) from #temp where number=@k
117set @n=1
118
119while @n<=@colid
120begin
121select @OrigSpText1=ctext,@encrypted=encrypted,@status=status FROM #temp WHERE colid=@n and number=@k
122
123SET @OrigSpText3=(SELECT ctext FROM syscomments WHERE id=object_id(@objectName) and colid=@n and number=@k)
124if @n=1
125begin
126if @type='P'
127SET @OrigSpText2=(case when @number>1 then 'CREATE PROCEDURE '+ @objectName +';'+rtrim(@k)+' WITH ENCRYPTION AS '
128 else 'CREATE PROCEDURE '+ @objectName +' WITH ENCRYPTION AS '
129 end)
130
131
132if @type='FN' or @type='TF' or @type='IF'
133SET @OrigSpText2=(case @type when 'TF' then
134'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end '
135when 'FN' then
136'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end'
137when 'IF' then
138'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a'
139end)
140
141if @type='TR'
142begin
143
144if @tr_parent_xtype='V'
145begin
146set @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTEAD OF INSERT AS PRINT 1 '
147end
148else
149begin
150set @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 '
151end
152
153end
154
155if @type='V'
156set @OrigSpText2='CREATE VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f'
157
158set @q=4000-len(@OrigSpText2)
159set @OrigSpText2=@OrigSpText2+REPLICATE('-',@q)
160end
161else
162begin
163SET @OrigSpText2=REPLICATE('-', 4000)
164end
165SET @i=1
166
167SET @resultsp = replicate(N'A', (datalength(@OrigSpText1) / 2))
168
169WHILE @i<=datalength(@OrigSpText1)/2
170BEGIN
171
172SET @resultsp = stuff(@resultsp, @i, 1, NCHAR(UNICODE(substring(@OrigSpText1, @i, 1)) ^
173 (UNICODE(substring(@OrigSpText2, @i, 1)) ^
174 UNICODE(substring(@OrigSpText3, @i, 1)))))
175 SET @i=@i+1
176END
177set @orgvarbin=cast(@OrigSpText1 as varbinary(8000))
178set @resultsp=(case when @encrypted=1
179 then @resultsp
180 else convert(nvarchar(4000),case when @status&2=2 then uncompress(@orgvarbin) else @orgvarbin end)
181 end)
182print @resultsp
183
184set @n=@n+1
185
186end
187
188end
189set @k=@k+1
190end
191
192drop table #temp
193rollback tran
194end
195
2drop procedure [dbo].[sp_decrypt]
3GO
4
5/*--破解函数,过程,触发器,视图.仅限于SQLSERVER2000
6
7--作者:J9988--*/
8/*--调用示例
9
10 --解密指定存储过程
11 exec sp_decrypt 'AppSP_test'
12
13 --对所有的存储过程解密
14 declare tb cursor for
15 select name from sysobjects where xtype='P' and status>0 and name<>'sp_decrypt'
16
17 declare @name sysname
18 open tb
19 fetch next from tb into @name
20 while @@fetch_status=0
21 begin
22 print '/*-------存储过程 ['+@name+'] -----------*/'
23 exec sp_decrypt @name
24 fetch next from tb into @name
25 end
26 close tb
27 deallocate tb
28--*/
29
30if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SP_DECRYPT]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
31 drop procedure [dbo].[SP_DECRYPT]
32GO
33
34CREATE PROCEDURE sp_decrypt(@objectName varchar(50))
35AS
36begin
37set nocount on
38--CSDN:j9988 copyright:2004.04.15
39--V3.1
40--破解字节不受限制,适用于SQLSERVER2000存储过程,函数,视图,触发器
41--修正上一版视图触发器不能正确解密错误
42--发现有错,请E_MAIL:CSDNj9988@tom.com
43begin tran
44declare @objectname1 varchar(100),@orgvarbin varbinary(8000)
45declare @sql1 nvarchar(4000),@sql2 varchar(8000),@sql3 nvarchar(4000),@sql4 nvarchar(4000)
46DECLARE @OrigSpText1 nvarchar(4000), @OrigSpText2 nvarchar(4000) , @OrigSpText3 nvarchar(4000), @resultsp nvarchar(4000)
47declare @i int,@status int,@type varchar(10),@parentid int
48declare @colid int,@n int,@q int,@j int,@k int,@encrypted int,@number int
49select @type=xtype,@parentid=parent_obj from sysobjects where id=object_id(@ObjectName)
50
51create table #temp(number int,colid int,ctext varbinary(8000),encrypted int,status int)
52insert #temp SELECT number,colid,ctext,encrypted,status FROM syscomments WHERE id = object_id(@objectName)
53select @number=max(number) from #temp
54set @k=0
55
56while @k<=@number
57begin
58if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)
59begin
60if @type='P'
61set @sql1=(case when @number>1 then 'ALTER PROCEDURE '+ @objectName +';'+rtrim(@k)+' WITH ENCRYPTION AS '
62 else 'ALTER PROCEDURE '+ @objectName+' WITH ENCRYPTION AS '
63 end)
64
65if @type='TR'
66begin
67declare @parent_obj varchar(255),@tr_parent_xtype varchar(10)
68select @parent_obj=parent_obj from sysobjects where id=object_id(@objectName)
69select @tr_parent_xtype=xtype from sysobjects where id=@parent_obj
70if @tr_parent_xtype='V'
71begin
72set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTERD OF INSERT AS PRINT 1 '
73end
74else
75begin
76set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 '
77end
78
79end
80if @type='FN' or @type='TF' or @type='IF'
81set @sql1=(case @type when 'TF' then
82'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end '
83when 'FN' then
84'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end'
85when 'IF' then
86'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a'
87end)
88
89if @type='V'
90set @sql1='ALTER VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f'
91
92set @q=len(@sql1)
93set @sql1=@sql1+REPLICATE('-',4000-@q)
94select @sql2=REPLICATE('-',8000)
95set @sql3='exec(@sql1'
96select @colid=max(colid) from #temp where number=@k
97set @n=1
98while @n<=CEILING(1.0*(@colid-1)/2) and len(@sQL3)<=3996
99begin
100set @sql3=@sql3+'+@'
101set @n=@n+1
102end
103set @sql3=@sql3+')'
104exec sp_executesql @sql3,N'@sql1 nvarchar(4000),@ varchar(8000)',@sql1=@sql1,@=@sql2
105
106end
107set @k=@k+1
108end
109
110set @k=0
111while @k<=@number
112begin
113
114if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)
115begin
116select @colid=max(colid) from #temp where number=@k
117set @n=1
118
119while @n<=@colid
120begin
121select @OrigSpText1=ctext,@encrypted=encrypted,@status=status FROM #temp WHERE colid=@n and number=@k
122
123SET @OrigSpText3=(SELECT ctext FROM syscomments WHERE id=object_id(@objectName) and colid=@n and number=@k)
124if @n=1
125begin
126if @type='P'
127SET @OrigSpText2=(case when @number>1 then 'CREATE PROCEDURE '+ @objectName +';'+rtrim(@k)+' WITH ENCRYPTION AS '
128 else 'CREATE PROCEDURE '+ @objectName +' WITH ENCRYPTION AS '
129 end)
130
131
132if @type='FN' or @type='TF' or @type='IF'
133SET @OrigSpText2=(case @type when 'TF' then
134'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns @b table(a varchar(10)) with encryption as begin insert @b select @a return end '
135when 'FN' then
136'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end'
137when 'IF' then
138'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a'
139end)
140
141if @type='TR'
142begin
143
144if @tr_parent_xtype='V'
145begin
146set @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTEAD OF INSERT AS PRINT 1 '
147end
148else
149begin
150set @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 '
151end
152
153end
154
155if @type='V'
156set @OrigSpText2='CREATE VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f'
157
158set @q=4000-len(@OrigSpText2)
159set @OrigSpText2=@OrigSpText2+REPLICATE('-',@q)
160end
161else
162begin
163SET @OrigSpText2=REPLICATE('-', 4000)
164end
165SET @i=1
166
167SET @resultsp = replicate(N'A', (datalength(@OrigSpText1) / 2))
168
169WHILE @i<=datalength(@OrigSpText1)/2
170BEGIN
171
172SET @resultsp = stuff(@resultsp, @i, 1, NCHAR(UNICODE(substring(@OrigSpText1, @i, 1)) ^
173 (UNICODE(substring(@OrigSpText2, @i, 1)) ^
174 UNICODE(substring(@OrigSpText3, @i, 1)))))
175 SET @i=@i+1
176END
177set @orgvarbin=cast(@OrigSpText1 as varbinary(8000))
178set @resultsp=(case when @encrypted=1
179 then @resultsp
180 else convert(nvarchar(4000),case when @status&2=2 then uncompress(@orgvarbin) else @orgvarbin end)
181 end)
182print @resultsp
183
184set @n=@n+1
185
186end
187
188end
189set @k=@k+1
190end
191
192drop table #temp
193rollback tran
194end
195