Skip to content

Commit

Permalink
v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon8RFC authored Mar 9, 2024
1 parent 9b617e4 commit cbe1432
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def __init__(self, extract_dir, date_id, mod_ver, manufacturer, model, device, r
self.sdk = sdk
self.apk_name = apk_name
self.strategy = strategy

self.smali_dir = None
self.on_unlocked_value = None
self.on_unlocked_value_and12 = None
self.on_unlocked_value_and13 = None

def disassemble(self):
subprocess.run(['./disassemble.sh', self.extract_dir, self.apk_name])
Expand Down Expand Up @@ -71,25 +71,24 @@ def log_stats(self, status='success'):
ts_str = os.path.basename(self.extract_dir)
date_iso = datetime.fromtimestamp(int(ts_str)).isoformat()
smali_dir = None if status == 'fail-disassemble' else os.path.basename(self.smali_dir)
fd.write(f'"{self.date_id}","{self.mod_ver}","{self.manufacturer}","{self.model}","{self.device}","{self.rom}","{self.release}","{self.sdk}","{self.apk_name}","{self.on_unlocked_value}","{smali_dir}","{self.strategy}","{status}","{date_iso}"\n')
on_unlocked_value = self.on_unlocked_value_and12 if self.on_unlocked_value_and12 is not None else self.on_unlocked_value_and13
fd.write(f'"{self.date_id}","{self.mod_ver}","{self.manufacturer}","{self.model}","{self.device}","{self.rom}","{self.release}","{self.sdk}","{self.apk_name}","{on_unlocked_value}","{smali_dir}","{self.strategy}","{status}","{date_iso}"\n')

def patch_ScreenStateHelper(self):

path = f'{self.smali_dir}/com/android/nfc/ScreenStateHelper.smali'
with open(path) as fd:
lines = fd.readlines()

on_unlocked_value = None
insert_index = None
method_start = None
method_end = None

for i, line in enumerate(lines):
if 'SCREEN_STATE_ON_UNLOCKED' in line:
on_unlocked_value = line.strip().split(' ')[-1]
self.on_unlocked_value_and12 = line.strip().split(' ')[-1]
break

if not on_unlocked_value:
if self.on_unlocked_value_and12 is None:
for i, line in enumerate(lines):
if '.method static screenStateToString' in line:
method_start = i
Expand All @@ -101,15 +100,16 @@ def patch_ScreenStateHelper(self):
if 'ON_UNLOCKED' in lines[i]:
for j in range(i - 1, method_start - 1, -1):
if 'const/' in lines[j]:
on_unlocked_value = lines[j].strip().split(' ')[-1]
self.on_unlocked_value_and13 = lines[j].strip().split(' ')[-1]
break

for i, line in enumerate(lines):
if 'checkScreenState' in line:
insert_index = i + 2
if on_unlocked_value:
lines = lines[:insert_index] + [f'const/16 v0, {on_unlocked_value}\n', 'return v0\n'] + lines[insert_index:]
break
if self.on_unlocked_value_and12 is not None:
lines = lines[:insert_index] + [f'const/16 v0, {self.on_unlocked_value_and12}\n', 'return v0\n'] + lines[insert_index:]
elif self.on_unlocked_value_and13 is not None:
lines = lines[:insert_index] + [f'const/16 v0, {self.on_unlocked_value_and13}\n', 'return v0\n'] + lines[insert_index:]

with open(path, 'w') as fd:
fd.writelines(lines)
Expand All @@ -118,20 +118,23 @@ def patch_NfcService(self):
path = f'{self.smali_dir}/com/android/nfc/NfcService.smali'
with open(path) as fd:
lines = fd.readlines()
for i, line in enumerate(lines):
if 'playSound(' in line:
insert_index = i + 2

# these appear to be what breaks the service after some time, and also causes crashes in android 14
#line = line.replace('SCREEN_OFF', 'SCREEN_OFF_DISABLED')
#line = line.replace('SCREEN_ON', 'SCREEN_ON_DISABLED')
#line = line.replace('USER_PRESENT', 'USER_PRESENT_DISABLED')
#line = line.replace('USER_SWITCHED', 'USER_SWITCHED_DISABLED')
#lines[i] = line

# patch sound
if insert_index:
lines = lines[:insert_index] + ['return-void\n'] + lines[insert_index:]

insert_index = None

for i, line in enumerate(lines):
if 'playSound(' in line:
insert_index = i + 2
if self.on_unlocked_value_and12 is not None:
# the below appear to be what break the service after some time in android 13 ~May 2023+, and also cause crashes in android 14
line = line.replace('SCREEN_OFF', 'SCREEN_OFF_DISABLED')
line = line.replace('SCREEN_ON', 'SCREEN_ON_DISABLED')
line = line.replace('USER_PRESENT', 'USER_PRESENT_DISABLED')
line = line.replace('USER_SWITCHED', 'USER_SWITCHED_DISABLED')
lines[i] = line
lines[i] = line
# patch sound
if insert_index:
lines = lines[:insert_index] + ['return-void\n'] + lines[insert_index:]

with open(path, 'w') as fd:
fd.writelines(lines)
Expand Down

0 comments on commit cbe1432

Please sign in to comment.