Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for stripped ZTS binaries #451

Open
wants to merge 1 commit into
base: 0.12.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Lib/Elf/Structure/Elf64/Elf64ProgramHeaderEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class Elf64ProgramHeaderEntry
public const PT_NOTE = 4;
public const PT_SHLIB = 5;
public const PT_PHDR = 6;
public const PT_TLS = 7;
public const PT_LOPROC = 0x70000000;
public const PT_HIPROC = 0x7fffffff;

Expand Down Expand Up @@ -73,4 +74,9 @@ public function isNote(): bool
{
return $this->p_type === self::PT_NOTE;
}

public function isTls(): bool
{
return $this->p_type === self::PT_TLS;
}
}
18 changes: 18 additions & 0 deletions src/Lib/Elf/Structure/Elf64/Elf64ProgramHeaderTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,22 @@ public function findDynamic(): array
}
return $result;
}

/** @return Elf64ProgramHeaderEntry[] */
public function findTls(): array
{
$result = [];
foreach ($this->entries as $entry) {
if ($entry->isTls()) {
$result[] = $entry;
}
}
return $result;
}

/** @return Elf64ProgramHeaderEntry[] */
public function getAllEntries(): array
{
return $this->entries;
}
}
34 changes: 34 additions & 0 deletions src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

final class ZendExecutorGlobals implements Dereferencable
{
/** @psalm-suppress PropertyNotSetInConstructor */
public Zval $uninitialized_zval;

/** @psalm-suppress PropertyNotSetInConstructor */
public Zval $error_zval;

/** @var Pointer<ZendExecuteData>|null */
public ?Pointer $current_execute_data;

Expand Down Expand Up @@ -61,6 +67,8 @@
private CastedCData $casted_cdata,
private Pointer $pointer,
) {
unset($this->uninitialized_zval);
unset($this->error_zval);
unset($this->current_execute_data);
unset($this->function_table);
unset($this->class_table);
Expand All @@ -75,6 +83,32 @@
public function __get(string $field_name): mixed
{
return match ($field_name) {
'uninitialized_zval' => $this->uninitialized_zval = new Zval(
new CastedCData(

Check failure on line 87 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgumentTypeCoercion

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:87:17: MixedArgumentTypeCoercion: Argument 1 of Reli\Lib\PhpInternals\Types\Zend\Zval::__construct expects Reli\Lib\PhpInternals\CastedCData<FFI\PhpInternals\zval>, but parent type Reli\Lib\PhpInternals\CastedCData<mixed> provided (see https://psalm.dev/194)

Check failure on line 87 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgumentTypeCoercion

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:87:17: MixedArgumentTypeCoercion: Argument 1 of Reli\Lib\PhpInternals\Types\Zend\Zval::__construct expects Reli\Lib\PhpInternals\CastedCData<FFI\PhpInternals\zval>, but parent type Reli\Lib\PhpInternals\CastedCData<mixed> provided (see https://psalm.dev/194)
$this->casted_cdata->casted->uninitialized_zval,

Check failure on line 88 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

UndefinedPropertyFetch

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:88:21: UndefinedPropertyFetch: Instance property FFI\PhpInternals\zend_executor_globals::$uninitialized_zval is not defined (see https://psalm.dev/039)

Check failure on line 88 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgument

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:88:21: MixedArgument: Argument 1 of Reli\Lib\PhpInternals\CastedCData::__construct cannot be mixed, expecting FFI\CData (see https://psalm.dev/030)

Check failure on line 88 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

UndefinedPropertyFetch

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:88:21: UndefinedPropertyFetch: Instance property FFI\PhpInternals\zend_executor_globals::$uninitialized_zval is not defined (see https://psalm.dev/039)

Check failure on line 88 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgument

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:88:21: MixedArgument: Argument 1 of Reli\Lib\PhpInternals\CastedCData::__construct cannot be mixed, expecting FFI\CData (see https://psalm.dev/030)
$this->casted_cdata->casted->uninitialized_zval

Check failure on line 89 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgument

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:89:21: MixedArgument: Argument 2 of Reli\Lib\PhpInternals\CastedCData::__construct cannot be mixed, expecting FFI\CData (see https://psalm.dev/030)

Check failure on line 89 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgument

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:89:21: MixedArgument: Argument 2 of Reli\Lib\PhpInternals\CastedCData::__construct cannot be mixed, expecting FFI\CData (see https://psalm.dev/030)
),
new Pointer(
Zval::class,
$this->pointer->address
+
\FFI::typeof($this->casted_cdata->casted)->getStructFieldOffset('uninitialized_zval'),
\FFI::sizeof($this->casted_cdata->casted->uninitialized_zval),

Check failure on line 96 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

ArgumentTypeCoercion

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:96:34: ArgumentTypeCoercion: Argument 1 of FFI::sizeof expects FFI\CData|FFI\CType, but parent type object provided (see https://psalm.dev/193)

Check failure on line 96 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

ArgumentTypeCoercion

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:96:34: ArgumentTypeCoercion: Argument 1 of FFI::sizeof expects FFI\CData|FFI\CType, but parent type object provided (see https://psalm.dev/193)
),
),
'error_zval' => $this->error_zval = new Zval(
new CastedCData(

Check failure on line 100 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgumentTypeCoercion

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:100:17: MixedArgumentTypeCoercion: Argument 1 of Reli\Lib\PhpInternals\Types\Zend\Zval::__construct expects Reli\Lib\PhpInternals\CastedCData<FFI\PhpInternals\zval>, but parent type Reli\Lib\PhpInternals\CastedCData<mixed> provided (see https://psalm.dev/194)

Check failure on line 100 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgumentTypeCoercion

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:100:17: MixedArgumentTypeCoercion: Argument 1 of Reli\Lib\PhpInternals\Types\Zend\Zval::__construct expects Reli\Lib\PhpInternals\CastedCData<FFI\PhpInternals\zval>, but parent type Reli\Lib\PhpInternals\CastedCData<mixed> provided (see https://psalm.dev/194)
$this->casted_cdata->casted->error_zval,

Check failure on line 101 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

UndefinedPropertyFetch

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:101:21: UndefinedPropertyFetch: Instance property FFI\PhpInternals\zend_executor_globals::$error_zval is not defined (see https://psalm.dev/039)

Check failure on line 101 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgument

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:101:21: MixedArgument: Argument 1 of Reli\Lib\PhpInternals\CastedCData::__construct cannot be mixed, expecting FFI\CData (see https://psalm.dev/030)

Check failure on line 101 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

UndefinedPropertyFetch

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:101:21: UndefinedPropertyFetch: Instance property FFI\PhpInternals\zend_executor_globals::$error_zval is not defined (see https://psalm.dev/039)

Check failure on line 101 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgument

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:101:21: MixedArgument: Argument 1 of Reli\Lib\PhpInternals\CastedCData::__construct cannot be mixed, expecting FFI\CData (see https://psalm.dev/030)
$this->casted_cdata->casted->error_zval

Check failure on line 102 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgument

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:102:21: MixedArgument: Argument 2 of Reli\Lib\PhpInternals\CastedCData::__construct cannot be mixed, expecting FFI\CData (see https://psalm.dev/030)

Check failure on line 102 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

MixedArgument

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:102:21: MixedArgument: Argument 2 of Reli\Lib\PhpInternals\CastedCData::__construct cannot be mixed, expecting FFI\CData (see https://psalm.dev/030)
),
new Pointer(
Zval::class,
$this->pointer->address
+
\FFI::typeof($this->casted_cdata->casted)->getStructFieldOffset('error_zval'),
\FFI::sizeof($this->casted_cdata->casted->error_zval),

Check failure on line 109 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

ArgumentTypeCoercion

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:109:34: ArgumentTypeCoercion: Argument 1 of FFI::sizeof expects FFI\CData|FFI\CType, but parent type object provided (see https://psalm.dev/193)

Check failure on line 109 in src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php

View workflow job for this annotation

GitHub Actions / psalm static code analysis

ArgumentTypeCoercion

src/Lib/PhpInternals/Types/Zend/ZendExecutorGlobals.php:109:34: ArgumentTypeCoercion: Argument 1 of FFI::sizeof expects FFI\CData|FFI\CType, but parent type object provided (see https://psalm.dev/193)
),
),
'current_execute_data' => $this->casted_cdata->casted->current_execute_data !== null
? Pointer::fromCData(
ZendExecuteData::class,
Expand Down
5 changes: 5 additions & 0 deletions src/Lib/PhpInternals/Types/Zend/Zval.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public function isNull(): bool
return $this->getType() === 'IS_NULL';
}

public function isError(): bool
{
return $this->u1->isError();
}

public function isScalar(): bool
{
return $this->isLong() || $this->isDouble() || $this->isBool() || $this->isNull();
Expand Down
5 changes: 5 additions & 0 deletions src/Lib/PhpInternals/Types/Zend/ZvalU1.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ public function getType(): string
default => 'UNKNOWN',
};
}

public function isError(): bool
{
return $this->type === 15;
}
}
5 changes: 3 additions & 2 deletions src/Lib/PhpProcessReader/PhpGlobalsFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class PhpGlobalsFinder
public function __construct(
private PhpSymbolReaderCreator $php_symbol_reader_creator,
private IntegerByteSequenceReader $integer_reader,
private MemoryReaderInterface $memory_reader
private MemoryReaderInterface $memory_reader,
private PhpTsrmLsCacheFinder $tsrm_ls_cache_finder,
) {
}

Expand All @@ -58,7 +59,7 @@ public function findTsrmLsCache(
}
return $tsrm_ls_cache_address;
}
return null;
return $this->tsrm_ls_cache_finder->findByBruteForcing($process_specifier, $target_php_settings);
}

/**
Expand Down
Loading
Loading