<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts on HAOUTIL.COM</title><link>https://haoutil.com/posts/</link><description>Recent content in Posts on HAOUTIL.COM</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Tue, 30 Aug 2016 19:17:00 +0800</lastBuildDate><atom:link href="https://haoutil.com/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>使用Xposed添加自定义系统服务</title><link>https://haoutil.com/posts/xposed-add-custom-system-service/</link><pubDate>Tue, 30 Aug 2016 19:17:00 +0800</pubDate><guid>https://haoutil.com/posts/xposed-add-custom-system-service/</guid><description>Xposed 是 Android 平台上一个著名的框架。基于这个框架，我们可以在不需要 root 的情况下修改（hook）任何系统和 App 的类和方法，正如作者介绍的那样 modify your ROM - without modifying any APK (developers) or flashing (users)!。
Xposed 可以 hook 任何类的任何方法，但是仅限于在方法执行前和执行后加入钩子（hook），而并不能修改方法原有的代码。这在大多是情况是够用的，但是当涉及到多进程时就不行了。举个例子，你 hook 了微信，获取到了微信昵称，想将昵称显示在 QQ 中，如果你想简单的通过一个变量来传值是行不通的，因为微信和 QQ 运行在不同的进程中，在 QQ 进程中获取到的还是变量的初始值。
广播（Broadcast）是解决该问题的一种方法。但是广播的缺点是：1.不能确定什么时候能够收到， 2.创建广播和广播接收者都需要用到 Context ，而在 hook 的类里并不总是有 Context。
最好的方法就是添加一个自定义的系统服务来进行进程间的数据共享。系统服务的优点有：1.服务从开机就启动了，并且一直存活到关机，2.可以简单的通过ServiceManager.getService()来调用。
在正常情况下是不能添加这样的系统服务的，但是我们可以借助 Xposed 来实现。实现进程间通信的服务需要用到 AIDL（Android Interface Definition Language），我们的服务也不例外。
首先，创建 android.os.ICustomService.aidl
package android.os; /** {@hide} */ interface ICustomService { // implemention } 以及它的实现类 CustomService.java
public class CustomService extends ICustomService.Stub { public static void register(final ClassLoader classLoader) { // implemention } } 然后，创建一个 Xposed 模块用于注册服务</description></item><item><title>解决win10“某些设置由你的组织来管理”</title><link>https://haoutil.com/posts/fix-win10-some-settings-are-managed-by-your-organization/</link><pubDate>Thu, 04 Aug 2016 14:10:00 +0800</pubDate><guid>https://haoutil.com/posts/fix-win10-some-settings-are-managed-by-your-organization/</guid><description>由于某些“未知”的原因，windows 10设置中出现了某些设置由你的组织来管理的提示，导致某些选项置灰，无法进行设置。
如果你没有加入某个域，有如下解决方法：
1. 在设置-隐私-反馈与诊断中，将诊断和使用情况数据修改为完整
2. 如果诊断和使用情况数据也是灰色不可设置的，则可以
在运行（Win + R）中打开gpedit.msc 找到计算机配置-管理模版-Windows 组件-数据收集和预览版本 打开允许遥测，修改为已启用，选项修改为3-完整，确定 再次打开允许遥测，修改为未配置，确定</description></item><item><title>redirector.uc.js UC版Redirector</title><link>https://haoutil.com/posts/redirector-ucjs/</link><pubDate>Tue, 12 Apr 2016 11:26:00 +0800</pubDate><guid>https://haoutil.com/posts/redirector-ucjs/</guid><description>redirector.uc.js是基于Firefox Http请求重定向原理制作的UserChromeJs脚本，对Http请求地址进行重定向，适用于Firefox。
redirector.uc.js支持自定义规则，规则支持正则、通配符以及完全匹配3种类型。具体请参考默认规则：
this.rules = [{ from: &amp;quot;about:haoutil&amp;quot;, // 需要重定向的地址 to: &amp;quot;https://haoutil.googlecode.com&amp;quot;, // 目标地址 wildcard: false, // 可选，true 表示 from 是通配符 regex: false, // 可选，true 表示 from 是正则表达式 resp: false, // 可选，true 表示替换 response body decode: false // 可选，true 表示尝试对 from 解码 },{ from: /^https?:\/\/www\.google\.com\/url\?.*url=([^&amp;amp;]+).*/i, to: &amp;quot;$1&amp;quot;, regex: true },{ from: /^http:\/\/(([^\.]+\.)?google\..+)/i, exclude: /google\.cn/i, // 可选，排除例外规则 to: &amp;quot;https://$1&amp;quot;, regex: true }]; redirector.uc.js已经开源，可以在github上找到它。
redirector_ui.uc.js是规则外置版，提供一个按钮以临时启用和修改规则，规则文件请放到chrome/local文件夹下，下载地址。</description></item><item><title>Firefox Http请求重定向</title><link>https://haoutil.com/posts/firefox-redirect/</link><pubDate>Sat, 31 Jan 2015 16:28:00 +0800</pubDate><guid>https://haoutil.com/posts/firefox-redirect/</guid><description>Firefox有 3个时机 可以重定向Http请求：
1. 在请求创建之前 Firefox支持一种称为内容策略（content policies）的机制[1]，所有资源的加载都需要先经过这个机制的过滤。
扩展和UC脚本可以通过实现nsIContentPolicy接口来注册自己的内容策略，在shouldLoad方法中决定是否拒绝当前Http请求并创建新的请求来达到重定向的目的。
2. 在请求发送到服务器之前 当一个Http请求创建完成时，Firefox会发出一个名为http-on-modify-request的通知。扩展和UC脚本可以通过实现nsIObserver接口来接收这个通知。
在Firefox 20之前，对于关闭一个Http请求并发起新的请求比较麻烦，https-everywhere扩展对此有相关的实现，而在在Firefox 20之后的版本中可以方便的使用redirectTo方法方法来实现。
3. 响应返回后对响应内容进行修改 和Http请求创建一样，在收到响应时，Firefox会发出一个名http-on-examine-response的通知（除了这2种，还有各种各样的通知，详情可以查看MDN）。
修改响应内容可以通过实现nsITraceableChannel接口[2]来实现。
虽然，现在我们在3个时机都可以对Http请求进行重定向，但是还需要解决：
1. 对服务器发起的30X重定向进行重定向 对于30X重定向，上述3个方法都无能为力。好在Firefox提供了nsIChannelEventSink接口，每次30X发生都会调用这个接口。所以通过实现这个接口，就可以对30X后的连接进行判断是否需要重定向了。
2. 带“href=&amp;quot;_blank&amp;quot;的链接不会在新标签页（窗口）打开 这个问题是由于在时机1中，是在新标签（窗口）创建之前就发生了重定向造成的。对于这个问题，我们可以实现nsIDOMEventListener接口，监听DOM点击事件，缓存带“href=&amp;quot;_blank&amp;quot;的链接，在时机1中跳过这些链接即可。</description></item></channel></rss>