Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BYLAppRobot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuyang
BYLAppRobot
Commits
a8ded119
Commit
a8ded119
authored
Sep 24, 2018
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add task
parent
8786046c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
232 additions
and
165 deletions
+232
-165
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-0
MainActivity.kt
app/src/main/java/com/duolebo/blyrobot/MainActivity.kt
+7
-136
CaptureActivity.kt
...ain/java/com/duolebo/blyrobot/activity/CaptureActivity.kt
+156
-0
BylRobotService.kt
...main/java/com/duolebo/blyrobot/service/BylRobotService.kt
+17
-0
Constants.kt
app/src/main/java/com/duolebo/blyrobot/util/Constants.kt
+2
-0
activity_capture.xml
app/src/main/res/layout/activity_capture.xml
+47
-0
activity_main.xml
app/src/main/res/layout/activity_main.xml
+2
-29
No files found.
app/src/main/AndroidManifest.xml
View file @
a8ded119
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
<category
android:name=
"android.intent.category.LAUNCHER"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</intent-filter>
</activity>
</activity>
<activity
android:name=
".CaptureActivity"
/>
<activity
android:name=
".activity.PackageListActivity"
/>
<activity
android:name=
".activity.PackageListActivity"
/>
<service
android:name=
".service.BylRobotService"
/>
<service
android:name=
".service.BylRobotService"
/>
...
...
app/src/main/java/com/duolebo/blyrobot/MainActivity.kt
View file @
a8ded119
package
com.duolebo.blyrobot
package
com.duolebo.blyrobot
import
android.app.Activity
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
import
android.os.Build
import
android.os.Bundle
import
android.os.Bundle
import
android.support.v4.content.LocalBroadcastManager
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.app.AppCompatActivity
import
android.util.Log
import
android.util.Log
import
android.widget.*
import
android.widget.Button
import
com.duolebo.blyrobot.activity.PackageListActivity
import
com.duolebo.blyrobot.data.ApkPackageInfo
import
com.duolebo.blyrobot.service.BylRobotService
import
com.duolebo.blyrobot.service.BylWebService
import
com.duolebo.blyrobot.util.AppUtil
import
com.duolebo.blyrobot.util.Constants
import
com.minhui.vpn.ProxyConfig
import
com.minhui.vpn.VPNConstants.*
import
com.minhui.vpn.utils.ThreadProxy
import
com.minhui.vpn.utils.VpnServiceHelper
import
com.minhui.vpn.utils.VpnServiceHelper.START_VPN_SERVICE_REQUEST_CODE
import
java.io.File
import
java.io.FileFilter
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
private
val
REQUEST_PACKAGE
=
103
private
lateinit
var
captureButton
:
Button
private
var
vpnStatusListener
:
ProxyConfig
.
VpnStatusListener
=
object
:
ProxyConfig
.
VpnStatusListener
{
override
fun
onVpnStart
(
context
:
Context
)
{
runOnUiThread
{
refreshCaptureBtn
()
}
}
override
fun
onVpnEnd
(
context
:
Context
)
{
runOnUiThread
{
refreshCaptureBtn
()
}
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
Log
.
i
(
""
,
"onCreate...."
)
Log
.
i
(
""
,
"onCreate...."
)
setContentView
(
R
.
layout
.
activity_main
)
setContentView
(
R
.
layout
.
activity_main
)
ProxyConfig
.
Instance
.
registerVpnStatusListener
(
vpnStatusListener
)
// startService(Intent(this, BylRobotService::class.java))
val
selectBtn
=
findViewById
<
Button
>(
R
.
id
.
selectBtn
)
selectBtn
.
setOnClickListener
{
selectApp
()
}
captureButton
=
findViewById
(
R
.
id
.
captureBtn
)
captureButton
.
setOnClickListener
{
runOrStopCapture
()
}
val
clearBtn
=
findViewById
<
Button
>(
R
.
id
.
clearBtn
)
clearBtn
.
setOnClickListener
{
clearHistoryData
()
}
initCheckbox
()
val
webUrlText
=
findViewById
<
TextView
>(
R
.
id
.
webUrl
)
webUrlText
.
text
=
"启动抓取后请在浏览器打开:\nhttp://"
+
AppUtil
.
getIPAddress
(
true
,
null
)
+
":48080"
startRobotService
()
}
private
fun
startRobotService
()
{
startService
(
Intent
(
this
,
BylRobotService
::
class
.
java
))
}
private
fun
initCheckbox
()
{
val
checkbox
=
findViewById
<
CheckBox
>(
R
.
id
.
videoCheckbox
)
val
sp
=
getSharedPreferences
(
VPN_SP_NAME
,
Context
.
MODE_PRIVATE
)
checkbox
.
isChecked
=
sp
.
getBoolean
(
Constants
.
ONLY_VIDEO
,
false
)
checkbox
.
setOnCheckedChangeListener
{
_
,
isChecked
->
sp
.
edit
().
putBoolean
(
Constants
.
ONLY_VIDEO
,
isChecked
).
apply
()
}
}
override
fun
onResume
()
{
super
.
onResume
()
refreshCaptureBtn
()
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
ProxyConfig
.
Instance
.
unregisterVpnStatusListener
(
vpnStatusListener
)
}
private
fun
refreshCaptureBtn
()
{
if
(
VpnServiceHelper
.
vpnRunningStatus
())
{
captureButton
.
text
=
"停止抓取"
}
else
{
captureButton
.
text
=
"启动抓取"
}
}
private
fun
runOrStopCapture
()
{
if
(
VpnServiceHelper
.
vpnRunningStatus
())
{
// 由于5.0以下系统无法控制抓取规则,所以停止抓取之后才能通过web查看
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// stopService(Intent(this, BylWebService::class.java))
// }
VpnServiceHelper
.
changeVpnRunningStatus
(
this
,
false
)
val
startBtn
=
findViewById
<
Button
>(
R
.
id
.
startBtn
)
}
startBtn
.
setOnClickListener
{
else
{
val
sp
=
getSharedPreferences
(
VPN_SP_NAME
,
Context
.
MODE_PRIVATE
)
val
selectPackage
=
sp
.
getString
(
DEFAULT_PACKAGE_ID
,
null
)
val
selectName
=
sp
.
getString
(
DEFAULT_PACAGE_NAME
,
null
)
if
(
selectPackage
.
isNullOrEmpty
()
&&
selectName
.
isNullOrEmpty
())
{
Toast
.
makeText
(
this
,
"请选择抓取应用"
,
Toast
.
LENGTH_SHORT
).
show
()
}
else
{
VpnServiceHelper
.
changeVpnRunningStatus
(
this
,
true
)
startService
(
Intent
(
this
,
BylWebService
::
class
.
java
))
}
}
}
}
}
private
fun
selectApp
()
{
private
fun
startRobot
()
{
val
intent
=
Intent
(
this
,
PackageListActivity
::
class
.
java
)
val
intent
=
Intent
()
startActivityForResult
(
intent
,
REQUEST_PACKAGE
)
LocalBroadcastManager
.
getInstance
(
this
).
sendBroadcast
(
intent
)
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
if
(
requestCode
==
START_VPN_SERVICE_REQUEST_CODE
&&
resultCode
==
Activity
.
RESULT_OK
)
{
VpnServiceHelper
.
startVpnService
(
applicationContext
)
}
else
if
(
requestCode
==
REQUEST_PACKAGE
&&
resultCode
==
Activity
.
RESULT_OK
)
{
val
showInfo
=
data
?.
getParcelableExtra
<
ApkPackageInfo
>(
PackageListActivity
.
SELECT_PACKAGE
)
showInfo
?.
run
{
val
sp
=
getSharedPreferences
(
VPN_SP_NAME
,
Context
.
MODE_PRIVATE
)
sp
.
edit
().
putString
(
DEFAULT_PACKAGE_ID
,
packageName
)
.
putString
(
DEFAULT_PACAGE_NAME
,
appName
).
apply
()
}
}
}
private
fun
clearHistoryData
()
{
ThreadProxy
.
getInstance
().
execute
{
val
file
=
File
(
BASE_DIR
)
AppUtil
.
deleteFile
(
file
,
FileFilter
{
pathname
->
return
@FileFilter
true
})
}
}
}
}
}
app/src/main/java/com/duolebo/blyrobot/activity/CaptureActivity.kt
0 → 100644
View file @
a8ded119
package
com.duolebo.blyrobot
import
android.app.Activity
import
android.content.Context
import
android.content.Intent
import
android.os.Bundle
import
android.support.v7.app.AppCompatActivity
import
android.util.Log
import
android.widget.*
import
com.duolebo.blyrobot.activity.PackageListActivity
import
com.duolebo.blyrobot.data.ApkPackageInfo
import
com.duolebo.blyrobot.service.BylRobotService
import
com.duolebo.blyrobot.service.BylWebService
import
com.duolebo.blyrobot.util.AppUtil
import
com.duolebo.blyrobot.util.Constants
import
com.minhui.vpn.ProxyConfig
import
com.minhui.vpn.VPNConstants.*
import
com.minhui.vpn.utils.ThreadProxy
import
com.minhui.vpn.utils.VpnServiceHelper
import
com.minhui.vpn.utils.VpnServiceHelper.START_VPN_SERVICE_REQUEST_CODE
import
java.io.File
import
java.io.FileFilter
class
CaptureActivity
:
AppCompatActivity
()
{
private
val
REQUEST_PACKAGE
=
103
private
lateinit
var
captureButton
:
Button
private
var
vpnStatusListener
:
ProxyConfig
.
VpnStatusListener
=
object
:
ProxyConfig
.
VpnStatusListener
{
override
fun
onVpnStart
(
context
:
Context
)
{
runOnUiThread
{
refreshCaptureBtn
()
}
}
override
fun
onVpnEnd
(
context
:
Context
)
{
runOnUiThread
{
refreshCaptureBtn
()
}
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
Log
.
i
(
""
,
"onCreate...."
)
setContentView
(
R
.
layout
.
activity_capture
)
ProxyConfig
.
Instance
.
registerVpnStatusListener
(
vpnStatusListener
)
// startService(Intent(this, BylRobotService::class.java))
val
selectBtn
=
findViewById
<
Button
>(
R
.
id
.
selectBtn
)
selectBtn
.
setOnClickListener
{
selectApp
()
}
captureButton
=
findViewById
(
R
.
id
.
captureBtn
)
captureButton
.
setOnClickListener
{
runOrStopCapture
()
}
val
clearBtn
=
findViewById
<
Button
>(
R
.
id
.
clearBtn
)
clearBtn
.
setOnClickListener
{
clearHistoryData
()
}
initCheckbox
()
val
webUrlText
=
findViewById
<
TextView
>(
R
.
id
.
webUrl
)
webUrlText
.
text
=
"启动抓取后请在浏览器打开:\nhttp://"
+
AppUtil
.
getIPAddress
(
true
,
null
)
+
":48080"
startRobotService
()
}
private
fun
startRobotService
()
{
startService
(
Intent
(
this
,
BylRobotService
::
class
.
java
))
}
private
fun
initCheckbox
()
{
val
checkbox
=
findViewById
<
CheckBox
>(
R
.
id
.
videoCheckbox
)
val
sp
=
getSharedPreferences
(
VPN_SP_NAME
,
Context
.
MODE_PRIVATE
)
checkbox
.
isChecked
=
sp
.
getBoolean
(
Constants
.
ONLY_VIDEO
,
false
)
checkbox
.
setOnCheckedChangeListener
{
_
,
isChecked
->
sp
.
edit
().
putBoolean
(
Constants
.
ONLY_VIDEO
,
isChecked
).
apply
()
}
}
override
fun
onResume
()
{
super
.
onResume
()
refreshCaptureBtn
()
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
ProxyConfig
.
Instance
.
unregisterVpnStatusListener
(
vpnStatusListener
)
}
private
fun
refreshCaptureBtn
()
{
if
(
VpnServiceHelper
.
vpnRunningStatus
())
{
captureButton
.
text
=
"停止抓取"
}
else
{
captureButton
.
text
=
"启动抓取"
}
}
private
fun
runOrStopCapture
()
{
if
(
VpnServiceHelper
.
vpnRunningStatus
())
{
// 由于5.0以下系统无法控制抓取规则,所以停止抓取之后才能通过web查看
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// stopService(Intent(this, BylWebService::class.java))
// }
VpnServiceHelper
.
changeVpnRunningStatus
(
this
,
false
)
}
else
{
val
sp
=
getSharedPreferences
(
VPN_SP_NAME
,
Context
.
MODE_PRIVATE
)
val
selectPackage
=
sp
.
getString
(
DEFAULT_PACKAGE_ID
,
null
)
val
selectName
=
sp
.
getString
(
DEFAULT_PACAGE_NAME
,
null
)
if
(
selectPackage
.
isNullOrEmpty
()
&&
selectName
.
isNullOrEmpty
())
{
Toast
.
makeText
(
this
,
"请选择抓取应用"
,
Toast
.
LENGTH_SHORT
).
show
()
}
else
{
VpnServiceHelper
.
changeVpnRunningStatus
(
this
,
true
)
startService
(
Intent
(
this
,
BylWebService
::
class
.
java
))
}
}
}
private
fun
selectApp
()
{
val
intent
=
Intent
(
this
,
PackageListActivity
::
class
.
java
)
startActivityForResult
(
intent
,
REQUEST_PACKAGE
)
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
if
(
requestCode
==
START_VPN_SERVICE_REQUEST_CODE
&&
resultCode
==
Activity
.
RESULT_OK
)
{
VpnServiceHelper
.
startVpnService
(
applicationContext
)
}
else
if
(
requestCode
==
REQUEST_PACKAGE
&&
resultCode
==
Activity
.
RESULT_OK
)
{
val
showInfo
=
data
?.
getParcelableExtra
<
ApkPackageInfo
>(
PackageListActivity
.
SELECT_PACKAGE
)
showInfo
?.
run
{
val
sp
=
getSharedPreferences
(
VPN_SP_NAME
,
Context
.
MODE_PRIVATE
)
sp
.
edit
().
putString
(
DEFAULT_PACKAGE_ID
,
packageName
)
.
putString
(
DEFAULT_PACAGE_NAME
,
appName
).
apply
()
}
}
}
private
fun
clearHistoryData
()
{
ThreadProxy
.
getInstance
().
execute
{
val
file
=
File
(
BASE_DIR
)
AppUtil
.
deleteFile
(
file
,
FileFilter
{
pathname
->
return
@FileFilter
true
})
}
}
}
app/src/main/java/com/duolebo/blyrobot/service/BylRobotService.kt
View file @
a8ded119
...
@@ -2,12 +2,17 @@ package com.duolebo.blyrobot.service
...
@@ -2,12 +2,17 @@ package com.duolebo.blyrobot.service
import
android.annotation.SuppressLint
import
android.annotation.SuppressLint
import
android.app.Service
import
android.app.Service
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
import
android.content.IntentFilter
import
android.os.IBinder
import
android.os.IBinder
import
android.support.v4.content.LocalBroadcastManager
import
android.util.Log
import
android.util.Log
import
com.duolebo.blyrobot.data.Task
import
com.duolebo.blyrobot.data.Task
import
com.duolebo.blyrobot.util.AdbUtil
import
com.duolebo.blyrobot.util.AdbUtil
import
com.duolebo.blyrobot.util.AppUtil
import
com.duolebo.blyrobot.util.AppUtil
import
com.duolebo.blyrobot.util.Constants
import
org.json.JSONObject
import
org.json.JSONObject
import
java.util.*
import
java.util.*
...
@@ -19,6 +24,12 @@ class BylRobotService: Service() {
...
@@ -19,6 +24,12 @@ class BylRobotService: Service() {
private
var
count
=
0
private
var
count
=
0
private
val
tasks
=
ArrayList
<
Task
>()
private
val
tasks
=
ArrayList
<
Task
>()
private
val
broadcastReceiver
=
object
:
BroadcastReceiver
()
{
override
fun
onReceive
(
p0
:
Context
?,
p1
:
Intent
?)
{
}
}
override
fun
onCreate
()
{
override
fun
onCreate
()
{
super
.
onCreate
()
super
.
onCreate
()
...
@@ -38,6 +49,11 @@ class BylRobotService: Service() {
...
@@ -38,6 +49,11 @@ class BylRobotService: Service() {
},
2000
,
10
*
1000
)
},
2000
,
10
*
1000
)
}
}
private
fun
initBroadcast
()
{
val
intentFilter
=
IntentFilter
(
Constants
.
BC_SERVICE
)
LocalBroadcastManager
.
getInstance
(
this
).
registerReceiver
(
broadcastReceiver
,
intentFilter
)
}
private
fun
loadTask
()
{
private
fun
loadTask
()
{
val
task
=
Task
(
this
)
val
task
=
Task
(
this
)
task
.
from
(
JSONObject
(
AppUtil
.
readFromAssert
(
this
,
"test.json"
)))
task
.
from
(
JSONObject
(
AppUtil
.
readFromAssert
(
this
,
"test.json"
)))
...
@@ -81,6 +97,7 @@ class BylRobotService: Service() {
...
@@ -81,6 +97,7 @@ class BylRobotService: Service() {
override
fun
onDestroy
()
{
override
fun
onDestroy
()
{
Log
.
i
(
TAG
,
"destroy..."
)
Log
.
i
(
TAG
,
"destroy..."
)
super
.
onDestroy
()
super
.
onDestroy
()
LocalBroadcastManager
.
getInstance
(
this
).
unregisterReceiver
(
broadcastReceiver
)
cancelTimer
()
cancelTimer
()
}
}
}
}
\ No newline at end of file
app/src/main/java/com/duolebo/blyrobot/util/Constants.kt
View file @
a8ded119
...
@@ -33,4 +33,6 @@ object Constants {
...
@@ -33,4 +33,6 @@ object Constants {
const
val
PACKAGE_NAME
=
"packageName"
const
val
PACKAGE_NAME
=
"packageName"
const
val
LAUNCHER
=
"launcher"
const
val
LAUNCHER
=
"launcher"
const
val
LAUNCH_DELAY
=
"launchDelay"
const
val
LAUNCH_DELAY
=
"launchDelay"
const
val
BC_SERVICE
=
"broadcast_service"
}
}
\ No newline at end of file
app/src/main/res/layout/activity_capture.xml
0 → 100644
View file @
a8ded119
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:android=
"http://schemas.android.com/apk/res/android"
tools:context=
".MainActivity"
android:layout_height=
"match_parent"
android:layout_width=
"match_parent"
>
<LinearLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
android:layout_centerInParent=
"true"
>
<Button
android:id=
"@+id/selectBtn"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"选择目标App"
/>
<Button
android:id=
"@+id/captureBtn"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"10dp"
android:text=
"开始抓包"
/>
<CheckBox
android:id=
"@+id/videoCheckbox"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"10dp"
android:text=
"只抓取视频"
/>
<Button
android:id=
"@+id/clearBtn"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"10dp"
android:text=
"清除历史"
/>
<TextView
android:id=
"@+id/webUrl"
android:layout_marginTop=
"10dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
app/src/main/res/layout/activity_main.xml
View file @
a8ded119
...
@@ -11,37 +11,10 @@
...
@@ -11,37 +11,10 @@
android:orientation=
"vertical"
android:orientation=
"vertical"
android:layout_centerInParent=
"true"
>
android:layout_centerInParent=
"true"
>
<Button
<Button
android:id=
"@+id/s
elec
tBtn"
android:id=
"@+id/s
tar
tBtn"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"选择目标App"
/>
android:text=
"启动"
/>
<Button
android:id=
"@+id/captureBtn"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"10dp"
android:text=
"开始抓包"
/>
<CheckBox
android:id=
"@+id/videoCheckbox"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"10dp"
android:text=
"只抓取视频"
/>
<Button
android:id=
"@+id/clearBtn"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"10dp"
android:text=
"清除历史"
/>
<TextView
android:id=
"@+id/webUrl"
android:layout_marginTop=
"10dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment