]> git.saurik.com Git - ldid.git/commitdiff
Provide compatibility with Sam Bingner's era ldid.
authorJay Freeman (saurik) <saurik@saurik.com>
Tue, 19 Feb 2019 05:25:00 +0000 (21:25 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Tue, 19 Feb 2019 05:25:00 +0000 (21:25 -0800)
ldid.cpp

index 6d03d1b131301b03111aa1ffedf0848fd15e3f0a..30c8b6d9dea00c283378f3ea8548ed1ee922f869 100644 (file)
--- a/ldid.cpp
+++ b/ldid.cpp
@@ -1035,16 +1035,21 @@ struct AlgorithmSHA256 :
     }
 };
 
+static bool do_sha1(true);
+static bool do_sha256(true);
+
 static const std::vector<Algorithm *> &GetAlgorithms() {
     static AlgorithmSHA1 sha1;
     static AlgorithmSHA256 sha256;
 
-    static Algorithm *array[] = {
-        &sha1,
-        &sha256,
-    };
+    static std::vector<Algorithm *> algorithms;
+    if (algorithms.empty()) {
+        if (do_sha1)
+            algorithms.push_back(&sha1);
+        if (do_sha256)
+            algorithms.push_back(&sha256);
+    }
 
-    static std::vector<Algorithm *> algorithms(array, array + sizeof(array) / sizeof(array[0]));
     return algorithms;
 }
 
@@ -2724,6 +2729,8 @@ int main(int argc, char *argv[]) {
     bool flag_e(false);
     bool flag_q(false);
 
+    bool flag_H(false);
+
 #ifndef LDID_NOFLAGT
     bool flag_T(false);
 #endif
@@ -2793,6 +2800,27 @@ int main(int argc, char *argv[]) {
 
             case 'q': flag_q = true; break;
 
+            case 'H': {
+                const char *hash = argv[argi] + 2;
+
+                if (!flag_H) {
+                    flag_H = true;
+
+                    do_sha1 = false;
+                    do_sha256 = false;
+
+                    fprintf(stderr, "WARNING: -H is only present for compatibility with a fork of ldid\n");
+                    fprintf(stderr, "         you should NOT be manually specifying the hash algorithm\n");
+                }
+
+                if (false);
+                else if (strcmp(hash, "sha1") == 0)
+                    do_sha1 = true;
+                else if (strcmp(hash, "sha256") == 0)
+                    do_sha256 = true;
+                else _assert(false);
+            } break;
+
             case 'Q': {
                 const char *xml = argv[argi] + 2;
                 requirements.open(xml, O_RDONLY, PROT_READ, MAP_PRIVATE);