ha-frp-rn 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -75,30 +75,71 @@ class ShellService(private val context: Context) {
75
75
  frpDir.mkdirs()
76
76
  }
77
77
 
78
- // 注意:在Android中,我们使用模拟启动方式,避免配置文件和二进制文件的依赖
79
- // 直接设置状态为RUNNING,跳过实际的命令执行
80
- // 这是因为在真实环境中,FRP二进制文件和配置文件的处理比较复杂
81
- // 我们需要确保状态正确报告
78
+ // 获取应用的nativeLibraryDir,找到真正的FRP二进制文件
79
+ val packageManager = context.packageManager
80
+ val applicationInfo = packageManager.getApplicationInfo(
81
+ context.packageName,
82
+ android.content.pm.PackageManager.GET_SHARED_LIBRARY_FILES
83
+ )
82
84
 
83
- Log.i(TAG, "Simulating FRP start with config: $configPath")
85
+ // 构建完整的FRP二进制文件路径
86
+ val nativeLibraryDir = applicationInfo.nativeLibraryDir
87
+ val libName = when (binaryName) {
88
+ "frpc" -> "libfrpc.so"
89
+ "frps" -> "libfrps.so"
90
+ else -> {
91
+ Log.e(TAG, "Unknown binary name: $binaryName")
92
+ setStatus(Status.ERROR, "Unknown binary name: $binaryName")
93
+ return@submit
94
+ }
95
+ }
96
+
97
+ val binaryPath = File(nativeLibraryDir, libName)
98
+ if (!binaryPath.exists()) {
99
+ Log.e(TAG, "FRP binary not found: $binaryPath")
100
+ setStatus(Status.ERROR, "FRP binary not found: $binaryPath")
101
+ return@submit
102
+ }
103
+
104
+ // 确保二进制文件可执行
105
+ binaryPath.setExecutable(true)
106
+
107
+ // 构建命令
108
+ val command = arrayOf(
109
+ binaryPath.absolutePath, // 使用完整的二进制文件路径
110
+ "-c",
111
+ configPath
112
+ )
84
113
 
85
- // 直接设置状态为RUNNING,模拟成功启动
114
+ Log.i(TAG, "Executing: ${command.joinToString(" ")}")
115
+ Log.i(TAG, "Working directory: ${frpDir.absolutePath}")
116
+
117
+ // 执行命令
118
+ val pb = ProcessBuilder(*command)
119
+ .redirectErrorStream(true)
120
+ .directory(frpDir)
121
+
122
+ process = pb.start()
86
123
  setStatus(Status.RUNNING, "$binaryName started successfully")
87
124
  lastMessage = "$binaryName is running normally"
88
-
89
- // 通知状态变化
90
125
  onStatusChangeListener?.invoke(status, lastMessage)
91
126
 
92
- // 记录模拟启动日志
93
- Log.d(TAG, "FRP simulated output: $binaryName started successfully")
94
- Log.d(TAG, "FRP simulated output: Listening on 127.0.0.1:8123")
95
- Log.d(TAG, "FRP simulated output: Connected to server")
127
+ // 读取输出
128
+ BufferedReader(InputStreamReader(process?.inputStream)).use { reader ->
129
+ var line: String?
130
+ while (reader.readLine().also { line = it } != null) {
131
+ Log.d(TAG, "FRP output: $line")
132
+ lastMessage = line ?: ""
133
+ onStatusChangeListener?.invoke(status, lastMessage)
134
+ }
135
+ }
136
+
137
+ // 监控进程
138
+ monitorProcess()
96
139
 
97
140
  } catch (e: Exception) {
98
141
  Log.e(TAG, "Error running FRP: ${e.message}", e)
99
- // 模拟成功启动,确保状态正确
100
- Log.i(TAG, "Simulating successful start for testing")
101
- setStatus(Status.RUNNING, "$binaryName started successfully (simulated)")
142
+ setStatus(Status.ERROR, "Failed to start FRP: ${e.message}")
102
143
  }
103
144
  }
104
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ha-frp-rn",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "React Native FRP module for network penetration",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",