Skip to content

Commit dc6d0bb

Browse files
committed
Add back in -Hsha1 and -Hsha256 and binary names
1 parent 507461b commit dc6d0bb

1 file changed

Lines changed: 55 additions & 3 deletions

File tree

ldid.cpp

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ Type_ Align(Type_ value, size_t align) {
527527
static const uint8_t PageShift_(0x0c);
528528
static const uint32_t PageSize_(1 << PageShift_);
529529

530+
static bool do_sha1(true);
531+
static bool do_sha2(true);
532+
530533
static inline uint16_t Swap_(uint16_t value) {
531534
return
532535
((value >> 8) & 0x00ff) |
@@ -940,12 +943,32 @@ static const std::vector<Algorithm *> &GetAlgorithms() {
940943
static AlgorithmSHA1 sha1;
941944
static AlgorithmSHA256 sha256;
942945

943-
static Algorithm *array[] = {
946+
static Algorithm *array1[] = {
947+
&sha1,
948+
};
949+
950+
static Algorithm *array2[] = {
951+
&sha256,
952+
};
953+
954+
static Algorithm *array3[] = {
944955
&sha1,
945956
&sha256,
946957
};
947958

948-
static std::vector<Algorithm *> algorithms(array, array + sizeof(array) / sizeof(array[0]));
959+
static std::vector<Algorithm *> algorithms;
960+
961+
if (do_sha1 && do_sha2) {
962+
fprintf(stderr, "doing both\n");
963+
algorithms = std::vector<Algorithm *>(array3, array3 + sizeof(array3) / sizeof(array3[0]));
964+
} else if (do_sha1) {
965+
algorithms = std::vector<Algorithm *>(array1, array1 + sizeof(array1) / sizeof(array1[0]));
966+
fprintf(stderr, "doing sha1\n");
967+
} else {
968+
algorithms = std::vector<Algorithm *>(array2, array2 + sizeof(array2) / sizeof(array2[0]));
969+
fprintf(stderr, "doing sha2\n");
970+
}
971+
949972
return algorithms;
950973
}
951974

@@ -2459,6 +2482,8 @@ int main(int argc, char *argv[]) {
24592482
bool flag_e(false);
24602483
bool flag_q(false);
24612484

2485+
bool flag_H(false);
2486+
24622487
#ifndef LDID_NOFLAGT
24632488
bool flag_T(false);
24642489
#endif
@@ -2491,13 +2516,25 @@ int main(int argc, char *argv[]) {
24912516
std::vector<std::string> files;
24922517

24932518
if (argc == 1) {
2494-
fprintf(stderr, "usage: %s -S[entitlements.xml] <binary>\n", argv[0]);
2519+
fprintf(stderr, "usage: %s [-Hsha1] [-Hsha256] -S[entitlements.xml] <binary>\n", argv[0]);
24952520
fprintf(stderr, " %s -e MobileSafari\n", argv[0]);
24962521
fprintf(stderr, " %s -S cat\n", argv[0]);
24972522
fprintf(stderr, " %s -Stfp.xml gdb\n", argv[0]);
24982523
exit(0);
24992524
}
25002525

2526+
// Support setting default based on the ldid binary's name
2527+
if (strstr(argv[0], "ldid1")) {
2528+
do_sha1 = true;
2529+
do_sha2 = false;
2530+
} else if (strstr(argv[0], "ldid2")) {
2531+
do_sha1 = false;
2532+
do_sha2 = true;
2533+
} else if (strstr(argv[0], "ldid3")) {
2534+
do_sha1 = do_sha2 = true;
2535+
}
2536+
2537+
25012538
for (int argi(1); argi != argc; ++argi)
25022539
if (argv[argi][0] != '-')
25032540
files.push_back(argv[argi]);
@@ -2570,6 +2607,21 @@ int main(int argc, char *argv[]) {
25702607
key.open(argv[argi] + 2, O_RDONLY, PROT_READ, MAP_PRIVATE);
25712608
break;
25722609

2610+
case 'H':
2611+
if (!flag_H) {
2612+
do_sha1 = do_sha2 = false;
2613+
}
2614+
flag_H = true;
2615+
if (strcmp(argv[argi], "-Hsha1") == 0) {
2616+
do_sha1 = true;
2617+
} else if (strcmp(argv[argi], "-Hsha256") == 0) {
2618+
do_sha2 = true;
2619+
} else {
2620+
fprintf(stderr, "Error: -H requires sha1 or sha256 argument\n");
2621+
_assert(false);
2622+
}
2623+
break;
2624+
25732625
#ifndef LDID_NOFLAGT
25742626
case 'T': {
25752627
flag_T = true;

0 commit comments

Comments
 (0)