void menu_handle_keys() { // górna para lewo/prawo if ( keys_get(KEYS_S1) ) { menu_pos--; menu_sub_pos = 0; menu_updated = 1; } else if ( keys_get(KEYS_S2) ) { menu_pos++; menu_sub_pos = 0; menu_updated = 1; } // dolna para lewo/prawo if ( keys_get(KEYS_S3) ) { menu_sub_pos--; menu_updated = 1; } else if ( keys_get(KEYS_S4) ) { menu_sub_pos++; menu_updated = 1; } }
static void decrypt_spkg(void) { u16 flags; u16 type; struct keylist *k; flags = be16(pkg + 0x08); type = be16(pkg + 0x0a); hdr_len = be64(pkg + 0x10); dec_size = be64(pkg + 0x18); if (type != 3) fail("no .spkg file"); k = keys_get(KEY_SPKG); if (k == NULL) fail("no key found"); if (sce_decrypt_header(pkg, k) < 0) fail("header decryption failed"); meta_offset = be32(pkg + 0x0c); n_sections = be32(pkg + meta_offset + 0x60 + 0xc); if (n_sections != 3) fail("invalid section count: %d", n_sections); }
static struct keylist *self_load_keys(fileinfo* info) { enum sce_key id; switch (info->app_type) { case 1: id = KEY_LV0; break; case 2: id = KEY_LV1; break; case 3: id = KEY_LV2; break; case 4: id = KEY_APP; break; case 8: id = KEY_APP; break; case 5: id = KEY_ISO; break; case 6: id = KEY_LDR; break; default: fail("invalid type: %08x", info->app_type); } return keys_get(id); }
static struct keylist * load_keys(APP_INFO *app_info) { enum sce_key id; switch (app_info->self_type) { case 1: id = KEY_LV0; break; case 2: id = KEY_LV1; break; case 3: id = KEY_LV2; break; case 4: id = KEY_APP; break; case 5: id = KEY_ISO; break; case 6: id = KEY_LDR; break; case 8: id = KEY_NPDRM; break; default: fprintf (stderr, "SELF type is invalid : 0x%08X\n", app_info->self_type); exit (-4); } return keys_get(id); }
static void read_pkg_header(u8* ptr, fileinfo* info) { info->flags = be16(ptr + 0x08); info->meta_offset = be32(ptr + 0x0c); info->header_len = be64(ptr + 0x10); info->filesize = be64(ptr + 0x18); klist = keys_get(KEY_PKG); }
static void read_spp_header(void) { flags = be16(ptr + 0x08); meta_offset = be32(ptr + 0x0c); header_len = be64(ptr + 0x10); filesize = be64(ptr + 0x18); klist = keys_get(KEY_SPP); }
static int *keys_update(int *base, int key, int val) { int *kv; int n = base[0]; int l = keys_lower_bound(base, key, 0, n); if (l < n) { kv = keys_get(base, l); if (kv[0] == key) { kv[1] = val; } else { int sz = keys_size(n); assert(kv[0] > key); if (n + 1 > sz) { int *tmp; ptrdiff_t diff = kv - base; sz = keys_size(n + 1); tmp = realloc(base, (sz * 2 + 1) * sizeof(int)); if (!tmp) abort(); base = tmp; kv = base + diff; } base[0] = n + 1; memmove(kv + 2, kv, 2 * sizeof(int) * (n - l)); kv[0] = key; kv[1] = val; } } else { int sz = keys_size(n); if (n + 1 > sz) { void * tmp; sz = keys_size(n + 1); tmp = realloc(base, (sz * 2 + 1) * sizeof(int)); if (!tmp) abort(); base = (int *)tmp; } base[0] = n + 1; kv = keys_get(base, l); kv[0] = key; kv[1] = val; } return base; }
void poll_keyboard() { uint8_t key = keys_get(); if (key == 0) { return; } message_stop_beeps(); /* Global keys. */ if (key == KPWR) { sleepy_ = 1; return; } if (state_ == STATE_VIEW) { switch (key) { case KMNU: switch_state(STATE_COMPOSE); break; case KBYE: switch_state(STATE_INFO); break; default: inbox_handle_keypress(key); break; } } else if (state_ == STATE_COMPOSE) { switch (key) { case KMNU: switch_state(STATE_VIEW); break; case KBYE: switch_state(STATE_INFO); break; default: compose_handle_keypress(key); break; } } else if (state_ == STATE_INFO) { switch (key) { case KBYE: case KMNU: switch_state(STATE_VIEW); break; default: info_handle_keypress(key); break; } } }
int key_get(attrib *alist, int key) { attrib *a; assert(key != 0); a = a_find(alist, &at_keys); if (a) { int *keys = (int *)a->data.v; if (keys) { int n = keys[0]; int l = keys_lower_bound(keys, key, 0, n); if (l < n) { int * kv = keys_get(keys, l); if (kv[0] == key) { return kv[1]; } } } } return 0; }
void key_unset(attrib ** alist, int key) { attrib *a; assert(key != 0); a = a_find(*alist, &at_keys); if (a) { int *keys = (int *)a->data.v; if (keys) { int n = keys[0]; int l = keys_lower_bound(keys, key, 0, n); if (l < n) { int *kv = keys_get(keys, l); if (kv[0] == key) { kv[1] = 0; /* do not delete, just set to 0 */ } } } } }
static void parse_pkg_sce(void) { u16 flags; u16 type; u32 hdr_len; u8 *ptr; struct keylist *k; flags = be16(pkg + 0x08); type = be16(pkg + 0x0a); hdr_len = be64(pkg + 0x10); dec_size = be64(pkg + 0x18); if (type != 3) fail("no update .pkg file"); if (flags & 0x8000) { pkg += hdr_len; return parse_pkg(); } k = keys_get(KEY_PKG); if (sce_decrypt_header(pkg, k) < 0) fail("header decryption failed"); if (sce_decrypt_data(pkg) < 0) fail("data decryption failed"); ptr = malloc(dec_size); memset(ptr, 0, dec_size); decompress_pkg(ptr); pkg = ptr; parse_pkg(); }
void main(void) { unsigned char keys; static bit disp_choice; unsigned char t_hour = 15,t_min=45; /*TODO criar struct em RTC.h*/ #ifdef _18F2620 /* Configure the oscillator for the device */ ConfigureOscillator(); #endif /* Initialize I/O and Peripherals for application */ InitApp(); CLRWDT(); power_heat1 = 0; power_heat2 = 0; // No heatelement activated menu_item = 0; sprintf(str_buf, mensagens_main[Forno]); printstr_rs232(str_buf);//"Forno SMD v1.0\n\r"); sprintf(str_buf, mensagens_main[Forno1]); lcd_print_line(str_buf, 0);//"Forno SMD v1.0", 0); sprintf(str_buf, mensagens_main[Inicializando]); lcd_print_line(str_buf, 1);//" Inicializando", 1); Buzzer_stat = 1; for (keys = 50; keys != 0; keys--) wait_1ms(); Buzzer_stat = 0; sprintf(str_buf, mensagens_main[Forno_SMD]); printstr_rs232(str_buf);//"\n\r\n\rForno SMD\n\r"); if (is_24c1024_present() == 0) { sprintf(str_buf, mensagens_main[FALHA]); lcd_print_line(str_buf, 0);//"FALHA DA EEPROM!", 0); sprintf(str_buf, mensagens_main[troque]); lcd_print_line(str_buf, 1);//"troque o 24c1024", 1); while ((keys_get() & KEY_ENTER) == 0) { } }; tmp_log = 0; // Switch off the log-function to preserve EEPROM oven_overshoot = read_byte_24c1024(0x00); // Read the calibration-value keys = ~read_byte_24c1024(0x01); if ( oven_overshoot != keys){ // Check if it is ok. sprintf(str_buf, mensagens_main[Calibracao]); lcd_print_line(str_buf, 0);//"Calibracao", 0); //Else start the calibration-procedure sprintf(str_buf, mensagens_main[ENT]); lcd_print_line(str_buf, 1);//"[ENT] inicia", 1); while ((keys_get() & KEY_ENTER) == 0) { } calibrate(); } read_buffer_24c1024(PROFILES_START_ADR, (unsigned char*) &perfil.profile, sizeof (perfil.profile)); disp_choice = 1; sprintf(str_buf, mensagens_main[DINST]); lcd_print_line(str_buf, 0);//"DINST SMD-OVEN", 0); menu_item = MENU_MIN; while (true) { keys = keys_get(); // get key-status if (keys & KEY_RIGHT) ++menu_item; if (keys & KEY_LEFT) --menu_item; if (menu_item > MENU_MAX) menu_item = MENU_MIN; if (menu_item < MENU_MIN) menu_item = MENU_MAX; if (keys != 0) disp_choice = 1; if (disp_choice != 0) switch (menu_item) { case MENU_START: sprintf(str_buf, mensagens_main[Iniciar]); lcd_print_line(str_buf, 1);//"->Iniciar Solda", 1); break; case MENU_EDIT: sprintf(str_buf, mensagens_main[Editar]); lcd_print_line(str_buf, 1);//"->Editar Perfil", 1); break; case MENU_LOG: sprintf(str_buf, mensagens_main[Registrar]); lcd_print_line(str_buf, 1);//"->Registrar", 1); break; case MENU_CAL: sprintf(str_buf, mensagens_main[Calibrar]); lcd_print_line(str_buf, 1);//"->Calibrar", 1); break; default: menu_item = MENU_MIN; } if (keys & KEY_ENTER) { switch (menu_item) { case MENU_START: controle(); break; case MENU_CAL: calibrate(); break; case MENU_EDIT: edit(); break; case MENU_LOG: logging(); break; default: break; } sprintf(str_buf, mensagens_main[Terminado]); lcd_print_line(str_buf, 0);//"Terminado", 0); sprintf(str_buf, mensagens_main[press]); lcd_print_line(str_buf, 1); //"press [ENT]", 1); while ((keys_get() & KEY_ENTER) == 0) { power_heat1 = 0; power_heat2 = 0; // No heatelement activated }; // lcd_print_line("DINST SMD-OVEN", 0); disp_choice = 1; } // read_time; /*TODO criar rotina de leitura RTC if (secflag) { sprintf(str_buf, mensagens_main[DINST1], t_hour, t_min);//"DINST %2uh%2um", t_hour, t_min); lcd_print_line(str_buf, 0); secflag = 0; } wait_1ms(); power_heat1 = 0; power_heat2 = 0; // No heatelement activated } }
// func. for decrypting the spp file int decrypt_spp(u8* pInSpp, u64* pDecSize, char* pKeyName) { u16 keyrev = 0; u16 type = 0; struct keylist *pMyKeyList = NULL; struct key MyKey = {0}; sce_header_t* pSceHdr = NULL; static u32 meta_offset; static u32 n_sections; u32 hdr_len; int retval = -1; // validate input params if ( (pInSpp == NULL) || (pDecSize == NULL) ) goto exit; // assign sce hdr to start of buffer pSceHdr = (sce_header_t*)pInSpp; // verify SCE header magic! if ( verify_sce_header((u8*)pSceHdr, SIG_SCE_SPP) != STATUS_SUCCESS ) { printf("SCE Header is not a valid SPP header!, exiting!\n"); goto exit; } // derive the hdr offsets keyrev = be16((u8*)&pSceHdr->key_revision); // key-revision type = be16((u8*)&pSceHdr->header_type); // hdr type hdr_len = (u32)be64((u8*)&pSceHdr->header_len); // hdr len *pDecSize = be64((u8*)&pSceHdr->data_len); // data len // check the hdr type if (type != SCE_HEADER_TYPE_SPP) { printf("not a valid SPP file\n"); goto exit; } ///////////////// KEYS LOADING ////////////////////////////////////////// // // If we are OVERRIDING the default key from the 'keys' file, then // attempt to find it, first from the new 'keys' file, and if not, // manually by the exact 'keyname' specified if ( b_DefaultKeyListOverride == TRUE ) { if ( load_singlekey_by_name(pKeyName, &pMyKeyList) != STATUS_SUCCESS ) { // failed to find the 'override' key in 'KEYS' file, // so try 'old-style' keys printf("Error: Failed to find override SPP key(%s) in new \"KEYS\" file, trying old style keys...\n", pKeyName); if ( key_get_old(KEY_SPP, pKeyName, &MyKey) == STATUS_SUCCESS ) { // now populate the "keylist*" with the key we just found if ( load_keylist_from_key(&pMyKeyList, &MyKey) != STATUS_SUCCESS ) { printf("Error: Unexpected failure loading single 'keylist' from 'key' structure....exiting....\n"); goto exit; } } else { printf("key_get() for SPKG key failed"); goto exit; } } } // end if (KeyListOverride....) else { // try to get keys via the new 'keys' format first, if not, // failover to the old keys style if ( load_all_type_keys(&pMyKeyList, KEYTYPE_SPP) != STATUS_SUCCESS ) { printf("Failed to find SPP keys in new \"KEYS\" file, trying old keys files....\n"); // grab the decrypt keys pMyKeyList = keys_get(KEY_SPP); if (pMyKeyList->n == 0) { printf("no key found\n"); goto exit; } } } // //////////////////////////////////////////////////////////////////////////////// // go and decrypt the SPKG hdr if ( sce_decrypt_header_pkgtool(pInSpp, pMyKeyList) != STATUS_SUCCESS ) { printf("header decryption failed\n"); goto exit; } // decrypt the main data if (sce_decrypt_data_pkgtool(pInSpp) < 0) { printf("data decryption failed\n"); goto exit; } // status success retval = STATUS_SUCCESS; exit: // free any alloc'd memory if (pMyKeyList != NULL) free(pMyKeyList); // if we failed, then return "0" if (retval != STATUS_SUCCESS) *pDecSize = 0; return retval; }