Commits

asuhan committed 9a8f9ed

Store static_variables as new-style hash in op_array and use them

  • Participants
  • Parent commits 4e81def

Comments (0)

Files changed (4)

File happy_execute.py

 def zend_get_target_symbol_table(EG, opline):
     if opline.get_op2().EA_type == tphp.ZendExecutor.ZEND_FETCH_GLOBAL_LOCK:
         return EG.symbol_table
+    elif opline.get_op2().EA_type == tphp.ZendExecutor.ZEND_FETCH_STATIC:
+        if not EG.active_op_array.static_variables:
+            raise Exception('Not implemented yet')
+        return EG.active_op_array.static_variables
     else:
         raise Exception('Not implemented yet')
+    return None
 
 def zend_fetch_dimension_address_inner(EG, ht, dim, type):
     retval_ptr = zval_utils.zppp_stack(tphp.null_zval_ptr_ptr)

File happy_hash.py

         pDest.assign(p)
     return SUCCESS
 
-zend_hash_add = functools.partial(_zend_hash_add_or_update, flag=_HASH_ADD)
+def zend_hash_add(ht, arKey, nKeyLength, h, pData, nDataSize, pDest):
+    return _zend_hash_add_or_update(ht, arKey, nKeyLength, h, pData, nDataSize,
+        pDest, _HASH_ADD)
+
 zend_hash_update = functools.partial(_zend_hash_add_or_update, flag=_HASH_UPDATE)
 
 def _zend_hash_index_update_or_next_insert(ht, h, pData, nDataSize, pDest, flag):

File read_apc_dump.py

           op_array_struct[23].int_value,
           APCFile.build_ZEND_try_catch_element)
       self.last_try_catch = op_array_struct[23].int_value
-      self.static_variables = apc_file.read_ptr(
+
+      import happy_hash
+      import targetphpstandalone as tphp
+      import zval_utils
+      static_variables = apc_file.read_ptr(
           op_array_struct[24].int_value,
           APCFile.build_ZEND_HashTable,
           const_args = (APCFile.build_ZEND_zval, True))
+      self.static_variables = None
+      if not isinstance(static_variables, APCFile.NullStruct):
+        self.static_variables = happy_hash.zend_hash_init(None, 0, None, None, False)
+        for static_var in static_variables.members():
+          varname = static_var.arKey[:-1]
+          happy_hash.zend_hash_add(self.static_variables, varname, len(varname), 0,
+            zval_utils.zpp_stack(zval_utils.zp_stack(static_var.pData)),
+            0, tphp.null_zval_ptr_ptr_ptr)
+
       self.start_op = apc_file.read_ptr(
           op_array_struct[25].int_value,
           APCFile.build_ZEND_op)

File targetphpstandalone.py

             if opline.get_op2().EA_type == ZendExecutor.ZEND_FETCH_GLOBAL_LOCK:
                 if opline.get_op1().get_op_type() == rad.APCFile.ZEND_znode.IS_VAR and not free_op1.var().is_null():
                     raise Exception('Not implemented yet')
+            elif opline.get_op2().EA_type == ZendExecutor.ZEND_FETCH_STATIC:
+                # TODO: implement & use zval_update_constant
+                pass
             else:
                 raise Exception('Not implemented yet')