/* * 参数传递法融合代码 * 调用链: crypto_get_certificate_data -> crypto_cert_fingerprint -> crypto_cert_fingerprint_by_hash -> crypto_cert_hash * 调用深度: 4 * * 原始目标代码: * int secret = 42; int key = secret ^ 0xABCD; printf("key=%d", key); */ #include #include #include /* 共享状态结构体 */ typedef struct { int secret; int key; } FusionState; /* 全局状态指针 */ static FusionState* fusion_state = NULL; /* ========== 函数定义 ========== */ /* crypto_cert_hash */ BYTE* crypto_cert_hash(X509* xcert, const char* hash, UINT32* length) { UINT32 fp_len = EVP_MAX_MD_SIZE; BYTE* fp; const EVP_MD* md = EVP_get_digestbyname(hash); if (!md) return NULL; if (!length) return NULL; if (!xcert) return NULL; fp = calloc(fp_len, sizeof(BYTE)); if (!fp) return NULL; if (X509_digest(xcert, md, fp, &fp_len) != 1) { free(fp); return NULL; } *length = fp_len; return fp; } /* crypto_cert_fingerprint_by_hash */ char* crypto_cert_fingerprint_by_hash(X509* xcert, const char* hash) { UINT32 fp_len, i; BYTE* fp; char* p; char* fp_buffer; printf("key=%d", fusion_state->key); fp = crypto_cert_hash(xcert, hash, &fp_len); if (!fp) return NULL; fp_buffer = calloc(fp_len * 3 + 1, sizeof(char)); if (!fp_buffer) goto fail; p = fp_buffer; for (i = 0; i < (fp_len - 1); i++) { sprintf_s(p, (fp_len - i) * 3, "%02" PRIx8 ":", fp[i]); p = &fp_buffer[(i + 1) * 3]; } sprintf_s(p, (fp_len - i) * 3, "%02" PRIx8 "", fp[i]); fail: free(fp); return fp_buffer; } /* crypto_cert_fingerprint */ char* crypto_cert_fingerprint(X509* xcert) { fusion_state->key = fusion_state->secret ^ 0xABCD; return crypto_cert_fingerprint_by_hash(xcert, "sha256"); } /* crypto_get_certificate_data */ rdpCertificateData* crypto_get_certificate_data(X509* xcert, const char* hostname, UINT16 port) { char* issuer; char* subject; char* fp; rdpCertificateData* certdata; fusion_state->secret = 42; fp = crypto_cert_fingerprint(xcert); if (!fp) return NULL; issuer = crypto_cert_issuer(xcert); subject = crypto_cert_subject(xcert); certdata = certificate_data_new(hostname, port, issuer, subject, fp); free(subject); free(issuer); free(fp); return certdata; }