forked from bmanojlovic/msshlnkdecoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_lnkdecoder.php
183 lines (157 loc) · 5.58 KB
/
test_lnkdecoder.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* @desc simple test script for lnkdecoder.class.php
*
*/
require 'lnkdecoder.class.php';
function giveme_files($store=array()){
foreach ($store as $key => $f){
$f = mb_convert_encoding($f, 'UTF-8');
try{
echo " =================== " . PHP_EOL;
echo " Working $f " . PHP_EOL;
echo " =================== " . PHP_EOL;
// var_dump($of->__toString());
$of = new SplFileInfo("$f");
if ($of->isFile()){
echo 'fichier ';
if ($of->isReadable()){
echo "lisible";
}else{
echo "non lisible";
}
echo PHP_EOL;
}elseif ($of->isDir()){
echo 'répertoire ';
if ($of->isReadable()){
echo "lisible";
}else{
echo "non lisible";
}
echo PHP_EOL;
}elseif (!$of->isReadable()){
echo " No target available ".PHP_EOL;
}else{
echo " --- Ceci est un bug --- ".PHP_EOL;
// Debug
// print "************************** Debug **************";
// print $of->getType() . '
// ' . $of->getPath() . ' ' . $of->getPathname() . '
// ' . $of->getFilename() . ' ' .$of->getBasename() . ' ' . $of->getExtension() . '
// ' . $of->getATime() . ' ' . $of->getCTime() . ' ' . $of->getMTime() . '
// ' . $of->getOwner() . ':' . $of->getGroup() . ' ' . $of->getPerms() . '
// ' . $of->getInode() . ' ' . $of->getSize() . PHP_EOL;
}
}catch ( RuntimeException $r){
echo sprintf("%s : %s",$r->getCode(), $r->getMessage()).PHP_EOL;
echo $r->getTraceAsString() . PHP_EOL;
}catch ( Exception $e){
echo sprintf("%s : %s",$e->getCode(), $e->getMessage()).PHP_EOL;
echo $e->getTraceAsString() . PHP_EOL;
// die();
}
}
}
// http://www.php.net/manual/en/function.chr.php#89488
function echocolor($text,$color="normal",$back=0)
{
$colors = array('light_red' => "[1;31m", 'light_green' => "[1;32m", 'yellow' => "[1;33m",
'light_blue' => "[1;34m", 'magenta' => "[1;35m", 'light_cyan' => "[1;36m",
'white' => "[1;37m", 'normal' => "[0m", 'black' => "[0;30m",
'red' => "[0;31m", 'green' => "[0;32m", 'brown' => "[0;33m",
'blue' => "[0;34m", 'cyan' => "[0;36m", 'bold' => "[1m",
'underscore' => "[4m", 'reverse' => "[7m" );
$out = $colors["$color"];
$ech = chr(27)."$out"."$text".chr(27)."[0m";
if($back)
{
return $ech;
}
else
{
echo $ech . PHP_EOL;
}
}
function failed ()
{
echocolor(" FAILED",$color="red",$back=0);
}
function passed ()
{
echocolor(" PASSED",$color="green",$back=0);
}
function separator ()
{
echocolor (" =====", $color="magenta",$back=0);
}
$msshlnk = array();
$FOLDER = 'samples';
$test_files = new DirectoryIterator($FOLDER);
echo "=======================================" . PHP_EOL;
echo "======== Test Suite for MSSHLNK =======" . PHP_EOL;
echo "=======================================" . PHP_EOL;
echo " Opening Files" . PHP_EOL;
echo "=======================================" . PHP_EOL;
foreach ($test_files as $file)
{
if (!$test_files->isDot()) {
$f = $file->getFilename();
echo 'Opening lnk file "' . $f . '"... ' ;
//var_dump($file);
$msshlnk[$f] = new MSshlnk();
if (!$msshlnk[$f]->open($file->getPathname())) {
failed() . PHP_EOL;
echo ' errno='
. $msshlnk[$f]->errno
. ' errstring="'
. $msshlnk[$f]->errstring
. '"' . PHP_EOL;
unset($msshlnk[$f]);
} else {
passed() . PHP_EOL;
}
echo PHP_EOL;
}
}
unset ($test_files);
unset ($file);
clearstatcache();
$tomove=array();
// $file_store = "/tmp/store_lnk.csv";
// try{
// $fs = new SplFileObject($file_store, 'wb');
// }catch(Exception $e){
// die($e->getCode . ' ' . $e->getMessage());
// }
foreach($msshlnk as $key => $lnk) {
echo PHP_EOL;
echo PHP_EOL;
echo PHP_EOL;
echo "=======================================" . PHP_EOL;
echo " =================== " . PHP_EOL;
echo " parse_LinkInfo for $key" . PHP_EOL;
echo " =================== " . PHP_EOL;
$lnk->parse();
// echo "LinkFlags= "; print_r($lnk->LinkFlags);
// echo "StructSize= "; print_r($lnk->StructSize);
// echo "ParsedInfo= "; @print_r($lnk->ParsedInfo);
// echo "Path source to move = " . str_replace('\\', '/', $lnk->ParsedInfo['LinkInfo']['CommonPathSuffix']).PHP_EOL;
// $tomove[] = rtrim('/sigeom/install/'.str_replace('\\', '/', $lnk->ParsedInfo['LinkInfo']['CommonPathSuffix']));
$tomove[] = '/sigeom/install/'.str_replace('\\', '/', $lnk->ParsedInfo['LinkInfo']['CommonPathSuffix']);
unset($lnk);
// $fs->fwrite(rtrim($str));
// echo mb_convert_encoding(rtrim($str),'UTF-8');
// echo "debug" . PHP_EOL;
// foreach (str_split(rtrim($str)) as $char){
// printf ("%s ", ord($char));
echo "=======================================" . PHP_EOL;
}
unset ($msshlnk);
clearstatcache();
echo PHP_EOL;
echo PHP_EOL;
echo "=======================================" . PHP_EOL;
// $store = serialize($tomove);
giveme_files($tomove);
//print_r( str_split($msshlnk[$key]->lnk_bin));
echo "========== End of test suite ==========" . PHP_EOL;