gabefromsimplebit commited on
Commit
3f46b26
·
verified ·
1 Parent(s): 11c4812

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +28 -34
app.py CHANGED
@@ -15,24 +15,6 @@ BASE_URL = "https://gabefromsimplebit-simplebit-signer.hf.space"
15
  def home():
16
  return "SimpleBit Signer is Online!"
17
 
18
- def get_actual_bundle_id(ipa_path):
19
- """ Extracts the actual Bundle ID from the IPA's Info.plist """
20
- try:
21
- # Use unzip to peek at the Info.plist and grep for the ID
22
- # This is more reliable than parsing zsign logs
23
- cmd = f"unzip -p {ipa_path} Payload/*.app/Info.plist | grep -A1 'CFBundleIdentifier' | grep 'string' | sed 's/<[^>]*>//g' | str.strip()"
24
- # Using a more robust subprocess call for the same logic:
25
- result = subprocess.run(
26
- f"unzip -p {ipa_path} Payload/*.app/Info.plist | grep -A1 'CFBundleIdentifier'",
27
- shell=True, capture_output=True, text=True
28
- )
29
- match = re.search(r"<string>(.*)</string>", result.stdout)
30
- if match:
31
- return match.group(1).strip()
32
- except Exception:
33
- pass
34
- return None
35
-
36
  @app.route('/sign', methods=['POST'])
37
  def sign():
38
  job_id = str(uuid.uuid4())[:8]
@@ -52,10 +34,25 @@ def sign():
52
  p12.save(p12_path)
53
  prov.save(prov_path)
54
 
55
- # STEP 1: Get the REAL Bundle ID first
56
- bundle_id = get_actual_bundle_id(ipa_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- # STEP 2: Sign the app
 
 
59
  command = [
60
  "zsign",
61
  "-k", p12_path,
@@ -67,17 +64,11 @@ def sign():
67
  ]
68
 
69
  try:
70
- result = subprocess.run(command, capture_output=True, text=True, check=True)
71
-
72
- # If extraction failed earlier, try one last time from zsign logs
73
- if not bundle_id:
74
- combined_output = result.stdout + result.stderr
75
- match = re.search(r"Bundle\s?Id:\s+([a-zA-Z0-9\.-]+)", combined_output, re.IGNORECASE)
76
- bundle_id = match.group(1).strip() if match else "com.simplebit.dynamic"
77
 
78
- # Save the confirmed ID for the /plist route
79
- with open(os.path.join(job_id, "bundle_id.txt"), "w") as f:
80
- f.write(bundle_id)
81
 
82
  plist_url = f"{BASE_URL}/plist/{job_id}"
83
  return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
@@ -88,10 +79,13 @@ def sign():
88
  @app.route('/plist/<job_id>')
89
  def serve_plist(job_id):
90
  try:
91
- with open(os.path.join(job_id, "bundle_id.txt"), "r") as f:
92
- bundle_id = f.read().strip()
 
 
93
  except:
94
  bundle_id = "com.simplebit.dynamic"
 
95
 
96
  ipa_direct_url = f"{BASE_URL}/download/{job_id}"
97
 
@@ -120,7 +114,7 @@ def serve_plist(job_id):
120
  <key>kind</key>
121
  <string>software</string>
122
  <key>title</key>
123
- <string>SimpleBit Signed App</string>
124
  </dict>
125
  </dict>
126
  </array>
 
15
  def home():
16
  return "SimpleBit Signer is Online!"
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  @app.route('/sign', methods=['POST'])
19
  def sign():
20
  job_id = str(uuid.uuid4())[:8]
 
34
  p12.save(p12_path)
35
  prov.save(prov_path)
36
 
37
+ # --- Working Extraction Method ---
38
+ # We use the same 'unzip -p' logic to get both ID and Name
39
+ plist_data = subprocess.run(
40
+ f"unzip -p {ipa_path} Payload/*.app/Info.plist",
41
+ shell=True, capture_output=True, text=True
42
+ ).stdout
43
+
44
+ # Extract Bundle ID
45
+ id_match = re.search(r"<key>CFBundleIdentifier</key>\s*<string>(.*?)</string>", plist_data)
46
+ bundle_id = id_match.group(1).strip() if id_match else "com.simplebit.dynamic"
47
+
48
+ # Extract App Name (Checks Display Name first, then falling back to Bundle Name)
49
+ name_match = re.search(r"<key>CFBundleDisplayName</key>\s*<string>(.*?)</string>", plist_data)
50
+ if not name_match:
51
+ name_match = re.search(r"<key>CFBundleName</key>\s*<string>(.*?)</string>", plist_data)
52
 
53
+ app_name = name_match.group(1).strip() if name_match else "Signed App"
54
+
55
+ # Sign the app
56
  command = [
57
  "zsign",
58
  "-k", p12_path,
 
64
  ]
65
 
66
  try:
67
+ subprocess.run(command, capture_output=True, text=True, check=True)
 
 
 
 
 
 
68
 
69
+ # Store metadata for the /plist route
70
+ with open(os.path.join(job_id, "meta.txt"), "w") as f:
71
+ f.write(f"{bundle_id}\n{app_name}")
72
 
73
  plist_url = f"{BASE_URL}/plist/{job_id}"
74
  return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
 
79
  @app.route('/plist/<job_id>')
80
  def serve_plist(job_id):
81
  try:
82
+ with open(os.path.join(job_id, "meta.txt"), "r") as f:
83
+ lines = f.readlines()
84
+ bundle_id = lines[0].strip()
85
+ app_name = lines[1].strip()
86
  except:
87
  bundle_id = "com.simplebit.dynamic"
88
+ app_name = "SimpleBit App"
89
 
90
  ipa_direct_url = f"{BASE_URL}/download/{job_id}"
91
 
 
114
  <key>kind</key>
115
  <string>software</string>
116
  <key>title</key>
117
+ <string>{app_name}</string>
118
  </dict>
119
  </dict>
120
  </array>