bool table_base::fetch_fact(table_fact & f) const { if(get_signature().functional_columns()==0) { return contains_fact(f); } else { unsigned sig_sz = get_signature().size(); unsigned non_func_cnt = sig_sz-get_signature().functional_columns(); table_base::iterator it = begin(); table_base::iterator iend = end(); table_fact row; for(; it!=iend; ++it) { it->get_fact(row); bool differs = false; for(unsigned i=0; i<non_func_cnt; i++) { if(row[i]!=f[i]) { differs = true; } } if(differs) { continue; } for(unsigned i=non_func_cnt; i<sig_sz; i++) { f[i]=row[i]; } return true; } return false; } }
// returns the number of blocks where the write was not successful. static ssize_t write_test(bdev_t *device) { uint8_t *test_buffer = memalign(DMA_ALIGNMENT, device->block_size); for (bnum_t bnum = 0; bnum < device->block_count; bnum++) { memset(test_buffer, get_signature(bnum), device->block_size); ssize_t err = bio_write_block(device, test_buffer, bnum, 1); if (err < 0) { free(test_buffer); return err; } } size_t num_errors = 0; uint8_t expected_pattern[1]; for (bnum_t bnum = 0; bnum < device->block_count; bnum++) { expected_pattern[0] = get_signature(bnum); if (!is_valid_block(device, bnum, expected_pattern, sizeof(expected_pattern))) { num_errors++; } } free(test_buffer); return num_errors; }
expr_ref udoc_relation::to_formula(tbv const& t) const { udoc_plugin& p = get_plugin(); ast_manager& m = p.get_ast_manager(); expr_ref result(m); expr_ref_vector conjs(m); for (unsigned i = 0; i < get_num_cols(); ++i) { var_ref v(m); v = m.mk_var(i, get_signature()[i]); unsigned lo = column_idx(i); unsigned hi = column_idx(i+1); rational r(0); unsigned lo1 = lo; bool is_x = true; for (unsigned j = lo; j < hi; ++j) { switch(t[j]) { case BIT_0: if (is_x) is_x = false, lo1 = j, r.reset(); break; case BIT_1: if (is_x) is_x = false, lo1 = j, r.reset(); r += rational::power_of_two(j - lo1); break; case BIT_x: if (!is_x) { SASSERT(p.bv.is_bv_sort(get_signature()[i])); conjs.push_back(m.mk_eq(p.bv.mk_extract(j-1-lo,lo1-lo,v), p.bv.mk_numeral(r,j-lo1))); } is_x = true; break; default: UNREACHABLE(); } } if (!is_x) { expr_ref num(m); if (lo1 == lo) { num = p.mk_numeral(r, get_signature()[i]); conjs.push_back(m.mk_eq(v, num)); } else { num = p.bv.mk_numeral(r, hi-lo1); conjs.push_back(m.mk_eq(p.bv.mk_extract(hi-1-lo,lo1-lo,v), num)); } } } result = mk_and(m, conjs.size(), conjs.c_ptr()); return result; }
void state_save_save_finish(void) { UINT32 signature; UINT8 flags = 0; TRACE(logerror("Finishing save\n")); /* compute the flags */ #ifndef LSB_FIRST flags |= SS_MSB_FIRST; #endif /* build up the header */ memcpy(ss_dump_array, ss_magic_num, 8); ss_dump_array[8] = SAVE_VERSION; ss_dump_array[9] = flags; memset(ss_dump_array+0xa, 0, 10); strcpy((char *)ss_dump_array+0xa, Machine->gamedrv->name); /* copy in the signature */ signature = get_signature(); *(UINT32 *)&ss_dump_array[0x14] = LITTLE_ENDIANIZE_INT32(signature); /* write the file */ mame_fwrite(ss_dump_file, ss_dump_array, ss_dump_size); /* free memory and reset the global states */ free(ss_dump_array); ss_dump_array = NULL; ss_dump_size = 0; ss_dump_file = NULL; }
udoc_relation * udoc_relation::clone() const { udoc_relation* result = udoc_plugin::get(get_plugin().mk_empty(get_signature())); for (unsigned i = 0; i < m_elems.size(); ++i) { result->m_elems.push_back(dm.allocate(m_elems[i])); } return result; }
static LLVMValueRef get_prototype(compile_t* c, gentype_t* g, const char *name, ast_t* typeargs, ast_t* fun) { // Behaviours and actor constructors also have sender functions. bool sender = false; switch(ast_id(fun)) { case TK_NEW: sender = g->underlying == TK_ACTOR; break; case TK_BE: sender = true; break; default: {} } // Get a fully qualified name: starts with the type name, followed by the // type arguments, followed by the function name, followed by the function // level type arguments. const char* funname = genname_fun(g->type_name, name, typeargs); // If the function already exists, just return it. LLVMValueRef func = LLVMGetNamedFunction(c->module, funname); if(func != NULL) return func; LLVMTypeRef ftype = get_signature(c, g, fun); if(ftype == NULL) return NULL; // If the function exists now, just return it. func = LLVMGetNamedFunction(c->module, funname); if(func != NULL) return func; if(sender) { // Generate the sender prototype. const char* be_name = genname_be(funname); func = codegen_addfun(c, be_name, ftype); // Change the return type to void for the handler. size_t count = LLVMCountParamTypes(ftype); size_t buf_size = count *sizeof(LLVMTypeRef); LLVMTypeRef* tparams = (LLVMTypeRef*)pool_alloc_size(buf_size); LLVMGetParamTypes(ftype, tparams); ftype = LLVMFunctionType(c->void_type, tparams, (int)count, false); pool_free_size(buf_size, tparams); } // Generate the function prototype. return codegen_addfun(c, funname, ftype); }
external_relation * external_relation::complement(func_decl* p) const { ast_manager& m = m_rel.get_manager(); family_id fid = get_plugin().get_family_id(); expr_ref res(m); expr* rel = m_rel; func_decl_ref fn(m.mk_func_decl(fid, OP_RA_COMPLEMENT,0,0, 1, &rel), m); get_plugin().reduce(fn, 1, &rel, res); return alloc(external_relation, get_plugin(), get_signature(), res); }
void table_base::ensure_fact(const table_fact & f) { if(get_signature().functional_columns()==0) { add_fact(f); } else { remove_fact(f); add_fact(f); } }
external_relation * external_relation::clone() const { ast_manager& m = m_rel.get_manager(); family_id fid = get_plugin().get_family_id(); expr* rel = m_rel.get(); expr_ref res(m.mk_fresh_const("T", m.get_sort(rel)), m); expr* rel_out = res.get(); func_decl_ref fn(m.mk_func_decl(fid, OP_RA_CLONE,0,0, 1, &rel), m); get_plugin().reduce_assign(fn, 1, &rel, 1, &rel_out); return alloc(external_relation, get_plugin(), get_signature(), res); }
void unite_with_data(const relation_fact & f) { if (empty()) { assign_data(f); return; } unsigned n=get_signature().size(); SASSERT(f.size()==n); for (unsigned i=0; i<n; i++) { SASSERT(!is_undefined(i)); m_data[i] = get_plugin().mk_union(m_data[i], f[i]); } }
user_opt user_opt_init(char *api_key, char *api_secret) { user_opt user_info; char * uuid; strcpy(user_info.api_key, api_key); strcpy(user_info.api_secret, api_secret); get_timestamp(user_info.timestamp); uuid = get_uuid(); strcpy(user_info.salt, uuid); get_signature(user_info.timestamp, user_info.salt, user_info.api_secret, user_info.signature); free(uuid); return user_info; }
/** \brief Default method for complementation. It assumes that the compiler creates only tables with at most one column (0 or 1 columns). Complementation of tables with more than one columns is transformed into a cross product of complements and/or difference. */ table_base * table_base::complement(func_decl* p, const table_element * func_columns) const { const table_signature & sig = get_signature(); SASSERT(sig.functional_columns()==0 || func_columns!=0); SASSERT(sig.first_functional() <= 1); table_base * res = get_plugin().mk_empty(sig); table_fact fact; fact.resize(sig.first_functional()); fact.append(sig.functional_columns(), func_columns); if (sig.first_functional() == 0) { if (empty()) { res->add_fact(fact); } return res; } VERIFY(sig.first_functional() == 1); uint64 upper_bound = get_signature()[0]; bool empty_table = empty(); if (upper_bound > (1 << 18)) { std::ostringstream buffer; buffer << "creating large table of size " << upper_bound; if (p) buffer << " for relation " << p->get_name(); warning_msg(buffer.str().c_str()); } for(table_element i = 0; i < upper_bound; i++) { fact[0] = i; if(empty_table || !contains_fact(fact)) { res->add_fact(fact); } } return res; }
/******************************************************************** * メイン処理 ******************************************************************** */ void USBmonit(void) { uchar buf[PACKET_SIZE]; int rc=0; get_signature(); Init_Monitor(); while(1) { rc = USBgetpacket(buf,PACKET_SIZE); if( (rc<0) || (buf[0] != MONIT_SOF) ) return; memcpy(PacketFromPC.raw,buf+1,PACKET_SIZE-1); ProcessIO(); } }
static bool get_visible_signatures( const AmSong* song, const AmTrack* track, AmTime leftTime, AmTime rightTime, AmSignature& leftSig, AmSignature& rightSig) { if (!get_signature(song, track, leftTime, leftSig)) return false; if (!get_signature(song, track, rightTime, rightSig)) return false; /* If the left signature is bisected, get the next one over. */ if ( leftSig.StartTime() < leftTime ) { if (!get_signature(song, track, leftSig.EndTime() + 1, leftSig)) return false; } /* If the right signature is bisected, get the previous one. */ if ( rightSig.EndTime() > rightTime ) { if (rightSig.StartTime() - 1 < 0) return false; if (!get_signature(song, track, rightSig.StartTime() - 1, rightSig)) return false; } /* Only succeed if they are either the same signature or the left is actually * left of the right. */ return leftSig.StartTime() <= rightSig.StartTime(); }
table_base * table_base::clone() const { table_base * res = get_plugin().mk_empty(get_signature()); iterator it = begin(); iterator iend = end(); table_fact row; for(; it!=iend; ++it) { it->get_fact(row); res->add_new_fact(row); } return res; }
void table_base::display(std::ostream & out) const { out << "table with signature "; print_container(get_signature(), out); out << ":\n"; iterator it = begin(); iterator iend = end(); for(; it!=iend; ++it) { const row_interface & r = *it; r.display(out); } out << "\n"; }
LLVMTypeRef genfun_sig(compile_t* c, gentype_t* g, const char *name, ast_t* typeargs) { // If the function already exists, return its type. const char* funname = genname_fun(g->type_name, name, typeargs); LLVMValueRef func = LLVMGetNamedFunction(c->module, funname); if(func != NULL) return LLVMGetElementType(LLVMTypeOf(func)); ast_t* fun = get_fun(g, name, typeargs); LLVMTypeRef type = get_signature(c, g, fun); ast_free_unattached(fun); return type; }
bool table_base::suggest_fact(table_fact & f) { if(get_signature().functional_columns()==0) { if(contains_fact(f)) { return false; } add_new_fact(f); return true; } else { if(fetch_fact(f)) { return false; } add_new_fact(f); return true; } }
state_save_error state_save_read_file(running_machine *machine, mame_file *file) { state_private *global = machine->state_data; UINT32 signature = get_signature(machine); UINT8 header[HEADER_SIZE]; state_callback *func; state_entry *entry; int flip; /* if we have illegal registrations, return an error */ if (global->illegal_regs > 0) return STATERR_ILLEGAL_REGISTRATIONS; /* read the header and turn on compression for the rest of the file */ mame_fcompress(file, FCOMPRESS_NONE); mame_fseek(file, 0, SEEK_SET); if (mame_fread(file, header, sizeof(header)) != sizeof(header)) return STATERR_READ_ERROR; mame_fcompress(file, FCOMPRESS_MEDIUM); /* verify the header and report an error if it doesn't match */ if (validate_header(header, machine->gamedrv->name, signature, popmessage, _("Error: ")) != STATERR_NONE) return STATERR_INVALID_HEADER; /* determine whether or not to flip the data when done */ flip = NATIVE_ENDIAN_VALUE_LE_BE((header[9] & SS_MSB_FIRST) != 0, (header[9] & SS_MSB_FIRST) == 0); /* read all the data, flipping if necessary */ for (entry = global->entrylist; entry != NULL; entry = entry->next) { UINT32 totalsize = entry->typesize * entry->typecount; if (mame_fread(file, entry->data, totalsize) != totalsize) return STATERR_READ_ERROR; /* handle flipping */ if (flip) flip_data(entry); } /* call the post-load functions */ for (func = global->postfunclist; func != NULL; func = func->next) (*func->func.postload)(machine, func->param); return STATERR_NONE; }
libspectrum_error libspectrum_sign_data( libspectrum_byte **signature, size_t *signature_length, libspectrum_byte *data, size_t data_length, libspectrum_rzx_dsa_key *key ) { int error; gcry_mpi_t r, s; error = get_signature( &r, &s, data, data_length, key ); if( error ) return error; error = serialise_mpis( signature, signature_length, r, s ); if( error ) { gcry_mpi_release( r ); gcry_mpi_release( s ); return error; } gcry_mpi_release( r ); gcry_mpi_release( s ); return LIBSPECTRUM_ERROR_NONE; }
AmEvent* ArpVaccineFilter::HandleEvent(AmEvent* event, const am_filter_params* params) { if (!event) return event; if (mFrequency == 0 || mAmount == 0) return event; if (event->Type() != event->NOTEON_TYPE && event->Type() != event->NOTEOFF_TYPE) return event; if ( !ShouldVaccinate(mFrequency) ) return event; ArpVALIDATE(params && params->cur_signature, return event); const AmSignature* curSig = params->cur_signature; AmSignature sig; if ( !get_signature(event->StartTime(), curSig, sig) ) return event; int32 prox = (int32)(proximity_to_beat(event->StartTime(), sig) * 100); float prox2 = (float)abs(mProximity - prox) / 100; // printf("proximity is %ld, that puts prox2 at %f\n", prox, prox2); if (prox2 < 0) prox2 = 0; else if (prox2 > 1) prox2 = 1; prox2 = 1 - prox2; /* If there are tool params, set my amount based on the param data. */ int32 amount = mAmount; if (params->flags&AMFF_TOOL_PARAMS) { if (mAmount >= 0) amount = (int32)(params->view_orig_y_pixel - params->view_cur_y_pixel); else amount = (int32)(params->view_cur_y_pixel - params->view_orig_y_pixel); if (amount < MIN_AMOUNT) amount = MIN_AMOUNT; else if (amount > MAX_AMOUNT) amount = MAX_AMOUNT; } if (event->Type() == event->NOTEON_TYPE) { AmNoteOn* noe = dynamic_cast<AmNoteOn*>(event); if (noe) { int32 vel = noe->Velocity(); float scale = ((float)amount / 100) * prox2; vel = vel + (int32)(vel * scale); if (vel < 0) vel = 0; else if (vel > 127) vel = 127; noe->SetVelocity(vel); } } else if (event->Type() == event->NOTEOFF_TYPE) { } return event; }
int state_save_check_file(mame_file *file, const char *gamename, int validate_signature, void (CLIB_DECL *errormsg)(const char *fmt, ...)) { UINT32 signature = 0; UINT8 header[0x18]; /* if we want to validate the signature, compute it */ if (validate_signature) signature = get_signature(); /* seek to the beginning and read the header */ mame_fseek(file, 0, SEEK_SET); if (mame_fread(file, header, sizeof(header)) != sizeof(header)) { if (errormsg) errormsg("Could not read " APPNAME " save file header"); return -1; } /* let the generic header check work out the rest */ return validate_header(header, gamename, signature, errormsg, ""); }
int state_save_load_begin(mame_file *file) { TRACE(logerror("Beginning load\n")); /* read the file into memory */ ss_dump_size = mame_fsize(file); ss_dump_array = malloc(ss_dump_size); ss_dump_file = file; mame_fread(ss_dump_file, ss_dump_array, ss_dump_size); /* verify the header and report an error if it doesn't match */ if (validate_header(ss_dump_array, NULL, get_signature(), popmessage, "Error: ")) { free(ss_dump_array); return 1; } /* compute the total size and offset of all the entries */ compute_size_and_offsets(); return 0; }
/** * Take a signature and decrypt it. */ static bigint *ICACHE_FLASH_ATTR sig_verify(BI_CTX *ctx, const uint8_t *sig, int sig_len, bigint *modulus, bigint *pub_exp) { int i, size; bigint *decrypted_bi, *dat_bi; bigint *bir = NULL; uint8_t *block = (uint8_t *)os_malloc(sig_len); /* decrypt */ dat_bi = bi_import(ctx, sig, sig_len); ctx->mod_offset = BIGINT_M_OFFSET; /* convert to a normal block */ decrypted_bi = bi_mod_power2(ctx, dat_bi, modulus, pub_exp); bi_export(ctx, decrypted_bi, block, sig_len); ctx->mod_offset = BIGINT_M_OFFSET; i = 10; /* start at the first possible non-padded byte */ while (block[i++] && i < sig_len); size = sig_len - i; /* get only the bit we want */ if (size > 0) { int len; const uint8_t *sig_ptr = get_signature(&block[i], &len); if (sig_ptr) { bir = bi_import(ctx, sig_ptr, len); } } /* save a few bytes of memory */ bi_clear_cache(ctx); os_free(block); return bir; }
state_save_error state_save_check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...)) { UINT8 header[HEADER_SIZE]; UINT32 signature = 0; /* if we want to validate the signature, compute it */ if (machine != NULL) signature = get_signature(machine); /* seek to the beginning and read the header */ mame_fcompress(file, FCOMPRESS_NONE); mame_fseek(file, 0, SEEK_SET); if (mame_fread(file, header, sizeof(header)) != sizeof(header)) { if (errormsg != NULL) (*errormsg)(_("Could not read " APPNAME " save file header")); return STATERR_READ_ERROR; } /* let the generic header check work out the rest */ return validate_header(header, gamename, signature, errormsg, ""); }
static UINT search_sig_name( MSIPACKAGE *package, const WCHAR *sigName, MSISIGNATURE *sig, WCHAR **appValue ) { UINT rc; *appValue = NULL; rc = get_signature( package, sig, sigName ); if (rc == ERROR_SUCCESS) { rc = search_components( package, appValue, sig ); if (rc == ERROR_SUCCESS && !*appValue) { rc = search_reg( package, appValue, sig ); if (rc == ERROR_SUCCESS && !*appValue) { rc = search_ini( package, appValue, sig ); if (rc == ERROR_SUCCESS && !*appValue) rc = search_dr( package, appValue, sig ); } } } return rc; }
state_save_error state_save_write_file(running_machine *machine, mame_file *file) { state_private *global = machine->state_data; UINT32 signature = get_signature(machine); UINT8 header[HEADER_SIZE]; state_callback *func; state_entry *entry; /* if we have illegal registrations, return an error */ if (global->illegal_regs > 0) return STATERR_ILLEGAL_REGISTRATIONS; /* generate the header */ memcpy(&header[0], ss_magic_num, 8); header[8] = SAVE_VERSION; header[9] = NATIVE_ENDIAN_VALUE_LE_BE(0, SS_MSB_FIRST); strncpy((char *)&header[0x0a], machine->gamedrv->name, 0x1c - 0x0a); *(UINT32 *)&header[0x1c] = LITTLE_ENDIANIZE_INT32(signature); /* write the header and turn on compression for the rest of the file */ mame_fcompress(file, FCOMPRESS_NONE); mame_fseek(file, 0, SEEK_SET); if (mame_fwrite(file, header, sizeof(header)) != sizeof(header)) return STATERR_WRITE_ERROR; mame_fcompress(file, FCOMPRESS_MEDIUM); /* call the pre-save functions */ for (func = global->prefunclist; func != NULL; func = func->next) (*func->func.presave)(machine, func->param); /* then write all the data */ for (entry = global->entrylist; entry != NULL; entry = entry->next) { UINT32 totalsize = entry->typesize * entry->typecount; if (mame_fwrite(file, entry->data, totalsize) != totalsize) return STATERR_WRITE_ERROR; } return STATERR_NONE; }
inline entry_t xml_db_file_source::get_entry( rapidxml::xml_node<>* node ) { entry_t entry; if ( std::memcmp( node->name(), "entry", node->name_size() ) != 0 ) throw std::runtime_error( "invalid db file" ); for ( rapidxml::xml_attribute<>* attr = node->first_attribute(); attr; attr = attr->next_attribute() ) { if ( std::memcmp( attr->name(), "name", attr->name_size() ) == 0 ) entry.name = normalize_string( attr->value() ); else if ( std::memcmp( attr->name(), "url", attr->name_size() ) == 0 ) entry.url = normalize_string( attr->value() ); else if ( std::memcmp( attr->name(), "description", attr->name_size() ) == 0 ) entry.description = normalize_string( attr->value() ); else if ( std::memcmp( attr->name(), "author", attr->name_size() ) == 0 ) entry.author = normalize_string( attr->value() ); else if ( std::memcmp( attr->name(), "priority", attr->name_size() ) == 0 ) entry.priority = normalize_string( attr->value() ); else throw std::runtime_error( "invalid db file" ); } for ( rapidxml::xml_node<>* next_node = node->first_node(); next_node; next_node = next_node->next_sibling() ) { if ( std::memcmp( next_node->name(), "signature", next_node->name_size() ) == 0 ) entry.signatures.push_back( get_signature( next_node ) ); else if ( std::memcmp( next_node->name(), "unpacker", next_node->name_size() ) == 0 ) entry.unpackers.push_back( get_unpacker( next_node ) ); else throw std::runtime_error( "invalid db file" ); } return entry; }
udoc_relation * udoc_relation::complement(func_decl* f) const { udoc_relation* result = udoc_plugin::get(get_plugin().mk_empty(get_signature())); m_elems.complement(dm, result->m_elems); return result; }
void table_base::remove_facts(unsigned fact_cnt, const table_element * facts) { for(unsigned i=0; i<fact_cnt; i++) { remove_fact(facts + i*get_signature().size()); } }