仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2910|回复: 19
打印 上一主题 下一主题

[学习教程] JAVA网页设计Java搅浑编译器(转apusic.com)

[复制链接]
若相依 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:55:15 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
再说说缺点:首先java功能强大的背后是其复杂性,就拿web来说,当今流行的框架有很多,什么struts,spring,jQuery等等,而这无疑增加了java的复杂性。编译比来试用了几个Java搅浑器(JavaObfuscator),感到没有一个完整另人中意的,因而想爽性本人写一个得了。翻了几页Java假造机标准以后突发奇想,其余搅浑器都是在编译好的bytecode上做文章,能不克不及从源码间接编译成经由搅浑的class文件呢?就如许花了一个多礼拜的工夫写了一个Java搅浑编译器(JavaObfuscatorCompiler)。


Q:甚么是搅浑器?
A:因为Java程序运转时是静态毗连的,因而编译成的方针文件中包括有标记表,使得Java程序很简单被反编译,搅浑器能够打乱class文件中的标记信息,使反向工程变得十分坚苦。


Q:现有的搅浑器有甚么成绩?
A:现有的搅浑器都是对编译好的class文件举行搅浑,如许就必要编译和搅浑两个步骤。并非一切的标记都必要搅浑,假如你开辟的是一个类库,大概某些类必要静态装载,那些大众API就必需保存标记稳定,如许他人才干利用你的类库。现有的搅浑器供应了GUI或剧本的体例来对那些必要保存的标记称号举行设置,假如程序较年夜时设置事情变得很庞大,而程序一旦修正设置事情又要从头举行。某些搅浑器可以调剂字节码的按次,使反编译加倍坚苦,但我履历过搅浑以后的程序运转堕落的情形。


Q:Java搅浑编译器是怎样事情的?
A:Java搅浑编译器是在SunJDK中供应的Java编译器(javac)的基本上完成的,修正了代码天生历程,对编译器天生的两头代码举行搅浑,最初再天生class文件,如许编译和搅浑只必要一个步骤就能够完成。别的能够在源程序中拔出标记保存指令来把持哪些标记必要保存,不必要独自的设置。


Q:怎样安装和运转JOC?
A:下载joc.jar(http://www.apusic.com/product/cpsy.htm),运转java-jarjoc.jar就能够启动Java搅浑编译器,joc的命令行参数和javac完整不异,但增添了一个新的参数-Xobfuscate,它的用法以下:
-Xobfuscate:<level>
个中<level>指定搅浑级别,能够是以下几种级别:
-Xobfuscate:none不举行搅浑
-Xobfuscate:private对一切private会见级其余元素举行搅浑
-Xobfuscate:package对一切private或packageprivate元素举行搅浑
-Xobfuscate:protected对一切private,packageprivate,protected元素举行搅浑
-Xobfuscate:public对一切的元素都举行搅浑
-Xobfuscate:all相称于-Xobfuscate:public
假如利用-Xobfuscate不带级别参数,则相称于-Xobfuscate:package


Q:怎样利用标记保存指令?
A:除在命令行用-Xobfuscate参数把持标记搅浑级别外,还能够在源代码中利用标记保存指令来把持那些标记必要保存,标记保存指令是一个Java文档正文指令,能够拔出在类和类成员的文档正文中,比方:
/**
*Thisclassshouldpreserve.
*@preserve
*/
publicclassFoo{
/**
*Youcanspecifywhichfieldshouldbepreserved.
*@preserve
*/
privateintx;


/**
*Thisfieldisnotpreserved.
*/
privateinty;


/**
*Youcanalsopreservemethods.
*@preserve
*/
publicvoidhello(){}


/**
*Thismethodisnotpreserved.
*/
privatevoidcollect(){}
}
假如没有@preserve指令,则依据搅浑级别及成员的会见级别来断定标记是不是保存。


关于类的标记保存指令能够附带一个保存级别参数,来把持类成员的标记保存,包含:
@preserve仅对类名举行保存,类成员的保存依据-Xobfuscate命令行参数决意
@preservepublic保存一切public成员
@preserveprotected保存一切public和protected成员
@preservepackage保存一切public,protected,packageprivate成员
@preserveprivate保存一切成员
@preserveall相称于@preserveprivate


Q:JOC有哪些限定?
A:不撑持分离编译,必需对一切的源文件举行搅浑编译。




最初给出一个JOC搅浑的效果:


源文件:


importjava.awt.event.*;
importjavax.swing.*;


publicclassAboutBoxextendsJDialog
{
publicAboutBox()
{
initForm();
}


JPanelpanel1=newJPanel();
JButtonbutton1=newJButton();
JLabeljLabel2=newJLabel();
JTextAreajTextArea1=newJTextArea();


/**
*NOTE:Thefollowingcodeisrequiredbytheformdesigner.
*Itcanbemodifiedusingtheformeditor.Donot
*modifyitusingthecodeeditor.
*/


privatevoidinitForm()
{
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.getContentPane().setLayout(newjava.awt.CardLayout());
this.setModal(true);
this.setResizable(false);
this.setTitle("About...");
panel1.setLayout(null);
button1.setText("OK");
button1.setBounds(272,168,88,24);
panel1.add(button1);
jLabel2.setText("FileSystemViewerforSwing1.1.1");
jLabel2.setVerticalAlignment(SwingConstants.TOP);
jLabel2.setBounds(64,32,240,56);
panel1.add(jLabel2);
jTextArea1.setFont(newjava.awt.Font("Dialog",0,10));
jTextArea1.setLineWrap(true);
jTextArea1.setOpaque(false);
jTextArea1.setText("Thiscomputerprogramisprotectedbycopyrightlaw.");
jTextArea1.setWrapStyleWord(true);
jTextArea1.setBounds(8,112,256,80);
panel1.add(jTextArea1);
this.getContentPane().add(panel1,"Card1");
this.setSize(376,228);
button1.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventev){
button1_actionPerformed(ev);
}});
}


privatevoidbutton1_actionPerformed(ActionEventev)
{
this.dispose();
}
}


经Javac编译后用JAD反编译的了局:


importjava.awt.*;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.*;
importjavax.swing.text.JTextComponent;


publicclassAboutBoxextendsJDialog
{


JPanelpanel1;
JButtonbutton1;
JLabeljLabel2;
JTextAreajTextArea1;


publicAboutBox()
{
panel1=newJPanel();
button1=newJButton();
jLabel2=newJLabel();
jTextArea1=newJTextArea();
initForm();
}


privatevoidinitForm()
{
setDefaultCloseOperation(2);
getContentPane().setLayout(newCardLayout());
setModal(true);
setResizable(false);
setTitle("About...");
panel1.setLayout(null);
button1.setText("OK");
button1.setBounds(272,168,88,24);
panel1.add(button1);
jLabel2.setText("FileSystemViewerforSwing1.1.1");
jLabel2.setVerticalAlignment(1);
jLabel2.setBounds(64,32,240,56);
panel1.add(jLabel2);
jTextArea1.setFont(newFont("Dialog",0,10));
jTextArea1.setLineWrap(true);
jTextArea1.setOpaque(false);
jTextArea1.setText("Thiscomputerprogramisprotectedbycopyrightlaw.");
jTextArea1.setWrapStyleWord(true);
jTextArea1.setBounds(8,112,256,80);
panel1.add(jTextArea1);
getContentPane().add(panel1,"Card1");
setSize(376,228);
button1.addActionListener(newActionListener(){


publicvoidactionPerformed(ActionEventactionevent)
{
button1_actionPerformed(actionevent);
}


});
}


privatevoidbutton1_actionPerformed(ActionEventactionevent)
{
dispose();
}
}


经JOC搅浑编译后用JAD反编译的了局:


importjava.awt.*;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.*;
importjavax.swing.text.JTextComponent;


publicclassAboutBoxextendsJDialog
{


JPanel_$1;
JButton_$2;
JLabel_$3;
JTextArea_$4;


publicAboutBox()
{
_$1=newJPanel();
_$2=newJButton();
_$3=newJLabel();
_$4=newJTextArea();
_$1();
}


privatevoid_$1()
{
2;
this;
JVMINSTRswap;
setDefaultCloseOperation();
getContentPane().setLayout(newCardLayout());
true;
this;
JVMINSTRswap;
setModal();
false;
this;
JVMINSTRswap;
setResizable();
"About...";
this;
JVMINSTRswap;
setTitle();
_$1.setLayout(null);
_$2.setText("OK");
_$2;
168;
272;
JVMINSTRswap;
24;
88;
JVMINSTRswap;
setBounds();
_$1.add(_$2);
_$3.setText("FileSystemViewerforSwing1.1.1");
_$3.setVerticalAlignment(1);
_$3;
32;
64;
JVMINSTRswap;
56;
240;
JVMINSTRswap;
setBounds();
_$1.add(_$3);
_$4;
JVMINSTRnew#13<ClassFont>;
JVMINSTRdup;
0;
"Dialog";
JVMINSTRswap;
10;
Font();
setFont();
_$4.setLineWrap(true);
_$4.setOpaque(false);
_$4.setText("Thiscomputerprogramisprotectedbycopyrightlaw.");
_$4.setWrapStyleWord(true);
_$4;
112;
8;
JVMINSTRswap;
80;
256;
JVMINSTRswap;
setBounds();
_$1.add(_$4);
getContentPane().add(_$1,"Card1");
376;
this;
JVMINSTRswap;
228;
setSize();
_$2.addActionListener(newIIlIlIIIIlllIIII(this));
return;
}


privatevoid_$1(ActionEventactionevent)
{
dispose();
}




/*
staticvoidaccess$0(AboutBoxaboutbox,ActionEventactionevent)
{
actionevent;
aboutbox;
JVMINSTRswap;
_$1();
return;
}


*/


//Unreferencedinnerclasses:


/*anonymousclass*/
finalclassIIlIlIIIIlllIIII
implementsActionListener
{


publicvoidactionPerformed(ActionEventactionevent)
{
AboutBox.access$0(AboutBox.this,actionevent);
}



{
AboutBox.this;
this;
JVMINSTRswap;
this$0;
}
}
}

什么时候上述的三种开发工具能和三为一,什么时候java的竞争力才更强,才有机会拉拢更多的程序员投入到对java的开发上,因为到时的开发工具将会比.net的更简单。还有一点也很关键,什么时候java推出的jsf能成为真正意义上的标准。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-5 23:56

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表