Git Product home page Git Product logo

Comments (3)

obilodeau avatar obilodeau commented on July 26, 2024

Did some work on this tonight but I'm dropping the ball. See the construct-2.9 branch for a bit of progress.

I'm not convinced the issue is only with construct, I think PHP changed the opcache format.

from php7-opcache-override.

obilodeau avatar obilodeau commented on July 26, 2024

This commit 2233aa0 introduced a dockerized setup to avoid the construct 2.9 API breakage problems. Documentation is here: https://github.com/GoSecure/php7-opcache-override#dockerized-setup

from php7-opcache-override.

WangYihang avatar WangYihang commented on July 26, 2024

I've got access to opcache files to analyse. I tried the disassembler and got:

$ ./opcache_disassembler.py opcache.bin 
Traceback (most recent call last):
  File "/xxx/php7-opcache-override/analysis_tools/opcache_disassembler.py", line 6, in <module>
    import opcache_parser
  File "/xxx/php7-opcache-override/analysis_tools/opcache_parser.py", line 212, in <module>
    Script = "script" / Struct(Pointer_To("filename", Zend_String("filename"), False),
  File "/xxx/php7-opcache-override/analysis_tools/opcache_parser.py", line 135, in Zend_String
    "val" / String(this.len))
TypeError: String() takes exactly 2 arguments (1 given)

Turns out construct between 2.8 and 2.9 made string types mandatory: https://construct.readthedocs.io/en/latest/advanced.html#strings

This issue can be fixed by replacing the function String with the function Bytes, see the document.

diff --git a/analysis_tools/opcache_parser.py b/analysis_tools/opcache_parser.py
index 430c55e..f8bf3c3 100644
--- a/analysis_tools/opcache_parser.py
+++ b/analysis_tools/opcache_parser.py
@@ -132,7 +132,7 @@ def Zend_String(name):
     return name / Struct(Zend_Refcounted_H("gc"),
                   "h" / Int32ul,
                   "len" / Int32ul,
-                  "val" / String(this.len))
+                  "val" / Bytes(this.len))
 
 def Zend_Arg_Info(name):
     return name / Struct(Pointer_To("name", Zend_String("name")),
@@ -214,8 +214,8 @@ Script = "script" / Struct(Pointer_To("filename", Zend_String("filename"), False
                 Hash_Table("function_table", unserialize_zend_function),
                 Hash_Table("class_table", unserialize_class))
 
-Meta = "meta" / Struct("magic" / String(8),
-              "system_id" / String(32),
+Meta = "meta" / Struct("magic" / Bytes(8),
+              "system_id" / Bytes(32),
               "mem_size" / Int32ul,
               "str_size" / Int32ul,
               "script_offset" / Int32ul,
diff --git a/analysis_tools/opcache_parser_64.py b/analysis_tools/opcache_parser_64.py
index 6b6cfeb..bc221d6 100644
--- a/analysis_tools/opcache_parser_64.py
+++ b/analysis_tools/opcache_parser_64.py
@@ -132,7 +132,7 @@ def Zend_String(name):
     return name / Struct(Zend_Refcounted_H("gc"),
                   "h" / Int64ul,
                   "len" / Int64ul,
-                  "val" / String(this.len))
+                  "val" / Bytes(this.len))
 
 def Zend_Arg_Info(name):
     return name / Struct(Pointer_To("name", Zend_String("name")),
@@ -214,8 +214,8 @@ Script = "script" / Struct(Pointer_To("filename", Zend_String("filename"), False
                 Hash_Table("function_table", unserialize_zend_function),
                 Hash_Table("class_table", unserialize_class))
 
-Meta = "meta" / Struct("magic" / String(8),
-              "system_id" / String(32),
+Meta = "meta" / Struct("magic" / Bytes(8),
+              "system_id" / Bytes(32),
               "mem_size" / Int64ul,
               "str_size" / Int64ul,
               "script_offset" / Int64ul,

After substitution, the opcache_disassembler.py runs correctly.

$ python2 ./analysis_tools/opcache_disassembler.py
Usage : ./analysis_tools/opcache_disassembler.py [-tc] [-a(32|64)] [file]
    -t Print syntax tree
    -c Print pseudocode
    -n Disables colored output
    -a Architecture (-a32 for 32bit or -a64 for 64bit)

from php7-opcache-override.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.