int main(int argc, char *argv[]) { FILE *binfile; int max_steps = MAX_STEP; y86sim_t *sim; mem_t *saver, *savem; int step = 0; stat_t e = STAT_AOK; if (argc < 2 || argc > 3) usage(argv[0]); /* set max steps */ if (argc > 2) max_steps = atoi(argv[2]); /* load binary file to memory */ if (strcmp(argv[1]+(strlen(argv[1])-4), ".bin")) usage(argv[0]); /* only support *.bin file */ binfile = fopen(argv[1], "rb"); if (!binfile) { err_print("Can't open binary file '%s'", argv[1]); exit(1); } sim = new_y86sim(MEM_SIZE); if (load_binfile(sim->m, binfile) < 0) { err_print("Failed to load binary file '%s'", argv[1]); free_y86sim(sim); exit(1); } fclose(binfile); /* save initial register and memory stat */ saver = dup_reg(sim->r); savem = dup_mem(sim->m); /* execute binary code step-by-step */ for (step = 0; step < max_steps && e == STAT_AOK; step++) e = nexti(sim); /* print final stat of y86sim */ printf("Stopped in %d steps at PC = 0x%x. Status '%s', CC %s\n", step, sim->pc, stat_name(e), cc_name(sim->cc)); printf("Changes to registers:\n"); diff_reg(saver, sim->r, stdout); printf("\nChanges to memory:\n"); diff_mem(savem, sim->m, stdout); free_y86sim(sim); free_reg(saver); free_mem(savem); return 0; }
void sc_pkcs11_register_openssl_mechanisms(struct sc_pkcs11_card *card) { #if OPENSSL_VERSION_NUMBER >= 0x10000000L && !defined(OPENSSL_NO_ENGINE) void (*locking_cb)(int, int, const char *, int); ENGINE *e; locking_cb = CRYPTO_get_locking_callback(); if (locking_cb) CRYPTO_set_locking_callback(NULL); e = ENGINE_by_id("gost"); if (!e) { #if !defined(OPENSSL_NO_STATIC_ENGINE) && !defined(OPENSSL_NO_GOST) ENGINE_load_gost(); e = ENGINE_by_id("gost"); #else /* try to load dynamic gost engine */ e = ENGINE_by_id("dynamic"); if (!e) { ENGINE_load_dynamic(); e = ENGINE_by_id("dynamic"); } if (e && (!ENGINE_ctrl_cmd_string(e, "SO_PATH", "gost", 0) || !ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))) { ENGINE_free(e); e = NULL; } #endif /* !OPENSSL_NO_STATIC_ENGINE && !OPENSSL_NO_GOST */ } if (e) { ENGINE_set_default(e, ENGINE_METHOD_ALL); ENGINE_free(e); } if (locking_cb) CRYPTO_set_locking_callback(locking_cb); #endif /* OPENSSL_VERSION_NUMBER >= 0x10000000L && !defined(OPENSSL_NO_ENGINE) */ openssl_sha1_mech.mech_data = EVP_sha1(); sc_pkcs11_register_mechanism(card, dup_mem(&openssl_sha1_mech, sizeof openssl_sha1_mech)); #if OPENSSL_VERSION_NUMBER >= 0x00908000L openssl_sha256_mech.mech_data = EVP_sha256(); sc_pkcs11_register_mechanism(card, dup_mem(&openssl_sha256_mech, sizeof openssl_sha256_mech)); openssl_sha384_mech.mech_data = EVP_sha384(); sc_pkcs11_register_mechanism(card, dup_mem(&openssl_sha384_mech, sizeof openssl_sha384_mech)); openssl_sha512_mech.mech_data = EVP_sha512(); sc_pkcs11_register_mechanism(card, dup_mem(&openssl_sha512_mech, sizeof openssl_sha512_mech)); #endif openssl_md5_mech.mech_data = EVP_md5(); sc_pkcs11_register_mechanism(card, dup_mem(&openssl_md5_mech, sizeof openssl_md5_mech)); openssl_ripemd160_mech.mech_data = EVP_ripemd160(); sc_pkcs11_register_mechanism(card, dup_mem(&openssl_ripemd160_mech, sizeof openssl_ripemd160_mech)); #if OPENSSL_VERSION_NUMBER >= 0x10000000L openssl_gostr3411_mech.mech_data = EVP_get_digestbynid(NID_id_GostR3411_94); sc_pkcs11_register_mechanism(card, dup_mem(&openssl_gostr3411_mech, sizeof openssl_gostr3411_mech)); #endif }
mem_t *dup_reg(mem_t *oldr) { return dup_mem(oldr); }
/* * 'Clean up' this string. */ char * clean(char *s, int sending) { char temp[STR_LEN], cur_chr; char *s1, *phchar; int add_return = sending; #define isoctal(chr) (((chr) >= '0') && ((chr) <= '7')) s1 = temp; /* Don't overflow buffer, leave room for chars we append later */ while (*s && s1 - temp < (off_t)(sizeof(temp) - 2 - add_return)) { cur_chr = *s++; if (cur_chr == '^') { cur_chr = *s++; if (cur_chr == '\0') { *s1++ = '^'; break; } cur_chr &= 0x1F; if (cur_chr != 0) { *s1++ = cur_chr; } continue; } if (cur_chr != '\\') { *s1++ = cur_chr; continue; } cur_chr = *s++; if (cur_chr == '\0') { if (sending) { *s1++ = '\\'; *s1++ = '\\'; } break; } switch (cur_chr) { case 'b': *s1++ = '\b'; break; case 'c': if (sending && *s == '\0') add_return = 0; else *s1++ = cur_chr; break; case '\\': case 'K': case 'p': case 'd': if (sending) *s1++ = '\\'; *s1++ = cur_chr; break; case 'T': if (sending && phone_num) { for ( phchar = phone_num; *phchar != '\0'; phchar++) *s1++ = *phchar; } else { *s1++ = '\\'; *s1++ = 'T'; } break; case 'U': if (sending && phone_num2) { for ( phchar = phone_num2; *phchar != '\0'; phchar++) *s1++ = *phchar; } else { *s1++ = '\\'; *s1++ = 'U'; } break; case 'q': quiet = 1; break; case 'r': *s1++ = '\r'; break; case 'n': *s1++ = '\n'; break; case 's': *s1++ = ' '; break; case 't': *s1++ = '\t'; break; case 'N': if (sending) { *s1++ = '\\'; *s1++ = '\0'; } else *s1++ = 'N'; break; default: if (isoctal (cur_chr)) { cur_chr &= 0x07; if (isoctal (*s)) { cur_chr <<= 3; cur_chr |= *s++ - '0'; if (isoctal (*s)) { cur_chr <<= 3; cur_chr |= *s++ - '0'; } } if (cur_chr != 0 || sending) { if (sending && (cur_chr == '\\' || cur_chr == 0)) *s1++ = '\\'; *s1++ = cur_chr; } break; } if (sending) *s1++ = '\\'; *s1++ = cur_chr; break; } } if (add_return) *s1++ = '\r'; *s1++ = '\0'; /* guarantee closure */ *s1++ = '\0'; /* terminate the string */ return dup_mem (temp, (size_t) (s1 - temp)); /* may have embedded nuls */ }
void * copy_of(char *s) { return dup_mem (s, strlen (s) + 1); }
/* * 'Clean up' this string. */ static char *clean( char *s, int sending ) /* set to 1 when sending (putting) this string. */ { char temp[STR_LEN], env_str[STR_LEN], cur_chr; register char *s1, *phchar; int add_return = sending; #define isoctal(chr) (((chr) >= '0') && ((chr) <= '7')) #define isalnumx(chr) ((((chr) >= '0') && ((chr) <= '9')) \ || (((chr) >= 'a') && ((chr) <= 'z')) \ || (((chr) >= 'A') && ((chr) <= 'Z')) \ || (chr) == '_') s1 = temp; while (*s) { cur_chr = *s++; if (cur_chr == '^') { cur_chr = *s++; if (cur_chr == '\0') { *s1++ = '^'; break; } cur_chr &= 0x1F; if (cur_chr != 0) { *s1++ = cur_chr; } continue; } if (use_env && cur_chr == '$') { /* ARI */ phchar = env_str; while (isalnumx(*s)) *phchar++ = *s++; *phchar = '\0'; phchar = getenv(env_str); if (phchar) while (*phchar) *s1++ = *phchar++; continue; } if (cur_chr != '\\') { *s1++ = cur_chr; continue; } cur_chr = *s++; if (cur_chr == '\0') { if (sending) { *s1++ = '\\'; *s1++ = '\\'; } break; } switch (cur_chr) { case 'b': *s1++ = '\b'; break; case 'c': if (sending && *s == '\0') add_return = 0; else *s1++ = cur_chr; break; case '\\': case 'K': case 'p': case 'd': if (sending) *s1++ = '\\'; *s1++ = cur_chr; break; case 'T': if (sending && phone_num) { for (phchar = phone_num; *phchar != '\0'; phchar++) *s1++ = *phchar; } else { *s1++ = '\\'; *s1++ = 'T'; } break; case 'U': if (sending && phone_num2) { for (phchar = phone_num2; *phchar != '\0'; phchar++) *s1++ = *phchar; } else { *s1++ = '\\'; *s1++ = 'U'; } break; case 'q': quiet = 1; break; case 'r': *s1++ = '\r'; break; case 'n': *s1++ = '\n'; break; case 's': *s1++ = ' '; break; case 't': *s1++ = '\t'; break; case 'N': if (sending) { *s1++ = '\\'; *s1++ = '\0'; } else *s1++ = 'N'; break; case '$': /* ARI */ if (use_env) { *s1++ = cur_chr; break; } /* FALL THROUGH */ default: if (isoctal (cur_chr)) { cur_chr &= 0x07; if (isoctal (*s)) { cur_chr <<= 3; cur_chr |= *s++ - '0'; if (isoctal (*s)) { cur_chr <<= 3; cur_chr |= *s++ - '0'; } } if (cur_chr != 0 || sending) { if (sending && (cur_chr == '\\' || cur_chr == 0)) *s1++ = '\\'; *s1++ = cur_chr; } break; } if (sending) *s1++ = '\\'; *s1++ = cur_chr; break; } } if (add_return) *s1++ = '\r'; *s1++ = '\0'; /* guarantee closure */ *s1++ = '\0'; /* terminate the string */ return dup_mem (temp, (size_t) (s1 - temp)); /* may have embedded nuls */ }