ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 能超过4000字的unwrap

能超过4000字的unwrap

原创 Linux操作系统 作者:fengjin821 时间:2009-06-12 12:56:01 0 删除 编辑

set serveroutput on;

 CREATE TABLE SYS.IDLTRANSLATE
    (
    C_BASE64DECODE  VARCHAR2(2) NOT NULL,
    C_LZDEFLATECODE VARCHAR2(2)     NULL
    )

 

需要确保对照表恰好有256行不同的
我是运行1次'PACKAGE' 1次'FUNCTION'得到的


 

为了输出中文,要修改java过程

create or replace java source named UNWRAPPER
as
import java.io.*;
import java.util.zip.*;

public class UNWRAPPER
{
  public static String Inflate( byte[] src )
  {
    try
    {
      ByteArrayInputStream bis = new ByteArrayInputStream( src );
      InflaterInputStream iis = new InflaterInputStream( bis );
      StringBuffer sb = new StringBuffer();
      for( int c = iis.read(); c != -1; c = iis.read() )
      {
        sb.append( (char) c );
      }
String hello = new String(sb.toString().getBytes("iso8859-1"), "GBK");
      return hello;

    } catch ( Exception e )
    {
    }
    return null;
  }
  public static byte[] Deflate( String src, int quality )
  {
    try
    {
      byte[] tmp = new byte[ src.length() + 100 ];
      Deflater defl = new Deflater( quality );
      defl.setInput( src.getBytes( "UTF-8" ) );
      defl.finish();
      int cnt = defl.deflate( tmp );
      byte[] res = new byte[ cnt ];
      for( int i = 0; i < cnt; i++ )
        res = tmp;
      return res;
    } catch ( Exception e )
    {
    }
    return null;
  }
}
/

alter java source UNWRAPPER compile
/

然后用包把JAVA声明进来:

create or replace package amosunwrapper
is
  function deflate( src in varchar2 )
  return raw;
  function deflate( src in varchar2, quality in number )
  return raw;
  function inflate( src in raw )
  return varchar2;
end;
/

 


create or replace package body amosunwrapper
is
  function deflate( src in varchar2 )
  return raw
  is
  begin
    return deflate( src, 6 );
  end;

  function deflate( src in varchar2, quality in number )
  return raw
  as language java
  name 'UNWRAPPER.Deflate( java.lang.String, int ) return byte[]';

  function inflate( src in raw )
  return varchar2
  as language java
  name 'UNWRAPPER.Inflate( byte[] ) return java.lang.String';

end;
/



create or replace procedure unwrap(o in varchar,n in varchar, t in varchar)
as
        vWrappedtext                Varchar2(32767);               
        vtrimtext                Varchar2(32767);               
        vChar                                        Varchar2(2);
        vRepchar                                Varchar2(2);
        vLZinflatestr                        Varchar2(32767);
        nLen                Integer;
        nLoop        Integer;
        nCnt                Integer;
type vartab is table of varchar2(2) index by varchar2(2);

mytbl vartab;
cursor getchar is select C_BASE64DECODE xr,C_LZDEFLATECODE dr from sys.idltranslate;
Begin
for i in getchar loop --sys.idltranslate表内容存到字符数组
   mytbl(i.xr):=i.dr;
end loop;
vtrimtext:='';
select count(*) into ncnt                         from DBA_SOURCE
                        Where wner=o
                        And Name = n
                        And Type=t ;
if ncnt >0 and ncnt <5 then
for i in 1..ncnt loop
if i=1 then
select rtrim( substr( TEXT, instr( TEXT, chr( 10 ), 1, 20 ) + 1 ), chr(10) )   --保存去掉换行的BASE64码正文
into vLZinflatestr
                        from DBA_SOURCE
                        Where wner=o
                        And Name = n
                        And Type=t and line=i;
else
select text into vLZinflatestr
                        from DBA_SOURCE
                        Where wner=o
                        And Name = n
                        And Type=t and line=i;
end if;
vtrimtext:=vtrimtext||vLZinflatestr;
end loop;
end if;
vtrimtext:=replace(vtrimtext,chr(10),'');
nLen := Length(vtrimtext)/64 ;
vWrappedtext :='';
for i in 0..nLen  loop  
if i< nLen   then
vWrappedtext:=vWrappedtext||utl_encode.base64_decode( utl_raw.cast_to_raw(substrb(vtrimtext,64*i+1 , 64 ))) ;
else
vWrappedtext:=vWrappedtext||utl_encode.base64_decode( utl_raw.cast_to_raw(substrb(vtrimtext,64*i+1  ))) ;
end if;
        --DBMS_OUTPUT.PUT_LINE(vWrappedtext);
        End Loop;
--vWrappedtext:=substr(vWrappedtext,41);
    nLen := Length(vWrappedtext)/2 - 1;

        vLZinflatestr :='';

        For nLoop In 20..nLen Loop --从第41字节开始
                vChar := Substrb(vWrappedtext,nLoop*2+1,2);
                /*
                Select Count(*) Into nCnt From SYS.IDLTRANSLATE Where C_BASE64DECODE=vChar;
                If nCnt <> 1 Then
                        DBMS_OUTPUT.PUT_LINE('SUBSTATION TABLE WARNING: Count not find following char--'||vChar);
                        Return;
                Else
                        Select C_LZDEFLATECODE Into vRepchar From SYS.IDLTRANSLATE Where C_BASE64DECODE=vChar;
                End If;
                */
                vLZinflatestr := vLZinflatestr || mytbl(vChar); --从字符数组匹配
                --DBMS_OUTPUT.PUT_LINE(vLZinflatestr);
        End Loop;
        --DBMS_OUTPUT.PUT_LINE(vLZinflatestr);
        DBMS_OUTPUT.PUT_LINE(amosunwrapper.inflate(vLZinflatestr));
End;
/

exec unwrap('SYS','HANMON','PACKAGE BODY');

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

/
conn sys/sys@orcl as sysdba
set lines 132 pages 50000 timi on
set serverout on
exec unwrap('SYS','HANMON','PACKAGE BODY');

这个程序的功能就是把用wrap命令打包的oracle 10g的存储过程/函数/包的源代码显示出来
对直接用pl/sql写的没有用,还没有做错误处理

----------------------------------------------------------------------------------------
 
 
wrap和unwrap的过程
1.假定有一个函数dl2ml需要打包
SQL> drop function dl2ml;

函数已删除。

已用时间:  00: 00: 00.01
SQL> ho

2.先用文本编辑器做成一个sql脚本

D:\app>type f:\oracle\dl2ml.sql
 
create or replace function dl2ml(hy in varchar)
return varchar
as
x varchar(2);
begin
select
case
when hy >='01' and hy<= '05' then 1
when hy >='06' and hy<= '11' then 2
when hy >='13' and hy<= '43' then 3
when hy >='44' and hy<= '46' then 4
when hy >='47' and hy<= '50' then 5
when hy >='51' and hy<= '59' then 6
when hy >='60' and hy<= '62' then 7
when hy  ='63' or  hy = '65' then 8
when hy >='66' and hy<= '67' then 9
when hy >='68' and hy<= '71' then 10
when hy >='72' and hy<= '72' then 11
when hy >='73' and hy<= '74' then 12
when hy >='75' and hy<= '78' then 13
when hy >='79' and hy<= '81' then 14
when hy >='82' and hy<= '83' then 15
when hy >='84' and hy<= '84' then 16
when hy >='85' and hy<= '87' then 17
when hy >='88' and hy<= '92' then 18
when hy >='93' and hy<= '98' then 19
else null
end
into x from dual;
return x;
end;
/
D:\app>exit

3.用sql脚本创建函数

SQL> @ f:\oracle\dl2ml.sql

函数已创建。

已用时间:  00: 00: 00.01

4.测试函数


SQL> select dl2ml('45') from dual;

DL2ML('45')
----------------------------------------------------------------------------------------
4

已用时间:  00: 00: 00.01
SQL> drop function dl2ml;

函数已删除。

已用时间:  00: 00: 00.01
SQL> ho
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

5.将sql脚本打包成funtion.plb


D:\app>wrap iname=f:\oracle\dl2ml.sql name=f:\oracle\dl2ml.plb

PL/SQL Wrapper: Release 10.2.0.3.0- Production on 星期五 6月  12 11:14:41 2009

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

Processing function.sql to funtion.plb

D:\app>type funtion.plb
create or replace function dl2ml wrapped
a000000
354
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
335 199
ndEQSpIvhV202FWf2jLyxpFnjQMwg1zrr0hGyo5EUOI6GMTHyUnF4S3rRsXrfy11DmGfmkPS
tcQ9Nue/OhW9vrvTuRMesVKf0vjY+UGcxijwSrxfuyzUD1jEHovrR0cVM1dx5fbGGc3GfbTg
SQVk2HhtAZooHn1TQ80riTTKhkALI+3MzBisPE7I1t7HakJ8XEgwkBPoy+j/Luup3tbe3YVo
42UE9/37WALL6NcuuovoO6z3+lA4SokDsMd7LmhMrwBLEtXWs3DDSJGKB5yt8ZQOBOOE69Oj
iS6iaQ2OqcOiUA13rQk+tok7yrcY0NRreURk6AkbTbo1G5T2BtMv0hpeRGlTQJ71g9yC2mKn
aN8uR0U38EiQ3rCYTyTetEd3lapLv8FC/psoXEq+ww==

/
D:\app>exit

6.执行funtion.plb创建函数

SQL> @ f:\oracle\dl2ml.plb

函数已创建。

已用时间:  00: 00: 00.00

6.测试函数

SQL> select dl2ml('45') from dual;

DL2ML('45')
----------------------------------------------------------------------------------------
--
4

已用时间:  00: 00: 00.00

5.查看源代码,是加密后的

SQL> select text from user_source where name='DL2ML';

TEXT
----------------------------------------------------------------------------------------
function dl2ml wrapped
a000000
354
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
335 199
ndEQSpIvhV202FWf2jLyxpFnjQMwg1zrr0hGyo5EUOI6GMTHyUnF4S3rRsXrfy11DmGfmkPS
tcQ9Nue/OhW9vrvTuRMesVKf0vjY+UGcxijwSrxfuyzUD1jEHovrR0cVM1dx5fbGGc3GfbTg
SQVk2HhtAZooHn1TQ80riTTKhkALI+3MzBisPE7I1t7HakJ8XEgwkBPoy+j/Luup3tbe3YVo
42UE9/37WALL6NcuuovoO6z3+lA4SokDsMd7LmhMrwBLEtXWs3DDSJGKB5yt8ZQOBOOE69Oj
iS6iaQ2OqcOiUA13rQk+tok7yrcY0NRreURk6AkbTbo1G5T2BtMv0hpeRGlTQJ71g9yC2mKn
aN8uR0U38EiQ3rCYTyTetEd3lapLv8FC/psoXEq+ww==


已用时间:  00: 00: 00.01
7.解密函数,看到源码

SQL> exec unwrap('SYS','DL2ML','FUNCTION');
FUNCTION dl2ml(HY IN VARCHAR)
RETURN VARCHAR
AS
X VARCHAR(2);
BEGIN
SELECT
CASE
WHEN HY >='01' AND HY<= '05' THEN 1
WHEN HY >='06'
AND HY<= '11' THEN 2
WHEN HY >='13' AND HY<= '43' THEN 3
WHEN HY >='44' AND HY<= '46' THEN 4
WHEN HY >='47' AND HY<= '50' THEN
5
WHEN HY >='51' AND HY<= '59' THEN 6
WHEN HY >='60' AND HY<= '62' THEN 7
WHEN HY  ='63' OR  HY = '65' THEN 8
WHEN HY >='66' AND
HY<= '67' THEN 9
WHEN HY >='68' AND HY<= '71' THEN 10
WHEN HY >='72' AND HY<= '72' THEN 11
WHEN HY >='73' AND HY<= '74' THEN 12
WHEN
HY >='75' AND HY<= '78' THEN 13
WHEN HY >='79' AND HY<= '81' THEN 14
WHEN HY >='82' AND HY<= '83' THEN 15
WHEN HY >='84' AND HY<=
'84' THEN 16
WHEN HY >='85' AND HY<= '87' THEN 17
WHEN HY >='88' AND HY<= '92' THEN 18
WHEN HY >='93' AND HY<= '98' THEN 19
ELSE
NULL
END
INTO X FROM DUAL;
RETURN X;
END;

PL/SQL 过程已成功完成。

已用时间:  00: 00: 00.01
SQL>
 
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13165828/viewspace-606012/,如需转载,请注明出处,否则将追究法律责任。

下一篇: HanMon.txt
请登录后发表评论 登录
全部评论

注册时间:2009-04-29

  • 博文量
    191
  • 访问量
    504973