Managing WRAP PL/SQL
---------------------
Toad->Wrap Utility
1. Create a script file with extension of .sql and containing functions, procedures, packages and triggers.
2. cmd>wrap iname=c:\script.sql oname=c:\wrap_script.plb –create wrapped script file
3. cmd>wrap iname=c:\script.sql –create wrapped script file
4. SQL>@c:\wrap_script.plb –execute wrapped script file, stored procedures will be created
5. begin call_stored_procedure_name; end; call/execute stored procedure
Note: Wrap is irreversible.
Protect the Code at Source: WRAP Package
----------------------------------------
PL/SQL program units often contain very sensitive and confidential information about company procedures and trade secrets, which makes them a protected entity group, similar to tables. To prevent unauthorized viewing of the source code, the programs are often obfuscated using the wrap command line utility.
You can invoke wrap only after the PL/SQL script is created; the utility creates a wrapped file from the input clear text. However, in some cases you may want to generate the wrapper dynamically inside PL/SQL code. In such a case, the wrap utility can't be invoked because no source file exists yet.
Thankfully, Oracle Database 10g Release 2 provides a supplied package that you can use to create the code in a wrapped format. This package complements, not replaces, the wrap utility. The latter is still appropriate in cases where you want to wrap a large number of source files quickly using a command line option.
For instance, imagine that you want to create the simple procedure p1 in wrapped format.
create or replace procedure p1 as
begin
null;
end;
Inside the PL/SQL unit, you can create it dynamically but in wrapped format with:
begin
dbms_ddl.create_wrapped
('create or replace procedure p1 as begin null; end;')
end;
/
Now you want to confirm the wrapped procedure. You can select the source text from the dictionary.
SQL> select text from user_source where name = 'P1';
Sometimes you may have a slightly different requirement; you may decide to generate the PL/SQL code but not create the procedure, for example.
In that case, you may save it in a file or table to be executed later. But because the above approach creates the procedure, it won't work here.
Rather, you need to call another function in the package:
SQL> select dbms_ddl.wrap
2 ('create or replace procedure p1 as begin null; end;')
3 from dual
4 /
If you have a large file of source code then use a supplied datatype: varchar2s in the package DBMS_SQL.
1 declare
2 l_input_code dbms_sql.varchar2s;
3 begin
4 l_input_code (1) := 'Array to hold the MYPROC';
5 l_input_code (2) := 'create or replace procedure myproc as ';
6 l_input_code (3) := ' l_key VARCHAR2(200);';
7 l_input_code (4) := 'begin ';
8 l_input_code (5) := ' l_key := ''ARUPNANDA'';';
9 l_input_code (6) := 'end;';
10 l_input_code (7) := 'the end';
11 sys.dbms_ddl.create_wrapped (
12 ddl => l_input_code,
13 lb => 2,
14 ub => 6
15 );
16* end;
In reality, you may be forced to use quite long lines,up to 32KB in size.
To let the wrapping work on only the valid lines, I have specified the lowest (2) and highest elements (6) of the collection that stores our code in lines 13 and 14. The parameter LB shows the lower bound of the array, which is 2 in our example, and HB, the higher bound (6).
WRAP Utility for procedure/function and pakage body etc.
--------------------------------------------------------
1. Create a script file for a package specification i.e. misc.sql
2. Create a second script file for a package body i.e. misc_body.sql
3. cmd>cd oracle\product\10.2.0\db_1\BIN>wrap iname=c:\misc_body.sql oname=c:\misc_body.sql
4. It will create a decoded version of your script or code which is not convertable back to
text file so be careful.
Wrap utility with function
--------------------------
Create a script of this function and save it on C drive.
c:\wrap iname=c:\myfunction.sql
References:
http://oracle-base.com/articles/10g/wrap-and-dbms_ddl-10gr2.php
---------------------
Toad->Wrap Utility
1. Create a script file with extension of .sql and containing functions, procedures, packages and triggers.
2. cmd>wrap iname=c:\script.sql oname=c:\wrap_script.plb –create wrapped script file
3. cmd>wrap iname=c:\script.sql –create wrapped script file
4. SQL>@c:\wrap_script.plb –execute wrapped script file, stored procedures will be created
5. begin call_stored_procedure_name; end; call/execute stored procedure
Note: Wrap is irreversible.
Protect the Code at Source: WRAP Package
----------------------------------------
PL/SQL program units often contain very sensitive and confidential information about company procedures and trade secrets, which makes them a protected entity group, similar to tables. To prevent unauthorized viewing of the source code, the programs are often obfuscated using the wrap command line utility.
You can invoke wrap only after the PL/SQL script is created; the utility creates a wrapped file from the input clear text. However, in some cases you may want to generate the wrapper dynamically inside PL/SQL code. In such a case, the wrap utility can't be invoked because no source file exists yet.
Thankfully, Oracle Database 10g Release 2 provides a supplied package that you can use to create the code in a wrapped format. This package complements, not replaces, the wrap utility. The latter is still appropriate in cases where you want to wrap a large number of source files quickly using a command line option.
For instance, imagine that you want to create the simple procedure p1 in wrapped format.
create or replace procedure p1 as
begin
null;
end;
Inside the PL/SQL unit, you can create it dynamically but in wrapped format with:
begin
dbms_ddl.create_wrapped
('create or replace procedure p1 as begin null; end;')
end;
/
Now you want to confirm the wrapped procedure. You can select the source text from the dictionary.
SQL> select text from user_source where name = 'P1';
Sometimes you may have a slightly different requirement; you may decide to generate the PL/SQL code but not create the procedure, for example.
In that case, you may save it in a file or table to be executed later. But because the above approach creates the procedure, it won't work here.
Rather, you need to call another function in the package:
SQL> select dbms_ddl.wrap
2 ('create or replace procedure p1 as begin null; end;')
3 from dual
4 /
If you have a large file of source code then use a supplied datatype: varchar2s in the package DBMS_SQL.
1 declare
2 l_input_code dbms_sql.varchar2s;
3 begin
4 l_input_code (1) := 'Array to hold the MYPROC';
5 l_input_code (2) := 'create or replace procedure myproc as ';
6 l_input_code (3) := ' l_key VARCHAR2(200);';
7 l_input_code (4) := 'begin ';
8 l_input_code (5) := ' l_key := ''ARUPNANDA'';';
9 l_input_code (6) := 'end;';
10 l_input_code (7) := 'the end';
11 sys.dbms_ddl.create_wrapped (
12 ddl => l_input_code,
13 lb => 2,
14 ub => 6
15 );
16* end;
In reality, you may be forced to use quite long lines,up to 32KB in size.
To let the wrapping work on only the valid lines, I have specified the lowest (2) and highest elements (6) of the collection that stores our code in lines 13 and 14. The parameter LB shows the lower bound of the array, which is 2 in our example, and HB, the higher bound (6).
WRAP Utility for procedure/function and pakage body etc.
--------------------------------------------------------
1. Create a script file for a package specification i.e. misc.sql
2. Create a second script file for a package body i.e. misc_body.sql
3. cmd>cd oracle\product\10.2.0\db_1\BIN>wrap iname=c:\misc_body.sql oname=c:\misc_body.sql
4. It will create a decoded version of your script or code which is not convertable back to
text file so be careful.
Wrap utility with function
--------------------------
Create a script of this function and save it on C drive.
c:\wrap iname=c:\myfunction.sql
References:
http://oracle-base.com/articles/10g/wrap-and-dbms_ddl-10gr2.php
No comments:
Post a Comment