forked from lphooge/libKeePHPass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKdbGroup.php
More file actions
118 lines (102 loc) · 3.4 KB
/
KdbGroup.php
File metadata and controls
118 lines (102 loc) · 3.4 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* @author Lutz-Peter Hooge
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LESSER GENERAL PUBLIC LICENSE
* @package libKeePHPass
*/
class KdbGroup{
const TIME_NORMAL = 1072911600; // 1.1.2004 00:00:00
const TIME_EXPIRE = 66995251199; // 28.12.4092 23:59:59
public $id = null; // unique (in db) group id
public $image_id = 0; // index of icon in icon image list
public $name = null;
public $group_id = null; // this is internally generated, not saved in file
public $creation_time = self::TIME_NORMAL;
public $modification_time = self::TIME_NORMAL;
public $access_time = self::TIME_NORMAL;
public $expiration_time = self::TIME_EXPIRE;
public $level = 0; // indentation level in the tree.
public $flags = 0; // default=0, currently not used
public $entries = array(); // sub entries
public $groups = array(); // sub groups
public function getEntries(){
return $this->entries;
}
/**
* @return array
*/
public function getGroups(){
return $this->groups;
}
public function parse($input){ /* @var $input BinStr */
if(is_string($input)){
$input = new BinStr(new StringStream($input));
}
while(true){
$position_original = $input->tell();
$field_type = $input->readUnsignedShort(); //$input->readUnsignedShort(); // 2 bytes
$field_size = $input->readUnsignedLong(); // 4 bytes
$value = $input->read($field_size);
//echo "read file type $field_type length=$field_size, val=".BinStr::toHex($value)." <br>";
switch($field_type){
case 0:
// Ignore field
break;
case 1:
$this->id = BinStr::toInt(substr($value,0,4));
break;
case 2:
$this->name = trim($value, "\0");
break;
case 3:
$this->creation_time = KdbUtil::unpackTime($value); // acompressedtime
break;
case 4:
$this->modification_time = KdbUtil::unpackTime($value);
break;
case 5:
$this->access_time = KdbUtil::unpackTime($value);
break;
case 6:
$this->expiration_time = KdbUtil::unpackTime($value);
break;
case 7:
$this->image_id = BinStr::toInt(substr($value,0,4));
break;
case 8:
$this->level = BinStr::toUInt($value);
break;
case 9:
$this->flags = BinStr::toInt(substr($value,0,4));
break;
case 0xFFFF:
return; // end of Group
default:
throw new Exception("unknow field type $field_type");
break;
}
}
return $this;
}
protected static function writeField($stream,$type,$value){
$stream->write(BinStr::fromInt($type,2)); // field type
$stream->write(BinStr::fromInt(strlen($value),4)); // field size
$stream->write($value);
}
public function write($stream=null){ /* @var $input BinStr */
if(!$stream instanceof BinStr){
$stream = new BinStr(new StringStream($input));
}
self::writeField($stream, 1, BinStr::fromInt($this->id, 4));
self::writeField($stream, 2, $this->name."\0");
self::writeField($stream, 3, KdbUtil::packTime($this->creation_time));
self::writeField($stream, 4, KdbUtil::packTime($this->modification_time));
self::writeField($stream, 5, KdbUtil::packTime($this->access_time));
self::writeField($stream, 6, KdbUtil::packTime($this->expiration_time));
self::writeField($stream, 7, BinStr::fromInt($this->image_id,4));
self::writeField($stream, 8, BinStr::fromInt($this->level,2));
self::writeField($stream, 9, BinStr::fromInt($this->flags,4));
self::writeField($stream, 0xFFFF, '');
return $stream;
}
}