The WRAP Utility and the DBMS_DDL Package

On occasion it is necessary to hide (obfuscate) your PL/SQL source code. Traditionally this has been done using the WRAP utility, but Oracle 10g Release 2 also allows this to be done dynamically using the DBMS_DDLpackage. This article presents examples of both methods of PL/SQL source obfuscation.

The WRAP Utility

The wrap utility is a command line utility that obfuscates the contents of a PL/SQL source file. The syntax for the wrap utility is shown below.

wrap iname=input_file [oname=output_file]

The iname parameter specifies the source file, while the oname parameter specifies the destination file. If the destination file is not specified it defaults to the source file name with a ".pld" extension.

To see how the wrap utility works we must create a dummy source file called get_date_string.sql with the following contents.

CREATE OR REPLACE FUNCTION get_date_string RETURN VARCHAR2 AS
BEGIN
RETURN TO_CHAR(SYSDATE, 'DD-MON-YYYY');
END get_date_string;
/

We can then run the two variants of the wrap utility, specifying our source file.

wrap iname=get_date_string.sql

PL/SQL Wrapper: Release 10.2.0.1.0- Production on Wed Oct 05 10:54:14 2005

Copyright (c) 1993, 2004, Oracle.  All rights reserved.

Processing get_date_string.sql to get_date_string.plb

wrap iname=get_date_string.sql oname=get_date_string_wrap.sql

PL/SQL Wrapper: Release 10.2.0.1.0- Production on Wed Oct 05 10:55:01 2005

Copyright (c) 1993, 2004, Oracle.  All rights reserved.

Processing get_date_string.sql to /tmp/get_date_string_wrap.sql

Notice that the output file name is defaulted as expected when it is not specified on the command line. The resulting output files contain the wrapped code which is listed below.

CREATE OR REPLACE FUNCTION get_date_string wrapped
a000000
b2
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
71 ae
P29RDhRZX0orO0ED/mMF8i12Glkwg8eZgcfLCNL+XlquYvSuoVah8JbRPpdHDOrnwLK9spte
58d0wDO4dGUJuHSLwMAy/tKGCamhAs7G1hohrO/WTHaEcTKOd0xx9RBzc/XvN2dM6+zZPXLp
r1UqFBwU/Sx2010pwUjXpqZCvywG /

The DBMS_DDL package for Dynamic Wrapping

The DBMS_DDL package contains three overloaded functions called WRAP, the simplest of which accepts a VARCHAR2 input parameter containing a PL/SQL CREATE OR REPLACE statement and returns the obfuscated PL/SQL, which can be written to a file or stored in a table. The following example shows how the basic WRAP function is used from PL/SQL.

SET SERVEROUTPUT ON SIZE UNLIMITED
DECLARE
l_source VARCHAR2(32767);
l_wrap VARCHAR2(32767);
BEGIN
l_source := 'CREATE OR REPLACE FUNCTION get_date_string RETURN VARCHAR2 AS' ||
'BEGIN ' ||
'RETURN TO_CHAR(SYSDATE, ''DD-MON-YYYY''); ' ||
'END get_date_string;'; l_wrap := SYS.DBMS_DDL.WRAP(ddl => l_source);
DBMS_OUTPUT.put_line(l_wrap);
END;
/
CREATE OR REPLACE FUNCTION get_date_string wrapped a000000
b2
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
6f
aa
mV4eMSJ8EqqgErJT91l6UZ0pdDUwgyr6LZ5GfHSmUPiJfkEObQpeDb6D7glajI+ONulxdqC1
0HvOPP4eJpQs5zxsKXpj6XL1
fvieXyWCr3BTzXTqcGYhfXrtqDVPztR/o+9UZ8l5OijDSsRW
ZPv6rISzFyqeEsCBweFUFyxd PL/SQL procedure successfully completed. SQL>

This works fine for PL/SQL source that is less than or equal to 32K in size, but the VARCHAR2 input parameter means it can't cope with source larger than this. Fortunately the other overloads of this function allow us to work with source greater than 32K in size.

DBMS_DDL.WRAP(
ddl DBMS_SQL.VARCHAR2S,
lb PLS_INTEGER,
ub PLS_INTEGER)
RETURN DBMS_SQL.VARCHAR2S; DBMS_DDL.WRAP(
ddl DBMS_SQL.VARCHAR2A,
lb PLS_INTEGER,
ub PLS_INTEGER)
RETURN DBMS_SQL.VARCHAR2A;

In both overloads the source is passed in and out using an associative array (index-by table). The difference between the two is that the DBMS_SQL.VARCHAR2S type is limited to 256 bytes per line, while theDBMS_SQL.VARCHAR2A type can hold a maximum of 32K per line. The following example uses the DBMS_SQL.VARCHAR2A version to shows how these overloads work.

SET SERVEROUTPUT ON SIZE UNLIMITED
DECLARE
l_source DBMS_SQL.VARCHAR2A;
l_wrap DBMS_SQL.VARCHAR2A;
BEGIN
l_source(1) := 'CREATE OR REPLACE FUNCTION get_date_string RETURN VARCHAR2 AS ';
l_source(2) := 'BEGIN ';
l_source(3) := 'RETURN TO_CHAR(SYSDATE, ''DD-MON-YYYY''); ';
l_source(4) := 'END get_date_string;'; l_wrap := SYS.DBMS_DDL.WRAP(ddl => l_source,
lb => 1,
ub => l_source.count); FOR i IN 1 .. l_wrap.count LOOP
DBMS_OUTPUT.put_line(l_wrap(i));
END LOOP;
END;
/
CREATE OR REPLACE FUNCTION get_date_string wrapped a000000
b2
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
6f
aa
mV4eMSJ8EqqgErJT91l6UZ0pdDUwgyr6LZ5GfHSmUPiJfkEObQpeDb6D7glajI+ONulxdqC1
0HvOPP4eJpQs5zxsKXpj6XL1
fvieXyWCr3BTzXTqcGYhfXrtqDVPztR/o+9UZ8l5OijDSsRW
ZPv6rISzFyqeEsCBweFUFyxd PL/SQL procedure successfully completed. SQL>

In addition to the WRAP functions, the DBMS_DDL package also contains three overloaded procedures called CREATE_WRAPPED. These procedure have the same parameter lists as the three WRAP function overloads, and are used to wrap and compile the specified source. The following example shows how the DBMS_SQL.VARCHAR2A version is used.

SET SERVEROUTPUT ON SIZE UNLIMITED
DECLARE
l_source DBMS_SQL.VARCHAR2A;
l_wrap DBMS_SQL.VARCHAR2A;
BEGIN
l_source(1) := 'CREATE OR REPLACE FUNCTION get_date_string RETURN VARCHAR2 AS ';
l_source(2) := 'BEGIN ';
l_source(3) := 'RETURN TO_CHAR(SYSDATE, ''DD-MON-YYYY''); ';
l_source(4) := 'END get_date_string;'; SYS.DBMS_DDL.CREATE_WRAPPED(ddl => l_source,
lb => 1,
ub => l_source.count);
END;
/ PL/SQL procedure successfully completed. SET PAGESIZE 100
SELECT text
FROM user_source
WHERE name = 'GET_DATE_STRING'
AND type = 'FUNCTION'; TEXT
------------------------------------------------------------------------
FUNCTION get_date_string wrapped
a000000
b2
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
6f aa
mV4eMSJ8EqqgErJT91l6UZ0pdDUwgyr6LZ5GfHSmUPiJfkEObQpeDb6D7glajI+ONulxdqC1
0HvOPP4eJpQs5zxsKXpj6XL1fvieXyWCr3BTzXTqcGYhfXrtqDVPztR/o+9UZ8l5OijDSsRW
ZPv6rISzFyqeEsCBweFUFyxd 1 row selected. SQL>

The CREATE_WRAPPED procedures are the equivalent of passing the wrapped source returned from the WRAP function into an EXECUTE IMMEDIATE or DBMS_SQL.PARSE call, but they are optimized to give better performance.

-------------------------------------------------------------------------

present  by  dylan.

Oracle代码封装工具和DBMS_DDL包的使用的更多相关文章

  1. 将PL/SQL代码封装在机灵的包中

    将代码封装在机灵的包中 http://www.oracle.com/technetwork/issue-archive/2013/13-jan/o13plsql-1872456.html 绝大多数基于 ...

  2. 初识代码封装工具SWIG(回调Python函数)

    这不是我最早使用swig了,之前在写Kynetix的时候就使用了swig为python封装了C语言写的扩展模块.但是当时我对C++还不是很了解,对其中的一些概念也只是拿来直接用,没有理解到底是什么,为 ...

  3. JAVA之旅(五)——this,static,关键字,main函数,封装工具类,生成javadoc说明书,静态代码块

    JAVA之旅(五)--this,static,关键字,main函数,封装工具类,生成javadoc说明书,静态代码块 周末收获颇多,继续学习 一.this关键字 用于区分局部变量和成员变量同名的情况 ...

  4. oracle wrapped 代码解密工具 unwraper

    Oracle中的Wrap 功能是为了不让别人看到函数/存储过程的SQL源码的明文, 作为技术宅,有的时候想看源码但是看不到的那种心情是可以理解的, 发一个简单易用的 Oracle wrapped 解码 ...

  5. 用Java代码实现拦截区域网数据包

    起因: 吃饭的时间在想如果区域网内都是通过路由器上网,那如何实现拦截整个区域网的数据包,从而实现某种窥探欲. 思路:      正常是通过电脑网卡预先设置或分配的IP+网关对路由器进行通讯,比如访问百 ...

  6. 更新整理本人所有博文中提供的代码与工具(C++,2014.01)

    为了更方便地管理博文中涉及的各种代码与工具资源,现在把这些资源迁移到 Google Code 中,有兴趣者可前往下载. C++ 1.<通用高性能 Windows Socket 组件 HP-Soc ...

  7. 更新整理本人所有博文中提供的代码与工具(C++,2013.11)

    为了更方便地管理博文中涉及的各种代码与工具资源,现在把这些资源迁移到 Google Code 中,有兴趣者可前往下载. C++ 1.<通用高性能 Windows Socket 组件 HP-Soc ...

  8. 更新整理本人所有博文中提供的代码与工具(C++,2013.10)

    为了更方便地管理博文中涉及的各种代码与工具资源,现在把这些资源迁移到 Google Code 中,有兴趣者可前往下载. C++ 1.<通用高性能 Windows Socket 组件 HP-Soc ...

  9. 更新整理本人所有博文中提供的代码与工具(C++,2013.08)

    为了更方便地管理博文中涉及的各种代码与工具资源,现在把这些资源迁移到 Google Code 中,有兴趣者可前往下载. C++ 1.<通用高性能 Windows Socket 组件 HP-Soc ...

  10. 静态代码扫描工具PMD定制xml的规则(一)操作篇

    0.前言 PMD作为开源的静态代码扫描工具有很强的扩展能力,可使用java或xpath定制rule.第一篇从操作上讲解如何定制一个用于扫描xml是否规范的规则.首先我们知道xml格式的文件在java工 ...

随机推荐

  1. .net core 3.0 获取 IServiceProvider 实例

    .net core 3.0后,获取IServiceProvider需要绕点弯路 首先,新建一个类: public class MyServiceProviderFactory : IServicePr ...

  2. Linux-日期时间-date

  3. [转帖]prometheus和node_exporter中的磁盘监控

    https://www.ipcpu.com/2021/04/prometheus-node_exporter/ prometheus和node_exporter中的磁盘监控.md 对于磁盘问题,我们主 ...

  4. [转帖]Percolator 和 TiDB 事务算法

    https://cn.pingcap.com/blog/percolator-and-txn 本文先概括的讲一下 Google Percolator 的大致流程.Percolator 是 Google ...

  5. [转帖]比较不同CPU下的分支预测

    https://plantegg.github.io/2023/04/16/%E6%AF%94%E8%BE%83%E4%B8%8D%E5%90%8CCPU%E4%B8%8B%E7%9A%84%E5%8 ...

  6. SPECJVM2008的简单结果

    SPECJVM2008的简单结果 摘要 前面两天学习了SPECJVM2008简单使用. 今天进行一下简单的数据采集. 需要说明一下SPECJVM2008貌似仅兼容JDK1.8 更新的LTS版本都不兼容 ...

  7. echarts设置标题样式

    <!DOCTYPE html> <html> <!-- https://blog.csdn.net/weixin_42698255/article/details/892 ...

  8. 微信对话平台API开发

    接入官方文档接入文档 下面我们开始使用前端来进行接入 <!DOCTYPE html> <html> <head> <meta charset="UT ...

  9. 机器学习算法(四): 基于支持向量机的分类预测(SVM)

    机器学习算法(四): 基于支持向量机的分类预测 本项目链接:https://www.heywhale.com/home/column/64141d6b1c8c8b518ba97dcc 1.相关流程 支 ...

  10. LyScript 插件实现UPX寻找入口

    LyScript 插件可实现对压缩壳的快速脱壳操作,目前支持两种脱壳方式,一种是运用API接口自己编写脱壳过程,另一种是直接加载现有的脱壳脚本运行脱壳. 插件地址:https://github.com ...