-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcustomize.py
More file actions
1147 lines (922 loc) · 39.8 KB
/
customize.py
File metadata and controls
1147 lines (922 loc) · 39.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import copy
import io
import os
import re
import shutil
import sys
from glob import iglob
import ccglobal
import config
from build.apkfile import ApkFile
from build.smali import MethodSpecifier
from build.xml import XmlFile
from util import template
def rm_files():
def ignore_comment(line: str):
annotation_index = line.find('#')
if annotation_index >= 0:
line = line[:annotation_index]
return line.strip()
with open(f'{sys.path[0]}/remove-files.txt', 'r', encoding='utf-8') as f:
for item in map(ignore_comment, f.readlines()):
if len(item) == 0:
continue
if os.path.exists(item):
ccglobal.log(f'删除文件: {item}')
if os.path.isfile(item):
os.remove(item)
else:
shutil.rmtree(item)
else:
ccglobal.log(f'文件不存在: {item}')
def replace_installer():
ccglobal.log('替换 PUI 软件包安装程序')
shutil.rmtree('system_ext/priv-app/OppoPackageInstaller')
pui_dir = 'system_ext/priv-app/PUIPackageInstaller'
os.makedirs(pui_dir)
shutil.copy(f'{ccglobal.MISC_DIR}/PUIPackageInstaller.apk', pui_dir)
def disable_cn_gms():
ccglobal.log('禁用国行 GMS 限制')
xml = XmlFile('my_product/etc/permissions/oplus_google_cn_gms_features.xml')
root = xml.get_root()
element = root.find('feature[@name="cn.google.services"]')
root.remove(element)
xml.commit()
with open('system/system/etc/init/hw/init.rc', 'r+', encoding='utf-8', newline='') as f:
content = re.sub(r'(?<=setprop remote_provisioning\.hostname remoteprovisioning\.)googleapis\.com(?=\n)', 'grapheneos.org', f.read())
f.seek(0)
f.truncate()
f.write(content)
def disable_activity_start_dialog():
ccglobal.log('禁用关联启动对话框')
xml = XmlFile('my_stock/etc/extension/com.oplus.oplus-feature.xml')
root = xml.get_root()
element = root.find('oplus-feature[@name="oplus.software.activity_start_manager"]')
root.remove(element)
xml.commit()
def turn_off_flashlight_with_power_key():
ccglobal.log('启用电源键关闭手电筒')
xml = XmlFile('system_ext/etc/permissions/com.oplus.features_config.xml')
root = xml.get_root()
element = root.find('oplus-feature[@name="oplus.software.powerkey_disbale_turnoff_torch"]')
root.remove(element)
xml.commit()
def disable_signature_verification():
apk = ApkFile('system/system/framework/framework.jar')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('禁用 V3 签名完整性验证')
smali = apk.open_smali('android/util/apk/ApkSigningBlockUtils.smali')
specifier = MethodSpecifier()
specifier.name = 'parseVerityDigestAndVerifySourceLength'
specifier.parameters = '[BJLandroid/util/apk/SignatureInfo;'
specifier.return_type = '[B'
new_body = '''\
.method static blacklist parseVerityDigestAndVerifySourceLength([BJLandroid/util/apk/SignatureInfo;)[B
.locals 2
const/4 v0, 0x0
const/16 v1, 0x20
invoke-static {p0, v0, v1}, Ljava/util/Arrays;->copyOfRange([BII)[B
move-result-object v0
return-object v0
.end method
'''
smali.method_replace(specifier, new_body)
specifier = MethodSpecifier()
specifier.name = 'verifyIntegrityForVerityBasedAlgorithm'
specifier.parameters = '[BLjava/io/RandomAccessFile;Landroid/util/apk/SignatureInfo;'
smali.method_nop(specifier)
apk.build(remove_oat=False)
os.remove(f'{apk.file}.fsv_meta')
for file in iglob('system/system/framework/**/boot-framework.*', recursive=True):
if not os.path.samefile(apk.file, file):
os.remove(file)
def patch_oplus_services():
apk = ApkFile('system/system/framework/oplus-services.jar')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('禁用 ADB 安装确认')
smali = apk.open_smali('com/android/server/pm/OplusPackageInstallInterceptManager.smali')
specifier = MethodSpecifier()
specifier.name = 'allowInterceptAdbInstallInInstallStage'
specifier.parameters = 'ILandroid/content/pm/PackageInstaller$SessionParams;Ljava/io/File;Ljava/lang/String;Landroid/content/pm/IPackageInstallObserver2;'
smali.method_return_boolean(specifier, False)
ccglobal.log('去除已激活 VPN 通知')
smali = apk.open_smali('com/android/server/connectivity/VpnExtImpl.smali')
specifier = MethodSpecifier()
specifier.name = 'showNotification'
specifier.parameters = 'Ljava/lang/String;IILjava/lang/String;Landroid/app/PendingIntent;Lcom/android/internal/net/VpnConfig;'
smali.method_nop(specifier)
apk.build(remove_oat=False)
os.remove(f'{apk.file}.fsv_meta')
for file in iglob('system/system/framework/oat/arm64/oplus-services.*'):
if not os.path.samefile(apk.file, file):
os.remove(file)
def patch_system_ui():
apk = ApkFile('system_ext/priv-app/SystemUI/SystemUI.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('禁用控制中心时钟红1')
smali = apk.open_smali('com/oplus/systemui/common/clock/OplusClockExImpl.smali')
specifier = MethodSpecifier()
specifier.name = 'setTextWithRedOneStyle'
specifier.parameters = 'Landroid/widget/TextView;Ljava/lang/CharSequence;'
specifier.return_type = 'Z'
new_body = '''\
.method public setTextWithRedOneStyle(Landroid/widget/TextView;Ljava/lang/CharSequence;)Z
.locals 0
invoke-virtual {p1, p2}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V
iget-boolean p0, p0, Lcom/oplus/systemui/common/clock/OplusClockExImpl;->mIsDateTimePanel:Z
return p0
.end method
'''
smali.method_replace(specifier, new_body)
smali = apk.open_smali('com/oplus/keyguard/utils/KeyguardUtils$Companion.smali')
specifier = MethodSpecifier()
specifier.name = 'getSpannedHourString'
specifier.parameters = 'Landroid/content/Context;Ljava/lang/String;'
specifier.return_type = 'Landroid/text/SpannableStringBuilder;'
new_body = '''\
.method public final getSpannedHourString(Landroid/content/Context;Ljava/lang/String;)Landroid/text/SpannableStringBuilder;
.locals 0
new-instance p1, Landroid/text/SpannableStringBuilder;
invoke-direct {p1, p2}, Landroid/text/SpannableStringBuilder;-><init>(Ljava/lang/CharSequence;)V
return p1
.end method
'''
smali.method_replace(specifier, new_body)
ccglobal.log('去除开发者选项通知')
smali = apk.open_smali('com/oplus/systemui/statusbar/controller/SystemPromptController.smali')
specifier = MethodSpecifier()
specifier.name = 'updateDeveloperMode'
smali.method_nop(specifier)
ccglobal.log('去除免打扰模式通知')
smali = apk.open_smali('com/oplus/systemui/statusbar/notification/helper/DndAlertHelper.smali')
specifier = MethodSpecifier()
specifier.name = 'operateNotification'
specifier.parameters = 'IJZ'
smali.method_nop(specifier)
ccglobal.log('禁用 USB 选择弹窗')
smali = apk.open_smali('com/oplus/systemui/usb/UsbService.smali')
specifier = MethodSpecifier()
specifier.name = 'performUsbDialogAction'
insert = '''\
const/16 v0, 0x3ea
if-eq p1, v0, :jump_return
const/16 v0, 0x3eb
if-ne p1, v0, :jump_normal
:jump_return
return-void
:jump_normal
'''
smali.method_insert_before(specifier, insert)
ccglobal.log('禁用自动进入超级省电模式')
smali = apk.open_smali('com/oplus/systemui/statusbar/notification/power/supersave/OplusSuperSaveControllerImpl.smali')
old_body = smali.find_constructor('Landroid/content/Context;Lcom/android/systemui/settings/UserTracker;Ljava/util/concurrent/Executor;\
Lcom/android/systemui/statusbar/policy/KeyguardStateController;Lcom/oplus/systemui/statusbar/notification/power/OplusPowerUISoundUtil;\
Lcom/android/systemui/statusbar/policy/DeviceProvisionedController;')
pattern = r'''
const-string ([v|p]\d+), "persist.vendor.battery_value_min"
(?:.|\n)*?
invoke-static {[v|p]\d+, [v|p]\d+}, Landroid/os/SystemProperties;->getInt\(Ljava/lang/String;I\)I
(?:.|\n)*?
move-result ([v|p]\d+)
'''
repl = r'''
const-string \g<1>, "persist.vendor.battery_value_min"
const/4 \g<2>, -0x1
invoke-static {\g<1>, \g<2>}, Landroid/os/SystemProperties;->getInt(Ljava/lang/String;I)I
move-result \g<2>
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
apk.build()
def patch_launcher():
apk = ApkFile('system_ext/priv-app/OplusLauncher/OplusLauncher.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('允许最近任务显示内存信息')
smali = apk.open_smali('com/oplus/quickstep/memory/MemoryInfoManager.smali')
specifier = MethodSpecifier()
specifier.name = 'judgeWhetherAllowMemoDisplay'
new_body = '''\
.method private judgeWhetherAllowMemoDisplay()V
.locals 1
const/4 v0, 0x1
iput-boolean v0, p0, Lcom/oplus/quickstep/memory/MemoryInfoManager;->mAllowMemoryInfoDisplay:Z
invoke-direct {p0, v0}, Lcom/oplus/quickstep/memory/MemoryInfoManager;->saveAllowMemoryInfoDisplay(Z)Z
return-void
.end method
'''
smali.method_replace(specifier, new_body)
ccglobal.log('禁用最近任务自动聚焦到下一个应用')
smali = apk.open_smali('com/android/common/util/AppFeatureUtils.smali')
specifier = MethodSpecifier()
specifier.name = 'isSupportAutoFocusToNextPageInOverviewState'
specifier.parameters = 'Z'
smali.method_return_boolean(specifier, False)
ccglobal.log('桌面主页设置为第二页')
smali = apk.open_smali('com/android/launcher3/Workspace.smali')
specifier = MethodSpecifier()
specifier.name = 'initWorkspace'
old_body = smali.find_method(specifier)
pattern = r'''
invoke-static {}, Lcom/android/launcher/mode/LauncherModeManager;->getInstance\(\)Lcom/android/launcher/mode/LauncherModeManager;
(?:.|\n)*?
move-result [v|p]\d+
(sput ([v|p]\d+), Lcom/android/launcher3/Workspace;->DEFAULT_PAGE:I)
'''
repl = r'''
const/4 \g<2>, 0x1
\g<1>
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
apk.build()
def patch_theme_store():
apk = ApkFile('my_stock/app/KeKeThemeSpace/KeKeThemeSpace.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('去除主题商店广告')
# Remove splash ads
smali = apk.find_smali('"s-1"', '"getSplashScreen finish splashDto is null"').pop()
specifier = MethodSpecifier()
specifier.parameters = 'Lcom/oppo/cdo/card/theme/dto/SplashDto;Landroid/os/Handler;'
specifier.return_type = 'V'
specifier.keywords.add('"s-1"')
specifier.keywords.add('"getSplashScreen finish splashDto is null"')
old_body = smali.find_method(specifier)
pattern = '''\
(\\.method public \\S+\\(Lcom/oppo/cdo/card/theme/dto/SplashDto;Landroid/os/Handler;\\)V)
(?:.|\n)*?
iget-object (?:[v|p]\\d+, ){2}(\\S+)
(?:.|\n)*?
const-string(?:/jumbo)? [v|p]\\d+, "s-1"
(?:.|\n)*?
const-string [v|p]\\d+, "getSplashScreen finish splashDto is null"
(?:.|\n)*?
invoke-static {(?:[v|p]\\d+, ){3}[v|p]\\d+}, (\\S+Ljava/lang/String;Ljava/lang/String;Z\\)V)
'''
match = re.search(pattern, old_body)
new_body = f'''\
{match.group(1)}
.locals 3
move-object/from16 v0, p0
iget-object v0, v0, {match.group(2)}
const-string v1, ""
const/4 v2, 0x1
invoke-static {{v0, v1, v1, v2}}, {match.group(3)}
return-void
.end method
'''
smali.method_replace(old_body, new_body)
# Remove theme preview ads
smali = apk.open_smali('com/oppo/cdo/theme/domain/dto/response/HorizontalDto.smali')
specifier = MethodSpecifier()
specifier.name = 'getCode'
smali.method_return_int(specifier, 0)
ccglobal.log('破解主题免费')
smali = apk.open_smali('com/oppo/cdo/card/theme/dto/vip/VipUserDto.smali')
specifier = MethodSpecifier()
specifier.name = 'getVipStatus'
smali.method_return_int(specifier, 1)
specifier = MethodSpecifier()
specifier.name = 'getVipDays'
smali.method_return_int(specifier, 999)
smali = apk.open_smali('com/oppo/cdo/theme/domain/dto/response/PublishProductItemDto.smali')
specifier = MethodSpecifier()
specifier.name = 'getIsVipAvailable'
smali.method_return_int(specifier, 1)
ccglobal.log('禁用主题自动恢复')
smali = apk.open_smali('com/nearme/themespace/trial/ThemeTrialExpireReceiver.smali')
specifier = MethodSpecifier()
specifier.name = 'onReceive'
specifier.parameters = 'Landroid/content/Context;Landroid/content/Intent;'
smali.method_return_null(specifier)
apk.build()
def disable_lock_screen_red_one():
apk = ApkFile('system_ext/app/KeyguardClockBase/KeyguardClockBase.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('禁用锁屏时钟红1')
smali = apk.open_smali('com/oplus/keyguard/clock/base/widget/CustomizedTextView.smali')
specifier = MethodSpecifier()
specifier.name = 'setHourText'
specifier.parameters = 'Z'
smali.method_nop(specifier)
apk.build()
def disable_launcher_clock_red_one():
apk = ApkFile('my_stock/app/Clock/Clock.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('禁用桌面时钟小部件红1')
smali = apk.find_smali('"DeviceUtils"', '"not found class:com.oplus.widget.OplusTextClock"').pop()
specifier = MethodSpecifier()
specifier.access = MethodSpecifier.Access.PUBLIC
specifier.is_static = True
specifier.parameters = ''
specifier.return_type = 'Z'
specifier.keywords.add('"not found class:com.oplus.widget.OplusTextClock"')
smali.method_return_boolean(specifier, False)
apk.build()
def show_touchscreen_panel_info():
apk = ApkFile('system_ext/app/OplusCommercialEngineerMode/OplusCommercialEngineerMode.apk')
if apk.not_need_modify():
return
apk.refactor()
apk.decode(no_res=False)
ccglobal.log('显示工程模式中的屏生产信息')
xml = apk.open_xml('xml/as_multimedia_test.xml')
root = xml.get_root()
attr_title = xml.make_attr_key('android:title')
for index, element in enumerate(root):
if element.tag == 'androidx.preference.Preference' and element.get(attr_title) == '@string/lcd_brightness':
new_element = copy.deepcopy(element)
new_element.set(attr_title, '@string/lcd_info_title')
new_element.set(xml.make_attr_key('android:key'), 'lcd_info')
new_element.find('intent').set(xml.make_attr_key('android:targetClass'), 'com.oplus.engineermode.display.lcd.modeltest.LcdInfoActivity')
root.insert(index + 1, new_element)
xml.commit()
apk.build()
def show_netmask_and_gateway():
apk = ApkFile('system_ext/priv-app/WirelessSettings/WirelessSettings.apk')
if apk.not_need_modify():
return
apk.decode()
apk.add_smali(f'{ccglobal.MISC_DIR}/smali/WirelessSettings.smali', 'com/meolunr/colorcleaner/CcInjector.smali')
ccglobal.log('显示 WLAN 设置中的子网掩码和网关')
smali = apk.open_smali('com/oplus/wirelesssettings/wifi/detail2/WifiAddressController.smali')
old_body = smali.find_constructor('Landroid/content/Context;Lcom/android/wifitrackerlib/WifiEntry;')
context_field = re.search(r'iput-object p1, p0, Lcom/oplus/wirelesssettings/wifi/detail2/WifiAddressController;->(\S+):Landroid/content/Context;', old_body).group(1)
specifier = MethodSpecifier()
specifier.name = 'displayPreference'
specifier.parameters = 'Landroidx/preference/PreferenceScreen;'
old_body = smali.find_method(specifier)
pattern1 = r'''
const-string [v|p]\d+, "{key}"
'''
pattern2 = r'''
invoke-virtual {p1, [v|p]\d+}, Landroidx/preference/PreferenceGroup;->findPreference\(Ljava/lang/CharSequence;\)Landroidx/preference/Preference;
move-result-object [v|p]\d+
iput-object [v|p]\d+, p0, Lcom/oplus/wirelesssettings/wifi/detail2/WifiAddressController;->(\S+):Landroidx/preference/Preference;
'''
ip_preference_field = re.search(f'{pattern1.format(key='current_ip_address')}{pattern2}', old_body).group(1)
ipv4_preference_field = re.search(f'{pattern1.format(key='current_ipv4_address')}{pattern2}', old_body).group(1)
ipv6_preference_field = re.search(f'{pattern1.format(key='current_ipv6_address')}{pattern2}', old_body).group(1)
specifier = MethodSpecifier()
specifier.parameters = ''
specifier.return_type = 'Z'
specifier.keywords.add('"WifiAddressController"')
specifier.keywords.add('"updateIpInfo:')
update_ip_info_method = re.search(r'\.method public final (\S+?)\(\)Z', smali.find_method(specifier)).group(1)
specifier = MethodSpecifier()
specifier.parameters = ''
specifier.return_type = 'Z'
specifier.keywords.add(f'Lcom/oplus/wirelesssettings/wifi/detail2/WifiAddressController;->{update_ip_info_method}()Z')
old_body = smali.find_method(specifier)
pattern = f'''\
.locals 1
((?:.|\\n)*?
invoke-virtual {{p0}}, Lcom/oplus/wirelesssettings/wifi/detail2/WifiAddressController;->\\S+\\(\\)Z
)
move-result p0
((?:.|\\n)*?
invoke-virtual {{p0}}, Lcom/oplus/wirelesssettings/wifi/detail2/WifiAddressController;->{update_ip_info_method}\\(\\)Z
)
move-result p0
((?:.|\\n)*?)
return p0
'''
repl = f'''\
.locals 4
\\g<1>
move-result v0
\\g<2>
move-result v0
if-eqz v0, :jump
iget-object v1, p0, Lcom/oplus/wirelesssettings/wifi/detail2/WifiAddressController;->{context_field}:Landroid/content/Context;
iget-object v2, p0, Lcom/oplus/wirelesssettings/wifi/detail2/WifiAddressController;->{ip_preference_field}:Landroidx/preference/Preference;
iget-object v3, p0, Lcom/oplus/wirelesssettings/wifi/detail2/WifiAddressController;->{ipv4_preference_field}:Landroidx/preference/Preference;
iget-object p0, p0, Lcom/oplus/wirelesssettings/wifi/detail2/WifiAddressController;->{ipv6_preference_field}:Landroidx/preference/Preference;
invoke-static {{v1, v2, v3, p0}}, Lcom/meolunr/colorcleaner/CcInjector;->\
showNetmaskAndGateway(Landroid/content/Context;Landroidx/preference/Preference;Landroidx/preference/Preference;Landroidx/preference/Preference;)V
:jump\\g<3>
return v0
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
apk.build()
def patch_settings():
apk = ApkFile('system_ext/priv-app/Settings/Settings.apk')
if apk.not_need_modify():
return
apk.decode()
apk.add_smali(f'{ccglobal.MISC_DIR}/smali/Settings.smali', 'com/meolunr/colorcleaner/CcInjector.smali')
ccglobal.log('禁用设备名称敏感词检查')
smali = apk.open_smali('com/oplus/settings/feature/deviceinfo/aboutphone/PhoneNameVerifyUtil.smali')
specifier = MethodSpecifier()
specifier.name = 'activeNeedServerVerify'
specifier.parameters = 'Ljava/lang/String;'
smali.method_return_boolean(specifier, False)
ccglobal.log('显示应用详情中的包名和版本代码')
smali = apk.open_smali('com/oplus/settings/feature/appmanager/AppInfoFeature.smali')
specifier = MethodSpecifier()
specifier.name = 'setAppLabelAndIcon'
specifier.parameters = 'Lcom/android/settings/applications/appinfo/AppButtonsPreferenceController;'
old_body = smali.find_method(specifier)
pattern = r'''
invoke-virtual {p0, ([v|p]\d+)}, Lcom/oplus/settings/feature/appmanager/AppInfoFeature;->getVersionName\(Landroid/content/pm/PackageInfo;\)Ljava/lang/CharSequence;
(?:.|\n)*?
invoke-virtual {p1, [v|p]\d+, [v|p]\d+}, Landroidx/fragment/app/Fragment;->getString\(I\[Ljava/lang/Object;\)Ljava/lang/String;
move-result-object [v|p]\d+
invoke-virtual {([v|p]\d+), [v|p]\d+}, Landroid/widget/TextView;->setText\(Ljava/lang/CharSequence;\)V
'''
repl = r'''
invoke-static {\g<2>, \g<1>}, Lcom/meolunr/colorcleaner/CcInjector;->setPackageAndVersion(Landroid/widget/TextView;Landroid/content/pm/PackageInfo;)V
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
apk.build()
def patch_phone_manager():
apk = ApkFile('my_stock/priv-app/PhoneManager/PhoneManager.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('去除手机管家广告')
smali = apk.find_smali('"AdHelper.kt"', '"ro.vendor.oplus.market.name"', package='com/oplus/phonemanager/common/ad').pop()
specifier = MethodSpecifier()
specifier.name = 'invoke'
specifier.return_type = 'Ljava/lang/Boolean;'
specifier.keywords.add('"ro.vendor.oplus.market.name"')
new_body = '''\
.method public final invoke()Ljava/lang/Boolean;
.locals 1
const/4 v0, 0x0
invoke-static {v0}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean;
move-result-object v0
return-object v0
.end method\
'''
smali.method_replace(specifier, new_body)
ccglobal.log('去除手机管家中的安全事件')
smali = apk.find_smali('MainWithMenuFragment.kt', '"com.coloros.securityguard"', package='com/oplus/phonemanager').pop()
specifier = MethodSpecifier()
specifier.access = MethodSpecifier.Access.PRIVATE
specifier.is_final = True
specifier.parameters = 'Landroid/content/Context;Landroid/view/Menu;'
specifier.return_type = 'V'
specifier.keywords.add('"com.coloros.securityguard"')
old_body = smali.find_method(specifier)
pattern = r'''
new-instance [v|p]\d+, Landroid/content/Intent;
(?:.|\n)*?
invoke-direct {[v|p]\d+}, Landroid/content/Intent;-><init>\(\)V
(?:.|\n)*?
const-string [v|p]\d+, "coloros\.intent\.action\.SECURITY_GUARD"
(?:.|\n)*?
( const [v|p]\d+, .+
(?:.|\n)*?
invoke-interface {[v|p]\d+, [v|p]\d+}, Landroid/view/Menu;->removeItem\(I\)V)
'''
repl = r'''
\g<1>
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
ccglobal.log('禁用应用安装监控')
smali = apk.open_smali('com/oplus/phonemanager/virusdetect/receiver/RealTimeMonitorReceiver.smali')
specifier = MethodSpecifier()
specifier.name = 'onReceive'
specifier.parameters = 'Landroid/content/Context;Landroid/content/Intent;'
smali.method_return_null(specifier)
ccglobal.log('病毒扫描永远安全')
smali = apk.find_smali('"InfectedAppDao_Impl.java"', '"select * from infected_app"').pop()
specifier = MethodSpecifier()
specifier.access = MethodSpecifier.Access.PUBLIC
specifier.parameters = 'Ljava/util/List;'
specifier.return_type = 'V'
specifier.keywords.add('"Lcom/oplus/phonemanager/virusdetect/database/entity/InfectedApp;"')
specifier.keywords.add('->insert(Ljava/lang/Iterable;)V')
smali.method_nop(specifier)
apk.build()
def patch_tele_service():
apk = ApkFile('system_ext/priv-app/TeleService/TeleService.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('显示首选网络类型设置')
smali = apk.find_smali('"SIMS_OplusSimInfoActivity"', '"changeNetworkModeConfig type:"', package='com/android/simsettings/activity').pop()
specifier = MethodSpecifier()
specifier.access = MethodSpecifier.Access.PUBLIC
specifier.parameters = 'ILjava/lang/String;Z'
specifier.return_type = 'V'
specifier.keywords.add('"changeNetworkModeConfig type:"')
insert = '''\
const/4 v0, 0x1
if-ne p1, v0, :jump
const/4 p3, 0x1
:jump
'''
smali.method_insert_before(specifier, insert)
ccglobal.log('去除移动网络中的流量卡广告')
smali = apk.find_smali('"SIMS_TrafficCardUtils"', '"clearHighDataSimCardConfiguration"').pop()
specifier = MethodSpecifier()
specifier.name = 'run'
specifier.parameters = ''
old_body = smali.find_method(specifier)
pattern = r'''
sget-object [v|p]\d+, Lcom/android/phone/ConfigurationConstants;->INSTANCE:Lcom/android/phone/ConfigurationConstants;
invoke-virtual {[v|p]\d+}, Lcom/android/phone/ConfigurationConstants;->getTRAFFIC_CARD_PACKAGE_NAME\(\)Ljava/lang/String;
move-result-object [v|p]\d+
const-string [v|p]\d+, "basewallet_traffic_card_support"
const-string [v|p]\d+, "true"
invoke-static {(?:[v|p]\d+, ){3}[v|p]\d+}, Lcom/android/phone/oplus/share/\S+;->\S+\(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;\)Z
move-result ([v|p]\d+)
'''
repl = '''
const/4 \\g<1>, 0x0
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
apk.build()
def remove_traffic_monitor_ads():
apk = ApkFile('system_ext/priv-app/TrafficMonitor/TrafficMonitor.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('去除流量管理中的流量卡广告')
smali = apk.find_smali('"datausage_TrafficCardController"', '"updateHighDataSimCardConfiguration"').pop()
specifier = MethodSpecifier()
specifier.access = MethodSpecifier.Access.PUBLIC
specifier.is_final = True
specifier.parameters = 'Landroid/content/Context;I'
specifier.return_type = 'V'
specifier.keywords.add('"updateHighDataSimCardConfiguration"')
old_body = smali.find_method(specifier)
pattern = r'''
const-string [v|p]\d+, "basewallet_traffic_card_support"
const-string [v|p]\d+, "true"
invoke-static {p1(?:, [v|p]\d+){3}}, L\S+;->\S+\(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;\)Z
move-result ([v|p]\d+)
'''
repl = '''
const/4 \\g<1>, 0x0
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
smali = apk.find_smali('"datausage_SysFeatureUtils"').pop()
specifier = MethodSpecifier()
specifier.access = MethodSpecifier.Access.PUBLIC
specifier.is_final = True
specifier.parameters = ''
specifier.return_type = 'Ljava/lang/String;'
for keyword in ('"com.oplus.trafficmonitor.wallet_uri"', '"com.oplus.trafficmonitor.wallet_H5_uri"'):
specifier.keywords.clear()
specifier.keywords.add(keyword)
smali.method_return_null(specifier)
apk.build()
def show_icon_for_silent_notification():
apk = ApkFile('system_ext/app/NotificationCenter/NotificationCenter.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('允许显示静默通知的图标')
smali = apk.open_smali('com/oplus/notificationmanager/fragments/main/MoreSettingFragment.smali')
specifier = MethodSpecifier()
specifier.name = 'onCreateView'
specifier.parameters = 'Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Landroid/os/Bundle;'
old_body = smali.find_method(specifier)
pattern = '''\
const-string [v|p]\\d+, "hide_silence_notification_icon_enable"
invoke-static {}, Lcom/oplus/notificationmanager/config/BaseFeatureOption;->isExpVersion\\(\\)Z
move-result [v|p]\\d+
invoke-static {(?:[v|p]\\d+, ){3}[v|p]\\d+}, Lcom/oplus/notificationmanager/view/PerferenceExKt;->\
initPreference\\(Landroidx/preference/PreferenceFragmentCompat;Ljava/lang/String;Ljava/lang/Class;Z\\)Landroidx/preference/Preference;
'''
new_body = re.sub(pattern, '', old_body)
smali.method_replace(old_body, new_body)
apk.build()
def remove_system_notification_ads():
apk = ApkFile('my_stock/app/MCS/MCS.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('去除系统通知广告')
smali = apk.find_smali('"excellent recommendation"', r'"\u7cbe\u5f69\u63a8\u8350"').pop()
specifier = MethodSpecifier()
specifier.is_static = True
specifier.parameters = 'Landroid/content/Context;Z'
specifier.keywords.add('"excellent recommendation"')
specifier.keywords.add(r'"\u7cbe\u5f69\u63a8\u8350"')
smali.method_nop(specifier)
apk.build()
def remove_mms_ads():
apk = ApkFile('my_stock/priv-app/Mms/Mms.apk')
if apk.not_need_modify():
return
apk.decode()
apk.add_smali(f'{ccglobal.MISC_DIR}/smali/Mms.smali', 'com/meolunr/colorcleaner/CcInjector.smali')
ccglobal.log('去除短信输入框广告')
smali = apk.open_smali('com/oplus/mms/ted/smart/NumberInfoViewModel.smali')
specifier = MethodSpecifier()
specifier.access = MethodSpecifier.Access.PUBLIC
specifier.parameters = ''
specifier.return_type = 'V'
specifier.keywords.add('"NumberInfoViewModel"')
specifier.keywords.add('"startLoadMenus:start "')
smali.method_nop(specifier)
ccglobal.log('去除短信下方广告')
smali = apk.find_smali('"SmsEntityUtil.kt"').pop()
specifier = MethodSpecifier()
specifier.Access = MethodSpecifier.Access.PRIVATE
specifier.is_static = True
specifier.is_final = True
specifier.parameters = 'Lorg/json/JSONObject;'
specifier.return_type = 'Lkotlin/Pair;'
old_body = smali.find_method(specifier)
pattern = r'''
( invoke-virtual {p0, [v|p]\d+}, Lorg/json/JSONArray;->getJSONObject\(I\)Lorg/json/JSONObject;
(?:.|\n)*?
move-result-object ([v|p]\d+))
((?:.|\n)*?
const-string ([v|p]\d+), "channel"
(?:.|\n)*?
(:cond_\d+)
:goto_\d+
add-int/lit8 [v|p]\d+, [v|p]\d+, 0x1)
'''
repl = r'''
\g<1>
invoke-static {\g<2>}, Lcom/meolunr/colorcleaner/CcInjector;->shouldFilterButton(Lorg/json/JSONObject;)Z
move-result \g<4>
if-nez \g<4>, \g<5>
\g<3>
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
apk.build()
def remove_calendar_ads():
apk = ApkFile('my_stock/app/Calendar/Calendar.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('去除日历广告')
smali = apk.open_smali('com/android/calendar/module/subscription/almanac/adapter/AlmanacPagesAdapter.smali')
specifier = MethodSpecifier()
specifier.name = 'getItemViewType'
specifier.parameters = 'I'
new_body = '''\
.method public getItemViewType(I)I
.locals 0
invoke-super {p0, p1}, Landroidx/recyclerview/widget/RecyclerView$Adapter;->getItemViewType(I)I
move-result p0
return p0
.end method
'''
smali.method_replace(specifier, new_body)
smali = apk.open_smali('com/coloros/calendar/app/cloudconfig/CloudOperate.smali')
specifier = MethodSpecifier()
specifier.name = 'loadUnSupportAdPhoneConfig'
specifier.parameters = ''
smali.method_nop(specifier)
smali = apk.open_smali('com/coloros/calendar/app/cloudconfig/utils/UnSupportAdPhoneHelp.smali')
specifier = MethodSpecifier()
specifier.name = 'isUnsupportedPhone'
specifier.parameters = 'Ljava/lang/String;'
smali.method_return_boolean(specifier, True)
apk.build()
def patch_weather():
apk = ApkFile('my_stock/app/OppoWeather2/OppoWeather2.apk')
if apk.not_need_modify():
return
apk.decode()
ccglobal.log('去除天气广告')
smali = apk.open_smali('com/oplus/weather/uiconfig/UIConfigManager.smali')
specifier = MethodSpecifier()
specifier.name = 'getHotRecommendSwitch'
specifier.parameters = 'Landroid/content/Context;'
smali.method_return_boolean(specifier, False)
specifier = MethodSpecifier()
specifier.name = 'getWonderfulRecommendSwitch'
specifier.parameters = 'Landroid/content/Context;'
smali.method_return_boolean(specifier, False)
ccglobal.log('禁用未来 15 日天气展开')
specifier = MethodSpecifier()
specifier.name = 'isAllow15DayExpand'
specifier.parameters = 'Lcom/oplus/weather/main/model/WeatherWrapper;'
smali.method_return_boolean(specifier, False)
ccglobal.log('逐小时天气跳转折线图')
smali = apk.open_smali('com/oplus/weather/main/view/itemview/HourlyChildWeatherItem.smali')
specifier = MethodSpecifier()
specifier.name = 'onHourlyItemClick'
specifier.parameters = 'Landroid/view/View;'
old_body = smali.find_method(specifier)
pattern = r'''
iget-wide ([v|p]\d+), p0, Lcom/oplus/weather/main/view/itemview/HourlyChildWeatherItem;->time:J
'''
repl = r'''
const-wide/16 \g<1>, -0x1
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
ccglobal.log('未来 15 日天气跳转折线图')
smali = apk.open_smali('com/oplus/weather/main/view/itemview/FutureDayWeatherChildItem.smali')
specifier = MethodSpecifier()
specifier.name = 'onFutureDayClicked'
specifier.parameters = 'Landroid/view/View;'
old_body = smali.find_method(specifier)
pattern = '''
iget ([v|p]\\d+), p0, Lcom/oplus/weather/main/view/itemview/FutureDayWeatherChildItem;->weatherIndex:I
(?!if-ltz \\1)\
'''
repl = r'''
const/4 \g<1>, 0x0
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
smali = apk.open_smali('com/oplus/weather/main/view/itemview/FutureDayWeatherItemCreator.smali')
specifier = MethodSpecifier()
specifier.name = 'parseFutureData'
specifier.parameters = 'Landroid/content/Context;Lcom/oplus/weather/main/model/WeatherWrapper;Z'
old_body = smali.find_method(specifier)
pattern = r'''
invoke-virtual {([v|p]\d+)}, Lcom/oplus/weather/service/provider/model/WeatherInfoModel;->getMDailyDetailsAdLink\(\)Ljava/lang/String;
'''
repl = r'''
invoke-virtual {\g<1>}, Lcom/oplus/weather/service/provider/model/WeatherInfoModel;->getMFutureFifteenAdLink()Ljava/lang/String;
'''
new_body = re.sub(pattern, repl, old_body)
smali.method_replace(old_body, new_body)
ccglobal.log('禁用天气详情跳转浏览器')
start_web_activity_code = '''
const/4 v0, 0x1
const-string v1, ""
invoke-static {{{context}, {url}, v0, v1, v0}}, Lcom/oplus/weather/plugin/webview/BrowserCommonUtils;->startWeatherWebActivity(Landroid/content/Context;Ljava/lang/String;ZLjava/lang/String;Z)V\
'''
smali = apk.open_smali('com/oplus/weather/utils/SecondaryPageUtil.smali')
specifier = MethodSpecifier()
specifier.name = 'startJumpToBrowser'
specifier.parameters = 'Landroid/content/Context;Ljava/lang/String;Z'
new_body = f'''\
.method public static final startJumpToBrowser(Landroid/content/Context;Ljava/lang/String;Z)V
.locals 2
{start_web_activity_code.format(context='p0', url='p1')}
return-void
.end method
'''
smali.method_replace(specifier, new_body)
specifier = MethodSpecifier()
specifier.name = 'startJumpToBrowser'
specifier.parameters = 'Landroid/content/Context;Ljava/lang/String;ZZZZZLjava/lang/Integer;Ljava/lang/String;Lkotlin/jvm/functions/Function0;'
new_body = f'''\
.method public static final startJumpToBrowser(Landroid/content/Context;Ljava/lang/String;ZZZZZLjava/lang/Integer;Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
.locals 2
{start_web_activity_code.format(context='p0', url='p1')}
invoke-interface/range {{p9 .. p9}}, Lkotlin/jvm/functions/Function0;->invoke()Ljava/lang/Object;
return-void
.end method
'''
smali.method_replace(specifier, new_body)
smali = apk.open_smali('com/oplus/weather/utils/LocalUtils.smali')
specifier = MethodSpecifier()
specifier.name = 'startBrowserForUrl'
specifier.parameters = 'ILandroid/content/Context;Ljava/lang/String;Ljava/lang/String;ZZZZ'
new_body = f'''\
.method public static startBrowserForUrl(ILandroid/content/Context;Ljava/lang/String;Ljava/lang/String;ZZZZ)V
.locals 2
{start_web_activity_code.format(context='p1', url='p2')}
return-void