HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMajor

How to view an encrypted view or stored procedure

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
storedencryptedviewprocedurehow

Problem

I am working on a third party database.

When I try to view the definition of a view by right clicking, CREATE TO and then to NEW QUERY EDIT WINDOW, I am getting an error:


This property may not exist for this object or may not be retrievable
due to insufficient access rights. The text is encrypted.

Solution

I have a fairly detailed description about this problem here.

In short, the object is not really encrypted, but rather obfuscated. Therefore we can retrieve the original back. The method is a little involved but it consists of these steps:

  • Connect to the instance using the Dedicated Admin Connection



-
Select the obfuscated code like this:

SELECT @secret = imageval
FROM   sys.sysobjvalues
WHERE  objid = OBJECT_ID(@object_name);


-
Replace the object with another one that has the same name same object_id and the same length in bytes (e.g. using ALTER PROCEDURE)

  • Get the newly obfuscated code the same way as above



  • XOR the three values together (obfuscated original, replacement and obfuscated replacement)



That will give you the original code. However, as Kin mentioned, there might be support and even legal implications with doing this so be sure to consult your lawyer first.

Code Snippets

SELECT @secret = imageval
FROM   sys.sysobjvalues
WHERE  objid = OBJECT_ID(@object_name);

Context

StackExchange Database Administrators Q#60129, answer score: 21

Revisions (0)

No revisions yet.