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. Shell-表达式-比较-文件判断-权限判断-条件-逻辑

  2. [转帖]Kubernetes1.25.6部署文档 使用cri-docker部署K8s1.25.6

    https://zhuanlan.zhihu.com/p/600808149 本文档将通过kubeadm+docker部署K8s集群,本次集群使用的容器运行工具为docker,K8s的容器运行工具也可 ...

  3. [转帖]学习如何编写 Shell 脚本(进阶篇)

    https://juejin.cn/post/6935365727205457928 前言 在<学习如何编写 Shell 脚本(基础篇)>一文中已经讲解了 Shell 脚本编程的基础知识, ...

  4. [转帖]Linux中查看各文件夹大小命令du -h --max-depth=1

    https://www.cnblogs.com/the-tops/p/8798678.html 最近排查服务器异常的时候,常会遇到磁盘慢的情况,这个时候,查找那个文件夹占用的内存的时候常用到这个命令: ...

  5. [转帖]TIDB-TIDB节点磁盘已满报警

    一.背景 今日突然收到tidb节点的磁盘报警,磁盘容量已经超过了80%,但是tidb是不放数据的,磁盘怎么会满,这里就需要排查了 二.问题排查 解决步骤 1.df -h查看哪里占用磁盘比较多,然后通过 ...

  6. [转帖]kafka压测多维度分析实战

    设置虚拟机不同的带宽来进行模拟压测 ---------kafka数据压测-------------------1.公司生产kafka集群硬盘:单台500G.共3台.日志保留7天.         1. ...

  7. [转帖]CPU缓存行

    https://www.jianshu.com/p/e338b550850f CPU缓存 执行程序是靠运行CPU执行主存中代码,但是CPU和主存的速度差异是非常大的,为了降低这种差距,在架构中使用了C ...

  8. Docker 镜像减少体积的思路和方法

    Docker 镜像减少体积的思路和方法 背景 有一个项目感觉镜像有点大 这边同事喊着一起帮忙处理一下. 今天基本上就在客户现场进行处理了. 想着应该把自己想到的东西整理一下. 整体思路 1. 清理do ...

  9. 在线安装gfortran的方法-CentOS8 or 阿里龙蜥

    在线安装gfortran的方法-CentOS8 or 阿里龙蜥 背景 在阿里云上面进行了 speccpu2006的测试验证 但是发现总是很多包安装不过去 原因是阿里最小化安装的龙蜥系统. 缺少很多编译 ...

  10. Redis IO多线程的简要测试结果

    Redis IO多线程的简要测试结果 摘要 最近想简单确认一下IO多线程的对吞吐量的提升情况. 正好手头有鲲鹏的机器, 所以想直接进行一下验证 顺便用一下4216 进行一下对比. 发现 在CPU核心比 ...