ControlFlow Class Reference

#include <Obfuscator.h>

Inheritance diagram for ControlFlow:

Inheritance graph
[legend]
Collaboration diagram for ControlFlow:

Collaboration graph
[legend]

Detailed Description

Definition at line 57 of file Obfuscator.h.


Public Member Functions

 ControlFlow ()
 ControlFlow (const std::string &flowXML)
virtual ~ControlFlow ()
virtual void operator() (tree< AstNode > &, MapClasses *classes=0, MapVariables *vars=0, MapFunctions *func=0)

Data Fields

Ast flowAST

Constructor & Destructor Documentation

ControlFlow::ControlFlow (  )  [inline]

Definition at line 62 of file Obfuscator.h.

00062 {}

ControlFlow::ControlFlow ( const std::string &  flowXML  )  [inline]

Definition at line 63 of file Obfuscator.h.

References flowAST.

00063                                           { 
00064         flowAST = Ast(flowXML);
00065     }

virtual ControlFlow::~ControlFlow (  )  [inline, virtual]

Definition at line 66 of file Obfuscator.h.

00066 {}


Member Function Documentation

void ControlFlow::operator() ( tree< AstNode > &  tr,
MapClasses classes = 0,
MapVariables vars = 0,
MapFunctions func = 0 
) [virtual]

Generic control flow modification

Implements Obfuscator.

Definition at line 274 of file Obfuscator.cpp.

References applyModification(), tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::child(), clean_pattern(), tree< T, tree_node_allocator >::end(), flowAST, Ast::getTreeConstPtr(), insert_branch(), insert_statement(), and tree< T, tree_node_allocator >::parent().

00274                                                                                                            {
00275 
00276     // 1 - Detect which if modifiying (select all the unticked_statement grand children of top_statement)
00277     AstNodeIteratorList affectedNode;
00278     tree<AstNode>::iterator iter, parent, grandparent;
00279     for (iter=tr.begin(); iter!=tr.end();++iter)
00280     {
00281         if (iter->getType() == "statement"
00282         && tr.parent(iter)->getType() == "top_statement")
00283         {
00284             // We put the parent =? 'statement' in the list
00285             affectedNode.push_back(iter);
00286         }
00287     }
00288 
00289     // 2 - Let's study a little out resource...
00290     tree<AstNode>::iterator endStatement;
00291     AstNodeIteratorList branchs;
00292     AstNodeIteratorList br_func;
00293     AstNodeIteratorList br_classe;
00294 
00295     // 2+1/2 - Look for renaming? ($rand_name will be a generateName())
00296     applyModification(flowAST);
00297     tree<AstNode> def = *(flowAST.getTreeConstPtr());
00298 
00299     // 2+3/4 - Cut the external resource to implant it into the tree (get the nodes into the flowAST)
00300     for (tree<AstNode>::iterator iter=def.begin(); iter!=def.end(); ++iter)
00301     {
00302         if (iter->getValue() == "$enter_the_new_statement") {
00303             endStatement = iter;
00304             // rewind to the statement, not interesting by everything after this statement
00305             do { 
00306                 endStatement = def.parent(endStatement);
00307             } while (endStatement->getType() != "statement" && def.parent(endStatement)->getType() != "inner_statement");
00308             //endStatement = def.child(endStatement, 0);
00309         }
00310         else if (iter->getType() == "top_statement") {
00311             if (tr.child(iter,0)->getType() == "function_declaration_statement")
00312                 br_func.push_back(iter);
00313             else if (tr.child(iter,0)->getType() == "class_declaration_statement")
00314                 br_classe.push_back(iter);
00315             else
00316                 branchs.push_back(iter);
00317         }
00318     }
00319     //
00320     // 3 - Adding the nodes: merging the two trees
00321     tree<AstNode>::iterator topDeclarations = tr.begin();
00322     for (;topDeclarations!= tr.end(); ++topDeclarations) {
00323         if (topDeclarations->getType() == "top_statement_list")
00324         {
00325             for (tree<AstNode>::iterator tmp=topDeclarations;tmp->getType()=="top_statement_list";++tmp)
00326                 topDeclarations = tmp;
00327             break;
00328         }
00329     }
00330     // Insert the classes
00331     for (AstNodeIteratorList::iterator bter=br_classe.begin();bter!=br_classe.end();++bter)
00332         insert_branch(topDeclarations, *bter, tr, *(flowAST.getTreeConstPtr()));
00333 
00334     // Insert the functions
00335     for (AstNodeIteratorList::iterator bter=br_func.begin();bter!=br_func.end();++bter)
00336         insert_branch(topDeclarations, *bter, tr, *(flowAST.getTreeConstPtr()));
00337 
00338     // Insert the obfuscation template (empty)
00339     for (AstNodeIteratorList::iterator bter=branchs.begin();bter!=branchs.end();++bter)
00340         insert_branch(topDeclarations, *bter, tr, *(flowAST.getTreeConstPtr()));
00341 
00342     //Select the place to insert
00343     for (tree<AstNode>::iterator iter=tr.begin();iter!=tr.end();++iter)
00344     {
00345         if (iter->getType() == "text" && iter->getValue() == "$enter_the_new_statement") {
00346             // Let's Insert Here!!
00347             for (AstNodeIteratorList::iterator jter=affectedNode.begin(); jter!=affectedNode.end();++jter) {
00348                 insert_statement(iter, *jter ,tr);
00349             }
00350         }
00351     }
00352     clean_pattern(tr);
00353 }

Here is the call graph for this function:


Field Documentation

Ast ControlFlow::flowAST

Definition at line 60 of file Obfuscator.h.

Referenced by ControlFlow(), and operator()().


The documentation for this class was generated from the following files:
Generated on Wed Feb 27 20:31:46 2008 for php.ast.svn.src. by  doxygen 1.5.3