创建好了工具,我们先来看看下面的SQL:
with src AS ( select 'PACKAGE a' txt from dual ),
wrap as ( select src.txt , dbms_ddl.wrap( 'create ' || src.txt ) wrap from src ),
subst as (select substr( utl_encode.base64_decode( utl_raw.cast_to_raw(rtrim( substr( wrap.wrap, instr( wrap.wrap, chr( 10 ), 1, 20 ) + 1 ), chr(10) ) ) ), 41 ) x,
amosunwrapper.deflate( wrap.txt || chr(0), 9 ) d
from wrap )
select substr( x, r * 2 - 1, 2 ) c_base64,
substr( d, r * 2 - 1, 2 ) c_translatecode
from subst , ( select rownum r from dual connect by rownum <= ( select length( x ) / 2 from subst ) );
结果如下:
C_BASE64 C_TRANSLATECODE
30 78
83 DA
99 0B
B8 70
F5 74
33 F6
9F 76
F5 74
BF 77
5C 55
5A 48
91 64
A6 00
A6 00
CB 0E
C4 B7
E1 02
48 6E
通过对结果的排序,没有出现同一个BASE64编码对应不同的十六进制的情况,因此我们知道了可以用这个SQL为基础,通过用不同的SOURCE串来产生替换表的内容。
根据上面的SQL俺就可以写首先建一个表来存储替换表的内容,然后写一段PLSQL块来生成替换表的内容:
SQL>connect sys/XXXX@xxxx as sysdba;
SQL> CREATE TABLE SYS.IDLTRANSLATE
(
C_BASE64DECODE VARCHAR2(2) NOT NULL,
C_LZDEFLATECODE VARCHAR2(2) NULL
)
/
declare
nCnt integer;
nLoop integer;
nSLoop integer;
nCharmax integer;
nCharmin integer;
vChar Varchar2(3);
cursor getchar is
with src AS ( select 'PACKAGE '||vChar txt from dual ),
wrap as ( select src.txt , dbms_ddl.wrap( 'create ' || src.txt ) wrap from src ),
subst as (select substr( utl_encode.base64_decode( utl_raw.cast_to_raw(rtrim( substr( wrap.wrap, instr( wrap.wrap, chr( 10 ), 1, 20 ) + 1 ), chr(10) ) ) ), 41 ) x,
amosunwrapper.deflate( wrap.txt || chr(0), 9 ) d
from wrap )
select substr( x, r * 2 - 1, 2 ) xr ,
substr( d, r * 2 - 1, 2 ) dr
from subst , ( select rownum r from dual connect by rownum <= ( select length( x ) / 2 from subst ) );
begin
nCharmax:=97;
nCharmin:=122;
For nLoop In 97..122 Loop
For nSloop In 0..99 Loop
vChar := chr(nLoop)||to_char(nSloop);
For abc In getchar Loop
Select Count(*) Into nCnt From sys.idltranslate WHERE c_base64decode = abc.xr;
If nCnt < 1 Then
Insert INTO sys.idltranslate VALUES (abc.xr,abc.dr);
Commit;
Else
Select Count(*) Into ncnt From sys.idltranslate WHERE c_base64decode = abc.xr AND c_lzdeflatecode=abc.dr;
If nCnt < 1 Then
DBMS_OUTPUT.PUT_LINE('wrong orginal char:'||vchar||' hex base64:'||abc.xr);
End If;
End If;
End Loop;
End Loop;
End Loop;
end;
运行上面这段SQL大概会产生1百多条记录,还未达到00-FF总共256条记录的要求,建议替换
select 'PACKAGE '||vChar txt from dual 中的PACKAGE关健字为procedure或者function类似的,继续运行直到
替换表中有不重复的256条记录为止。
有了替换表的内容,还有前面的JAVA工具包和ORACLE工具包,已经无限接近终点了!
俺将在后面写一段程序来验证unwrap的威力,矛头嘛就直接指向ORACLE自身的包了。