-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathprofiledecoder.php
More file actions
88 lines (72 loc) · 1.58 KB
/
profiledecoder.php
File metadata and controls
88 lines (72 loc) · 1.58 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
<?php
/*
dalo app的profile.dat的反解
*/
class ProfileDecoder{
public $profile_dat;
public $offset;
public $line_dir;
public function __construct( $path,$offset){
$this->profile_dat = $path;
$this->offset = $offset;
$this->line_dir = "lines";
}
private function pack_array($format, $arg)
{
$result="";
foreach ($arg as $item) $result .= pack ($format, $item);
return $result;
}
public function longtobytes($n)
{
$res = array();
$j=0;
$ll = 8;
for($i=0;$i<$ll;$i++){
array_push($res, ($n >> $j) & 0xff);
$j+=8;
}
$rev = array_reverse($res);
return $this->pack_array("C",$rev);
}
public function loadFromfile()
{
$fp = fopen($this->profile_dat,"r");
if($fp){
fseek($fp,$this->offset);
$cnt = "";
while(!feof($fp)){
$cnt .= fread($fp,8192);
}
$cnt = gzdecode($cnt);
}
fclose($fp);
return $cnt;
}
}
$OFFSET=8;
$options = getopt("hd:vf:");
if($argv && $argv[0] && realpath($argv[0]) === __FILE__) { //equal python __main__
if(!isset($options["f"])){
die("no profile.dat");
}
$_file = $options["f"];
$tt = new ProfileDecoder( $_file,$OFFSET);
$data = json_decode( $tt->loadFromfile(),true) ;
if(isset($options["v"])){
foreach ($data["profiles"] as $value){
echo $value["name"]."\n";
echo $value["content"]."\n";
}
}
if(isset($options["d"])){
mkdir($options["d"]);
foreach($data["profiles"] as $value){
echo $options["d"]."/".$value["name"].".ovpn\n";
file_put_contents($options["d"]."/".$value["name"].".ovpn", $value["content"]);
}
}
if(isset($options["h"])){
echo "php me -d outputdir -f profile.dat\n";
}
}