-
Notifications
You must be signed in to change notification settings - Fork 6
/
Packet.php
84 lines (74 loc) · 1.85 KB
/
Packet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
* DecMcpe
*
* Copyright (C) 2016 PEMapModder
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PEMapModder
*/
class Packet{
/** @type string */
public $name;
/** @type int */
public $id;
/** @type string */
public $idHex;
/** @var Instruction[] */
public $instr;
public $instrOffsetIndex;
/** @type PacketField[][] */
public $fields;
/** @var Flow[] */
public $flows = [];
public function __construct($name){
$this->name = $name;
}
public function dumpInfo(){
return [
"id" => $this->idHex,
"fields" => array_map(function ($fieldSet){
return array_map(function (PacketField $field){
return $field->dumpInfo();
}, $fieldSet);
}, $this->fields),
];
}
public function startAnalyze(){
$this->fields = [];
$this->instr = [];
$this->instrOffsetIndex = [];
}
public function analyze($line){
$instr = new Instruction($line);
$this->instrOffsetIndex[$instr->offsetHex] = $i = count($this->instr);
$this->instr[$i] = $instr;
}
public function stopAnalyze(){
$flow = new Flow($this);
$this->flows[] = $flow;
$flow->flow();
$fieldSets = [];
foreach($this->flows as $flow){
$fields = $flow->getFields();
foreach($fieldSets as $fieldSet){
if($fieldSet == $fields){
continue 2;
}
}
$fieldSets[] = $fields;
}
$this->fields = $fieldSets;
echo "\rFinished analyzing $this->name (memory: " . round(memory_get_usage() / 1024, 2) . " KB)\n";
unset($this->instr);
gc_collect_cycles();
echo "Freed resources (memory: " . round(memory_get_usage() / 1024, 2) . " KB)\n";
}
public function isReady(){
return isset($this->id) and isset($this->fields);
}
}