search
Homephp教程PHP源码 PHP静态分析与跨站脚本检测(二)

<script>ec(2);</script>
        今天继续昨天的话题,这次仍然是为了理解php解析过程而做得工作。这次是将ProgramConverter中对PHP文件解析产生的ParseTree显示出来,使用JTree。
        当然ProgramConverter中没有返回ParseTree的方法,如果另外在Checker中重新解析一遍,毫无疑问是不划算的,因而改写ProgramConverter,添加几行代码就行了。然后再Checker中调用具体产生JTree的类,将这个ParseTree作为参数传进去,然后OK。
        这里相比昨天的Draw,使用了JTabbedPane作为底层容器,分别承载DrawPanel和今天的ParseTreePanel,这些地方的改动就不写出来了。
下边列出将ParseTree转换为JTree的类文件:


package at.ac.tuwien.infosys.www.pixy;

import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import at.ac.tuwien.infosys.www.phpparser.*;


public class ParseTreePanel extends JPanel
{
    
private ParseTree parseTree;

    
public ParseTreePanel(ParseTree parseTree)
    
{
        
this.parseTree = parseTree;

        
this.add(new JTree(convert(this.parseTree.getRoot())),BorderLayout.CENTER);
    }

    
public DefaultMutableTreeNode convert(ParseNode parseNode)
    
{
        String name 
= parseNode.getName();
        
if (parseNode.isToken())
        
{
            name 
+= " : " + parseNode.getLineno();
        }

        DefaultMutableTreeNode dmtNode 
= new DefaultMutableTreeNode(name);
        java.util.List
ParseNode> list = parseNode.getChildren();
        
for (ParseNode node : list)
        
{
            dmtNode.add(convert(node));
        }

        
return dmtNode;
    }

}

这些都是些表面文章,没有涉及到Pixy的内涵。
顺便提一句,这个PhpParser跟Pixy是同一个人做的。很佩服啊!

        另外,今天看了下ASPA这个东西,将asp文件转换为php文件,本来是很神奇的东西,居然运行不了。但是我把AspParser.java重新编译一遍之后就可以运行了,否则会在引用的commons组件那里出点问题。不知道是否只有我是这样的。



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.