Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fawno/SimpleSCCU
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.0.1
Choose a base ref
...
head repository: fawno/SimpleSCCU
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 30, 2022

  1. Update unpack method

    alphp committed Apr 30, 2022
    Copy the full SHA
    6e7cbaa View commit details

Commits on May 1, 2022

  1. Code Improvement

    alphp committed May 1, 2022
    Copy the full SHA
    00ad768 View commit details
  2. Update readme

    alphp committed May 1, 2022

    Unverified

    The email in this signature doesn’t match the committer email.
    Copy the full SHA
    0f28aad View commit details
Showing with 15 additions and 27 deletions.
  1. +2 −2 .gitignore
  2. +0 −1 README.md
  3. +13 −24 src/SimpleSCCU.php
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@
/config/app.php
/config/.env
/logs/*
/tmp/*
/vendor/*
/tmp/
/vendor/
/webroot/files/*

# OS generated files #
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[![GitHub license](https://img.shields.io/github/license/fawno/SimpleSCCU)](https://github.com/fawno/SimpleSCCU/blob/master/LICENSE)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/fawno/SimpleSCCU)](https://github.com/fawno/SimpleSCCU/tags)
[![GitHub release](https://img.shields.io/github/release/fawno/SimpleSCCU)](https://github.com/fawno/SimpleSCCU/releases)
[![Packagist](https://img.shields.io/packagist/v/fawno/simplesccu)](https://packagist.org/packages/fawno/simplesccu)
[![Packagist Downloads](https://img.shields.io/packagist/dt/fawno/simplesccu)](https://packagist.org/packages/fawno/simplesccu/stats)
[![GitHub issues](https://img.shields.io/github/issues/fawno/SimpleSCCU)](https://github.com/fawno/SimpleSCCU/issues)
37 changes: 13 additions & 24 deletions src/SimpleSCCU.php
Original file line number Diff line number Diff line change
@@ -26,48 +26,37 @@ public static function unpack (string $bin) : array {
fwrite ($fp, $bin);
rewind($fp);

$header = unpack('a4app/Nlength/N2/Ncount/a', fread($fp, 21));
$header = unpack('a4app/Nlength/nver/x6/Ncount', fread($fp, 20));
if ($header['app'] != 'SCCU') {
throw new SimpleSCCUException('Invalid app mark', SimpleSCCUException::ERROR_FORMAT_UNKNOWN);
}

do {
fseek($fp, -1, SEEK_CUR);
$fhead = unpack('a2mark/Nlength/na/Nb', fread($fp, 12));
for ($i = $header['count']; $i; $i--) {
$fheader = unpack('a2start/Nlength/nmark/x4', fread($fp, 12));

$key = '';
while ("\x00" != $c = fread($fp, 1)) {
$key .= $c;
}
$string = fread($fp, $fheader['length'] - 12);

$value = '';
while ("\x00" != $c = fread($fp, 1)) {
$value .= $c;
}
$key = current(unpack('Z*', $string));
$field = unpack(sprintf('Z%ukey/x/Z*value', strlen($key)), $string);

$fields[$key] = $value;
$fields[$key] = $field['value'];
}

while ("\x00" == fread($fp, 1));
} while (!feof($fp));
fclose($fp);

return $fields;
}

public static function pack (array $fields) : string {
$sccu = pack('N*', 0x10000, 0, count($fields));
$sccu = pack('nx6N', 1, count($fields));

foreach ($fields as $key => $value) {
$mark = (strlen($key) < 10) ? "\x00\x0C" : "\x00\x16";
$mark .= "\x00\x00\x00\x00";
$mark = (strlen($key) < 10) ? 0x0C : 0x16;

$lenght = strlen($key . $value) + 13;
$end = 2 - ($lenght % 2);
$lenght += $end;
$end = strlen($key . $value) % 2;
$lenght = strlen($key . $value) + $end + 14;

$sccu .= '[[' . pack('N*', $lenght) . $mark;
$sccu .= $key . "\x00";
$sccu .= $value . str_repeat("\x00", $end);
$sccu .= '[[' . pack('Nnx4Z*Z*x' . $end, $lenght, $mark, $key, $value);
}

$sccu = 'SCCU' . pack('N*', strlen($sccu) + 8) . $sccu;