I'm developing a php extension with PHP-CPP, where I need to make an include of a php file within the extension, I'm doing this to protect the code. I'm trying this way:
Php::Value HomeController () {
std::string source = "";
source += "<?php\r\n";
source += "namespace App\Http\Controllers\ajax;\r\n";
source += "use Illuminate\Http\Request;\r\n";
source += "use App\Http\Requests;\r\n";
source += "use App\Http\Controllers\Controller;\r\n";
source += "class HorarioController extends Controller {\r\n";
source += "protected $page = \"ajax.horario\";\r\n";
source += "public function index(){\r\n";
source += "return $this->view;\r\n";
source += "}\r\n";
source += "}\r\n";
Php::Value val = Php::call("base64_encode", source);
std::string retorno = val;
retorno = "data://text/plain;base64,"+retorno;
return retorno;
}
but if the person removes the "data: // text / plain; base64," and using base64_decode has access to my class. Home I tried this way too:
void HomeControllerInclude () {
std::string source = "";
source += "<?php\r\n";
source += "namespace App\Http\Controllers\ajax;\r\n";
source += "use Illuminate\Http\Request;\r\n";
source += "use App\Http\Requests;\r\n";
source += "use App\Http\Controllers\Controller;\r\n";
source += "class HorarioController extends Controller {\r\n";
source += "protected $page = \"ajax.horario\";\r\n";
source += "public function index(){\r\n";
source += "return $this->view;\r\n";
source += "}\r\n";
source += "}\r\n";
Php::Value val = Php::call("base64_encode", source);
std::string retorno = val;
retorno = "data://text/plain;base64,"+retorno;
Php::call("include", retorno);
}
But I get the following error: Invalid call to include
Note: I'm using this method because it's the safest I know, the rest have dozens of reverse engineering methods.
EDITION:
I found a function in PHP-CPP that does the include, it's the function Php::include()
it works perfectly with php files, but when I have to use include with data://text/plain;base64,
I do not get an error message and does not include , what will it be?
Php::Value HomeControllerInclude () {
std::string source = "";
source = "<?php class novo { public static function coco() { return 20; } }";
Php::Value val = Php::call("base64_encode", source);
std::string retorno = val;
retorno = "data://text/plain;base64,"+retorno;
return include(retorno);
}