-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsamsung_enhanced.py
More file actions
275 lines (240 loc) · 10.5 KB
/
Copy pathsamsung_enhanced.py
File metadata and controls
275 lines (240 loc) · 10.5 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
"""
أقصى ما يمكن محاكاته على AOSP/Google APIs عبر setprop / settings:
تقليد طبقات product / vendor / system / csc / samsung كما على أجهزة حقيقية قدر الإمكان.
لا يضيف نواة Samsung أو One UI — فقط ما يقبله النظام بعد adb root عادة.
"""
from __future__ import annotations
import re
from typing import Any, Dict, List, Optional
def is_samsung_fingerprint(fp: Dict[str, Any]) -> bool:
m = (fp.get("manufacturer") or "").lower()
b = (fp.get("brand") or "").lower()
return m == "samsung" or b == "samsung"
def samsung_apply_user_notes(is_samsung: bool) -> tuple[Optional[str], Optional[str]]:
"""
نصوص لاستجابة تطبيق البصمة: توضيح أن رفض جزء من setprop على AVD متوقع وليس فشلاً.
يعيد (note_قصيرة, detail_أطول).
"""
if not is_samsung:
return None, None
return (
"على محاكي Google AVD يُرفض غالباً نصف خصائص Samsung الإضافية أو أكثر — سلوك متوقع، ليس عطلاً.",
(
"صورة النظام هي AOSP / Google APIs وليست روم One UI؛ طبقات vendor/samsung الحقيقية غير موجودة، "
"فلا يمكن للنظام قبول كل مفتاح. ما نجح يحدّث البصمة وحقول Build ويكفي لكثير من التطبيقات. "
"قائمة الرفض: report.failed. لتمويه أعمق: Frida أو جهاز فعلي."
),
)
def infer_sales_code_from_csc(csc_version: Optional[str]) -> str:
"""
Extract 3-char CSC sales code from a Samsung CSC version string.
Handles all Samsung model prefixes: G996B, S921B, S928B, A546B, etc.
Examples:
G996BOXMJHZC2 → OXM
S921BXXU3AWF1 → XXU (global)
S928BXXS2AXE2 → XXS (global)
A546BOXM7CXD1 → OXM
"""
if not csc_version or len(csc_version) < 8:
return "OXM"
# Samsung CSC version format: <ModelPrefix><SalesCode><BuildID>
# ModelPrefix is usually 5 chars (e.g. G996B, S921B, S928B, A546B, F926B)
# Then 3-char sales code follows
m = re.match(r"^[A-Z0-9]{5}([A-Z0-9]{3})", csc_version, re.I)
if m:
return m.group(1).upper()
return "OXM"
def merge_profile_defaults_for_apply(fp: Dict[str, Any]) -> Dict[str, Any]:
"""يملأ حقولاً تقنية تُستخدم فقط عند التطبيق (ليست كلها في جدول DB).
Generalized to work with ALL Samsung models (previously only SM-G996B).
"""
out = dict(fp)
model = (out.get("device_model") or "").upper()
if not model.startswith("SM-"):
return out
# Load defaults from DEVICE_PROFILES for any Samsung model
from core.fingerprint.generator import DEVICE_PROFILES
profile = next(
(p for p in DEVICE_PROFILES if p["device_model"].upper() == model),
None,
)
if profile:
for k in (
"security_patch",
"first_api_level",
"soc_model",
"soc_manufacturer",
"cpu_abi_list_spoof",
"build_version_codename",
):
if out.get(k) is None and profile.get(k):
out[k] = profile[k]
return out
def build_extended_samsung_prop_map(fp: Dict[str, Any]) -> Dict[str, str]:
"""
خريطة موسّعة لخصائص Samsung / تقسيمات AOSP الحديثة.
القيم تُستمد من fp؛ أي مفتاح فارغ يُتخطّى لاحقاً.
"""
if not is_samsung_fingerprint(fp):
return {}
model = fp.get("device_model") or ""
manu = (fp.get("manufacturer") or "samsung").lower()
brand = (fp.get("brand") or "samsung").lower()
codename = fp.get("device_codename") or "o1s"
# يطابق شكل البصمة samsung/o1sxeea/o1s على أجهزة S21+ EEA
product_name = "o1sxeea" if codename == "o1s" else f"{codename}xeea"
board = fp.get("board") or "lahaina"
hw = fp.get("hardware") or "qcom"
fingerprint = fp.get("build_fingerprint") or ""
release = str(fp.get("android_version") or "15")
sdk = str(fp.get("sdk_version") or "35")
ap = fp.get("ap_version") or ""
csc = fp.get("csc_version") or ""
serial = fp.get("serial_number") or ""
patch = str(fp.get("security_patch") or "2025-01-01")
first_api = str(fp.get("first_api_level") or "30")
soc = fp.get("soc_model") or "SM8350"
soc_m = fp.get("soc_manufacturer") or "QTI"
sales = infer_sales_code_from_csc(csc)
codename_rel = fp.get("build_version_codename") or "REL"
# بلد من fp إن وُجد
country = (fp.get("country") or "DE").upper()
country_iso2 = country if len(country) == 2 else "DE"
props: Dict[str, str] = {}
def add(k: str, v: Any):
if v is not None and str(v).strip() != "":
props[k] = str(v)
# ——— product (متعدد الأقسام كما على أجهزة حقيقية) ———
add("ro.product.model", model)
add("ro.product.brand", brand)
add("ro.product.manufacturer", manu)
add("ro.product.device", codename)
add("ro.product.name", product_name)
add("ro.product.board", board)
for partition in ("system", "system_ext", "vendor", "odm", "product"):
add(f"ro.product.{partition}.model", model)
add(f"ro.product.{partition}.brand", brand)
add(f"ro.product.{partition}.manufacturer", manu)
add(f"ro.product.{partition}.device", codename)
add(f"ro.product.{partition}.name", product_name)
add("ro.product.cpu.abi", "arm64-v8a")
abilist = fp.get("cpu_abi_list_spoof")
if abilist:
add("ro.product.cpu.abilist", abilist)
add("ro.product.cpu.abilist32", "armeabi-v7a,armeabi")
add("ro.product.cpu.abilist64", "arm64-v8a")
add("ro.vendor.product.cpu.abilist", abilist)
add("ro.kernel.qemu", "0")
add("ro.hardware", hw)
add("ro.soc.model", soc)
add("ro.soc.manufacturer", soc_m)
add("ro.boot.hardware", hw)
add("ro.boot.hardware.platform", "lahaina")
# ——— build / إصدارات ———
add("ro.build.version.release", release)
add("ro.build.version.sdk", sdk)
add("ro.build.version.release_or_codename", release)
add("ro.build.version.codename", codename_rel)
add("ro.build.version.security_patch", patch)
add("ro.build.version.base_os", "")
add("ro.product.first_api_level", first_api)
add("ro.board.first_api_level", first_api)
add("ro.build.characteristics", "default")
add("ro.treble.enabled", "true")
if fingerprint:
for key in (
"ro.build.fingerprint",
"ro.bootimage.build.fingerprint",
"ro.system.build.fingerprint",
"ro.system_ext.build.fingerprint",
"ro.vendor.build.fingerprint",
"ro.odm.build.fingerprint",
"ro.product.build.fingerprint",
):
add(key, fingerprint)
add("ro.vendor.build.security_patch", patch)
add("ro.system.build.security_patch", patch)
if ap:
add("ro.build.display.id", ap)
add("ro.build.version.incremental", ap)
add("ro.bootloader", ap)
add("ro.build.PDA", ap)
add("ro.build.changelist", ap)
add("gsm.version.baseband", ap)
if csc:
add("ro.csc.version", csc)
add("ro.csc.version_string", csc)
add("ro.omc.version", csc)
if not ap:
add("ro.build.changelist", csc)
if serial:
add("ro.serialno", serial)
add("ro.boot.serialno", serial)
# ——— CSC / OMC ———
add("ro.csc.sales_code", sales)
add("ro.csc.country_code", country_iso2)
add("ro.csc.countryiso_code", country_iso2)
add("ro.omc.enable", "true")
add("ro.omc.multi_csc", "OXM,EUX,EUY,BTU")
add("ro.config.ringtone", "Galaxy_Bells.ogg")
add("ro.config.notification_sound", "Spaceline.ogg")
# ——— مساحة اسم samsung (تُقرأ من تطبيقات Samsung أحياناً) ———
add("ro.samsung.model", model)
add("ro.samsung.device", codename)
add("ro.samsung.build.version", release)
# ——— Knox / Samsung security layer ———
# These mirror the properties KnoxPatch hooks intercept to restore Knox app functionality
add("knox.supported", "1")
add("knox.fbe.support", "1")
add("knox.kap.support", "1")
add("knox.kdp.support", "1")
add("knox.dp.support", "1")
add("ro.config.knox", "1")
add("ro.config.tima", "1")
add("ro.config.dm-verity", "false")
add("ro.securestorage.support", "true")
add("ro.hardware.keystore", "samsung")
add("ro.hardware.keystore_desede", "samsung")
add("ro.boot.warranty_bit", "0") # 0 = warranty intact
add("ro.warranty_bit", "0")
add("ro.boot.flash.locked", "1") # bootloader locked = 1
add("ro.boot.veritymode", "enforcing")
# Knox version strings (Samsung Knox 3.x on Android 13+, 4.x on Android 14+)
_knox_ver = "3.9" if int(release.split(".")[0]) <= 13 else "4.2"
add("ro.knox.version", _knox_ver)
add("ro.knox.knoxSDKVersion", _knox_ver)
add("ro.knox.baps.enrolled", "false")
add("ro.knox.baps.afw_enabled", "false")
# Samsung keystore TEE
add("ro.crypto.type", "file")
add("ro.crypto.state", "encrypted")
add("ro.crypto.uses_ext4_encryption", "true")
# Samsung Health / sensors (checked by Samsung Health app)
add("ro.hardware.sensors", "samsung")
add("ro.sensor.accel", "1")
add("ro.sensor.gyro", "1")
add("ro.sensor.hr", "0") # heart rate sensor — not on all models
# Samsung DEX
add("ro.samsung.dex.mode", "standalone")
add("sys.samsung.dex.enable", "1")
# Misc Samsung flags checked by various Samsung apps
add("ro.multisim.set_msin_back", "false")
add("ro.sf.lcd_density", sdk[:3] if len(sdk) >= 3 else "420")
add("persist.sys.samsung.emergencymode", "0")
# GPU (may be rejected on x86 AVD — harmless)
add("ro.hardware.egl", "adreno")
add("ro.opengles.version", "196610")
return props
def samsung_surface_settings_commands(fp: Dict[str, Any]) -> List[str]:
"""
أوامر shell لـ settings put — آمنة نسبياً لتحسين «مظهر» الجهاز بعد الإعداد.
"""
if not is_samsung_fingerprint(fp):
return []
model = fp.get("device_model") or "Samsung device"
return [
"settings put global device_provisioned 1",
"settings put secure user_setup_complete 1",
f"settings put secure bluetooth_name {model}",
"settings put global stay_on_while_plugged_in 3",
]