-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.dttk.wso.php
101 lines (88 loc) · 2.65 KB
/
lib.dttk.wso.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
<?php
class WSOWrapper {
function __construct(){
// $this->unRegCOMServer();
// return;
// sleep(1);
if( !$this->checkCOMServer() ) {
$this->regCOMServer();
sleep(1);
}
}
public function init(){
$wso = new COM("Scripting.WindowSystemObject");
return $wso;
}
private function getCPUArch(){
return 8 * PHP_INT_SIZE;
}
private function regCOMServer(){
$UAC = new COM("Shell.Application");
echo $UAC->ShellExecute( $this->findRegSvrPath(), "/s ".realpath("bin/WSO".$this->getCPUArch().".dll"), "", "runas", 1 );
}
private function unRegCOMServer(){
$UAC = new COM("Shell.Application");
echo $UAC->ShellExecute( $this->findRegSvrPath(), "/u /s ".realpath("bin/WSO".$this->getCPUArch().".dll"), "", "runas", 1 );
}
private function checkCOMServer(){
try {
new COM("Scripting.WindowSystemObject");
} catch (Exception $e) {
return false;
}
return true;
}
private function findRegSvrPath(){
exec("where regsvr32.exe",$output,$ret);
return $output[0];
}
public function AttachCOMEvent( $object, $event, callable $fn, $type="Control" ){
$handler = new class(){
public function addMethod($methodName, $methodCallable){
// var_dump($methodCallable);
if (!is_callable($methodCallable)) {
throw new InvalidArgumentException('Second param must be callable');
}
$this->methods[$methodName] = Closure::bind( $methodCallable, $this );
}
public function __call($methodName, array $args){
if (isset($this->methods[$methodName])) {
return call_user_func_array($this->methods[$methodName], $args);
}else{
// echo $methodName."\n";
return false;
}
// throw Exception('There is no method with the given name to call');
}
};
$handler->addMethod(strtolower($event),$fn);
// var_dump( $handler );
$dispinterfaces = [
"IControlEvents",
"IFormEvents",
"IActionEvents",
"ITimerEvents",
"IHeaderItemEvents",
"IHeaderEvents",
"IListViewEvents",
"ITreeViewEvents",
"IRichEditEvents",
"IComboBoxEvents",
"IFindReplaceDialogEvents",
"IFileOpenSaveDialogEvents",
"ISelectFolderDialogEvents",
"ITrayIconEvents",
"IEventHandlerEvents",
"IFontDialogEvents",
"IColorDialogEvents",
"IListControlEvents",
];
$di = "I".$type."Events";
if( !in_array($di, $dispinterfaces ) ){
throw new Exception("Undefined Dispinterface");
}else{
com_event_sink( $object, $handler, $di );
}
}
}
?>