寒假里边没有怎么搞明白
分类:热门新闻

最近在看PHP静态分析与跨站脚本检测的东西,用的是维也纳大学一个博士生做出来的Pixy,这个东西是开源的,而且也作了好几年了,功能逐渐增强。现在这个3.0.3版本里边有225个程序,Checker是主程序,现在所有结果都是显示在命令行的,如果被检测程序大,结果很多,当然是个问题。而我要做的大概是将其显示到GUI中去,并且改进它本身呈鼓里边一些不足的地方。从寒假就开始看他的程序,寒假里边没有怎么搞明白,又冷,手生冻疮了。回来以后,从头开始看吧,分析那一部分不是很明白,但是看到后来,检测漏洞的时候,我想暂时不管它存储的结构什么,反正都是Node之类的东西,看他是怎么检测的,有的细节地方那个暂时翻过去,结果感觉比前边analysze部分简单得多了,连那些存储结构什么的都明白些了。当然也看他的论文,论文换了一个寒假看完,没弄明白,像Cfg这些东西在论文中有,但是显示不出来,没有直观的感觉,不爽。所以这两天忙着弄了个GUI界面来显示这个Cfg控制流图,麻烦了一点,不过总算是出来了,看看好像也没有多大问题,献丑在这里了。另外,本来是自己使用的,有的地方考虑不周也无所谓,自己再调调就行了。共有3个文件,第一个是Coor.java,保存每个节点的坐标以及其子节点坐标: packageat.ac.tuwien.infosys.;importjava.util.*;publicclassCoor...{privateintx;privateinty;privateListCoorcoors;publicCoor(intx,inty)...{this.coors=newLinkedListCoor();this.x=x;this.y=y;}publicintgetX()...{returnthis.x;}publicintgetY()...{returnthis.y;}publicListCoorgetCoors()...{returnthis.coors;}publicvoidaddCoor(Coorcoor)...{this.coors.add(coor);}publicbooleanequals(Coorcoor)...{if(coor.getX()==this.xcoor.getY()==y)...{returntrue;}returnfalse;}publicbooleancontains(Coorc)...{for(Coorcoor:this.coors)...{if(coor.getX()==c.getX()coor.getY()==c.getY())...{returntrue;}}returnfalse;}}第二个是DrawPanel.java,负责画图的组件:packageat.ac.tuwien.infosys.;importat.ac.tuwien.infosys.;importat.ac.tuwien.infosys.*;importjava.util.*;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;/***//****@authorAdministrator*/publicclassDrawPanelextendsJPanel...{privatejava.util.ListCfgNodecfgList;privatejava.util.ListCoorcoorList;/***//**CreatesanewinstanceofOvalJPanel*/publicDrawPanel(java.util.ListCfgNodecfgList,java.util.ListCoorcoorList)...{this.cfgList=cfgList;this.coorList=coorList;}//在面板上绘制图形publicvoidpaintComponent(Graphicsg)...{for(inti=0;ithis.cfgList.size();i++)...{CfgNodecfgNode=this.cfgList.get(i);Coorcoor=this.coorList.get(i);intx=coor.getX();inty=coor.getY();g.setColor(Color.red);g.drawOval(x-50,y-15,100,30);g.setColor(Color.blue);g.drawString(cfgNode.toString(),x-30,y-5);g.drawString(Loc:+String.valueOf(cfgNode.getOrigLineno()),x,y+10);java.util.ListCoorcoors=coor.getCoors();for(Coorc:coors)...{intcx=c.getX();intcy=c.getY();g.setColor(Color.black);if(c.equals(coor))...{g.setColor(Color.yellow);}g.drawLine(x,y+15,cx,cy-15);}}}}第三个是Draw.java,主控制组件,只需要在Checker中调用该类,传以适当参数,就可以了。packageat.ac.tuwien.infosys.;importat.ac.tuwien.infosys.;importat.ac.tuwien.infosys.*;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.util.*;/***//****@authorAdministrator*/publicclassDraw...{//声明框架privateJFrameframe=newJFrame(ControlFlowGraph);//声明书签面板privateDrawPaneldraw;privateCfgcfg;privateMapCfgNode,Coormap;privatejava.util.ListCfgNodecfgList;privatejava.util.ListCoorcoorList;privateintstartX=50;privateintstartY=30;/***//**CreatesanewinstanceofTabbedJFrame*/publicDraw(Cfgcfg)...{//this.map=newTreeMapCfgNode,Coor();this.cfgList=newLinkedListCfgNode();this.coorList=newLinkedListCoor();this.cfg=cfg;}publicvoidshow()...{frame.add(newJScrollPane(newDrawPanel(this.cfgList,this.coorList)),BorderLayout.CENTER);frame.setSize(1000,1000);frame.setLocation(50,50);frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}/***//***将Cfg转换为cfgList和coorList.*/publicvoidconvert()...{CfgNodenode=this.cfg.getHead();intsize=this.cfg.size();Coorcoor=newCoor(startX,startY);this.cfgList.add(node);this.coorList.add(coor);System.out.println(size);java.util.ListCfgNodenoded=newLinkedListCfgNode();for(inti=0;isize;i++)...{intn=i;if(noded.contains(node))...{n=-1;for(CfgNodecfgNode:this.cfgList)...{n++;if(noded.contains(cfgNode))...{continue;}node=cfgNode;break;}}noded.add(node);//为了上边的if判断好做,故在此向noded中添加java.util.ListCfgNodelist=node.getSuccessors();intlen=list.size();if(len==0)...{continue;}intk=0;coor=this.coorList.get(this.cfgList.indexOf(node));startY=coor.getY()+60;for(CfgNodecfgNode:list)...{startX=coor.getX()+k*250;k++;if(this.cfgList.contains(cfgNode))...{Coorc=(Coor)this.coorList.get(this.cfgList.indexOf(cfgNode));if(!coor.contains(c))...{coor.addCoor(c);}continue;}coor.addCoor(newCoor(startX,startY));this.cfgList.add(cfgNode);this.coorList.add(newCoor(startX,startY));}node=list.get(0);//这里取到的CfgNode可能已经分析过了,通过上边的if判断可以从cfgList中另外取一个。}}publicvoidsetStartX(intx)...{this.startX=x;}publicvoidsetStartY(inty)...{this.startY=y;}publicintgetStartX()...{returnthis.startX;}publicintgetStartY()...{returnthis.startY;}publicvoiddump()...{System.out.println(------------------);for(inti=0;ithis.cfgList.size();i++)...{CfgNodecfgNode=this.cfgList.get(i);Coorcoor=this.coorList.get(i);System.out.println(cfgNode.toString()+/**//*+cfgNode.toString()*/++coor.getX()++coor.getY()++coor.getCoors().size());}System.out.println(------------------);}publicvoiddumpMap()...{java.util.ListCfgNodelist=this.cfg.dfPreOrder();System.out.println(******************);for(CfgNodenode:list)...{System.out.println(+node.toString()++node.getSuccessors().size());}System.out.println(******************);}publicstaticvoidmain(String[]args)...{//newDraw();}}可能这个项目还会做很久,中间会不会有些心得继续放到这个懒得管的空间中来呢,期待着。<

importjava.awt.*;importjava.net.*;importjava.io.*;importjava.util.*;importjava.awt.event.*;importjava.awt.geom.*;classOmokBoardextendsCanvas{publicstaticfinalintBLACK=1,WHITE=-1;//定义黑白颜色初始值privateint[][]map;//定义二维数组用于记录地图坐标privateintsize,cell;//定义大小和表格privateStringinfo="游戏终止";//定于提示信息privateintcolor=BLACK;//定义颜色初始值privatebooleanenable=false;//定义布尔类型值privatebooleanrunning=false;//定义布尔类型值privatePrintWriterwriter;privateGraphicsgboard,gbuff;//定义图形抽象类privateImagebuff;OmokBoard(ints,intc){this.size=s;this.cell=c;map=newint[size+2][];//实例化地图for(inti=0;imap.length;i++)//for循环生成地图map[i]=newint[size+2];//设置地图元素setBackground(newColor(200,200,100));//设置背景颜色及大小setSize(size*(cell+1)+size,size*(cell+1)+size);//设置大小addMouseListener(newMouseAdapter(){//鼠标监听事件publicvoidmousePressed(MouseEventme){//鼠标经过事件if(!enable)return;//判断enable的值intx=(int)Math.round(me.getX()/(double)cell);//四舍五入得到值inty=(int)Math.round(me.getY()/(double)cell);if(x==0||y==0||x==size+1||y==size+1)return;//判断并返回if(map[x][y]==BLACK||map[x][y]==WHITE)return;//判断并返回writer.println("[STONE]"+x+""+y);//打印出石子map[x][y]=color;//设置指定位置的颜色if(check(newPoint(x,y),color)){info="获胜.";//设置消息writer.println("[WIN]");//打印信息}elseinfo="等待对方落子.";//设置消息repaint();enable=false;//设置enable的值}});}publicbooleanisRunning(){returnrunning;}publicvoidstartGame(Stringcol){running=true;if(col.equals("BLACK")){//判断颜色enable=true;color=BLACK;info="开始游戏...请落子.";}else{enable=false;color=WHITE;info="开始游戏...请等待.";}}publicvoidstopGame(){reset();//重值默认为初始值writer.println("[STOPGAME]");enable=false;running=false;}publicvoidputOpponent(intx,inty){map[x][y]=-color;info="对手已落子...请落子.";repaint();}publicvoidsetEnable(booleanenable){this.enable=enable;}publicvoidsetWriter(PrintWriterwriter){this.writer=writer;}publicvoidupdate(Graphicsg){paint(g);}publicvoidpaint(Graphicsg){if(gbuff==null){buff=createImage(getWidth(),getHeight());gbuff=buff.getGraphics();}drawBoard(g);}publicvoidreset(){for(inti=0;imap.length;i++)for(intj=0;jmap[i].length;j++)map[i][j]=0;info="游戏终止";repaint();}privatevoiddrawLine(){gbuff.setColor(Color.black);for(inti=1;i=size;i++){gbuff.drawLine(cell,i*cell,cell*size,i*cell);gbuff.drawLine(i*cell,cell,i*cell,cell*size);}}privatevoiddrawBlack(intx,inty){Graphics2Dgbuff=(Graphics2D)this.gbuff;gbuff.setColor(Color.black);gbuff.fillOval(x*cell-cell/2,y*cell-cell/2,cell,cell);gbuff.setColor(Color.white);gbuff.drawOval(x*cell-cell/2,y*cell-cell/2,cell,cell);}privatevoiddrawWhite(intx,inty){gbuff.setColor(Color.white);gbuff.fillOval(x*cell-cell/2,y*cell-cell/2,cell,cell);gbuff.setColor(Color.black);gbuff.drawOval(x*cell-cell/2,y*cell-cell/2,cell,cell);}privatevoiddrawStones(){for(intx=1;x=size;x++)for(inty=1;y=size;y++){if(map[x][y]==BLACK)drawBlack(x,y);elseif(map[x][y]==WHITE)drawWhite(x,y);}}synchronizedprivatevoiddrawBoard(Graphicsg){gbuff.clearRect(0,0,getWidth(),getHeight());drawLine();drawStones();gbuff.setColor(Color.red);gbuff.drawString(info,20,15);g.drawImage(buff,0,0,this);}privatebooleancheck(Pointp,intcol){if(count(p,1,0,col)+count(p,-1,0,col)==4)returntrue;if(count(p,0,1,col)+count(p,0,-1,col)==4)returntrue;if(count(p,-1,-1,col)+count(p,1,1,col)==4)returntrue;if(count(p,1,-1,col)+count(p,-1,1,col)==4)returntrue;returnfalse;}privateintcount(Pointp,intdx,intdy,intcol){inti=0;for(;map[p.x+(i+1)*dx][p.y+(i+1)*dy]==col;i++);returni;}}publicclassOmokClientextendsFrameimplementsRunnable,ActionListener{privateTextAreamsgView=newTextArea("",1,1,1);privateTextFieldsendBox=newTextField("");privateTextFieldnameBox=newTextField();privateTextFieldroomBox=newTextField("0");privateLabelpInfo=newLabel("等待室:名");privatejava.awt.ListpList=newjava.awt.List();privateButtonstartButton=newButton("开始对决");privateButtonstopButton=newButton("弃权");privateButtonenterButton=newButton("入场");privateButtonexitButton=newButton("去待机室");privateLabelinfoView=newLabel("2019电子商务大作业",1);privateOmokBoardboard=newOmokBoard(15,30);privateBufferedReaderreader;privatePrintWriterwriter;privateSocketsocket;privateintroomNumber=-1;privateStringuserName=null;publicOmokClient(Stringtitle){super(title);setLayout(null);msgView.setEditable(false);infoView.setBounds(10,30,480,30);infoView.setBackground(newColor(200,200,255));board.setLocation(10,70);add(infoView);add(board);Panelp=newPanel();p.setBackground(newColor(200,255,255));p.setLayout(newGridLayout(3,3));p.add(newLabel("名子:",2));p.add(nameBox);p.add(newLabel("房间号:",2));p.add(roomBox);p.add(enterButton);p.add(exitButton);enterButton.setEnabled(false);p.setBounds(500,30,250,70);Panelp2=newPanel();p2.setBackground(newColor(255,255,100));p2.setLayout(newBorderLayout());Panelp2_1=newPanel();p2_1.add(startButton);p2_1.add(stopButton);p2.add(pInfo,"North");p2.add(pList,"Center");p2.add(p2_1,"South");startButton.setEnabled(false);stopButton.setEnabled(false);p2.setBounds(500,110,250,180);Panelp3=newPanel();p3.setLayout(newBorderLayout());p3.add(msgView,"Center");p3.add(sendBox,"South");p3.setBounds(500,300,250,250);add(p);add(p2);add(p3);sendBox.addActionListener(this);enterButton.addActionListener(this);exitButton.addActionListener(this);startButton.addActionListener(this);stopButton.addActionListener(this);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEventwe){System.exit(0);}});}publicvoidactionPerformed(ActionEventae){if(ae.getSource()==sendBox){Stringmsg=sendBox.getText();if(msg.length()==0)return;if(msg.length()=30)msg=msg.substring(0,30);try{writer.println("[MSG]"+msg);sendBox.setText("");}catch(Exceptionie){}}elseif(ae.getSource()==enterButton){try{if(Integer.parseInt(roomBox.getText())1){infoView.setText("房间号错误,大于1");return;}writer.println("[ROOM]"+Integer.parseInt(roomBox.getText()));msgView.setText("");}catch(Exceptionie){infoView.setText("输入的事项发生错误.");}}elseif(ae.getSource()==exitButton){try{goToWaitRoom();startButton.setEnabled(false);stopButton.setEnabled(false);}catch(Exceptione){}}elseif(ae.getSource()==startButton){try{writer.println("[START]");infoView.setText("等待对方决定.");startButton.setEnabled(false);}catch(Exceptione){}}elseif(ae.getSource()==stopButton){try{writer.println("[DROPGAME]");endGame("已弃权.");}catch(Exceptione){}}}voidgoToWaitRoom(){if(userName==null){Stringname=nameBox.getText().trim();if(name.length()=2||name.length()10){infoView.setText("房间号错误.3~10个数");nameBox.requestFocus();return;}userName=name;writer.println("[NAME]"+userName);nameBox.setText(userName);nameBox.setEditable(false);}msgView.setText("");writer.println("[ROOM]0");infoView.setText("已进待机室.");roomBox.setText("0");enterButton.setEnabled(true);exitButton.setEnabled(false);}publicvoidrun(){Stringmsg;try{while((msg=reader.readLine())!=null){if(msg.startsWith("[STONE]")){Stringtemp=msg.substring(7);intx=Integer.parseInt(temp.substring(0,temp.indexOf("")));inty=Integer.parseInt(temp.substring(temp.indexOf("")+1));board.putOpponent(x,y);board.setEnable(true);}elseif(msg.startsWith("[ROOM]")){if(!msg.equals("[ROOM]0")){enterButton.setEnabled(false);exitButton.setEnabled(true);infoView.setText(msg.substring(6)+"号房间已被进入.");}elseinfoView.setText("已进入待机室.");roomNumber=Integer.parseInt(msg.substring(6));if(board.isRunning()){board.stopGame();}}elseif(msg.startsWith("[FULL]")){infoView.setText("房间满员,禁止入内.");}elseif(msg.startsWith("[PLAYERS]")){nameList(msg.substring(9));}elseif(msg.startsWith("[ENTER]")){pList.add(msg.substring(7));playersInfo();msgView.append("["+msg.substring(7)+"]入场.n");}elseif(msg.startsWith("[EXIT]")){pList.remove(msg.substring(6));playersInfo();msgView.append("["+msg.substring(6)+"]进入其它房间.n");if(roomNumber!=0)endGame("对方已离开.");}elseif(msg.startsWith("[DISCONNECT]")){pList.remove(msg.substring(12));playersInfo();msgView.append("["+msg.substring(12)+"]中断连接.n");if(roomNumber!=0)endGame("对方离开.");

本文由威尼斯在线注册平台发布于热门新闻,转载请注明出处:寒假里边没有怎么搞明白

上一篇:威尼斯登录首页删除一个文件 下一篇:没有了
猜你喜欢
热门排行
精彩图文