Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F32166877
codegen.php
ori (Ori Livneh)
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
ori
Aug 15 2020, 5:52 PM
2020-08-15 17:52:28 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
codegen.php
View Options
<?php
// Generate randomized, self-verifying PHP code.
function
randomName
()
{
$alpha
=
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_'
;
$alphanum
=
$alpha
.
'0123456789'
;
$s
=
$alpha
[
mt_rand
(
0
,
strlen
(
$alpha
)-
1
)];
$len
=
mt_rand
(
1
,
20
);
while
(
strlen
(
$s
)
<
$len
)
{
$s
.=
$alphanum
[
mt_rand
(
0
,
strlen
(
$alphanum
)-
1
)];
}
return
$s
;
}
$className
=
randomName
();
$methodName
=
randomName
();
$arrayKey
=
randomName
();
$constName
=
randomName
();
$constValue
=
base64_encode
(
random_bytes
(
mt_rand
(
10
,
100
)));
$propName
=
randomName
();
$propValue
=
base64_encode
(
random_bytes
(
mt_rand
(
10
,
100
)));
$instName
=
randomName
();
$digest
=
md5
(
$constValue
.
$propValue
);
echo
<<<EOT
<?php
static \$arr = ["{$arrayKey}" => "{$digest}"];
class ParentClass {
protected function getKey(\$key) {
global \$arr;
return \$arr[\$key];
}
}
class {$className} extends ParentClass {
private const {$constName} = '{$constValue}';
function __construct(\$prop) {
\$this->{$propName} = \$prop;
}
function {$methodName}(\$key) {
\$digest = \$this->getKey(\$key);
if (md5(self::{$constName}.\$this->{$propName}) !== \$digest) {
die("check error: md5(" .self::{$constName}.\$this->{$propName}.") != " . \$digest);
}
echo "OK\\n";
}
}
\${$instName} = new {$className}("{$propValue}");
\${$instName}->{$methodName}("{$arrayKey}");
EOT;
File Metadata
Details
Attached
Mime Type
text/x-php
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8507075
Default Alt Text
codegen.php (1 KB)
Attached To
Mode
T253673: Avoid php-opcache corruption in WMF production
Attached
Detach File
Event Timeline
Log In to Comment