1313import android .system .Os ;
1414import android .util .Log ;
1515
16- import com .google .gson .Gson ;
17-
1816import org .lsposed .lspatch .loader .util .FileUtils ;
1917import org .lsposed .lspatch .loader .util .XLog ;
2018import org .lsposed .lspatch .service .LocalApplicationService ;
2119import org .lsposed .lspatch .service .RemoteApplicationService ;
22- import org .lsposed .lspatch .share .PatchConfig ;
2320import org .lsposed .lspd .core .Startup ;
2421import org .lsposed .lspd .service .ILSPApplicationService ;
22+ import org .json .JSONObject ;
2523
2624import java .io .BufferedReader ;
2725import java .io .File ;
3937import java .util .Collections ;
4038import java .util .Map ;
4139import java .util .function .BiConsumer ;
40+ import java .util .stream .Collectors ;
4241import java .util .zip .ZipFile ;
4342
4443import de .robv .android .xposed .XposedHelpers ;
@@ -58,7 +57,7 @@ public class LSPApplication {
5857 private static LoadedApk stubLoadedApk ;
5958 private static LoadedApk appLoadedApk ;
6059
61- private static PatchConfig config ;
60+ private static JSONObject config ;
6261
6362 public static boolean isIsolated () {
6463 return (android .os .Process .myUid () % PER_USER_RANGE ) >= FIRST_APP_ZYGOTE_ISOLATED_UID ;
@@ -78,7 +77,7 @@ public static void onLoad() throws RemoteException, IOException {
7877
7978 Log .d (TAG , "Initialize service client" );
8079 ILSPApplicationService service ;
81- if (config .useManager ) {
80+ if (config .optBoolean ( " useManager" ) ) {
8281 service = new RemoteApplicationService (context );
8382 } else {
8483 service = new LocalApplicationService (context );
@@ -94,7 +93,7 @@ public static void onLoad() throws RemoteException, IOException {
9493 Log .i (TAG , "Modules initialized" );
9594
9695 switchAllClassLoader ();
97- SigBypass .doSigBypass (context , config .sigBypassLevel );
96+ SigBypass .doSigBypass (context , config .optInt ( " sigBypassLevel" ) );
9897
9998 Log .i (TAG , "LSPatch bootstrap completed" );
10099 }
@@ -110,13 +109,13 @@ private static Context createLoadedApkWithContext() {
110109
111110 try (var is = baseClassLoader .getResourceAsStream (CONFIG_ASSET_PATH )) {
112111 BufferedReader streamReader = new BufferedReader (new InputStreamReader (is , StandardCharsets .UTF_8 ));
113- config = new Gson (). fromJson ( streamReader , PatchConfig . class );
114- } catch (IOException e ) {
115- Log .e (TAG , "Failed to load config file" );
112+ config = new JSONObject ( streamReader . lines (). collect ( Collectors . joining ()) );
113+ } catch (Throwable e ) {
114+ Log .e (TAG , "Failed to parse config file" , e );
116115 return null ;
117116 }
118- Log .i (TAG , "Use manager: " + config .useManager );
119- Log .i (TAG , "Signature bypass level: " + config .sigBypassLevel );
117+ Log .i (TAG , "Use manager: " + config .optBoolean ( " useManager" ) );
118+ Log .i (TAG , "Signature bypass level: " + config .optInt ( " sigBypassLevel" ) );
120119
121120 Path originPath = Paths .get (appInfo .dataDir , "cache/lspatch/origin/" );
122121 Path cacheApkPath ;
@@ -126,7 +125,9 @@ private static Context createLoadedApkWithContext() {
126125
127126 appInfo .sourceDir = cacheApkPath .toString ();
128127 appInfo .publicSourceDir = cacheApkPath .toString ();
129- appInfo .appComponentFactory = config .appComponentFactory ;
128+ if (config .has ("appComponentFactory" )) {
129+ appInfo .appComponentFactory = config .optString ("appComponentFactory" );
130+ }
130131
131132 if (!Files .exists (cacheApkPath )) {
132133 Log .i (TAG , "Extract original apk" );
@@ -165,11 +166,11 @@ private static Context createLoadedApkWithContext() {
165166 Log .i (TAG , "hooked app initialized: " + appLoadedApk );
166167
167168 var context = (Context ) XposedHelpers .callStaticMethod (Class .forName ("android.app.ContextImpl" ), "createAppContext" , activityThread , stubLoadedApk );
168- if (config .appComponentFactory != null ) {
169+ if (config .has ( " appComponentFactory" ) ) {
169170 try {
170- context .getClassLoader ().loadClass (config .appComponentFactory );
171+ context .getClassLoader ().loadClass (appInfo .appComponentFactory );
171172 } catch (ClassNotFoundException e ) { // This will happen on some strange shells like 360
172- Log .w (TAG , "Original AppComponentFactory not found: " + config .appComponentFactory );
173+ Log .w (TAG , "Original AppComponentFactory not found: " + appInfo .appComponentFactory );
173174 appInfo .appComponentFactory = null ;
174175 }
175176 }
0 commit comments