Visual Code 编辑器添加到右键菜单


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Visual Code]
@="Edit with Visual Code"
"icon"="D:\\Soft\\VSCode\\Code.exe, 0"

[HKEY_CLASSES_ROOT\*\shell\Visual Code\command]
@="D:\\Soft\\VSCode\\Code.exe %1"

golang模拟浏览器请求


import (
	"io/ioutil"
	"net/http"
)

func httpRequest(url string) []byte {
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return []byte{}
	}

	request.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
	request.Header.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
	request.Header.Add("Connection", "keep-alive")
	request.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36")

	client := http.Client{}
	response, err := client.Do(request)
	if err != nil {
		return []byte{}
	}
	defer response.Body.Close()

	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return []byte{}
	}

	return body
}

安装electron开发环境

第一步:安装 cnpm

npm install -g cnpm --registry=https://registry.npm.taobao.org

第二步:安装 electron 模块

cnpm install -g electron

第三步:安装

cnpm install -g electron-packager

第四步:打包

electron-packager . appName --platform=win32 --arch=x64 --electron-version=2.0.7

 

krpano解密tour.xml文件

krpano是一个很出名的全景图展示框架,他的配置文件 tour.xml 可被加密,加密后的文件是 `<encrypted><![CDATA[KENCPUZR****]]></encrypted>` 格式的,下面的方法可以解密这种加密文件

第一步:打断点

1. 用谷歌浏览器打开360全景页面
2. 按下 F12 打开开发者工具
3. 切换到 Sources 标签页,按下 F5 刷新页面
4. 在左边栏用鼠标点击 tour.js 然后点击右边窗口底部的一对大括号图标(Pretty print)显示格式化后的源代码
5. 在右边窗口内点击,按下 Ctrl + F 打开搜索框,搜索 eval
6. 找到 eval (437行附近)点击行号添加断点
7. 搜索 return d 添加断点
8. 按下 F5 刷新页面

第二步:获取解密后的源码

1. 点击执行断点按钮(Resume script execution)一次
2. 按下 F11 三次
3. 点击 Pretty print 格式化代码
4. 搜索 KENC (2228行附近)添加断点
5. 在 KENC 所在的函数结尾 } 的上一行添加断点(return n 所在的行)
6. 在右边工具栏 Watch 处添加监控变量 n
7. 点击执行断点按钮一次,在 Watch 处看到 n 的值变成了 “<krpano version” 开头
8. 切换到 control 标签页,输入命令 console.log(n)
9. 点击代码最后的 Copy 按钮,就可以得到解密后的源代码了

上传文件到阿里云OSS

/**
 *  阿里云 OSS 密钥
 */
define('AccessKeyId', 'AccessKeyId');
define('AccessKeySecret', 'AccessKeySecret');

/**
 *  上传文件到 OSS
 */
function ossUpload($bucket, $file, $upload){

	$date = gmdate('D, d M Y H:i:s \G\M\T');
	$sign = 'OSS ' . AccessKeyId . ':' . base64_encode(hash_hmac('sha1', "PUT\n\napplication/octet-stream\n" . $date . "\n/" . $bucket . $upload, AccessKeySecret, true));

	$header = array(
        'Date: ' . $date,
        'Authorization: ' . $sign,
		'Content-Type: application/octet-stream'
    );

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'https://moguapp.oss-cn-beijing.aliyuncs.com' . $upload);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
	curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
	curl_setopt($curl, CURLOPT_POSTFIELDS, file_get_contents($file));
    $respone = curl_exec($curl);
    $error = curl_error($curl);
    curl_close($curl);
	
    if ($error) {
        return $error;
    } else {
        return $respone;
    }

}

function main() {
	ossUpload('mogublog', '01.jpg', '/01.jpg');
}

main();

阿里云发送短信

define('AccessKeyId', 'Key');
define('AccessKeySecret', 'Secret');

/**
 *  获取签名
 */
function getSign($add){
    $data = array(
        "RegionId" => "cn-hangzhou",
        "Action" => "SendSms",
        "Version" => "2017-05-25",
        "SignatureMethod" => "HMAC-SHA1",
        "SignatureNonce" => uniqid(mt_rand(0,0xffff), true),
        "SignatureVersion" => "1.0",
        "AccessKeyId" => AccessKeyId,
        "Timestamp" => gmdate("Y-m-d\TH:i:s\Z"),
        "Format" => "JSON",
    );
    $data = array_merge($data, $add);
    ksort($data);
    $format = http_build_query($data);
    $signUrl = 'GET&%2F&' . urlencode($format);
    $sign = urlencode(base64_encode(hash_hmac('sha1', $signUrl, AccessKeySecret . '&', true)));
    return array('url' => $format, 'sign' => $sign);
}

/**
 *  发送短信
 */
function sendSMS($phone){
    $sign = getSign(['PhoneNumbers' => $phone, 'SignName' => '蘑菇博客', 'TemplateCode' => 'SMS_139000000', 'TemplateParam' => '{"code":"1234"}']);
    $url = 'https://dysmsapi.aliyuncs.com/?' . $sign['url'] . '&Signature=' . $sign['sign'];
    $request = json_decode(httpRequest($url));
    if (isset($request->Code) && $request->Code == 'OK'){
        return true;
    } else {
        return false;
    }
}

/**
 *  发起 HTTP 请求
 */
function httpRequest($url){
    $header = array(
        'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
        'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
        'Accept-Encoding: gzip, deflate',
        'Connection: close',
    );

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    $data = curl_exec($curl);
    $error = curl_error($curl);
    curl_close($curl);
    if ($error) {
        return $error;
    } else {
        return $data;
    }
}

function main() {
    sendSMS('18611508888');
}

main();

PHP简单的密码库系统


main();

function main(){
	$url = 'https://www.baidu.com/';
	$host = getHost($url);

	if (empty($host)) {
		echo respone(100, 'URL Formatting error');
		exit();
	}

	$pass = getPass($host);

	if (empty($pass)) {
		$pass = createPass();
		$db = getDB();
		$db->$host = $pass;
		updateDB($db);
	}

	echo respone(0, 'Get Password Success', ['Password' => $pass]);
}

function getHost($url){
	$parse = parse_url($url);
	if (isset($parse['host'])) {
		return $parse['host'];
	} else {
		return '';
	}
}

function createPass(){
	$pass = array_merge(
		array_rand(array_flip(range(1, 9)), 2), 
		array_rand(array_flip(range('a', 'z')), 4), 
		array_rand(array_flip(range('A', 'Z')), 4), 
		array_rand(array_flip(array('@', '#', '$', '%', '+', '-')), 2)
	);
	shuffle($pass);
	return implode('', $pass);
}

function getPass($host){
	$db = getDB();
	if (isset($db->$host)) {
		return $db->$host;
	} else {
		return '';
	}
}

function getDB(){
	try {
		return json_decode(substr(file_get_contents('db.php'), 16));
	} catch (Exception $e) {
		return [];
	}
}

function updateDB($db){
	file_put_contents('db.php', "<?php exit();\n//" . json_encode($db)); 
} 

function respone($code = 0, $message = '', $data = []){ $respone = array( 'code' => intval($code),
		'data' => $data,
		'message' => $message
	);
	return json_encode($respone);
}

PHP实现并发下载


class BatchDown
{

	public $curl;
	public $task = array();
	
	function __construct(){
		$this->curl = curl_multi_init();
	}

	function __destruct(){
		curl_multi_close($this->curl);
	}

	function addTask($url, $file){
		$header = array(
			'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36',
			'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
			'Accept-Encoding: gzip, deflate',
			'Connection: keep-alive'
		);
		$c = curl_init($url);
		curl_setopt($c, CURLOPT_ENCODING, 'gzip');
		curl_setopt($c, CURLOPT_HTTPHEADER, $header);
		curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($c, CURLOPT_TIMEOUT, 10);
		curl_multi_add_handle($this->curl, $c);
		$this->task[] = array(
			'url' => $url,
			'curl' => $c,
			'file' => $file
		);
	}

	function run(){
		$running = null;
		do {
			curl_multi_exec($this->curl, $running);
			curl_multi_select($this->curl);
		} while($running > 0);
		foreach ($this->task as $v) {
			$data = curl_multi_getcontent($v['curl']);
			file_put_contents($v['file'], $data);
			curl_multi_remove_handle($this->curl, $v['curl']);
			curl_close($v['curl']);
		}
	}

}

$url = 'https://www.baidu.com/';
$task = new BatchDown();

foreach (range(1, 3) as $v) {
	$task->addTask($url, $v . '.html');
}

$task->run();

使用阿里云API自动修改域名解析


define('AccessKeyId', 'KEY');
define('AccessKeySecret', 'Secret');

date_default_timezone_set('UTC');

/**
 *  获取本机 IP 地址
 */
function getIP() {
    $url = 'http://ip.taobao.com/service/getIpInfo.php?ip=myip';
    try {
        $json = json_decode(file_get_contents($url));
    } catch (Exception $e) {
        $json = [];
    }
    if (isset($json->code) && $json->code == 0) {
        return $json->data->ip;
    }
    return '';
}

/**
 *  获取请求签名
 */
function getSign($add){
    $nonce = time() . rand(11111, 99999);
    $time = date('Y-m-d') . 'T' . date('H:i:s') . 'Z';
    $data = array(
        'AccessKeyId' => AccessKeyId,
        'Format' => 'json',
        'SignatureMethod' => 'HMAC-SHA1',
        'SignatureNonce' => $nonce,
        'SignatureVersion' => '1.0',
        'Timestamp' => $time,
        'Version' => '2015-01-09'
    );
    $data = array_merge($data, $add);
    ksort($data);
    $format = http_build_query($data);
    $signUrl = 'GET&%2F&' . urlencode($format);
    $sign = urlencode(base64_encode(hash_hmac('sha1', $signUrl, AccessKeySecret . '&', true)));
    return array('url' => $format, 'sign' => $sign);
}

/**
 *  获取域名解析记录
 */
function getDNS($domain) {
    $sign = getSign(['Action' => 'DescribeSubDomainRecords', 'SubDomain' => $domain]);
    $url = 'https://alidns.aliyuncs.com/?' . $sign['url'] . '&Signature=' . $sign['sign'];
    $dns = json_decode(httpRequest($url));
    if (isset($dns->DomainRecords->Record[0])) {
        return $dns->DomainRecords->Record[0];
    }
    return '';
}

/**
 *  更新域名解析
 */
function updateDNS($id, $name, $ip) {
    $data = array(
        'Action' => 'UpdateDomainRecord',
        'RecordId' => $id,
        'RR' => $name,
        'Type' => 'A',
        'Value' => $ip,
    );
    $sign = getSign($data);
    $url = 'https://alidns.aliyuncs.com/?' . $sign['url'] . '&Signature=' . $sign['sign'];
    return httpRequest($url);
}

/**
 *  发起 HTTP 请求
 */
function httpRequest($url) {
    $header = array(
        'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
        'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
        'Accept-Encoding: gzip, deflate',
        'Connection: keep-alive',
    );

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    $data = curl_exec($curl);
    $error = curl_error($curl);
    curl_close($curl);
    if ($error) {
        return $error;
    } else {
        return $data;
    }
}

function main() {
    $dns = getDNS('www.test.com');
    $ip = getIP();
    if (isset($dns->RecordId)) {
        echo updateDNS($dns->RecordId, 'www', $ip);
    }
}

main();