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(); }
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"; } } echo "infect {$file} file..";
public static function hook($filename) { $hookfname = $filename . '.aop.php'; if (!file_exists($hookfname)) { // todo ... $cwd = getcwd(); $hookfname = $cwd . DIRECTORY_SEPARATOR . pathinfo($filename, PATHINFO_BASENAME) . '.aop.php'; if (!file_exists($hookfname)) { $includePaths = explode(';', get_include_path()); $found = false; foreach ($includePaths as $includePath) { $hookfname = $includePath . DIRECTORY_SEPARATOR . pathinfo($filename, PATHINFO_BASENAME) . '.aop.php'; if (file_exists($hookfname)) { $found = true; break; } } if (!$found) { $errmsg = 'Hook (.aop.php) not found for ' . $filename; if (self::EXCEPTION_ON_HOOK_NOT_FOUND) { throw new \Exception($errmsg); } if (self::WARNING_ON_HOOK_NOT_FOUND) { trigger_error($errmsg); } self::$errors[] = $errmsg; $hookfname = PointCut::getInstance()->hook($filename); PointCut::saveHooks(); } } else { $hookfname = $filename; } } return $hookfname; }