Comments (5)
Thanks for letting me know about this. I was not aware you could increment strings like that.
How do you do variable storage? How do I get the value of the specified variable?Is it $node->getAttribute(AttrName::VALUE)?
Yes, there is a utility function Utils::getValue
to convert a node to its value:
Line 59 in 35e9fbc
It looks like I may have missed the increment operators from the reducers, just needs to be added to UnaryReducer
https://github.com/simon816/PHPDeobfuscator/blob/35e9fbcff1be30b0fe9ac3f68f6868385b049ee1/src/Reducer/UnaryReducer.php
from phpdeobfuscator.
A complication with post increment/decrement operators is that they need to be split into two expressions, which is not possible to do in general.
For example:
$a = "a";
foo($a++);
I want to use something like the comma operator from JavaScript, i.e:
$a = "a";
foo( ($a = "b", "a") );
But this is not legal in PHP, so the assignment must go somewhere else, which could lead to a semantically different program.
from phpdeobfuscator.
Thank you for your reply.
My idea is to get the ASCII value of the last character of the string and convert it through chr()
and ord()
.
For example
public function reduceStringInc(Node\Expr\PostInc $node)
{
$val = Utils::getValue($node->var);
if(is_string($val)) {
if(strlen($val) > 1){
$status = True;
$forwardstr = substr($val,0,strlen($val)-1);
$backwardstr = substr($val,-1);
}else{
$status = False;
$backwardstr = $val;
}
$new_str = chr(ord($backwardstr) + 1);
if($status){
$new_string = $forwardstr . $new_str;
}else{
$new_string = $new_str;
}
return Utils::scalarToNode($new_string);
}elseif(is_int($val)){
return Utils::scalarToNode((int) $val + 1);
}
}
The result of this code is as follows
<?php
$a = "qazwsx";
$a++;
echo $a;
$b = 3;
$b++;
------------------------
$a = "qazwsx";
"qazwsy";
echo "qazwsx";
$b = 3;
4;
$a++
is reduced to qazwsy
.
But notice that the result of echo $a
is still qazwsx
If there are more than one $a++
operation, the result will be the same.
after each restore of $a++, we need to update the new value to the node of $a.
I tried to use
$node->var->setAttribute(AttrName::VALUE,$new_string);
But it doesn't seem to work 😂.
Is my thinking and method right? How can I update the variable value in real time?
from phpdeobfuscator.
You've over-complicated the incrementation. You can simply do $val++
and let PHP handle the incrementation 🙂
Something as simple as this:
public function reducePostInc(Node\Expr\PostInc $node)
{
$val = Utils::getValue($node->var);
$val++;
return new Node\Expr\Assign($node->var, Utils::scalarToNode($val));
}
However I see this still doesn't actually work, I think we need the new Expr\Assign
node to be handled in the Resolver
class.
from phpdeobfuscator.
increment is now implemented, this is what it returns for your sample:
<?php
$_ = [];
$_ = @"Array";
// $_='Array';
$_ = $_[false];
// $_=$_[0];
$___ = $_;
// A
$__ = $_;
$__ = "B";
$__ = "C";
$__ = "D";
$__ = "E";
$__ = "F";
$__ = "G";
$__ = "H";
$__ = "I";
$__ = "J";
$__ = "K";
$__ = "L";
$__ = "M";
$__ = "N";
$__ = "O";
$__ = "P";
$__ = "Q";
$__ = "R";
$__ = "S";
$___ = "AS";
// S
$___ = "ASS";
// S
$__ = $_;
$__ = "B";
$__ = "C";
$__ = "D";
$__ = "E";
// E
$___ = "ASSE";
$__ = $_;
$__ = "B";
$__ = "C";
$__ = "D";
$__ = "E";
$__ = "F";
$__ = "G";
$__ = "H";
$__ = "I";
$__ = "J";
$__ = "K";
$__ = "L";
$__ = "M";
$__ = "N";
$__ = "O";
$__ = "P";
$__ = "Q";
$__ = "R";
// R
$___ = "ASSER";
$__ = $_;
$__ = "B";
$__ = "C";
$__ = "D";
$__ = "E";
$__ = "F";
$__ = "G";
$__ = "H";
$__ = "I";
$__ = "J";
$__ = "K";
$__ = "L";
$__ = "M";
$__ = "N";
$__ = "O";
$__ = "P";
$__ = "Q";
$__ = "R";
$__ = "S";
$__ = "T";
// T
$___ = "ASSERT";
$____ = '_';
$__ = $_;
$__ = "B";
$__ = "C";
$__ = "D";
$__ = "E";
$__ = "F";
$__ = "G";
$__ = "H";
$__ = "I";
$__ = "J";
$__ = "K";
$__ = "L";
$__ = "M";
$__ = "N";
$__ = "O";
$__ = "P";
// P
$____ = "_P";
$__ = $_;
$__ = "B";
$__ = "C";
$__ = "D";
$__ = "E";
$__ = "F";
$__ = "G";
$__ = "H";
$__ = "I";
$__ = "J";
$__ = "K";
$__ = "L";
$__ = "M";
$__ = "N";
$__ = "O";
// O
$____ = "_PO";
$__ = $_;
$__ = "B";
$__ = "C";
$__ = "D";
$__ = "E";
$__ = "F";
$__ = "G";
$__ = "H";
$__ = "I";
$__ = "J";
$__ = "K";
$__ = "L";
$__ = "M";
$__ = "N";
$__ = "O";
$__ = "P";
$__ = "Q";
$__ = "R";
$__ = "S";
// S
$____ = "_POS";
$__ = $_;
$__ = "B";
$__ = "C";
$__ = "D";
$__ = "E";
$__ = "F";
$__ = "G";
$__ = "H";
$__ = "I";
$__ = "J";
$__ = "K";
$__ = "L";
$__ = "M";
$__ = "N";
$__ = "O";
$__ = "P";
$__ = "Q";
$__ = "R";
$__ = "S";
$__ = "T";
// T
$____ = "_POST";
$_ = $_POST;
ASSERT($_[_]);
// ASSERT($_POST[_]);
from phpdeobfuscator.
Related Issues (15)
- missing file HOT 2
- Variable restoration failure HOT 2
- Function names are case-insensitive HOT 1
- Goto calls HOT 8
- It does not seem to be able to restore system resource-related functions HOT 2
- Cannot be restored when the variable value is Superglobals HOT 4
- Problem HOT 1
- fclose(): supplied resource is not a valid stream resource HOT 1
- Problem decoding goto
- Not correct decode HOT 4
- PHP Fatal error: Uncaught LogicException: HOT 2
- Is there developer documentation here? HOT 2
- PHP Fatal error: Array and string offset access syntax with curly braces is no longer supported HOT 1
- Problem with more than two consecutive goto labels. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpdeobfuscator.