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. [转帖]深入JVM - Code Cache内存池

    深入JVM - Code Cache内存池 1. 本文内容 本文简要介绍JVM的 Code Cache(本地代码缓存池). 2. Code Cache 简要介绍 简单来说,JVM会将字节码编译为本地机 ...

  2. [转帖]HAProxy 在 TiDB 中的最佳实践

    https://docs.pingcap.com/zh/tidb/stable/haproxy-best-practices 本文介绍 HAProxy 在 TiDB 中的最佳配置和使用方法.HAPro ...

  3. [转帖]018、数据库管理之TiDB升级

    升级 使用TiUP进行补丁升级(HotFix) 版本升级流程 升级准备-更新TiUP 升级准备- 编辑TiUP Cluster 升级准备- 集群监控状态检查 升级TiDB 集群 验证TiDB集群升级结 ...

  4. [转帖]《Linux性能优化实战》笔记(八)—— 内存是怎么工作的

    一. 内存映射 我们通常所说的内存容量,指的是物理内存.物理内存也称为主存,大多数计算机用的主存都是动态随机访问内存(DRAM).只有内核才可以直接访问物理内存.那么,进程要访问内存时,该怎么办呢? ...

  5. 申威下单盘SSD与四块盘RAID5的性能测试结果

    申威下单盘SSD与四块盘RAID5的性能测试结果 背景 背景不在说了 申威服务器.. 结论 天坑 做了raid写入性能下降明显. 充分怀疑驱动不行. 四快盘的raid5 跟单盘的读几乎没区别. 感觉这 ...

  6. [转帖]Linux—CPU核数、上下文切换介绍及pidstat等命令详解

    https://www.jianshu.com/p/0ae0c1153c34 关注:CodingTechWork,一起学习进步. 引言 并发编程   并发编程的目的是为了改善串行程序执行慢问题,但是, ...

  7. vue3获取数据的注意点

    场景描述 在使用vue3的时候.我们很多人喜欢一个页面分成几个几个部分来写 这样做的目的是为了区分. 做的彼此的逻辑互相独立,互不干扰 但是有的时候,我们可能会去获取不属于自己区域的函数 这个时候我们 ...

  8. 手撕Vue-数据驱动界面改变上

    经过上一篇的介绍,已经实现了监听数据的变化,接下来就是要实现数据变化后,界面也跟着变化,这就是数据驱动界面改变. 想要实现数据变化之后更新UI界面,我们可以使用发布订阅模式来实现,先定义一个观察者类, ...

  9. Couldn't launch Python exit code 9009

    Couldn't launch Python exit code 9009 start stable-diffusion-webui,发现,python 环境没有,我本地其实是已经安装完毕的,后来发现 ...

  10. springboot项目导入外部jar包的bean的几种方式

    背景 公司封装了基础包和日志包,将公共的配置抽取出来,供所有项目使用,因此就需要考虑,怎么引入外部jar包的Bean实例: 思考 因为公司的jar包就是普通的jar,不支持springboot的自动配 ...