Texas Instruments matrix-gui-2.0 hacking -- generate.php

本文涉及的产品
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
简介:
<?php
/*
 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 
 * 
 * 
 *  Redistribution and use in source and binary forms, with or without 
 *  modification, are permitted provided that the following conditions 
 *  are met:
 *
 *    Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer.
 *
 *    Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the 
 *    documentation and/or other materials provided with the   
 *    distribution.
 *
 *    Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
*/
function get_contents($field_name,$filestring)
{    
    # stripos(string,find,start)
    # 返回字符串在另一个字符串中第一次出现的位置。
    # ------------------------------------------
    # | 参数    |   描述                       |
    # ------------------------------------------
    # | string    |   必需。规定被搜索的字符串。 |
    # | find    |   必需。规定要查找的字符。   |
    # | start    |   可选。规定开始搜索的位置。 |
    # ------------------------------------------
    # 如果没有找到该字符串,则返回 false。
    $pos =     stripos($filestring,$field_name."=");
    
    if($pos != false)       
    {
        $pos += strlen($field_name."=");
        # 找到当前行结束的地方
        $newlinepos = stripos($filestring,"\n",$pos);
        if($newlinepos == -1)
            $newlinepos = stripos($filestring,"\r",$pos);

        # substr(string,start,length)
        # ---------------------------------------------------
        # | 参数   |  描述                                  |
        # ---------------------------------------------------
        # | string |  必需。规定要返回其中一部分的字符串。  |
        # | start  |  必需。规定在字符串的何处开始。        |
        # ---------------------------------------------------
        $returnedstring = substr($filestring,$pos,$newlinepos-$pos);
        return $returnedstring;
    } 
    return -1;
}

# 每个app都有一个这样的对应文件
system("find  -name '*.desktop' -print > catdesktop.txt");

if(filesize("catdesktop.txt") == 0)
{
    echo "No .desktop files found";
    return;
}

# 读取文件
$handle = fopen("catdesktop.txt", "rb");
$contents = fread($handle,filesize("catdesktop.txt"));
fclose($handle);
# unlink() 函数删除文件。
# 若成功,则返回 true,失败则返回 false。
unlink('catdesktop.txt');

# 函数把字符串打散为数组。
# explode(separator,string,limit)
# ---------------------------------------------------------------------------------
# | 参数        |   描述                                                          |
# |--------------------------------------------------------------------------------
# | separator    |   必需。规定在哪里分割字符串。                                  | 
# |-------------------------------------------------------------------------------|
# | string        |   必需。要分割的字符串。                                        | 
# |-------------------------------------------------------------------------------|
# | limit        |   可选。规定所返回的数组元素的数目。                            | 
# |             |   可能的值:                                                    | 
# |             |   大于 0 - 返回包含最多 limit 个元素的数组                      | 
# |             |   小于 0 - 返回包含除了最后的 -limit 个元素以外的所有元素的数组 | 
# |             |   0 - 返回包含一个元素的数组                                    | 
# ---------------------------------------------------------------------------------
$contents = explode("\n",$contents);

# 这里strlen($contents[$x])>0限制了数据之间不能出现空行
for($x = 0;$x<count($contents)&&strlen($contents[$x])>0;$x++)
{
    # 从这里可以看出catdesktop.txt文件里是一些文件路径的配置
    $handle = fopen($contents[$x], "rb");
    $dotdesktop = fread($handle,filesize($contents[$x]));
    fclose($handle);
    
    # 应用名
    $top["Name"] = get_contents("Name",$dotdesktop);

    # 序号
    if(get_contents("X-MATRIX-DisplayPriority",$dotdesktop)!=-1)
        $top["Order"] = get_contents("X-MATRIX-DisplayPriority",$dotdesktop);
    else
        $top["Order"] = 999;

    # 图标的绝对路径
    $icon_path = get_contents("Icon",$dotdesktop);
    $webserver_root = "/usr/share/matrix-gui-2.0/";
    # 获取Icon的相对路径 
    $top["Icon"] = substr($icon_path,strlen($webserver_root));

    # 类型
    $type = strtolower(get_contents("Type",$dotdesktop));
    $top["Type"] = $type;

    # 分类
    $category = get_contents("Categories",$dotdesktop);
    $category =  trim(strtolower($category));

    if($type == "directory")
    {
        $top["Category"] = get_contents("X-MATRIX-CategoryTarget",$dotdesktop);

    }elseif($type == "application")
    {
        # 可执行程序的执行命令
        $top["Exec"] = get_contents("Exec",$dotdesktop);

        # 可执行程序的类型
        $top["ProgramType"] = get_contents("ProgramType",$dotdesktop);
        
        # 连接描述
        $top["Description_Link"] = get_contents("X-MATRIX-Description",$dotdesktop);

        # 锁
        $top["Lock"] = get_contents("X-MATRIX-LOCK",$dotdesktop);
    } 

    # 非分类放在主菜单中,其他的放在对应的分类中
    # 这里采用PHP的动态添加数组成员的方法
    if($category == -1)
        $application["main_menu"]["apps"][] = $top;    
    else
        $application[$category]["apps"][] = $top;

    # 用来销毁变量的,但很多时候,这个函数只把变量给销毁了,内存中存放的该变量的值
    # 仍然没有销毁,也就是没能达到我们想要的释放内存的效果。
    unset($top);
}

# 主要是完成数字大小的比较
function cmp($a, $b)
{
    if($a["Order"] < $b["Order"])
        return -1;
    elseif($a["Order"] == $b["Order"])
        return 0;
    elseif($a["Order"] > $b["Order"])
        return 1;
}

foreach ($application as $key => $value) {
    # 使用用户自定义的函数对数组排序,自动的函数名叫cmp,
    # 其实就是前面那个数字比较函数
    usort($application[$key]["apps"], "cmp");
}

# 将php对象编码成json对象,写到json.txt文件里面去
$ourFileName = "json.txt";
# die() 函数输出一条消息,并退出当前脚本。
# 该函数是 exit() 函数的别名。
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle,json_encode($application));
fclose($ourFileHandle);
?>

 

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
前端开发 JavaScript PHP
Texas Instruments matrix-gui-2.0 hacking -- index.php
Matrix Application Launcher var has_graphics = true; var link_history = ["submenu.
1026 0
|
7月前
|
关系型数据库 MySQL PHP
PHP 原生操作 Mysql
PHP 原生操作 Mysql
81 0
|
7月前
|
关系型数据库 MySQL 数据库连接
PHP 原生连接 Mysql
PHP 原生连接 Mysql
107 0
|
7月前
|
关系型数据库 MySQL Unix
PHP MySql 安装与连接
PHP MySql 安装与连接
130 0
|
3月前
|
关系型数据库 MySQL PHP
|
11天前
|
PHP
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册
web简易开发——通过php与HTML+css+mysql实现用户的登录,注册