-
Notifications
You must be signed in to change notification settings - Fork 202
/
tonyenc.php
executable file
·54 lines (45 loc) · 1.47 KB
/
tonyenc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* tonyenc.php: Encrypt or decrypt the script with tonyenc.
*
* A high performance and cross-platform encrypt extension for PHP source code.
*
* @author: Tony
* @site: lihancong.cn
* @github: github.com/lihancong/tonyenc
*/
if (version_compare(PHP_VERSION, 7, '<'))
die("PHP must later than version 7.0\n");
if (php_sapi_name() !== 'cli')
die("Must run in cli mode\n");
if (!extension_loaded('tonyenc'))
die("The extension: 'tonyenc' not loaded\n");
if ($argc <= 1)
die("\nusage: php tonyenc.php file.php ... encrypt the php file(s) or directory(s)\n\n");
array_shift($argv);
foreach ($argv as $fileName) {
if (is_file($fileName)) {
handle($fileName);
} elseif (is_dir($fileName)) {
$DirectoriesIt = new RecursiveDirectoryIterator($fileName, FilesystemIterator::SKIP_DOTS);
$AllIt = new RecursiveIteratorIterator($DirectoriesIt);
$it = new RegexIterator($AllIt, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
foreach ($it as $v)
handle($v[0]);
} else {
echo "Unknowing file: '$fileName'\n";
}
}
function handle($file)
{
if ($fp = fopen($file, 'rb+') and $fileSize = filesize($file)) {
$data = tonyenc_encode(fread($fp, $fileSize));
if ($data !== false) {
if (file_put_contents($file, '') !== false) {
rewind($fp);
fwrite($fp, $data);
}
}
fclose($fp);
}
}