/* main_loop: * The main loop of the program. Here we wait for events to come in from * any one of the event sources and react to each one accordingly. While * there are no events to react to the program sleeps and consumes very * little CPU time. See main() to see how the event sources and event queue * are set up. */ static void main_loop(void) { ALLEGRO_EVENT event; log_printf("Focus on the main window (black) and press keys to see events. "); log_printf("Escape quits.\n\n"); while (true) { /* Take the next event out of the event queue, and store it in `event'. */ al_wait_for_event(event_queue, &event); /* Check what type of event we got and act accordingly. ALLEGRO_EVENT * is a union type and interpretation of its contents is dependent on * the event type, which is given by the 'type' field. * * Each event also comes from an event source and has a timestamp. * These are accessible through the 'any.source' and 'any.timestamp' * fields respectively, e.g. 'event.any.timestamp' */ switch (event.type) { /* ALLEGRO_EVENT_KEY_DOWN - a keyboard key was pressed. */ case ALLEGRO_EVENT_KEY_DOWN: if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { return; } log_key("KEY_DOWN", event.keyboard.keycode, 0, 0); break; /* ALLEGRO_EVENT_KEY_UP - a keyboard key was released. */ case ALLEGRO_EVENT_KEY_UP: log_key("KEY_UP", event.keyboard.keycode, 0, 0); break; /* ALLEGRO_EVENT_KEY_CHAR - a character was typed or repeated. */ case ALLEGRO_EVENT_KEY_CHAR: { char const *label = (event.keyboard.repeat ? "repeat" : "KEY_CHAR"); log_key(label, event.keyboard.keycode, event.keyboard.unichar, event.keyboard.modifiers); break; } /* ALLEGRO_EVENT_DISPLAY_CLOSE - the window close button was pressed. */ case ALLEGRO_EVENT_DISPLAY_CLOSE: return; /* We received an event of some type we don't know about. * Just ignore it. */ default: break; } } }
void le_device_db_dump(void){ log_info("Central Device DB dump, devices: %d", le_device_db_count()); int i; for (i=0;i<LE_DEVICE_MEMORY_SIZE;i++){ if (le_devices[i].addr_type == INVALID_ENTRY_ADDR_TYPE) continue; log_info("%u: %u %s", i, le_devices[i].addr_type, bd_addr_to_str(le_devices[i].addr)); log_key("irk", le_devices[i].irk); log_key("csrk", le_devices[i].csrk); } }
/** * List all possible values for a configuration key. * * @param[in] driver The sr_dev_driver struct to query. Must not be NULL. * @param[in] sdi (optional) If the key is specific to a device, this must * contain a pointer to the struct sr_dev_inst to be checked. * Otherwise it must be NULL. If sdi is != NULL, sdi->priv must * also be != NULL. * @param[in] cg The channel group on the device for which to list the * values, or NULL. * @param[in] key The configuration key (SR_CONF_*). * @param[in,out] data A pointer to a GVariant where the list will be stored. * The caller is given ownership of the GVariant and must thus * unref the GVariant after use. However if this function * returns an error code, the field should be considered * unused, and should not be unreferenced. * * @retval SR_OK Success. * @retval SR_ERR Error. * @retval SR_ERR_ARG The driver doesn't know that key, but this is not to be * interpreted as an error by the caller; merely as an indication * that it's not applicable. * * @since 0.3.0 */ SR_API int sr_config_list(const struct sr_dev_driver *driver, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, uint32_t key, GVariant **data) { int ret; if (!driver || !data) return SR_ERR; else if (!driver->config_list) return SR_ERR_ARG; else if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) { if (check_key(driver, sdi, cg, key, SR_CONF_LIST, NULL) != SR_OK) return SR_ERR_ARG; } if (sdi && !sdi->priv) { sr_err("Can't list config (sdi != NULL, sdi->priv == NULL)."); return SR_ERR; } if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK) { log_key(sdi, cg, key, SR_CONF_LIST, *data); g_variant_ref_sink(*data); } return ret; }
/** * Query value of a configuration key at the given driver or device instance. * * @param[in] driver The sr_dev_driver struct to query. Must not be NULL. * @param[in] sdi (optional) If the key is specific to a device, this must * contain a pointer to the struct sr_dev_inst to be checked. * Otherwise it must be NULL. If sdi is != NULL, sdi->priv must * also be != NULL. * @param[in] cg The channel group on the device for which to list the * values, or NULL. * @param[in] key The configuration key (SR_CONF_*). * @param[in,out] data Pointer to a GVariant where the value will be stored. * Must not be NULL. The caller is given ownership of the GVariant * and must thus decrease the refcount after use. However if * this function returns an error code, the field should be * considered unused, and should not be unreferenced. * * @retval SR_OK Success. * @retval SR_ERR Error. * @retval SR_ERR_ARG The driver doesn't know that key, but this is not to be * interpreted as an error by the caller; merely as an indication * that it's not applicable. * * @since 0.3.0 */ SR_API int sr_config_get(const struct sr_dev_driver *driver, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, uint32_t key, GVariant **data) { int ret; if (!driver || !data) return SR_ERR; if (!driver->config_get) return SR_ERR_ARG; if (check_key(driver, sdi, cg, key, SR_CONF_GET, NULL) != SR_OK) return SR_ERR_ARG; if (sdi && !sdi->priv) { sr_err("Can't get config (sdi != NULL, sdi->priv == NULL)."); return SR_ERR; } if ((ret = driver->config_get(key, data, sdi, cg)) == SR_OK) { log_key(sdi, cg, key, SR_CONF_GET, *data); /* Got a floating reference from the driver. Sink it here, * caller will need to unref when done with it. */ g_variant_ref_sink(*data); } return ret; }
int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){ int i; int index = -1; for (i=0;i<LE_DEVICE_MEMORY_SIZE;i++){ if (le_devices[i].addr_type == INVALID_ENTRY_ADDR_TYPE){ index = i; break; } } if (index < 0) return -1; log_info("Central Device DB adding type %u - %s", addr_type, bd_addr_to_str(addr)); log_key("irk", irk); le_devices[index].addr_type = addr_type; memcpy(le_devices[index].addr, addr, 6); memcpy(le_devices[index].irk, irk, 16); le_devices[index].remote_counter = 0; return index; }
/** * Set value of a configuration key in a device instance. * * @param[in] sdi The device instance. Must not be NULL. sdi->driver and * sdi->priv must not be NULL either. * @param[in] cg The channel group on the device for which to list the * values, or NULL. * @param[in] key The configuration key (SR_CONF_*). * @param data The new value for the key, as a GVariant with GVariantType * appropriate to that key. A floating reference can be passed * in; its refcount will be sunk and unreferenced after use. * * @retval SR_OK Success. * @retval SR_ERR Error. * @retval SR_ERR_ARG The driver doesn't know that key, but this is not to be * interpreted as an error by the caller; merely as an indication * that it's not applicable. * * @since 0.3.0 */ SR_API int sr_config_set(const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, uint32_t key, GVariant *data) { int ret; g_variant_ref_sink(data); if (!sdi || !sdi->driver || !sdi->priv || !data) ret = SR_ERR; else if (!sdi->driver->config_set) ret = SR_ERR_ARG; else if (check_key(sdi->driver, sdi, cg, key, SR_CONF_SET, data) != SR_OK) return SR_ERR_ARG; else if ((ret = sr_variant_type_check(key, data)) == SR_OK) { log_key(sdi, cg, key, SR_CONF_SET, data); ret = sdi->driver->config_set(key, data, sdi, cg); } g_variant_unref(data); return ret; }
std::string search_key(Params ¶ms, TypeValidator *validator, size_t series_min, size_t series_max ) { if (validator == NULL) { printf("Validator not found!\n"); return ""; } size_t days = 0; int day_start = params.seed; int deadline = 2; //2 days max //--- int seed = params.seed; char key[0x100]; printf("Searching key started...\n"); #ifdef DEBUG printf("Start seed: %d = %#x\n----------\n", seed, seed); print_time_str(seed); #endif if (series_min != series_max) { #ifdef DEBUG printf("Smart search mode: ON!\nWarning: it works only if the file have a valid modification timestamp!\n"); printf("Series min = %d , max = %d\n----------\n", series_min, series_max); #endif } else { #ifdef DEBUG printf("Smart search mode: OFF!\n"); printf("Series min = %d , max = %d\n----------\n", series_min, series_max); #endif } size_t series = series_min; while (deadline > 0) { srand (seed); for (size_t key_num = 0; key_num < series; key_num++) { make_random_key(key, sizeof(key)); if (validator->testKey(key)) { if (validator->getAccuracy() >= PIVOT_MIN) { #ifdef DEBUG printf("Adjusting seed to to found one!\n"); #endif params.seed = seed; params.key_num = key_num; } printf(">> KEY FOUND: %s\n", key); printf("[SUCCESS]\n"); #ifdef DEBUG printf ("KEY: %s\nSEED %x = %d\nkey number in series: %d\n", key, seed, seed, key_num); #endif log_key(seed, key, key_num, params.filename); return key; } } if (params.incrementalMode) { seed++; } else { seed--; if (series < series_max) { //max number of encrypted files per milisecons series += series_min; } } if (abs(day_start - seed) > DAY_LEN) { day_start = seed; days++; deadline--; printf("%d day passed!\n", days); } } return ""; }