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

5
/*--破解函数,过程,触发器,视图.仅限于SQLSERVER20006

7
--作者:J9988--*/8
/*--调用示例9

10
--解密指定存储过程11
exec sp_decrypt 'AppSP_test'12

13
--对所有的存储过程解密14
declare tb cursor for15
select name from sysobjects where xtype='P' and status>0 and name<>'sp_decrypt'16
17
declare @name sysname18
open tb19
fetch next from tb into @name20
while @@fetch_status=021
begin22
print '/*-------存储过程 ['+@name+'] -----------*/'23
exec sp_decrypt @name24
fetch next from tb into @name25
end26
close tb27
deallocate tb28
--*/29

30
if 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]32
GO33

34
CREATE PROCEDURE sp_decrypt(@objectName varchar(50))35
AS36
begin37
set nocount on38
--CSDN:j9988 copyright:2004.04.15 39
--V3.1 40
--破解字节不受限制,适用于SQLSERVER2000存储过程,函数,视图,触发器41
--修正上一版视图触发器不能正确解密错误42
--发现有错,请E_MAIL:CSDNj9988@tom.com43
begin tran44
declare @objectname1 varchar(100),@orgvarbin varbinary(8000)45
declare @sql1 nvarchar(4000),@sql2 varchar(8000),@sql3 nvarchar(4000),@sql4 nvarchar(4000)46
DECLARE @OrigSpText1 nvarchar(4000), @OrigSpText2 nvarchar(4000) , @OrigSpText3 nvarchar(4000), @resultsp nvarchar(4000)47
declare @i int,@status int,@type varchar(10),@parentid int48
declare @colid int,@n int,@q int,@j int,@k int,@encrypted int,@number int49
select @type=xtype,@parentid=parent_obj from sysobjects where id=object_id(@ObjectName)50

51
create table #temp(number int,colid int,ctext varbinary(8000),encrypted int,status int)52
insert #temp SELECT number,colid,ctext,encrypted,status FROM syscomments WHERE id = object_id(@objectName)53
select @number=max(number) from #temp54
set @k=055

56
while @k<=@number 57
begin58
if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)59
begin60
if @type='P'61
set @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

65
if @type='TR'66
begin67
declare @parent_obj varchar(255),@tr_parent_xtype varchar(10)68
select @parent_obj=parent_obj from sysobjects where id=object_id(@objectName)69
select @tr_parent_xtype=xtype from sysobjects where id=@parent_obj70
if @tr_parent_xtype='V'71
begin72
set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTERD OF INSERT AS PRINT 1 '73
end74
else75
begin76
set @sql1='ALTER TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 '77
end78

79
end80
if @type='FN' or @type='TF' or @type='IF'81
set @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 '83
when 'FN' then84
'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end'85
when 'IF' then86
'ALTER FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a'87
end)88

89
if @type='V'90
set @sql1='ALTER VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f'91

92
set @q=len(@sql1)93
set @sql1=@sql1+REPLICATE('-',4000-@q)94
select @sql2=REPLICATE('-',8000)95
set @sql3='exec(@sql1'96
select @colid=max(colid) from #temp where number=@k 97
set @n=198
while @n<=CEILING(1.0*(@colid-1)/2) and len(@sQL3)<=399699
begin 100
set @sql3=@sql3+'+@'101
set @n=@n+1102
end103
set @sql3=@sql3+')'104
exec sp_executesql @sql3,N'@sql1 nvarchar(4000),@ varchar(8000)',@sql1=@sql1,@=@sql2105

106
end107
set @k=@k+1108
end109

110
set @k=0111
while @k<=@number 112
begin113

114
if exists(select 1 from syscomments where id=object_id(@objectname) and number=@k)115
begin116
select @colid=max(colid) from #temp where number=@k 117
set @n=1118

119
while @n<=@colid120
begin121
select @OrigSpText1=ctext,@encrypted=encrypted,@status=status FROM #temp WHERE colid=@n and number=@k122

123
SET @OrigSpText3=(SELECT ctext FROM syscomments WHERE id=object_id(@objectName) and colid=@n and number=@k)124
if @n=1125
begin126
if @type='P'127
SET @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

132
if @type='FN' or @type='TF' or @type='IF'133
SET @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 '135
when 'FN' then136
'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns char(1) with encryption as begin return @a end'137
when 'IF' then138
'CREATE FUNCTION '+ @objectName+'(@a char(1)) returns table with encryption as return select @a as a'139
end)140

141
if @type='TR' 142
begin143

144
if @tr_parent_xtype='V'145
begin146
set @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION INSTEAD OF INSERT AS PRINT 1 '147
end148
else149
begin150
set @OrigSpText2='CREATE TRIGGER '+@objectname+' ON '+OBJECT_NAME(@parentid)+' WITH ENCRYPTION FOR INSERT AS PRINT 1 '151
end152

153
end154

155
if @type='V'156
set @OrigSpText2='CREATE VIEW '+@objectname+' WITH ENCRYPTION AS SELECT 1 as f'157

158
set @q=4000-len(@OrigSpText2)159
set @OrigSpText2=@OrigSpText2+REPLICATE('-',@q)160
end161
else162
begin163
SET @OrigSpText2=REPLICATE('-', 4000)164
end165
SET @i=1166

167
SET @resultsp = replicate(N'A', (datalength(@OrigSpText1) / 2))168

169
WHILE @i<=datalength(@OrigSpText1)/2170
BEGIN171

172
SET @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+1176
END177
set @orgvarbin=cast(@OrigSpText1 as varbinary(8000))178
set @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)182
print @resultsp183

184
set @n=@n+1185

186
end187

188
end189
set @k=@k+1190
end191

192
drop table #temp193
rollback tran194
end195

