PHP-CPP Include file inside extension

Asked

Viewed 112 times

2

I am developing a php extension with PHP-CPP, where I need to make a include of a php file within the extension, I am 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 you remove "date://text/Plain;Base64," and use base64_decode you have access to my class.
I tried that 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 mistake: Invalid call to include

Note: I am using this method because it is the safest I know, the others have dozens of methods to do reverse engineering.

EDITION:
I ended up finding a function in PHP-CPP that does include, is the function Php::include() it works perfectly with php files, but when I have use include with the data://text/plain;base64, do not even receive an error message and does not include, which will 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);
}
  • I’m not sure, but I think the error occurs because include is not a function but a PHP "language-Construct".

  • True, I ended up finding a PHP-CPP function that does include, but I ended up encountering a problem, I’ll edit the question.

1 answer

1


The Php::include is only used to include real files and probably does not support the protocol data: which is usually (if not only) used for html applications.

Note that in the github include method tries to read a file:

Value include(const char *filename)
{
    // we can simply execute a file
    return File(filename).execute();
}

The correct would probably be to use Php::eval, see what his source is like:

Value eval(const char *phpCode) 
{
    // we have a script for this
    return Script(phpCode).execute();
}

The code should look something like:

Php::Value HomeControllerInclude () {
    std::string source = "";

    source = "<?php class novo { public static function coco() {  return 20; } }";

    return eval(source);
}

Or:

return Php::eval(source);

May occur from <?php affect the eval, so use it like this:

return eval("?>" + source);
  • I did exactly as you show me, but I get the message: PHP Parse error: parse error in Unknown on line 1

  • I solved the problem, removed <?php and ran smoothly.

  • @Pedrosoares this has nothing to do with what I did but with your string. Correct it and it will solve.

  • @Pedrosoares try like this too and tell me what happens return eval("?>" + source);

  • It also worked. Thank you very much, it helped me a lot.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.