int avm_open(const char* filename) { int (*open_wrapper) (const char*) = jar_open; if(strcmp(&filename[strlen(filename) - 6], ".class") == 0) open_wrapper = __java_assembly_open_wrapper; if(open_wrapper(filename) == J_OK) return J_OK; char buf[1024]; vector_t* v; for(v = path_vector; v; v = v->next) { const char* path = (const char*) v->value; memset(buf, 0, sizeof(buf)); strcat(buf, path); if(path[strlen(path) - 1] != '/') strcat(buf, "/"); strcat(buf, filename); if(open_wrapper(buf) == J_OK) return J_OK; } return J_ERR; }
void test_signature_file(const char * read_filepath, mpz_t hash) { signature_attr attr; gen_signature_attr(&attr); gen_keys_pair(&attr); signature sign; mpz_init(sign.r); mpz_init(sign.s); FILE * stream = open_wrapper(read_filepath, "rb"); mpz_inp_wrapper(sign.r, stream); mpz_inp_wrapper(sign.s, stream); close_wrapper(stream); printf("Signature verification..."); if (test_signature(&sign, &attr, hash)) { printf(" [Ok]\n"); } else { printf(" [Failed]\n"); } mpz_clear(sign.r); mpz_clear(sign.s); free_signature_attr(&attr); free_keys_pair(&attr); }
/// Interposes over the open64() function. /// @param[in] call the name of the interposed function in string form /// @param[in] next a pointer to the interposed function /// @param[in] path same as the wrapped function /// @param[in] oflag same as the wrapped function /// @param[in] mode same as the wrapped function /// @return same as the wrapped function /*static*/ int open64_wrapper(const char *call, int (*next) (const char *, int, ...), const char *path, int oflag, mode_t mode) { WRAPPER_DEBUG("ENTERING open64_wrapper() => %p [%s ...]\n", next, path); oflag |= O_LARGEFILE; return open_wrapper(call, next, path, oflag, mode); }
/// Interposes over the creat() function. /// @param[in] call the name of the interposed function in string form /// @param[in] next a pointer to the interposed function /// @param[in] path same as the wrapped function /// @param[in] mode same as the wrapped function /// @return same as the wrapped function /*static*/ int creat_wrapper(const char *call, int (*next) (const char *, mode_t), const char *path, mode_t mode) { int oflag; WRAPPER_DEBUG("ENTERING creat_wrapper() => %p [%s ...]\n", next, path); UNUSED(next); oflag = O_WRONLY | O_CREAT | O_TRUNC; return open_wrapper(call, open_real, path, oflag, mode); }
void write_signature_file(const char * write_filepath, mpz_t hash) { signature_attr attr; gen_signature_attr(&attr); gen_keys_pair(&attr); signature sign; mpz_init(sign.r); mpz_init(sign.s); make_signature(&sign, &attr, hash); FILE * stream = open_wrapper(write_filepath, "wb"); mpz_out_wrapper(stream, sign.r); mpz_out_wrapper(stream, sign.s); close_wrapper(stream); mpz_clear(sign.r); mpz_clear(sign.s); free_keys_pair(&attr); free_signature_attr(&attr); }