include __DIR__ . '/../../autoload.php'; use gymadarasz\aop\AOP; use gymadarasz\aop\PointCut; $file = realpath($argv[1]); if (!$file) { die($file . ' not found' . "\n"); } if (file_exists($file . '.aop.php')) { echo "delete " . $file . '.aop.php..'; if (unlink($file . '.aop.php')) { echo "OK\n"; } else { echo "failed\n"; } } $newfile = AOP::hook($file); echo "hook {$file} -> {$newfile}.."; if (PointCut::saveHooks()) { echo "OK\n"; } else { echo "failed\n"; } $hookstr = "<?php include '{$newfile}'; return; ?>"; $fdata = file_get_contents($file); $strpos = strpos($fdata, $hookstr); if ($strpos === 0) { die("file {$file} has already infected.\n"); } else { if ($strpos !== false) { echo "warning: infection already detected in {$file} but wrong position.\n"; }
protected function joomlaHookTest() { $testProjectPath = realpath('../../../administrator'); $this->nonequ($testProjectPath, false); $aop = AOP::getInstance($testProjectPath); $aop->addPointCut(PointCut::getInstance()->setFilename('index.php')); $pointCut = PointCut::getInstance(); $pointCut->setFilename('/components/com_login/controller.php'); //$pointCut->setNamespace(''); $pointCut->setClass('LoginController'); $pointCut->setFunction('login'); $pointCut->setType('before'); $pointCut->setCallback('gymadarasz\\aop\\AOPTests::testJoomlaAdminLoginBefore'); $aop->addPointCut($pointCut); $aop->infect(); }