在PHP中将十六进制代码转换为可读字符串 [英] Convert Hex Code into readable string in PHP
问题描述
您好StackOverflow社区,
这是我的问题,如何将具有十六进制代码的php转换为可读的字符串?
我的意思是在这2个php代码里面。
<?php
echo\x74\150\x69\163\x20\151\x73\40\x74\145\x73\164\x69\156\x67 \40\x6f\156\x6c\171\" ;
echo test ['\x74\171\x70\145'];
回声范围(\x61,\x7a);
?>
这是不可读的代码,我需要一些php函数,可以将那些不可读的代码转换为可读代码..
<?php
echo这只是测试;
echo test ['type'];
回声范围(a,z);
?>
我知道我只能回显该十六进制将其更改为可读的字符串,但我有巨大的php文件和很多的PHP文件,所以我需要PHP函数,可以自动将它们转换为可读代码。
谢谢..
似乎你的代码不仅用十六进制转义序列混淆,而且用八进制也是如此。我写了这个函数来为你解码:
函数decode_code($ code){
return preg_replace_callback(
@ \\\\(x)?([0-9a-f] {2,3})@,
function($ m){
return chr( $ m [1]?hexdec($ m [2]):octdec($ m [2]));
},
$ code
);
}
请参阅此处的操作: http://codepad.viper-7.com/NjiL84
Hi StackOverflow Community,
Here is my question, how to convert php that has hex code into readable string ? On what I mean is all inside this 2 php code..
<?php
echo "\x74\150\x69\163\x20\151\x73\40\x74\145\x73\164\x69\156\x67\40\x6f\156\x6c\171";
echo test['\x74\171\x70\145'];
echo range("\x61","\x7a");
?>
this is un-readable code, I need some php function that can convert those unreadable code into readable code..so it will become like this after convert..
<?php
echo "this is testing only";
echo test['type'];
echo range("a","z");
?>
I know i can just echo that hex to change it to readable string, but I have huge php file and lot's of php file that same like this, so I need php function that can automatically convert them all into readable code.
Thank..
It seems your code is obfuscated not only with hex escape sequences, but with octal as well. I've written this function to decode it for you:
function decode_code($code){
return preg_replace_callback(
"@\\\(x)?([0-9a-f]{2,3})@",
function($m){
return chr($m[1]?hexdec($m[2]):octdec($m[2]));
},
$code
);
}
See it in action here: http://codepad.viper-7.com/NjiL84
这篇关于在PHP中将十六进制代码转换为可读字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!