码迷,mamicode.com
首页 > 其他好文 > 详细

zpk文件分析

时间:2019-05-12 22:27:31      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:nbsp   lte   标识   lse   pre   als   foreach   end   hex   

 1 public function zpk_parser() {
 2 
 3         $res_path   = ROOT_PATH . "public/zpk/";
 4         $file_lists = glob($res_path . "*.zpk");
 5         foreach ($file_lists as $file_path) {
 6 
 7             $dir_name = explode(".zpk", $file_path)[0];
 8             if (!is_dir($dir_name)) {
 9                 mkdir($dir_name, "0777");
10             }
11             $zpk  = file_get_contents($file_path);
12             $bin  = bin2hex($zpk);
13             $json = [
14                 "head" => "7b22",
15                 "end"  => "227d"
16             ];
17             $jpg  = [
18                 "head" => "ffd8ff",
19                 "end"  => "ffd9"
20             ];
21             $jpeg = [
22                 "head" => "ffd8ff",
23                 "end"  => "ffd9"
24             ];
25             $gif  = [
26                 "head" => "474946383961",
27                 "end"  => ""
28             ];
29             $png  = [
30                 "head" => "89504e470d0a1a0a",
31                 "end"  => "0000000049454e44ae426082"
32             ];
33 
34             /**
35              * 读取文件列表
36              */
37             preg_match_all("/6d6574612e6a736f6e(.*)/", $bin, $matches_lists);
38             $matches_lists
39                      = array_map(function ($v) { return hex2bin($v); }, array_filter(explode("0a", $matches_lists[0][0])));
40             //根据文件位置确定标识
41             $mp3  = [
42                 "head" => $json["end"],
43                 "end"  => $jpg["head"]
44             ];
45             $aac  = [
46                 "head" => $jpg["end"],
47                 "end"  => $png["head"]
48             ];
49 
50             $message = var_export($matches_lists, true) . "\r\n";
51             $flag    = true;
52             foreach ($matches_lists as $v) {
53                 //遍历文件列表,从流中读取内容并生成相应文件
54                 $file_name = $v;
55                 $file_type = explode(".", $v)[1];
56 
57                 //跳过gif图片
58                 if ($file_type == "gif") continue;
59 
60                 $head = $$file_type["head"];
61                 $end  = $$file_type["end"];
62                 preg_match_all("/{$head}(.*?){$end}/i", $bin, $matches);
63                 $message .= $file_type . ":";
64                 if (!empty($matches[0][0])) {
65                     if (strlen($matches[0][0]) % 2 == 0) {
66                         file_put_contents($dir_name . DS . $file_name, hex2bin($matches[0][0]));
67                         $message .= "生成成功" . "\r\n";
68                     } else {
69                         $message .= "数据错误\r\n";
70                         $flag    = false;
71                     }
72                 } else {
73                     $message .= "没有匹配到数据";
74                 }
75             }
76             file_put_contents($dir_name . DS . ($flag ? "true.log" : "false.log"), $message, FILE_APPEND);
77             echo $file_path . "\r\n";
78         }
79     }

 

zpk文件分析

标签:nbsp   lte   标识   lse   pre   als   foreach   end   hex   

原文地址:https://www.cnblogs.com/houguang/p/10853983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!