910702665 发表于 2020-5-18 15:18

584530058 发表于 2020-5-18 15:13
需要一个正版的授权加机器码

没有的话就不能PJ咯,那patch有什么意义吗

Pluto 发表于 2020-5-18 16:17

肯定需要正版机器码跟对应key没有等于白给

910702665 发表于 2020-5-18 16:34

new882 发表于 2020-5-18 15:13
教程就是大牛出的啊 你还能比大牛厉害 大牛都要 你不要

那这个有什么意义呢,我有正版的会搞这些干嘛

影风 发表于 2020-5-18 16:39

patch的意义在于,只需要一组正确的机器码和KEY,即可逆向一机一码限制

yAYa 发表于 2020-5-18 20:43

本帖最后由 yAYa 于 2020-5-18 20:44 编辑

patch的前提是需要一组正版key和机器码,懂么。

白嫖怪 发表于 2020-5-18 22:48

{:5_127:}来晚了,我还想说,我写了一份劫持补丁,针对 SE的

pizazzboy 发表于 2020-5-20 14:33

白嫖怪 发表于 2020-5-18 22:48
来晚了,我还想说,我写了一份劫持补丁,针对 SE的

大佬,劫持补丁能否发出来,谢谢!

628721 发表于 2020-5-20 17:56

白嫖怪 发表于 2020-5-20 18:14

pizazzboy 发表于 2020-5-20 14:33
大佬,劫持补丁能否发出来,谢谢!

楼上说的对,楼下也说的对。{:5_124:}

Nooby 发表于 2020-5-22 03:44

没key 自己分解吧
丢一分RSA碰撞源码比分解快!。include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include <libmongoc-1.0/mongoc.h>
#include <signal.h>
mpz_t pool;
char poolstr;
char tmp;
bson_error_t error;
bson_t query;
bson_t update;
bson_t child;
bson_t child2;
size_t count;
uint8_t* pbuf;
bson_t fields;
int pool_id = 0;
mongoc_collection_t* collection;
//#define CHECK_POOL
bool bExit = false;
void exit_save_pool(void)
{
    FILE* f = fopen(poolstr, "wb");
    mpz_out_raw(f, pool);
    fclose(f);
}
void handle_signal(int sig)
{
    bExit = true;
}
void strip_factor(mpz_ptr out, mpz_srcptr n, mpz_srcptr f)
{
    mpz_t t;
    mpz_init_set(t, f);
    while (mpz_cmp_ui(t, 1) > 0) {
      mpz_divexact(out, n, t);
      mpz_gcd(t, out, t);
    }
    mpz_clear(t);
}
int do_work(const bson_t* doc) {
    bson_iter_t iter;
    bson_iter_init_find(&iter, doc, "N");
    mpz_t n;
    mpz_init(n);
    const uint8_t* pData;
    uint32_t len;
    bson_iter_binary(&iter, NULL, &len, &pData);
    mpz_import(n, len, 1, sizeof(pData), 0, 0, pData);
    bson_iter_init_find(&iter, doc, "_id");
    bson_iter_binary(&iter, NULL, &len, &pData);
    if (mpz_cmp_ui(n, 1) > 0) {
      mpz_t t;
      mpz_init(t);
      mpz_gcd(t, pool, n);
      if (mpz_cmp_ui(t, 1) > 0) {
            mpz_t addition;
            mpz_init_set_ui(addition, 1);
            mpz_t p;
            mpz_init(p);
            if (mpz_cmp(t, n) != 0) {
                mpz_set(p, t);
                mpz_divexact(addition, n, t);
                bson_init(&query);
                bson_append_int32(&query, "p", -1, pool_id);
                bson_append_null(&query, "result", -1);
                mongoc_cursor_t* cursor2 = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0, 0, &query, &fields, NULL);
                bson_destroy(&query);
                while (!mongoc_cursor_error(cursor2, &error) && mongoc_cursor_more(cursor2)) {
                  if (mongoc_cursor_next(cursor2, &doc)) {
                        bson_iter_init_find(&iter, doc, "N");
                        mpz_t n2;
                        mpz_init(n2);
                        const uint8_t* pData2;
                        uint32_t len2;
                        bson_iter_binary(&iter, NULL, &len2, &pData2);
                        mpz_import(n2, len2, 1, sizeof(pData2), 0, 0, pData2);
                        bson_iter_init_find(&iter, doc, "_id");
                        bson_iter_binary(&iter, NULL, &len2, &pData2);
                        mpz_gcd(t, n2, p);
                        if (mpz_cmp_ui(t, 1) > 0) {
                            mpz_divexact(t, n2, t);
                            if (mpz_cmp_ui(t, 1) > 0) {
                              bson_init(&query);
                              bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData2, len2);
                              bson_init(&update);
                              bson_append_document_begin(&update, "$set", -1, &child);
                              bson_append_array_begin(&child, "result", -1, &child2);
                              pbuf = (uint8_t*)mpz_export(NULL, &count, 1, sizeof(uint8_t), 0, 0, p);
                              bson_append_binary(&child2, "0", -1, BSON_SUBTYPE_BINARY, pbuf, count);
                              free(pbuf);
                              pbuf = (uint8_t*)mpz_export(NULL, &count, 1, sizeof(uint8_t), 0, 0, t);
                              bson_append_binary(&child2, "1", -1, BSON_SUBTYPE_BINARY, pbuf, count);
                              free(pbuf);
                              bson_append_array_end(&child, &child2);
                              bson_append_now_utc(&child, "tf", -1);
                              bson_append_document_end(&update, &child);
                              bson_append_document_begin(&update, "$unset", -1, &child);
                              bson_append_null(&child, "tc", -1);
                              bson_append_document_end(&update, &child);
                              if (!mongoc_collection_update(collection, MONGOC_UPDATE_NONE, &query, &update, NULL, &error)) {
                                    fprintf(stderr, "Update Failure: %s\n", error.message);
                                    exit_save_pool();
                                    return EXIT_FAILURE;
                              }
                              bson_destroy(&query);
                              bson_destroy(&update);
                            }
                        }
                        mpz_clear(n2);
                  }
                }
                mongoc_cursor_destroy(cursor2);
            }
            else {
                mpz_set(p, n);
                bson_init(&query);
                bson_append_int32(&query, "p", -1, pool_id);
                mongoc_cursor_t* cursor2 = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0, 0, &query, &fields, NULL);
                bson_destroy(&query);
                while (!mongoc_cursor_error(cursor2, &error) && mongoc_cursor_more(cursor2)) {
                  if (mongoc_cursor_next(cursor2, &doc)) {
                        bson_iter_init_find(&iter, doc, "N");
                        mpz_t n2;
                        mpz_init(n2);
                        const uint8_t* pData2;
                        uint32_t len2;
                        bson_iter_binary(&iter, NULL, &len2, &pData2);
                        mpz_import(n2, len2, 1, sizeof(pData2), 0, 0, pData2);
                        bson_iter_init_find(&iter, doc, "_id");
                        bson_iter_binary(&iter, NULL, &len2, &pData2);
                        mpz_gcd(t, n2, n);
                        if (mpz_cmp_ui(t, 1) > 0) {
                            if (!bson_iter_init_find(&iter, doc, "result") || BSON_ITER_HOLDS_NULL(&iter)) {
                              mpz_divexact(p, n2, t);
                              if (mpz_cmp_ui(p, 1) > 0) {
                                    bson_init(&query);
                                    bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData2, len2);
                                    bson_init(&update);
                                    bson_append_document_begin(&update, "$set", -1, &child);
                                    bson_append_array_begin(&child, "result", -1, &child2);
                                    pbuf = (uint8_t*)mpz_export(NULL, &count, 1, sizeof(uint8_t), 0, 0, p);
                                    bson_append_binary(&child2, "0", -1, BSON_SUBTYPE_BINARY, pbuf, count);
                                    free(pbuf);
                                    pbuf = (uint8_t*)mpz_export(NULL, &count, 1, sizeof(uint8_t), 0, 0, t);
                                    bson_append_binary(&child2, "1", -1, BSON_SUBTYPE_BINARY, pbuf, count);
                                    free(pbuf);
                                    bson_append_array_end(&child, &child2);
                                    bson_append_now_utc(&child, "tf", -1);
                                    bson_append_document_end(&update, &child);
                                    bson_append_document_begin(&update, "$unset", -1, &child);
                                    bson_append_null(&child, "tc", -1);
                                    bson_append_document_end(&update, &child);
                                    if (!mongoc_collection_update(collection, MONGOC_UPDATE_NONE, &query, &update, NULL, &error)) {
                                        fprintf(stderr, "Update Failure: %s\n", error.message);
                                        exit_save_pool();
                                        return EXIT_FAILURE;
                                    }
                                    bson_destroy(&query);
                                    bson_destroy(&update);
                              }
                            }
                            if (mpz_cmp(t, n) != 0) {
                              mpz_set(p, t);
                            }
                        }
                        mpz_clear(n2);
                  }
                }
                mongoc_cursor_destroy(cursor2);
            }
            if (mpz_cmp_ui(p, 1) > 0) {
                if (mpz_cmp_ui(addition, 1) == 0) {
                  mpz_gcd(t, n, p);
                  if (mpz_cmp_ui(t, 1) > 0) {
                        mpz_divexact(t, n, p);
                  }
                }
                else {
                  mpz_set(t, addition);
                }
                if (mpz_cmp_ui(t, 1) > 0) {
                  bson_init(&query);
                  bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
                  bson_append_null(&query, "p", -1);
                  bson_append_null(&query, "result", -1);
                  bson_init(&update);
                  bson_append_document_begin(&update, "$set", -1, &child);
                  bson_append_int32(&child, "p", -1, pool_id);
                  bson_append_array_begin(&child, "result", -1, &child2);
                  pbuf = (uint8_t*)mpz_export(NULL, &count, 1, sizeof(uint8_t), 0, 0, p);
                  bson_append_binary(&child2, "0", -1, BSON_SUBTYPE_BINARY, pbuf, count);
                  free(pbuf);
                  pbuf = (uint8_t*)mpz_export(NULL, &count, 1, sizeof(uint8_t), 0, 0, t);
                  bson_append_binary(&child2, "1", -1, BSON_SUBTYPE_BINARY, pbuf, count);
                  free(pbuf);
                  bson_append_array_end(&child, &child2);
                  bson_append_now_utc(&child, "tf", -1);
                  bson_append_document_end(&update, &child);
                  bson_append_document_begin(&update, "$unset", -1, &child);
                  bson_append_null(&child, "tc", -1);
                  bson_append_document_end(&update, &child);
                  bson_t doc2;
                  if (!mongoc_collection_find_and_modify(collection, &query, NULL, &update, NULL, false, false, false, &doc2, &error)) {
                        fprintf(stderr, "Update Failure: %s\n", error.message);
                        exit_save_pool();
                        return EXIT_FAILURE;
                  }
                  bson_destroy(&query);
                  bson_destroy(&update);
                  if (bson_iter_init_find(&iter, &doc2, "value") && !BSON_ITER_HOLDS_NULL(&iter)) {
                        mpz_gcd(t, pool, n);
                        strip_factor(n, n, t);
                        strip_factor(pool, pool, t);
                        mpz_mul(n, n, t);
                        mpz_mul(pool, pool, n);
                  }
                  else {
                        bson_init(&query);
                        bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
                        bson_append_null(&query, "result", -1);
                        mongoc_cursor_t* cursor2 = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0, 0, &query, &fields, NULL);
                        bson_destroy(&query);
                        while (!mongoc_cursor_error(cursor2, &error) && mongoc_cursor_more(cursor2)) {
                            if (mongoc_cursor_next(cursor2, &doc)) {
                              bson_iter_init_find(&iter, doc, "p");
                              int other_id = bson_iter_int32(&iter);
                              bson_init(&query);
                              bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
                              bson_append_null(&query, "result", -1);
                              bson_init(&update);
                              bson_append_document_begin(&update, "$set", -1, &child);
                              bson_append_int32(&child, "p", -1, pool_id);
                              bson_append_array_begin(&child, "result", -1, &child2);
                              pbuf = (uint8_t*)mpz_export(NULL, &count, 1, sizeof(uint8_t), 0, 0, p);
                              bson_append_binary(&child2, "0", -1, BSON_SUBTYPE_BINARY, pbuf, count);
                              free(pbuf);
                              pbuf = (uint8_t*)mpz_export(NULL, &count, 1, sizeof(uint8_t), 0, 0, t);
                              bson_append_binary(&child2, "1", -1, BSON_SUBTYPE_BINARY, pbuf, count);
                              free(pbuf);
                              bson_append_array_end(&child, &child2);
                              bson_append_now_utc(&child, "tf", -1);
                              char tmp2;
                              sprintf(tmp2, "r%d", other_id);
                              bson_append_bool(&child, tmp2, -1, true);
                              bson_append_document_end(&update, &child);
                              bson_append_document_begin(&update, "$unset", -1, &child);
                              bson_append_null(&child, "tc", -1);
                              bson_append_document_end(&update, &child);
                              bson_t doc3;
                              if (!mongoc_collection_find_and_modify(collection, &query, NULL, &update, NULL, false, false, false, &doc3, &error)) {
                                    fprintf(stderr, "Update Failure: %s\n", error.message);
                                    exit_save_pool();
                                    return EXIT_FAILURE;
                              }
                              bson_destroy(&query);
                              bson_destroy(&update);
                              if (bson_iter_init_find(&iter, &doc3, "value") && !BSON_ITER_HOLDS_NULL(&iter)) {
                                    mpz_gcd(t, pool, n);
                                    strip_factor(n, n, t);
                                    strip_factor(pool, pool, t);
                                    mpz_mul(n, n, t);
                                    mpz_mul(pool, pool, n);
                              }
                              bson_destroy(&doc3);
                            }
                        }
                        mongoc_cursor_destroy(cursor2);
                  }
                  bson_destroy(&doc2);
                }
                else {
                  bson_init(&query);
                  bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
                  bson_append_null(&query, "p", -1);
                  bson_init(&update);
                  bson_append_document_begin(&update, "$set", -1, &child);
                  bson_append_int32(&child, "p", -1, pool_id);
                  bson_append_now_utc(&child, "tc", -1);
                  bson_append_document_end(&update, &child);
                  bson_t doc2;
                  if (!mongoc_collection_find_and_modify(collection, &query, NULL, &update, NULL, false, false, false, &doc2, &error)) {
                        fprintf(stderr, "Update Failure: %s\n", error.message);
                        exit_save_pool();
                        return EXIT_FAILURE;
                  }
                  bson_destroy(&query);
                  bson_destroy(&update);
                  if (!bson_iter_init_find(&iter, &doc2, "value") || BSON_ITER_HOLDS_NULL(&iter)) {
                        bson_init(&query);
                        bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
                        mongoc_cursor_t* cursor2 = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0, 0, &query, &fields, NULL);
                        bson_destroy(&query);
                        while (!mongoc_cursor_error(cursor2, &error) && mongoc_cursor_more(cursor2)) {
                            if (mongoc_cursor_next(cursor2, &doc)) {
                              bson_iter_init_find(&iter, doc, "p");
                              int other_id = bson_iter_int32(&iter);
                              bson_init(&query);
                              bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
                              bson_append_null(&query, "result", -1);
                              bson_init(&update);
                              bson_append_document_begin(&update, "$set", -1, &child);
                              bson_append_int32(&child, "p", -1, pool_id);
                              bson_append_now_utc(&child, "tc", -1);
                              char tmp2;
                              sprintf(tmp2, "r%d", other_id);
                              bson_append_bool(&child, tmp2, -1, true);
                              bson_append_document_end(&update, &child);
                              bson_t doc3;
                              if (!mongoc_collection_find_and_modify(collection, &query, NULL, &update, NULL, false, false, false, &doc3, &error)) {
                                    fprintf(stderr, "Update Failure: %s\n", error.message);
                                    exit_save_pool();
                                    return EXIT_FAILURE;
                              }
                              bson_destroy(&query);
                              bson_destroy(&update);
                              bson_destroy(&doc3);
                            }
                        }
                        mongoc_cursor_destroy(cursor2);
                  }
                  strip_factor(pool, pool, n);
                  mpz_mul(pool, pool, n);
                  bson_destroy(&doc2);
                }
            }
            mpz_clear(p);
            mpz_clear(addition);
      }
      else if (mpz_size(pool) * sizeof(mp_limb_t) < 0x400 * 0x400 * 0x400) {
            bson_init(&query);
            bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
            bson_append_null(&query, "p", -1);
            bson_init(&update);
            bson_append_document_begin(&update, "$set", -1, &child);
            bson_append_int32(&child, "p", -1, pool_id);
            bson_append_now_utc(&child, "tc", -1);
            bson_append_document_end(&update, &child);
            bson_t doc2;
            if (!mongoc_collection_find_and_modify(collection, &query, NULL, &update, NULL, false, false, false, &doc2, &error)) {
                fprintf(stderr, "Update Failure: %s\n", error.message);
                exit_save_pool();
                return EXIT_FAILURE;
            }
            bson_destroy(&query);
            bson_destroy(&update);
            if (bson_iter_init_find(&iter, &doc2, "value") && !BSON_ITER_HOLDS_NULL(&iter)) {
                mpz_mul(pool, pool, n);
            }
            bson_destroy(&doc2);
      }
      mpz_clear(t);
    }
    else {
      bson_init(&query);
      bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
      bson_append_null(&query, "p", -1);
      bson_init(&update);
      bson_append_document_begin(&update, "$set", -1, &child);
      bson_append_int32(&child, "p", -1, pool_id);
      bson_append_now_utc(&child, "tc", -1);
      bson_append_document_end(&update, &child);
      bson_t doc2;
      if (!mongoc_collection_find_and_modify(collection, &query, NULL, &update, NULL, false, false, false, &doc2, &error)) {
            fprintf(stderr, "Update Failure: %s\n", error.message);
            exit_save_pool();
            return EXIT_FAILURE;
      }
      bson_destroy(&query);
      bson_destroy(&update);
      bson_destroy(&doc2);
    }
    bson_init(&query);
    bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
    bson_init(&update);
    bson_append_document_begin(&update, "$unset", -1, &child);
    bson_append_null(&child, tmp, -1);
    bson_append_null(&child, "pp", -1);
    bson_append_document_end(&update, &child);
    if (!mongoc_collection_update(collection, MONGOC_UPDATE_NONE, &query, &update, NULL, &error)) {
      fprintf(stderr, "Update Failure: %s\n", error.message);
      exit_save_pool();
      return EXIT_FAILURE;
    }
    bson_destroy(&query);
    bson_destroy(&update);
    mpz_clear(n);
    return 0;
}
int main(int argc, char* argv[])
{
    const char *uristr = "mongodb://127.0.0.1/";
    const char *db_name = "rsahunt";
    mongoc_init();
    if (argc > 1) {
      pool_id = atoi(argv);
    }
    sprintf(poolstr, "pool_%d.rhp", pool_id);
    FILE* f = fopen(poolstr, "ab+");
    mpz_init(pool);
    mpz_inp_raw(pool, f);
    fclose(f);
    if (mpz_cmp_ui(pool, 0) == 0) {
      mpz_set_ui(pool, 1);
    }
    signal(SIGINT, handle_signal);
    signal(SIGTERM, handle_signal);
    if (argc > 2) {
      uristr = argv;
    }
    if (argc > 3) {
      db_name = argv;
    }
    mongoc_client_t* client = mongoc_client_new(uristr);
    if (!client) {
      fprintf(stderr, "Failed to parse URI.\n");
      exit_save_pool();
      return EXIT_FAILURE;
    }
    collection = mongoc_client_get_collection(client, db_name, "rsahunt");
    bson_init(&fields);
    bson_append_int32(&fields, "certs", -1, 0);
    mongoc_cursor_t* cursor;
    bool bWork;
    while (!bExit) {
      sprintf(tmp, "c%d", pool_id);
      bson_init(&query);
      bson_append_bool(&query, tmp, -1, true);
      bson_append_int32(&query, "p", -1, pool_id);
      cursor = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0, 0, &query, &fields, NULL);
      bson_destroy(&query);
      while (!bExit && !mongoc_cursor_error(cursor, &error) && mongoc_cursor_more(cursor)) {
            const bson_t *doc;
            if (mongoc_cursor_next(cursor, &doc)) {
                bson_iter_t iter;
                bson_iter_init_find(&iter, doc, "N");
                mpz_t n;
                mpz_init(n);
                const uint8_t* pData;
                uint32_t len;
                bson_iter_binary(&iter, NULL, &len, &pData);
                mpz_import(n, len, 1, sizeof(pData), 0, 0, pData);
                bson_iter_init_find(&iter, doc, "_id");
                bson_iter_binary(&iter, NULL, &len, &pData);
                if (mpz_cmp_ui(n, 1) > 0) {
                  mpz_t t;
                  mpz_init(t);
                  mpz_gcd(t, pool, n);
                  strip_factor(n, n, t);
                  strip_factor(pool, pool, t);
                  mpz_mul(n, n, t);
                  mpz_mul(pool, pool, n);
                  mpz_clear(t);
                }
                bson_init(&query);
                bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
                bson_init(&update);
                bson_append_document_begin(&update, "$unset", -1, &child);
                bson_append_null(&child, tmp, -1);
                bson_append_document_end(&update, &child);
                if (!mongoc_collection_update(collection, MONGOC_UPDATE_NONE, &query, &update, NULL, &error)) {
                  fprintf(stderr, "Update Failure: %s\n", error.message);
                  exit_save_pool();
                  return EXIT_FAILURE;
                }
                bson_destroy(&query);
                bson_destroy(&update);
                mpz_clear(n);
            }
      }
      if (mongoc_cursor_error(cursor, &error)) {
            fprintf(stderr, "Cursor Failure: %s\n", error.message);
            exit_save_pool();
            return EXIT_FAILURE;
      }
      mongoc_cursor_destroy(cursor);
      if (!bExit) {
            sprintf(tmp, "r%d", pool_id);
            bson_init(&query);
            bson_append_bool(&query, tmp, -1, true);
            cursor = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0, 0, &query, &fields, NULL);
            bson_destroy(&query);
            while (!bExit && !mongoc_cursor_error(cursor, &error) && mongoc_cursor_more(cursor)) {
                const bson_t *doc;
                if (mongoc_cursor_next(cursor, &doc)) {
                  bson_iter_t iter;
                  bson_iter_init_find(&iter, doc, "N");
                  mpz_t n;
                  mpz_init(n);
                  const uint8_t* pData;
                  uint32_t len;
                  bson_iter_binary(&iter, NULL, &len, &pData);
                  mpz_import(n, len, 1, sizeof(pData), 0, 0, pData);
                  bson_iter_init_find(&iter, doc, "_id");
                  bson_iter_binary(&iter, NULL, &len, &pData);
                  if (mpz_cmp_ui(n, 1) > 0) {
                        mpz_t t;
                        mpz_init(t);
                        mpz_gcd(t, pool, n);
                        strip_factor(pool, pool, t);
                        bson_init(&query);
                        bson_append_document_begin(&query, "tf", -1, &child);
                        bson_append_bool(&child, "$exists", -1, true);
                        bson_append_document_end(&query, &child);
                        bson_append_int32(&query, "p", -1, pool_id);
                        mongoc_cursor_t* cursor2 = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0, 0, &query, &fields, NULL);
                        bson_destroy(&query);
                        while (!mongoc_cursor_error(cursor2, &error) && mongoc_cursor_more(cursor2)) {
                            if (mongoc_cursor_next(cursor2, &doc)) {
                              bson_iter_init_find(&iter, doc, "N");
                              mpz_t n2;
                              mpz_init(n2);
                              const uint8_t* pData2;
                              uint32_t len2;
                              bson_iter_binary(&iter, NULL, &len2, &pData2);
                              mpz_import(n2, len2, 1, sizeof(pData2), 0, 0, pData2);
                              mpz_gcd(t, pool, n2);
                              strip_factor(n2, n2, t);
                              strip_factor(pool, pool, t);
                              mpz_mul(n2, n2, t);
                              mpz_mul(pool, pool, n2);
                              mpz_clear(n2);
                            }
                        }
                        if (mongoc_cursor_error(cursor2, &error)) {
                            fprintf(stderr, "Cursor Failure: %s\n", error.message);
                            exit_save_pool();
                            return EXIT_FAILURE;
                        }
                        mongoc_cursor_destroy(cursor2);
                        mpz_clear(t);
                  }
                  mpz_clear(n);
                  bson_init(&query);
                  bson_append_binary(&query, "_id", -1, BSON_SUBTYPE_BINARY, pData, len);
                  bson_init(&update);
                  bson_append_document_begin(&update, "$unset", -1, &child);
                  bson_append_null(&child, tmp, -1);
                  bson_append_document_end(&update, &child);
                  if (!mongoc_collection_update(collection, MONGOC_UPDATE_NONE, &query, &update, NULL, &error)) {
                        fprintf(stderr, "Update Failure: %s\n", error.message);
                        exit_save_pool();
                        return EXIT_FAILURE;
                  }
                  bson_destroy(&query);
                  bson_destroy(&update);
                }
            }
            if (mongoc_cursor_error(cursor, &error)) {
                fprintf(stderr, "Cursor Failure: %s\n", error.message);
                exit_save_pool();
                return EXIT_FAILURE;
            }
            mongoc_cursor_destroy(cursor);
      }
#if defined(CHECK_POOL)
      if (!bExit) {
            int count = 0;
            mpz_t ref_pool;
            mpz_init_set_ui(ref_pool, 1);
            bson_init(&query);
            bson_append_int32(&query, "p", -1, pool_id);
            cursor = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0, 0, &query, &fields, NULL);
            bson_destroy(&query);
            while (!mongoc_cursor_error(cursor, &error) && mongoc_cursor_more(cursor)) {
                const bson_t *doc;
                if (mongoc_cursor_next(cursor, &doc)) {
                  bson_iter_t iter;
                  bson_iter_init_find(&iter, doc, "N");
                  mpz_t n;
                  mpz_init(n);
                  const uint8_t* pData;
                  uint32_t len;
                  bson_iter_binary(&iter, NULL, &len, &pData);
                  mpz_import(n, len, 1, sizeof(pData), 0, 0, pData);
                  mpz_t t;
                  mpz_init(t);
                  mpz_gcd(t, ref_pool, n);
                  strip_factor(n, n, t);
                  strip_factor(ref_pool, ref_pool, t);
                  mpz_mul(n, n, t);
                  mpz_mul(ref_pool, ref_pool, n);
                  mpz_clear(t);
                  mpz_clear(n);
                  if ((++count % 0x1000) == 0) {
                        printf("%d\n", count);
                  }
                }
            }
            if (mongoc_cursor_error(cursor, &error)) {
                fprintf(stderr, "Cursor Failure: %s\n", error.message);
                exit_save_pool();
                return EXIT_FAILURE;
            }
            mongoc_cursor_destroy(cursor);
            //mpz_set(pool, ref_pool);
            //return 0;
            int res = mpz_cmp(pool, ref_pool);
            if (res > 0) {
                printf("pool is not optimal\n");
            }
            else if (res < 0) {
                printf("pool error\n");
            }
            else
            {
                printf("pool is optimal\n");
            }
            mpz_clear(ref_pool);
            exit_save_pool();
            return 0;
      }
#endif
      if (!bExit) {
            bWork = false;
            sprintf(tmp, "c%d", pool_id);
            bson_init(&query);
            bson_append_int32(&query, "pp", -1, pool_id);
            bson_append_bool(&query, tmp, -1, true);
            bson_append_document_begin(&query, "p", -1, &child);
            bson_append_int32(&child, "$ne", -1, pool_id);
            bson_append_document_end(&query, &child);
            bson_append_null(&query, "result", -1);
            cursor = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0x1000, 0, &query, &fields, NULL);
            bson_destroy(&query);
            while (!bExit && !mongoc_cursor_error(cursor, &error) && mongoc_cursor_more(cursor)) {
                const bson_t *doc;
                if (mongoc_cursor_next(cursor, &doc)) {
                  bWork = true;
                  if (do_work(doc) != 0) {
                        return EXIT_FAILURE;
                  }
                }
            }
            if (mongoc_cursor_error(cursor, &error)) {
                fprintf(stderr, "Cursor Failure: %s\n", error.message);
                exit_save_pool();
                return EXIT_FAILURE;
            }
            mongoc_cursor_destroy(cursor);
      }
      if (!bExit && !bWork) {
            sprintf(tmp, "c%d", pool_id);
            bson_init(&query);
            bson_append_bool(&query, tmp, -1, true);
            bson_append_document_begin(&query, "p", -1, &child);
            bson_append_int32(&child, "$ne", -1, pool_id);
            bson_append_document_end(&query, &child);
            bson_append_null(&query, "result", -1);
            cursor = mongoc_collection_find(collection, MONGOC_QUERY_NO_CURSOR_TIMEOUT, 0, 0x1000, 0, &query, &fields, NULL);
            bson_destroy(&query);
            while (!bExit && !mongoc_cursor_error(cursor, &error) && mongoc_cursor_more(cursor)) {
                const bson_t *doc;
                if (mongoc_cursor_next(cursor, &doc)) {
                  bWork = true;
                  if (do_work(doc) != 0) {
                        return EXIT_FAILURE;
                  }
                }
            }
            if (mongoc_cursor_error(cursor, &error)) {
                fprintf(stderr, "Cursor Failure: %s\n", error.message);
                exit_save_pool();
                return EXIT_FAILURE;
            }
            mongoc_cursor_destroy(cursor);
            if (!bWork) {
                sleep(5);
            }
      }
    }
    bson_destroy(&fields);
    mongoc_collection_destroy(collection);
    mongoc_client_destroy(client);
    exit_save_pool();
    return 0;
}
页: 1 [2] 3
查看完整版本: se求patch机器码