Skip to content

Commit a2f7c82

Browse files
committed
fixed bypass chn-list failed bug. Ready to start review ss-libev code.
1 parent 0e9278d commit a2f7c82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+302
-2297
lines changed

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818
ndk {
1919
moduleName "Jni"
2020
stl "stlport_static"
21-
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
21+
abiFilters "armeabi-v7a", "arm64-v8a"
2222
}
2323
minifyEnabled true
2424
shrinkResources true
16 KB
Binary file not shown.
12 KB
Binary file not shown.
24 KB
Binary file not shown.
20 KB
Binary file not shown.

app/src/main/java/com/proxy/shadowsocksr/Consts.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ public class Consts
77
//Default ss profile
88
public final static String defaultIP = "1.2.3.4";
99
public final static String defaultCryptMethod = "aes-256-cfb";
10-
public final static String defaultPassword = "cs7cysc6ts6cstcst";
1110
public final static int remotePort = 2333;
12-
public final static int localPort = 23333;
11+
public final static int localPort = 1093;
1312
//SSR
1413
public final static String defaultTcpProtocol="origin";
1514
public final static String defaultObfsMethod="plain";

app/src/main/java/com/proxy/shadowsocksr/MainActivity.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ private void addNewServer(String server, int rmtPort, String method, String pwd)
248248
{
249249
String lbl = "Svr-" + System.currentTimeMillis();
250250
SSRProfile newPro = new SSRProfile(server, rmtPort, Consts.localPort, method, pwd,
251-
false, "origin", "plain", false, false);
251+
false, Consts.defaultTcpProtocol,
252+
Consts.defaultObfsMethod, false, false);
252253
Hawk.put(lbl, newPro);
253254

254255
ArrayList<String> lst = Hawk.get("ServerList");
@@ -275,11 +276,9 @@ private void addNewServer(String server, int rmtPort, String method, String pwd)
275276
switch (item.getItemId())
276277
{
277278
case R.id.action_maunally_add_server:
278-
addNewServer(
279-
Consts.defaultIP,
280-
Consts.remotePort,
281-
Consts.defaultCryptMethod,
282-
Consts.defaultPassword);
279+
addNewServer(Consts.defaultIP,
280+
Consts.remotePort,
281+
Consts.defaultCryptMethod, "");
283282
loadServerList();
284283
pref.reloadPref();
285284
break;
@@ -325,11 +324,9 @@ private void addNewServer(String server, int rmtPort, String method, String pwd)
325324
//
326325
if (list.size() == 0)
327326
{
328-
addNewServer(
329-
Consts.defaultIP,
330-
Consts.remotePort,
331-
Consts.defaultCryptMethod,
332-
Consts.defaultPassword);
327+
addNewServer(Consts.defaultIP,
328+
Consts.remotePort,
329+
Consts.defaultCryptMethod, "");
333330
}
334331
else
335332
{
@@ -385,7 +382,6 @@ private void addNewServer(String server, int rmtPort, String method, String pwd)
385382
}
386383
else
387384
{
388-
//START
389385
Intent vpn = SSRVPNService.prepare(this);
390386
if (vpn != null)
391387
{
@@ -479,7 +475,6 @@ else if (resultCode == RESULT_CANCELED)
479475

480476
@Override public void onBackPressed()
481477
{
482-
//drawer.isDrawerOpen(nav);
483478
if (nav.isShown())
484479
{
485480
drawer.closeDrawers();
@@ -504,6 +499,7 @@ public void switchUI(boolean enable)
504499
pref.setPrefEnabled(false);
505500
spinner.setEnabled(false);
506501
fab.setImageResource(android.R.drawable.ic_media_pause);
502+
//
507503
}
508504
}
509505
}

app/src/main/java/com/proxy/shadowsocksr/SSRApplication.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void init()
2525
.setEncryptionMethod(
2626
HawkBuilder.EncryptionMethod.NO_ENCRYPTION)//TODO: VER.2.0 local profile encrypt.
2727
.build();
28+
2829
boolean isFirstUse = Hawk.get("FirstUse", true);
2930

3031
if (isFirstUse)
@@ -34,8 +35,7 @@ public void init()
3435
Consts.remotePort,
3536
Consts.localPort,
3637
Consts.defaultCryptMethod,
37-
Consts.defaultPassword,
38-
false,
38+
"", false,
3939
Consts.defaultTcpProtocol,
4040
Consts.defaultObfsMethod,
4141
false,false);

app/src/main/java/com/proxy/shadowsocksr/SSRVPNService.java

+40-44
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import android.os.Parcel;
1313
import android.os.ParcelFileDescriptor;
1414
import android.os.RemoteException;
15-
import android.system.OsConstants;
15+
import android.util.Log;
1616

1717
import com.proxy.shadowsocksr.items.ConnectProfile;
1818
import com.proxy.shadowsocksr.items.GlobalProfile;
@@ -28,7 +28,6 @@
2828
import java.io.IOException;
2929
import java.io.InputStream;
3030
import java.io.OutputStream;
31-
import java.lang.reflect.InvocationTargetException;
3231
import java.lang.reflect.Method;
3332
import java.util.ArrayList;
3433
import java.util.List;
@@ -186,11 +185,11 @@ private void copyDaemonBin(String file, File out)
186185

187186
private void startRunner()
188187
{
188+
killProcesses();
189+
//
189190
vpnThread = new SSRVPNThread();
190191
vpnThread.start();
191192
//
192-
killProcesses();
193-
//
194193
new Thread(new Runnable()
195194
{
196195
@Override public void run()
@@ -297,31 +296,13 @@ private void stopRunner()
297296

298297
private void startSSRDaemon()
299298
{
300-
String[] acl = new String[0];
301-
switch (globalProfile.route)
302-
{
303-
case "bypass-lan":
304-
acl = getResources().getStringArray(R.array.private_route);
305-
break;
306-
case "bypass-lan-and-list":
307-
acl = getResources().getStringArray(R.array.chn_route_full);
308-
break;
309-
}
310-
311-
StringBuilder s = new StringBuilder();
312-
for (String a : acl)
313-
{
314-
s.append(a).append(Consts.lineSept);
315-
}
316-
ConfFileUtil.writeToFile(s.toString(), new File(Consts.baseDir + "acl.list"));
317-
318299
String ssrconf = String.format(ConfFileUtil.SSRConf,
319300
ssrProfile.server,
320301
ssrProfile.remotePort,
321302
ssrProfile.localPort,
322303
ssrProfile.passwd,
323304
ssrProfile.cryptMethod,
324-
20);
305+
10);
325306
ConfFileUtil.writeToFile(ssrconf, new File(Consts.baseDir + "ss-local-vpn.conf"));
326307

327308
StringBuilder sb = new StringBuilder();
@@ -334,7 +315,25 @@ private void startSSRDaemon()
334315

335316
if (!globalProfile.route.equals("all"))
336317
{
337-
sb.append(" --acl").append(Consts.baseDir + "acl.list");
318+
String[] acl = new String[0];
319+
switch (globalProfile.route)
320+
{
321+
case "bypass-lan":
322+
acl = getResources().getStringArray(R.array.private_route);
323+
break;
324+
case "bypass-lan-and-list":
325+
acl = getResources().getStringArray(R.array.chn_route_full);
326+
break;
327+
}
328+
329+
StringBuilder s = new StringBuilder();
330+
for (String a : acl)
331+
{
332+
s.append(a).append(Consts.lineSept);
333+
}
334+
ConfFileUtil.writeToFile(s.toString(), new File(Consts.baseDir + "acl.list"));
335+
//
336+
sb.append(" --acl ").append(Consts.baseDir + "acl.list");
338337
}
339338

340339
ShellUtil.runCmd(sb.toString());
@@ -365,11 +364,12 @@ private void startDnsDaemon()
365364
String blklst = getResources().getString(R.string.black_list);
366365

367366
pdnsd = String.format(ConfFileUtil.PdNSdDirect, "0.0.0.0", 8153,
368-
Consts.baseDir + "pdnsd-vpn.pid", reject, blklst, 8163, "reject = ::/0;");//IPV6
367+
Consts.baseDir + "pdnsd-vpn.pid", reject, blklst, 8163,
368+
"reject = ::/0;");//IPV6
369369
}
370370
else
371371
{
372-
pdnsd = String.format(ConfFileUtil.PDNSdLocal, "0.0.0.0", 8153,
372+
pdnsd = String.format(ConfFileUtil.PdNSdLocal, "0.0.0.0", 8153,
373373
Consts.baseDir + "pdnsd-vpn.pid", 8163, "reject = ::/0;");//IPV6
374374
}
375375

@@ -395,7 +395,7 @@ private int startVpn()
395395

396396
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
397397
{
398-
builder.allowFamily(OsConstants.AF_INET6);
398+
//builder.allowFamily(OsConstants.AF_INET6);
399399

400400
if (!globalProfile.globalProxy)
401401
{
@@ -419,9 +419,9 @@ private int startVpn()
419419
else
420420
{
421421
String[] privateLst = getResources().getStringArray(R.array.bypass_private_route);
422-
for (String p : privateLst)
422+
for (String cidr : privateLst)
423423
{
424-
String[] sp = p.split("/");
424+
String[] sp = cidr.split("/");
425425
builder.addRoute(sp[0], Integer.valueOf(sp[1]));
426426
}
427427
}
@@ -471,7 +471,7 @@ private int startVpn()
471471
return fd;
472472
}
473473

474-
@SuppressWarnings("ResultOfMethodCallIgnored") private void killProcesses()
474+
private void killProcesses()
475475
{
476476
String[] tasks = new String[]{"ss-local", "ss-tunnel", "pdnsd", "tun2socks"};
477477
List<String> cmds = new ArrayList<>();
@@ -492,13 +492,15 @@ private int startVpn()
492492
File pidf = new File(Consts.baseDir + t + "-vpn.pid");
493493
int pid = new Scanner(pidf).useDelimiter("\\Z").nextInt();
494494
android.os.Process.killProcess(pid);
495-
pidf.delete();
496495
}
497496
catch (Exception ignored)
498497
{
499498
}
500499
cmds.add(String.format("rm -f %s%s-vpn.conf", Consts.baseDir, t));
500+
cmds.add(String.format("rm -f %s%s-vpn.pid", Consts.baseDir, t));
501501
}
502+
cmds.add("rm -f " + Consts.baseDir + "protect_path");
503+
cmds.add("rm -f " + Consts.baseDir + "sock_path");
502504
cmdarr = new String[cmds.size()];
503505
cmds.toArray(cmdarr);
504506
ShellUtil.runCmd(cmdarr);
@@ -524,11 +526,10 @@ class SSRVPNThread extends Thread
524526
volatile private LocalServerSocket lss;
525527
volatile private boolean isRunning = true;
526528

527-
@SuppressWarnings("ResultOfMethodCallIgnored") @Override public void run()
529+
@Override public void run()
528530
{
529531
try
530532
{
531-
new File(Consts.baseDir + "protect_path").delete();
532533
LocalSocket ls = new LocalSocket();
533534
ls.bind(new LocalSocketAddress(Consts.baseDir + "protect_path",
534535
LocalSocketAddress.Namespace.FILESYSTEM));
@@ -548,7 +549,7 @@ class SSRVPNThread extends Thread
548549
final LocalSocket ls = lss.accept();
549550
exec.execute(new Runnable()
550551
{
551-
@Override public void run()
552+
@SuppressWarnings("ResultOfMethodCallIgnored") @Override public void run()
552553
{
553554
try
554555
{
@@ -568,29 +569,24 @@ class SSRVPNThread extends Thread
568569

569570
Jni.jniClose(fd);
570571

571-
if (ret)
572-
{
573-
os.write(0);
574-
}
575-
else
576-
{
577-
os.write(1);
578-
}
572+
os.write(ret ? 0 : 1);
579573

580574
is.close();
581575
os.close();
582576
ls.close();
583577
}
584578
}
585-
catch (InvocationTargetException | IOException | IllegalAccessException | NoSuchMethodException e)
579+
catch (Exception e)
586580
{
581+
Log.e("EXCE", e.getMessage());
587582
e.printStackTrace();
588583
}
589584
}
590585
});
591586
}
592-
catch (IOException e)
587+
catch (Exception e)
593588
{
589+
Log.e("EXCE","OUT");
594590
return;
595591
}
596592
}

app/src/main/java/com/proxy/shadowsocksr/fragment/PrefFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public void setPrefEnabled(boolean isEnable)
183183
ss.cryptMethod = sp.getString(key, Consts.defaultCryptMethod);
184184
break;
185185
case "password":
186-
ss.passwd = sp.getString(key, Consts.defaultPassword);
186+
ss.passwd = sp.getString(key, "");
187187
break;
188188
case "enable_ssr":
189189
ss.enableSSR = sp.getBoolean(key, false);

app/src/main/java/com/proxy/shadowsocksr/util/ConfFileUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ConfFileUtil
3333
"}";
3434

3535
//TODO must split line?
36-
public static String PDNSdLocal =
36+
public static String PdNSdLocal =
3737
"global {" + Consts.lineSept +
3838
" perm_cache = 2048;" + Consts.lineSept +
3939
" cache_dir = \"/data/data/com.proxy.shadowsocksr\";" + Consts.lineSept +
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
SUBDIRS = libsodium libcork libipset libudns libev src
22

33
ACLOCAL_AMFLAGS = -I m4
4-
man_MANS = man/shadowsocks-libev.8 man/ss-server.1 man/ss-local.1 man/ss-redir.1\
5-
man/ss-manager.1 man/ss-tunnel.1
4+
man_MANS = shadowsocks-libev.8
65

76
pkgconfiglibdir = $(libdir)/pkgconfig
87
pkgconfiglib_DATA = shadowsocks-libev.pc

0 commit comments

Comments
 (0)