这篇文章玩tasker玩出了花,作者不可考,收藏如下:
最近想实现一个功能:在笔记本上贴一个NFC标签,当把手机放上去的时候,手机内置的EStrong File Explorer ftp服务自动启动,这样通过笔记本电脑就可以访问手机的文件,当把手机拿开,自动关闭手机ftp服务。
研究了一下 Tasker 的Send Intent功能,以及EStrong File Explorer 反编译后的代码,发现了一些规律,于是决定试试,成功。
[size=13.63636302947998px]
Use task “Send Intent[size=13.63636302947998px]” to start/stop ES File Explorer ftp:[size=13.63636302947998px]1、StartESFtp
[size=13.63636302947998px]Tasks->New Task(“StartESFtp”)->Add Action->Misc->Send Intent->
[size=13.63636302947998px]Action: android.intent.action.MAIN
[size=13.63636302947998px]Package: com.estrongs.android.pop
[size=13.63636302947998px]Class: com.estrongs.android.pop.ftp.ESFtpShortcut
[size=13.63636302947998px]Target: Activity
[size=13.63636302947998px]2、StopESFtp
[size=13.63636302947998px]Tasks->New Task(“StopESFtp”)->Add Action->Misc->Send Intent->
[size=13.63636302947998px]Action: android.intent.action.MAIN
[size=13.63636302947998px]Extra1: mode:2
[size=13.63636302947998px]Package: com.estrongs.android.pop
[size=13.63636302947998px]Class: com.estrongs.android.pop.ftp.ESFtpShortcut
[size=13.63636302947998px]Target: Activity研究过程如下:
1、apktool 反编译 ESFileExplorer.apk
得到AndroidManifest.xml如下:
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest android:versionCode=”103″ android:versionName=”1.6.2.5″ android:installLocation=”auto” package=”com.estrongs.android.pop”
…
…
<service android:name=”.ftp.ESFtpService” android:exported=”false” />
<activity android:theme=”@style/Transparent” android:label=”@string/app_name” android:name=”.ftp.ESFtpShortcut” android:launchMode=”singleTop” android:configChanges=”keyboardHidden|orientation”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
</intent-filter>
</activity>
…从以上内容可以分析得到几个参数:
Action: android.intent.action.MAIN
Package: com.estrongs.android.pop
Class: com.estrongs.android.pop.ftp.ESFtpShortcut
于是尝试使用以上内容作为参数,调用Tasker的Send Intent,结果发现可以成功启动 ES ftp!!2、如何停止ftp呢?
研究com.estrongs.android.pop.ftp.ESFtpShortcut反编译得到的java代码和smali代码。
java代码:
public class ESFtpShortcut extends ESActivity
{
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
int i = 1;
Bundle localBundle = getIntent().getExtras();
if (localBundle != null)
i = localBundle.getInt(“mode”);
try
{
l locall = l.a();
locall.a(this, new k(this, i, locall));
finish();
return;
}
catch (Exception localException)
{
while (true)
localException.printStackTrace();
}
}
}发现Extra属性里有一个参数”mode”:
int i = 1;
Bundle localBundle = getIntent().getExtras();
if (localBundle != null)
i = localBundle.getInt(“mode”);
并且缺省值是1
int i = 1
推测mode=1表示启动ftp服务,如果mode=0呢?尝试了一下,没能够停止ftp服务。于是继续看用到这个参数i的地方:
locall.a(this, new k(this, i, locall));
看看k这个类是什么内容:
class k
implements n
{
k(ESFtpShortcut paramESFtpShortcut, int paramInt, l paraml)
{
}public void a()
{
while (true)
{
try
{
if (this.b == 1)
{
…
Intent localIntent = new Intent(this.a, ESFtpService.class);
this.a.startService(localIntent);
…
}
}
}
catch (Exception localException)
{
localException.printStackTrace();
}
if (this.b == 2)
this.c.c();
else if (this.b == 3)
this.c.e();
else if (this.b == 4)
this.c.f();
}
}
}this.b是什么玩意?这个反编译出来的java代码质量很差,没有反映出b变量是哪里来的,但是可以初步推断应该是和Extra的mode参数有关。因为b==1的时候startService,进一步查看smali代码:
# instance fields
.field final synthetic a:Lcom/estrongs/android/pop/ftp/ESFtpShortcut;.field private final synthetic b:I
.field private final synthetic c:Lcom/estrongs/android/pop/ftp/l;
# direct methods
.method constructor <init>(Lcom/estrongs/android/pop/ftp/ESFtpShortcut;ILcom/estrongs/android/pop/ftp/l;)V
.locals 0iput-object p1, p0, Lcom/estrongs/android/pop/ftp/k;->a:Lcom/estrongs/android/pop/ftp/ESFtpShortcut;
iput p2, p0, Lcom/estrongs/android/pop/ftp/k;->b:I
iput-object p3, p0, Lcom/estrongs/android/pop/ftp/k;->c:Lcom/estrongs/android/pop/ftp/l;
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method可以看到,b就是k的构造函数的第二个参数(p0==对象本身即this, p1为第一个参数,p2为第二个参数,p3为第三个参数) 。参照前面对k构造函数的调用:locall.a(this, new k(this, i, locall));
因此可以确定 b–>i–>Extra(“mode”)
于是决定将2、3、4分别代入mode中进行尝试,幸运的是,刚尝试了mode=2就成功停止了ES ftp!!
当然,还有个更牛逼的哥们,写了篇英文文章,用bing搜索,发现应该还真是他原创,帖链接在此
Tasker to create toggle widget for ES ftp service — Send Intent
只可惜,据此操作,并不成功,不知道是不是ES现在改了还是怎么的。