Skip to content

Commit fee4d6b

Browse files
feat: sync main branch updates
1 parent b375260 commit fee4d6b

File tree

4 files changed

+81
-11
lines changed

4 files changed

+81
-11
lines changed

cmdline.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
File autogenerated by gengetopt version 2.23
33
generated with the following command:
4-
gengetopt -i wrapper.ggo
4+
gengetopt
55
66
The developers of gengetopt consider the fixed text that goes in all
77
gengetopt output files to be in the public domain:
@@ -42,6 +42,7 @@ const char *gengetopt_args_info_help[] = {
4242
" -P, --proxy=STRING (default=`')",
4343
" -L, --login=STRING username:password",
4444
" -F, --code-from-file (default=off)",
45+
" -B, --base-dir=STRING \n (default=`/data/data/com.apple.android.music/files')",
4546
0
4647
};
4748

@@ -75,6 +76,7 @@ void clear_given (struct gengetopt_args_info *args_info)
7576
args_info->proxy_given = 0 ;
7677
args_info->login_given = 0 ;
7778
args_info->code_from_file_given = 0 ;
79+
args_info->base_dir_given = 0 ;
7880
}
7981

8082
static
@@ -92,6 +94,8 @@ void clear_args (struct gengetopt_args_info *args_info)
9294
args_info->login_arg = NULL;
9395
args_info->login_orig = NULL;
9496
args_info->code_from_file_flag = 0;
97+
args_info->base_dir_arg = gengetopt_strdup ("/data/data/com.apple.android.music/files");
98+
args_info->base_dir_orig = NULL;
9599

96100
}
97101

@@ -108,6 +112,7 @@ void init_args_info(struct gengetopt_args_info *args_info)
108112
args_info->proxy_help = gengetopt_args_info_help[5] ;
109113
args_info->login_help = gengetopt_args_info_help[6] ;
110114
args_info->code_from_file_help = gengetopt_args_info_help[7] ;
115+
args_info->base_dir_help = gengetopt_args_info_help[8] ;
111116

112117
}
113118

@@ -205,6 +210,8 @@ cmdline_parser_release (struct gengetopt_args_info *args_info)
205210
free_string_field (&(args_info->proxy_orig));
206211
free_string_field (&(args_info->login_arg));
207212
free_string_field (&(args_info->login_orig));
213+
free_string_field (&(args_info->base_dir_arg));
214+
free_string_field (&(args_info->base_dir_orig));
208215

209216

210217

@@ -251,6 +258,8 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
251258
write_into_file(outfile, "login", args_info->login_orig, 0);
252259
if (args_info->code_from_file_given)
253260
write_into_file(outfile, "code-from-file", 0, 0 );
261+
if (args_info->base_dir_given)
262+
write_into_file(outfile, "base-dir", args_info->base_dir_orig, 0);
254263

255264

256265
i = EXIT_SUCCESS;
@@ -519,10 +528,11 @@ cmdline_parser_internal (
519528
{ "proxy", 1, NULL, 'P' },
520529
{ "login", 1, NULL, 'L' },
521530
{ "code-from-file", 0, NULL, 'F' },
531+
{ "base-dir", 1, NULL, 'B' },
522532
{ 0, 0, 0, 0 }
523533
};
524534

525-
c = getopt_long (argc, argv, "hVH:D:M:P:L:F", long_options, &option_index);
535+
c = getopt_long (argc, argv, "hVH:D:M:P:L:FB:", long_options, &option_index);
526536

527537
if (c == -1) break; /* Exit from `while (1)' loop. */
528538

@@ -608,6 +618,18 @@ cmdline_parser_internal (
608618
goto failure;
609619

610620
break;
621+
case 'B': /* . */
622+
623+
624+
if (update_arg( (void *)&(args_info->base_dir_arg),
625+
&(args_info->base_dir_orig), &(args_info->base_dir_given),
626+
&(local_args_info.base_dir_given), optarg, 0, "/data/data/com.apple.android.music/files", ARG_STRING,
627+
check_ambiguity, override, 0, 0,
628+
"base-dir", 'B',
629+
additional_error))
630+
goto failure;
631+
632+
break;
611633

612634
case 0: /* Long option with no short option */
613635
case '?': /* Invalid option. */

cmdline.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct gengetopt_args_info
5656
const char *login_help; /**< @brief username:password help description. */
5757
int code_from_file_flag; /**< @brief (default=off). */
5858
const char *code_from_file_help; /**< @brief help description. */
59+
char * base_dir_arg; /**< @brief (default='/data/data/com.apple.android.music/files'). */
60+
char * base_dir_orig; /**< @brief original value given at command line. */
61+
const char *base_dir_help; /**< @brief help description. */
5962

6063
unsigned int help_given ; /**< @brief Whether help was given. */
6164
unsigned int version_given ; /**< @brief Whether version was given. */
@@ -65,6 +68,7 @@ struct gengetopt_args_info
6568
unsigned int proxy_given ; /**< @brief Whether proxy was given. */
6669
unsigned int login_given ; /**< @brief Whether login was given. */
6770
unsigned int code_from_file_given ; /**< @brief Whether code-from-file was given. */
71+
unsigned int base_dir_given ; /**< @brief Whether base-dir was given. */
6872

6973
} ;
7074

main.c

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ int file_exists(char *filename) {
2828
return (stat (filename, &buffer) == 0);
2929
}
3030

31+
char *strcat_b(char *dest, char* src) {
32+
size_t len1 = strlen(dest);
33+
size_t len2 = strlen(src);
34+
35+
char *result = malloc(len1 + len2 + 1);
36+
if (!result) return NULL;
37+
38+
strcpy(result, dest);
39+
strcat(result, src);
40+
41+
return result;
42+
}
43+
3144
static void dialogHandler(long j, struct shared_ptr *protoDialogPtr,
3245
struct shared_ptr *respHandler) {
3346
const char *const title = std_string_data(
@@ -147,12 +160,11 @@ static inline void init() {
147160
fprintf(stderr, "[+] starting...\n");
148161
setenv("ANDROID_DNS_MODE", "local", 1);
149162
if (args_info.proxy_given) {
150-
fprintf(stderr, "[+] Using proxy %s", args_info.proxy_arg);
151-
setenv("http_proxy", args_info.proxy_arg, 1);
152-
setenv("https_proxy", args_info.proxy_arg, 1);
163+
fprintf(stderr, "[+] Using proxy %s\n", args_info.proxy_arg);
164+
setenv("all_proxy", args_info.proxy_arg, 1);
153165
}
154166

155-
static const char *resolvers[2] = {"1.1.1.1", "1.0.0.1"};
167+
static const char *resolvers[2] = {"223.5.5.5", "223.6.6.6"};
156168
_resolv_set_nameservers_for_net(0, resolvers, 2, ".");
157169
#ifndef MyRelease
158170
subhook_install(subhook_new(
@@ -189,15 +201,15 @@ static inline void init() {
189201
static inline struct shared_ptr init_ctx() {
190202
fprintf(stderr, "[+] initializing ctx...\n");
191203

192-
struct shared_ptr *reqCtx = newRequestContext("/data/data/com.apple.android.music/files/mpl_db");
204+
struct shared_ptr *reqCtx = newRequestContext(strcat_b(args_info.base_dir_arg, "/mpl_db"));
193205
struct shared_ptr *reqCtxCfg = getRequestContextConfig();
194206

195207
prepareRequestContextConfig(reqCtxCfg);
196208
configureRequestContext(reqCtx);
197209

198210
static uint8_t buf[88];
199211
initRequestContext(buf, reqCtx, reqCtxCfg);
200-
setFairPlayDirectoryPath(reqCtx, "/data/data/com.apple.android.music/files");
212+
setFairPlayDirectoryPath(reqCtx, args_info.base_dir_arg);
201213
initPresentationInterface(&apInf, &dialogHandler, &credentialHandler);
202214
setPresentationInterface(reqCtx, &apInf);
203215

@@ -209,6 +221,12 @@ extern void *pbErrCallback;
209221

210222
inline static uint8_t login(struct shared_ptr reqCtx) {
211223
fprintf(stderr, "[+] logging in...\n");
224+
if (file_exists(strcat_b(args_info.base_dir_arg, "/STOREFRONT_ID"))) {
225+
remove(strcat_b(args_info.base_dir_arg, "/STOREFRONT_ID"));
226+
}
227+
if (file_exists(strcat_b(args_info.base_dir_arg, "/MUSIC_TOKEN"))) {
228+
remove(strcat_b(args_info.base_dir_arg, "/MUSIC_TOKEN"));
229+
}
212230
struct shared_ptr flow;
213231
_ZNSt6__ndk110shared_ptrIN17storeservicescore16AuthenticateFlowEE11make_sharedIJRNS0_INS1_14RequestContextEEEEEES3_DpOT_ASM(
214232
&flow, &reqCtx);
@@ -421,13 +439,38 @@ const char* get_m3u8_method_play(uint8_t leaseMgr[16], unsigned long adam) {
421439
_ZN22SVPlaybackLeaseManager12requestAssetERKmRKNSt6__ndk16vectorINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS7_IS9_EEEERKbASM(
422440
&ptr_result, leaseMgr, &adam, &HLSParam, &z0
423441
);
442+
443+
if (ptr_result.obj == NULL) {
444+
return NULL;
445+
}
446+
424447
if (_ZNK23SVPlaybackAssetResponse13hasValidAssetEv(ptr_result.obj)) {
425448
struct shared_ptr *playbackAsset = _ZNK23SVPlaybackAssetResponse13playbackAssetEv(ptr_result.obj);
426-
union std_string *m3u8 = malloc(24);
449+
if (playbackAsset == NULL || playbackAsset->obj == NULL) {
450+
return NULL;
451+
}
452+
453+
union std_string *m3u8 = malloc(sizeof(union std_string));
454+
if (m3u8 == NULL) {
455+
return NULL;
456+
}
457+
427458
void *playbackObj = playbackAsset->obj;
428459
_ZNK17storeservicescore13PlaybackAsset9URLStringEvASM(m3u8, playbackObj);
460+
461+
if (m3u8 == NULL || std_string_data(m3u8) == NULL) {
462+
free(m3u8);
463+
return NULL;
464+
}
465+
429466
const char *m3u8_str = std_string_data(m3u8);
430-
return m3u8_str;
467+
if (m3u8_str) {
468+
char *result = strdup(m3u8_str); // Make a copy
469+
free(m3u8);
470+
return result;
471+
} else {
472+
return NULL;
473+
}
431474
} else {
432475
return NULL;
433476
}

wrapper.ggo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ option "decrypt-port" D "" int optional default="10020"
66
option "m3u8-port" M "" int optional default="20020"
77
option "proxy" P "" string optional default=""
88
option "login" L "username:password" string optional
9-
option "code-from-file" F "" flag off
9+
option "code-from-file" F "" flag off
10+
option "base-dir" B "" string optional default="/data/data/com.apple.android.music/files"

0 commit comments

Comments
 (0)