forked from jean-voila/FeurStagram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply_network_patch.py
More file actions
executable file
·90 lines (67 loc) · 2.76 KB
/
apply_network_patch.py
File metadata and controls
executable file
·90 lines (67 loc) · 2.76 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
#!/usr/bin/env python3
"""
Apply network blocking patch to TigonServiceLayer.
This script patches Instagram's network layer to call our InstaFreeHooks.throwIfBlocked()
method before each request, allowing us to block unwanted content.
"""
import sys
import re
def patch_tigon_service_layer(filepath):
with open(filepath, 'r') as f:
content = f.read()
# Check if already patched
if 'InstaFreeHooks' in content:
print(f" Already patched: {filepath}")
return True
# Find the pattern where URI is extracted from the request object
# Pattern: iget-object vX, pY, LX/XXX;->AXX:Ljava/net/URI;
# This is where the request URI is loaded before being used
pattern = r'(iget-object\s+(v\d+),\s+p\d+,\s+LX/[^;]+;->[^:]+:Ljava/net/URI;\s*\n)'
matches = list(re.finditer(pattern, content))
if not matches:
print(f" Error: Could not find URI field access pattern in {filepath}")
return False
# We want to patch after the URI is loaded into a register
# Find the one that's inside a try block (likely the main request handling)
patched = False
for match in matches:
# Check if this is near a try_start
start_pos = match.start()
context_before = content[max(0, start_pos - 500):start_pos]
if ':try_start' in context_before:
uri_line = match.group(1)
uri_reg = match.group(2)
# Create the hook call
hook_code = f'''
# InstaFree: Check if this request should be blocked
invoke-static {{{uri_reg}}}, Lcom/instafree/InstaFreeHooks;->throwIfBlocked(Ljava/net/URI;)V
'''
# Insert the hook after the URI load
patched_content = content.replace(uri_line, uri_line + hook_code, 1)
with open(filepath, 'w') as f:
f.write(patched_content)
print(f" Patched: {filepath}")
print(f" Hook inserted after: {uri_line.strip()}")
patched = True
break
if not patched:
# Fallback: patch the first occurrence
match = matches[0]
uri_line = match.group(1)
uri_reg = match.group(2)
hook_code = f'''
# InstaFree: Check if this request should be blocked
invoke-static {{{uri_reg}}}, Lcom/instafree/InstaFreeHooks;->throwIfBlocked(Ljava/net/URI;)V
'''
patched_content = content.replace(uri_line, uri_line + hook_code, 1)
with open(filepath, 'w') as f:
f.write(patched_content)
print(f" Patched (fallback): {filepath}")
patched = True
return patched
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: apply_network_patch.py <TigonServiceLayer.smali>")
sys.exit(1)
if not patch_tigon_service_layer(sys.argv[1]):
sys.exit(1)