Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
536a1b4b
Commit
536a1b4b
authored
Dec 19, 2017
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refrain from using private APIs for parseNumericAddress
parent
2202041e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
28 deletions
+14
-28
core/src/main/java/com/github/shadowsocks/JniHelper.java
core/src/main/java/com/github/shadowsocks/JniHelper.java
+1
-1
core/src/main/jni/jni-helper.cpp
core/src/main/jni/jni-helper.cpp
+8
-23
mobile/src/main/java/com/github/shadowsocks/utils/Utils.kt
mobile/src/main/java/com/github/shadowsocks/utils/Utils.kt
+5
-4
No files found.
core/src/main/java/com/github/shadowsocks/JniHelper.java
View file @
536a1b4b
...
@@ -75,5 +75,5 @@ public class JniHelper {
...
@@ -75,5 +75,5 @@ public class JniHelper {
public
static
native
int
sendFd
(
int
fd
,
@NonNull
String
path
);
public
static
native
int
sendFd
(
int
fd
,
@NonNull
String
path
);
public
static
native
void
close
(
int
fd
);
public
static
native
void
close
(
int
fd
);
@Nullable
@Nullable
public
static
native
InetAddress
parseNumericAddress
(
@NonNull
String
str
);
public
static
native
byte
[]
parseNumericAddress
(
@NonNull
String
str
);
}
}
core/src/main/jni/jni-helper.cpp
View file @
536a1b4b
...
@@ -27,10 +27,10 @@ using namespace std;
...
@@ -27,10 +27,10 @@ using namespace std;
#define THROW(env, clazz, msg) do { env->ThrowNew(env->FindClass(clazz), msg); } while (0)
#define THROW(env, clazz, msg) do { env->ThrowNew(env->FindClass(clazz), msg); } while (0)
static
int
sdk_version
;
static
int
sdk_version
;
static
jclass
ProcessImpl
,
Inet4Address
,
Inet6Address
;
static
jclass
ProcessImpl
;
static
jfieldID
ProcessImpl_pid
,
ProcessImpl_exitValue
,
ProcessImpl_exitValueMutex
;
static
jfieldID
ProcessImpl_pid
,
ProcessImpl_exitValue
,
ProcessImpl_exitValueMutex
;
static
jmethodID
Inet4Address__init_
,
Inet6Address__init_
;
#pragma clang diagnostic ignored "-Wunused-parameter"
extern
"C"
{
extern
"C"
{
JNIEXPORT
jint
JNICALL
Java_com_github_shadowsocks_JniHelper_sigkill
(
JNIEnv
*
env
,
jobject
thiz
,
jint
pid
)
{
JNIEXPORT
jint
JNICALL
Java_com_github_shadowsocks_JniHelper_sigkill
(
JNIEnv
*
env
,
jobject
thiz
,
jint
pid
)
{
// Suppress "No such process" errors. We just want the process killed. It's fine if it's already killed.
// Suppress "No such process" errors. We just want the process killed. It's fine if it's already killed.
...
@@ -104,24 +104,20 @@ JNIEXPORT jint JNICALL
...
@@ -104,24 +104,20 @@ JNIEXPORT jint JNICALL
return
0
;
return
0
;
}
}
JNIEXPORT
j
object
JNICALL
JNIEXPORT
j
byteArray
JNICALL
Java_com_github_shadowsocks_JniHelper_parseNumericAddress
(
JNIEnv
*
env
,
jobject
thiz
,
jstring
str
)
{
Java_com_github_shadowsocks_JniHelper_parseNumericAddress
(
JNIEnv
*
env
,
jobject
thiz
,
jstring
str
)
{
const
char
*
src
=
env
->
GetStringUTFChars
(
str
,
0
);
const
char
*
src
=
env
->
GetStringUTFChars
(
str
,
0
);
jbyte
dst
[
max
(
sizeof
(
in_addr
),
sizeof
(
in6_addr
))];
jbyte
dst
[
max
(
sizeof
(
in_addr
),
sizeof
(
in6_addr
))];
j
object
result
=
nullptr
;
j
byteArray
arr
=
nullptr
;
if
(
inet_pton
(
AF_INET
,
src
,
dst
)
==
1
)
{
if
(
inet_pton
(
AF_INET
,
src
,
dst
)
==
1
)
{
jbyteArray
arr
=
env
->
NewByteArray
(
sizeof
(
in_addr
));
arr
=
env
->
NewByteArray
(
sizeof
(
in_addr
));
env
->
SetByteArrayRegion
(
arr
,
0
,
sizeof
(
in_addr
),
dst
);
env
->
SetByteArrayRegion
(
arr
,
0
,
sizeof
(
in_addr
),
dst
);
result
=
sdk_version
<
24
?
env
->
NewObject
(
Inet4Address
,
Inet4Address__init_
,
arr
,
str
)
:
env
->
NewObject
(
Inet4Address
,
Inet4Address__init_
,
str
,
arr
);
}
else
if
(
inet_pton
(
AF_INET6
,
src
,
dst
)
==
1
)
{
}
else
if
(
inet_pton
(
AF_INET6
,
src
,
dst
)
==
1
)
{
jbyteArray
arr
=
env
->
NewByteArray
(
sizeof
(
in6_addr
));
arr
=
env
->
NewByteArray
(
sizeof
(
in6_addr
));
env
->
SetByteArrayRegion
(
arr
,
0
,
sizeof
(
in6_addr
),
dst
);
env
->
SetByteArrayRegion
(
arr
,
0
,
sizeof
(
in6_addr
),
dst
);
result
=
sdk_version
<
24
?
env
->
NewObject
(
Inet6Address
,
Inet6Address__init_
,
arr
,
str
,
0
)
:
env
->
NewObject
(
Inet6Address
,
Inet6Address__init_
,
str
,
arr
,
0
);
}
}
env
->
ReleaseStringUTFChars
(
str
,
src
);
env
->
ReleaseStringUTFChars
(
str
,
src
);
return
result
;
return
arr
;
}
}
}
}
...
@@ -134,6 +130,7 @@ typedef union {
...
@@ -134,6 +130,7 @@ typedef union {
void
*
venv
;
void
*
venv
;
}
UnionJNIEnvToVoid
;
}
UnionJNIEnvToVoid
;
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
jint
JNI_OnLoad
(
JavaVM
*
vm
,
void
*
reserved
)
{
jint
JNI_OnLoad
(
JavaVM
*
vm
,
void
*
reserved
)
{
UnionJNIEnvToVoid
uenv
;
UnionJNIEnvToVoid
uenv
;
uenv
.
venv
=
NULL
;
uenv
.
venv
=
NULL
;
...
@@ -161,24 +158,12 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
...
@@ -161,24 +158,12 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
THROW(env, "java/lang/RuntimeException", "Field " #clazz "." name " with type " sig " not found"); \
THROW(env, "java/lang/RuntimeException", "Field " #clazz "." name " with type " sig " not found"); \
goto bail; \
goto bail; \
}
}
#define GET_METHOD(out, clazz, name, sig) \
if (!(out = env->GetMethodID(clazz, name, sig))) { \
THROW(env, "java/lang/RuntimeException", "Method " #clazz "." name sig " not found"); \
goto bail; \
}
FIND_CLASS
(
Inet4Address
,
"java/net/Inet4Address"
);
FIND_CLASS
(
Inet6Address
,
"java/net/Inet6Address"
);
if
(
sdk_version
<
24
)
{
if
(
sdk_version
<
24
)
{
FIND_CLASS
(
ProcessImpl
,
"java/lang/ProcessManager$ProcessImpl"
);
FIND_CLASS
(
ProcessImpl
,
"java/lang/ProcessManager$ProcessImpl"
);
GET_FIELD
(
ProcessImpl_pid
,
ProcessImpl
,
"pid"
,
"I"
)
GET_FIELD
(
ProcessImpl_pid
,
ProcessImpl
,
"pid"
,
"I"
)
GET_FIELD
(
ProcessImpl_exitValue
,
ProcessImpl
,
"exitValue"
,
"Ljava/lang/Integer;"
)
GET_FIELD
(
ProcessImpl_exitValue
,
ProcessImpl
,
"exitValue"
,
"Ljava/lang/Integer;"
)
GET_FIELD
(
ProcessImpl_exitValueMutex
,
ProcessImpl
,
"exitValueMutex"
,
"Ljava/lang/Object;"
)
GET_FIELD
(
ProcessImpl_exitValueMutex
,
ProcessImpl
,
"exitValueMutex"
,
"Ljava/lang/Object;"
)
GET_METHOD
(
Inet4Address__init_
,
Inet4Address
,
"<init>"
,
"([BLjava/lang/String;)V"
)
GET_METHOD
(
Inet6Address__init_
,
Inet6Address
,
"<init>"
,
"([BLjava/lang/String;I)V"
)
}
else
{
GET_METHOD
(
Inet4Address__init_
,
Inet4Address
,
"<init>"
,
"(Ljava/lang/String;[B)V"
)
GET_METHOD
(
Inet6Address__init_
,
Inet6Address
,
"<init>"
,
"(Ljava/lang/String;[BI)V"
)
}
}
result
=
JNI_VERSION_1_6
;
result
=
JNI_VERSION_1_6
;
...
...
mobile/src/main/java/com/github/shadowsocks/utils/Utils.kt
View file @
536a1b4b
...
@@ -12,8 +12,6 @@ import android.support.v7.util.SortedList
...
@@ -12,8 +12,6 @@ import android.support.v7.util.SortedList
import
android.util.TypedValue
import
android.util.TypedValue
import
com.github.shadowsocks.App.Companion.app
import
com.github.shadowsocks.App.Companion.app
import
com.github.shadowsocks.JniHelper
import
com.github.shadowsocks.JniHelper
import
java.lang.reflect.InvocationTargetException
import
java.net.Inet4Address
import
java.net.InetAddress
import
java.net.InetAddress
import
java.net.URLConnection
import
java.net.URLConnection
...
@@ -23,8 +21,11 @@ private val fieldChildFragmentManager by lazy {
...
@@ -23,8 +21,11 @@ private val fieldChildFragmentManager by lazy {
field
field
}
}
fun
String
.
isNumericAddress
()
=
parseNumericAddress
()
!=
null
fun
String
.
isNumericAddress
()
=
JniHelper
.
parseNumericAddress
(
this
)
!=
null
fun
String
.
parseNumericAddress
()
=
JniHelper
.
parseNumericAddress
(
this
)
fun
String
.
parseNumericAddress
():
InetAddress
?
{
val
addr
=
JniHelper
.
parseNumericAddress
(
this
)
return
if
(
addr
==
null
)
null
else
InetAddress
.
getByAddress
(
this
,
addr
)
}
fun
parsePort
(
str
:
String
?,
default
:
Int
,
min
:
Int
=
1025
):
Int
{
fun
parsePort
(
str
:
String
?,
default
:
Int
,
min
:
Int
=
1025
):
Int
{
val
x
=
str
?.
toIntOrNull
()
?:
default
val
x
=
str
?.
toIntOrNull
()
?:
default
...
...
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