Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there developer documentation here? #5

Open
L2ksy0d opened this issue Feb 15, 2022 · 2 comments
Open

Is there developer documentation here? #5

L2ksy0d opened this issue Feb 15, 2022 · 2 comments

Comments

@L2ksy0d
Copy link

L2ksy0d commented Feb 15, 2022

Hello, I plan to do a PHPDeobfuscator project as my graduation project, I plan to learn the processing mode of your project, but NOW I can only do some basic application of PHP-Parser, I am trying to understand your data flow processing, I have been reading the source code of ControlFlowVisitor recently, But sometimes I can't understand it well, and FuncCallReducer. Have you written any documentation to help others understand the flow of the program?

@simon816
Copy link
Owner

simon816 commented Feb 15, 2022

Hi, thanks for taking an interest in this project.

Unfortunately I have not written any documentation.
The general principle is to "reduce" expressions into simpler expressions, by performing a post-order traversal over the parse tree.
It is the same technique used by compiler optimizers, called "Constant folding" https://en.wikipedia.org/wiki/Constant_folding.

FuncCallReducer is one of the reducers, it reduces a function call. Classes that implement FunctionReducer register themselves with FuncCallReducer to handle certain functions.
For example, FuncCallReducer\PassThrough registers chr. For the expression chr(65), it returns "A" (because chr(65) returns "A").
Combined with BinaryOpReducer to handle the "concat" operator (the dot), for the expression chr(65) . chr(66) . chr(67) it returns "ABC"

The Resolver class is responsible for determining the value of variables, as well as which variables are accessible in the current scope.

ControlFlowVisitor is a particularly challenging class to understand, and could do with some improvements, but the idea is to rearrange chunks of code into a more linear sequence. This is what re-orders the goto label4 example in the readme.
It records the "entry" and "exit" locations of each block of code, where a block of code is not quite a "basic block", but is just something between a label and a goto.
It tries to align every "exit" and "entry" together, but being careful to handle loops and not to change execution order.

@L2ksy0d
Copy link
Author

L2ksy0d commented Feb 16, 2022

Thank you for your reply. I will try to understand the processing process mentioned in your reply. I will take it as my main work in the short term. I'll keep trying. Thank you again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants