void hashmap_put(HashMap *hashmap, const char *key, void *value) { assert(hashmap != NULL); assert(key != NULL); int h = entry_key_hash(key); int hash = key_hash(h); int index = index_for_hash(hash, hashmap->capacity_); for (Entry *entry = hashmap->entries_[index]; entry; entry = entry->next_) { if (hash == entry->hash_ || strcmp(entry->key_, key) == 0) { void *old_data = entry->data_; if (value == old_data) { return; } if (hashmap->on_entry_removed_) { hashmap->on_entry_removed_(entry->key_, old_data); } entry->data_ = value; return; } } add_entry(hashmap, hash, key, value, index); }
void smatrix::operator +=(const smatrix & m) { assert (nrows == m.get_nrows() && ncols == m.get_ncols()); node *cursor = head_ptr, * m_cursor = m.head_ptr; while (m_cursor != NULL) { if (cursor == NULL || (m_cursor->data() < cursor->data())) { add_entry(m_cursor->data()); m_cursor = m_cursor->link(); } else if (cursor->data() == m_cursor->data()) { entry new_data(cursor->data().r, cursor->data().c, cursor->data().v + m_cursor->data().v); cursor->set_data(new_data); m_cursor = m_cursor->link(); cursor = cursor->link(); } else cursor = cursor->link(); } }
static int load_entries(struct search *search, size_t offset) { if (find_first_entry(search->file, search->key, &offset) != 0) return -1; while (!is_full(search) && offset < search->size) { struct entry entry; if (get_entry(search->file, offset, &entry) != 0) return -1; if (entry.key != search->key) return 0; if (entry.weight != 0 && entry.move != 0) add_entry(search, &entry); ++offset; } return 0; }
void test_WriteFileWithSingleEntry(void) { kod_db_file = estrdup("kod-output-single"); add_entry("host1", "DENY"); // Here we must manipulate the timestamps, so they match the one in // the expected file. kod_db[0]->timestamp = 1; write_kod_db(); // Open file and compare sizes. FILE * actual = fopen(kod_db_file, "rb"); FILE * expected = fopen(CreatePath("kod-expected-single", INPUT_DIR),"rb"); TEST_ASSERT_NOT_NULL(actual); TEST_ASSERT_NOT_NULL(expected); TEST_ASSERT_EQUAL(GetFileSize(expected), GetFileSize(actual)); TEST_ASSERT_TRUE(CompareFileContent(expected, actual)); }
/*----------------------------------------------------------------------------*/ void test_flowtable(void) { uint8_t array[25] = { 20, 18, 0, 6, 0, 2, 82, 0, 15, 0, 1, 114, 0, 16, 0, 2, 50, 0, 17, 0, 5, 1, 4, 254, 0}; if (!list_length(flowtable)){ entry_t* e = get_entry_from_array(array,25); if (e != NULL){ add_entry(e); } }else{ entry_free(list_pop(flowtable)); } uint8_t array1[116] = { 1, 116, 0, 0, 0, 2, 2, 100, 0, 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 90, 10, 10, 10, 11, 22, 10, 12, 10, 35, 11, 14, 18, 16, 12, 10, 10, 10, 40, 40, 10, 18, 15, 11, 10, 10, 10, 10, 10, 50, 11, 13, 13, 12, 25, 25, 31, 11, 01, 61, 11, 17, 18, 16, 13, 10, 11, 10, 12, 71, 11, 17, 18, 16, 13, 10, 11, 10, 12, 81, 11, 17, 18, 16, 13, 10, 11, 10, 12, 91, 11, 17, 18, 16, 13, 10, 11, 10, 12, 11, 11, 17, 18, 16, 13, 10, 11, 10, 12, 10, 13, 254,11, 12, 13 }; packet_t* p = get_packet_from_array(array1); match_packet(p); packet_deallocate(p); }
static bool create_four_story_trie(void) { bool success = true; success &= add_entry("1.0.0.0", 32, "1::", 16); success &= add_entry("2.0.0.0", 32, "1:1::", 32); success &= add_entry("3.0.0.0", 32, "1:2::", 32); success &= add_entry("4.0.0.0", 32, "1:1:1::", 48); success &= add_entry("5.0.0.0", 32, "1:1:2::", 48); success &= add_entry("6.0.0.0", 32, "1:2:1::", 48); success &= add_entry("7.0.0.0", 32, "1:2:1:1::", 64); success &= remove_entry(NULL, 0, "1::", 0, -ESRCH); success &= remove_entry(NULL, 0, "1::", 15, -ESRCH); success &= remove_entry(NULL, 0, "1::", 17, -ESRCH); success &= remove_entry(NULL, 0, "1::", 128, -ESRCH); success &= remove_entry(NULL, 0, "1:2::", 0, -ESRCH); success &= remove_entry(NULL, 0, "1:2::", 31, -ESRCH); success &= remove_entry(NULL, 0, "1:2::", 33, -ESRCH); success &= remove_entry(NULL, 0, "1:2::", 128, -ESRCH); success &= remove_entry(NULL, 0, "1:1:2::", 0, -ESRCH); success &= remove_entry(NULL, 0, "1:1:2::", 47, -ESRCH); success &= remove_entry(NULL, 0, "1:1:2::", 49, -ESRCH); success &= remove_entry(NULL, 0, "1:1:2::", 128, -ESRCH); success &= remove_entry(NULL, 0, "1:2:1:1::", 0, -ESRCH); success &= remove_entry(NULL, 0, "1:2:1:1::", 63, -ESRCH); success &= remove_entry(NULL, 0, "1:2:1:1::", 65, -ESRCH); success &= remove_entry(NULL, 0, "1:2:1:1::", 128, -ESRCH); success &= test("1.0.0.0", "1::"); success &= test("2.0.0.0", "1:1::"); success &= test("3.0.0.0", "1:2::"); success &= test("4.0.0.0", "1:1:1::"); success &= test("5.0.0.0", "1:1:2::"); success &= test("6.0.0.0", "1:2:1::"); success &= test("7.0.0.0", "1:2:1:1::"); return success; }
/* For Next function */ int opcode_for(int program_counter, char *buf) { int pcounter = 0; int res = 0; /* Check if the loop already exists */ if(find_end(program_counter) == INVALID_LOOP) { add_entry(program_counter); } /* Evaluate For Condition */ str_addnewline(buf); res = eval_exp(buf); if(res) { /* Condition Valid = Execute loop */ pcounter = program_counter; } else { /* Condition Invalid = Exit loop */ pcounter = find_end(program_counter); } return pcounter; }
/* Read and parse a .dev file. Return the union of all its uniq_mode_ts. */ int read_dev(config_t * pconf, const char *arg) { string_item_t *item; const char *in; #define MAX_TOKEN 256 char *token = malloc(MAX_TOKEN + 1); char *category = malloc(MAX_TOKEN + 1); int file_index; int len; if (pconf->debug) printf("Reading %s;\n", arg); item = read_file(pconf, arg); if (item->index == uniq_first) { /* Don't need to read the file again. */ if (pconf->debug) printf("Skipping duplicate file.\n"); return uniq_first; } in = item->str; file_index = item - pconf->file_contents.items; strcpy(category, "obj"); while ((len = read_token(token, MAX_TOKEN, &in)) > 0) item->index |= add_entry(pconf, category, token, file_index); free(category); #undef MAX_TOKEN if (len < 0) { fprintf(stderr, "Token too long: %s.\n", token); exit(1); } if (pconf->debug) printf("Finished %s.\n", arg); free(token); return item->index; }
//---------------------------------------------------------------------- static void process_symbol_class(uint32 ea, uchar sclass, const char *name) { switch ( sclass ) { case kPEFCodeSymbol : case kPEFGlueSymbol : add_entry(ea, ea, name, 1); break; case kPEFTVectSymbol: process_vector(ea, name); break; case kPEFTOCSymbol : if ( segtype(ea) == SEG_DATA && ea < toc_ea ) { toc_ea = ea; ph.notify(processor_t::idp_notify(ph.loader+1), toc_ea); } toc.charset(ea, XMC_TD+1, 1); /* fall thru */ case kPEFDataSymbol : set_name(ea, name); break; } }
void selection_column::on_change( const inventory_entry &entry ) { inventory_entry my_entry( entry, selected_cat.get() ); const auto iter = std::find( entries.begin(), entries.end(), my_entry ); if( my_entry.chosen_count != 0 ) { if( iter == entries.end() ) { add_entry( my_entry ); } else { iter->chosen_count = my_entry.chosen_count; } } else { entries.erase( iter ); } prepare_paging(); // Now let's update selection const auto select_iter = std::find( entries.begin(), entries.end(), my_entry ); if( select_iter != entries.end() ) { select( std::distance( entries.begin(), select_iter ) ); } else { select( entries.empty() ? 0 : entries.size() - 1 ); // Just select the last one } }
void add_entry_rip(uint32_t network, uint32_t next_hop, char *interface, uint32_t mask, uint32_t metric) { printf("Debug: Adding route: Network: "); print_ip(network); printf(" ,Mask : "); print_ip(mask); printf(" ,Next hop : "); print_ip(next_hop); printf(" ,Interface : %s, Metric : %d", interface, metric); printf("\n"); /* Create entry */ router_entry *r_node = malloc(sizeof(router_entry)); r_node->network = network; r_node->next_hop = next_hop; r_node->mask = mask;; r_node->metric = metric; strcpy(r_node->interface, interface); /* Add entry */ add_entry(r_node); globals.rtable_keys[globals.rtable_size] = network; globals.rtable_size++; }
ContribLevelsetMenu::ContribLevelsetMenu(std::unique_ptr<World> world) : m_world(std::move(world)), m_levelset() { assert(m_world->is_levelset()); m_levelset = std::unique_ptr<Levelset>(new Levelset(m_world->get_basedir())); auto savegame = Savegame::from_file(m_world->get_savegame_filename()); LevelsetState state = savegame->get_levelset_state(m_world->get_basedir()); add_label(m_world->get_title()); add_hl(); for (int i = 0; i < m_levelset->get_num_levels(); ++i) { std::string filename = m_levelset->get_level_filename(i); std::string full_filename = FileSystem::join(m_world->get_basedir(), filename); std::string title = LevelParser::get_level_name(full_filename); LevelState level_state = state.get_level_state(filename); std::ostringstream out; if (level_state.solved) { out << title << " [*]"; } else { out << title << " [ ]"; } add_entry(i, out.str()); } add_hl(); add_back(_("Back")); }
int main() { struct link **book; book = new_book(); book = add_entry(book, "Eddie", "*****@*****.**"); book = add_entry(book, "Ed", "*****@*****.**"); book = add_entry(book, "HughJazz", "*****@*****.**"); book = add_entry(book, "SeymorButz", "*****@*****.**"); book = add_entry(book, "Fry", "*****@*****.**"); book = add_entry(book, "Bender", "*****@*****.**"); //OPEN FILE int fd = open("book.dat", O_CREAT | O_RDWR, 0644); //WRITE TO FILE int b; char n[256]; char e[256]; int a; struct link *p; p = (struct link *)malloc(sizeof(struct link)); for (a=0; a<26; a++){ p = book[a]; while(p){ strncpy(n, return_name(p), 256); strncpy(e, return_email(p), 256); b = write(fd, n, 256); b = write(fd, e, 256); p = p->next; } } book = free_book( book ); free(book); return 0; }
void place_rwp_node (node_struct * node) { int loc_num; double block_xmin, block_ymin; if (omg_param_list[node->type].rwp_type == RESTIRICTED_RWP) { loc_num = (int) randomgen (0, omg_param_list[node->type].max_vertices); node->x_pos = (double) vertice_xpos (loc_num, omg_param_list[node->type]); node->y_pos = (double) vertice_ypos (loc_num, omg_param_list[node->type]); //LOG_D(OMG,"location number %d x pos %.2f y pos %.2f \n\n",loc_num,node->x_pos,node->y_pos); } else if (omg_param_list[node->type].rwp_type == CONNECTED_DOMAIN) { node->block_num = (int) randomgen (0, omg_param_list[node->type].max_block_num); block_xmin = area_minx (node->block_num, omg_param_list[node->type]); block_ymin = area_miny (node->block_num, omg_param_list[node->type]); node->x_pos = (double) ((int) (randomgen (block_xmin, xloc_div + block_xmin) * 100)) / 100; node->y_pos = (double) ((int) (randomgen (block_ymin, yloc_div + block_ymin) * 100)) / 100; } else { node->x_pos = (double) ((int) (randomgen (omg_param_list[node->type].min_x, omg_param_list[node->type].max_x) * 100)) / 100; node->y_pos = (double) ((int) (randomgen (omg_param_list[node->type].min_y, omg_param_list[node->type].max_y) * 100)) / 100; } node->mob->x_from = node->x_pos; node->mob->x_to = node->x_pos; node->mob->y_from = node->y_pos; node->mob->y_to = node->y_pos; node->mob->speed = 0.0; node->mob->journey_time = 0.0; LOG_I (OMG, " #[RWP] Initial position of node ID: %d type: %d (X = %.2f, Y = %.2f) speed = 0.0\n ", node->id, node->type, node->x_pos, node->y_pos); node_vector_end[node->type] = (node_list *) add_entry (node, node_vector_end[node->type]); if (node_vector[node->type] == NULL) node_vector[node->type] = node_vector_end[node->type]; node_vector_len[node->type]++; //Initial_Node_Vector_len[RWP]++; }
/* * DirReadParameters * * Parse the parameters and switches of the command line and exports them */ static BOOL DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & switches */ LPTSTR** params, /* [OUT] The parameters after parsing */ LPINT entries, /* [OUT] The number of parameters after parsing */ LPDIRSWITCHFLAGS lpFlags) /* [IN/OUT] The flags after calculating switches */ { TCHAR cCurSwitch; /* The current switch */ TCHAR cCurChar; /* Current examing character */ TCHAR cCurUChar; /* Current upper examing character */ BOOL bNegative; /* Negative switch */ BOOL bPNegative; /* Negative switch parameter */ BOOL bIntoQuotes; /* A flag showing if we are in quotes (") */ LPTSTR ptrStart; /* A pointer to the first character of a parameter */ LPTSTR ptrEnd; /* A pointer to the last character of a parameter */ BOOL bOrderByNoPar; /* A flag to indicate /O with no switch parameter */ LPTSTR temp; /* Initialize parameter array */ *params = NULL; *entries = 0; /* Initialize variables; */ cCurSwitch = _T(' '); bNegative = FALSE; bPNegative = FALSE; /* We suppose that switch parameters were given to avoid setting them to default if the switch was not given */ bOrderByNoPar = FALSE; /* Main Loop (see README_DIR.txt) */ /* scan the command line char per char, and we process its char */ while (*Line) { /* we save current character as it is and its upper case */ cCurChar = *Line; cCurUChar = _totupper(*Line); /* 1st section (see README_DIR.txt) */ /* When a switch is expecting */ if (cCurSwitch == _T('/')) { while (*Line == _T(' ')) Line++; bNegative = (*Line == _T('-')); Line += bNegative; cCurChar = *Line; cCurUChar = _totupper(*Line); if ((cCurUChar == _T('A')) ||(cCurUChar == _T('T')) || (cCurUChar == _T('O'))) { /* If positive, prepare for parameters... if negative, reset to defaults */ switch (cCurUChar) { case _T('A'): lpFlags->stAttribs.dwAttribVal = 0L; lpFlags->stAttribs.dwAttribMask = 0L; if (bNegative) lpFlags->stAttribs.dwAttribMask = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM; break; case _T('T'): if (bNegative) lpFlags->stTimeField.eTimeField = TF_MODIFIEDDATE; break; case _T('O'): bOrderByNoPar = !bNegative; lpFlags->stOrderBy.sCriteriaCount = 0; break; } if (!bNegative) { /* Positive switch, so it can take parameters. */ cCurSwitch = cCurUChar; Line++; /* Skip optional leading colon */ if (*Line == _T(':')) Line++; continue; } } else if (cCurUChar == _T('L')) lpFlags->bLowerCase = ! bNegative; else if (cCurUChar == _T('B')) lpFlags->bBareFormat = ! bNegative; else if (cCurUChar == _T('C')) lpFlags->bTSeperator = ! bNegative; else if (cCurUChar == _T('W')) lpFlags->bWideList = ! bNegative; else if (cCurUChar == _T('D')) lpFlags->bWideListColSort = ! bNegative; else if (cCurUChar == _T('N')) lpFlags->bNewLongList = ! bNegative; else if (cCurUChar == _T('P')) lpFlags->bPause = ! bNegative; else if (cCurUChar == _T('Q')) lpFlags->bUser = ! bNegative; else if (cCurUChar == _T('S')) lpFlags->bRecursive = ! bNegative; else if (cCurUChar == _T('X')) lpFlags->bShortName = ! bNegative; else if (cCurChar == _T('4')) lpFlags->b4Digit = ! bNegative; else if (cCurChar == _T('?')) { DirHelp(); return FALSE; } else { error_invalid_switch ((TCHAR)_totupper (*Line)); return FALSE; } /* Make sure there's no extra characters at the end of the switch */ if (Line[1] && Line[1] != _T('/') && Line[1] != _T(' ')) { error_parameter_format(Line[1]); return FALSE; } cCurSwitch = _T(' '); } else if (cCurSwitch == _T(' ')) { /* 2nd section (see README_DIR.txt) */ /* We are expecting parameter or the unknown */ if (cCurChar == _T('/')) cCurSwitch = _T('/'); else if (cCurChar == _T(' ')) /* do nothing */; else { /* This is a file/directory name parameter. Find its end */ ptrStart = Line; bIntoQuotes = FALSE; while (*Line) { if (!bIntoQuotes && (*Line == _T('/') || *Line == _T(' '))) break; bIntoQuotes ^= (*Line == _T('"')); Line++; } ptrEnd = Line; /* Copy it to the entries list */ temp = cmd_alloc((ptrEnd - ptrStart + 1) * sizeof (TCHAR)); if(!temp) return FALSE; memcpy(temp, ptrStart, (ptrEnd - ptrStart) * sizeof (TCHAR)); temp[ptrEnd - ptrStart] = _T('\0'); StripQuotes(temp); if(!add_entry(entries, params, temp)) { cmd_free(temp); freep(*params); return FALSE; } cmd_free(temp); continue; } } else { /* 3rd section (see README_DIR.txt) */ /* We are waiting for switch parameters */ /* Check if there are no more switch parameters */ if ((cCurChar == _T('/')) || ( cCurChar == _T(' '))) { /* Wrong desicion path, reprocess current character */ cCurSwitch = _T(' '); continue; } /* Process parameter switch */ switch(cCurSwitch) { case _T('A'): /* Switch parameters for /A (attributes filter) */ if(cCurChar == _T('-')) bPNegative = TRUE; else if(cCurUChar == _T('D')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_DIRECTORY; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_DIRECTORY; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_DIRECTORY; } else if(cCurUChar == _T('R')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_READONLY; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_READONLY; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_READONLY; } else if(cCurUChar == _T('H')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_HIDDEN; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_HIDDEN; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_HIDDEN; } else if(cCurUChar == _T('A')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_ARCHIVE; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_ARCHIVE; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_ARCHIVE; } else if(cCurUChar == _T('S')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_SYSTEM; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_SYSTEM; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_SYSTEM; } else { error_parameter_format((TCHAR)_totupper (*Line)); return FALSE; } break; case _T('T'): /* Switch parameters for /T (time field) */ if(cCurUChar == _T('C')) lpFlags->stTimeField.eTimeField= TF_CREATIONDATE ; else if(cCurUChar == _T('A')) lpFlags->stTimeField.eTimeField= TF_LASTACCESSEDDATE ; else if(cCurUChar == _T('W')) lpFlags->stTimeField.eTimeField= TF_MODIFIEDDATE ; else { error_parameter_format((TCHAR)_totupper (*Line)); return FALSE; } break; case _T('O'): /* Switch parameters for /O (order) */ /* Ok a switch parameter was given */ bOrderByNoPar = FALSE; if(cCurChar == _T('-')) bPNegative = TRUE; else if(cCurUChar == _T('N')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_NAME; } else if(cCurUChar == _T('S')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_SIZE; } else if(cCurUChar == _T('G')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_DIRECTORY; } else if(cCurUChar == _T('E')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_EXTENSION; } else if(cCurUChar == _T('D')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_TIME; } else { error_parameter_format((TCHAR)_totupper (*Line)); return FALSE; } } /* We check if we calculated the negative value and realese the flag */ if ((cCurChar != _T('-')) && bPNegative) bPNegative = FALSE; } Line++; } /* /O with no switch parameters acts like /O:GN */ if (bOrderByNoPar) { lpFlags->stOrderBy.sCriteriaCount = 2; lpFlags->stOrderBy.eCriteria[0] = ORDER_DIRECTORY; lpFlags->stOrderBy.bCriteriaRev[0] = FALSE; lpFlags->stOrderBy.eCriteria[1] = ORDER_NAME; lpFlags->stOrderBy.bCriteriaRev[1] = FALSE; } return TRUE; }
/** \ingroup ConfigParsers */ play_tree_t* m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv) { int i,j,start_title=-1,end_title=-1; char *opt,*splitpos=NULL; char entbuf[15]; int no_more_opts = 0; int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything play_tree_t *last_parent, *last_entry = NULL, *root; #ifdef MP_DEBUG assert(config != NULL); assert(argv != NULL); assert(argc >= 1); #endif config->mode = M_COMMAND_LINE; mode = GLOBAL; #ifdef CONFIG_MACOSX_FINDER root=macosx_finder_args(config, argc, argv); if(root) return root; #endif last_parent = root = play_tree_new(); for (i = 1; i < argc; i++) { //next: opt = argv[i]; /* check for -- (no more options id.) except --help! */ if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0)) { no_more_opts = 1; if (i+1 >= argc) { mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_NoFileGivenOnCommandLine); goto err_out; } continue; } if((opt[0] == '{') && (opt[1] == '\0')) { play_tree_t* entry = play_tree_new(); UNSET_GLOBAL; if(last_parent->flags & PLAY_TREE_RND) entry->flags |= PLAY_TREE_RND; if(last_entry == NULL) { play_tree_set_child(last_parent,entry); } else { play_tree_append_entry(last_entry,entry); last_entry = NULL; } last_parent = entry; continue; } if((opt[0] == '}') && (opt[1] == '\0')) { if( ! last_parent || ! last_parent->parent) { mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too much }-\n"); goto err_out; } last_entry = last_parent; last_parent = last_entry->parent; continue; } if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */ { int tmp = 0; /* remove trailing '-' */ opt++; mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt); // We handle here some specific option // Loop option when it apply to a group if(strcasecmp(opt,"loop") == 0 && (! last_entry || last_entry->child) ) { int l; char* end = NULL; l = (i+1<argc) ? strtol(argv[i+1],&end,0) : 0; if(!end || *end != '\0') { mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_TheLoopOptionMustBeAnInteger, argv[i+1]); tmp = ERR_OUT_OF_RANGE; } else { play_tree_t* pt = last_entry ? last_entry : last_parent; l = l <= 0 ? -1 : l; pt->loop = l; tmp = 1; } } else if(strcasecmp(opt,"shuffle") == 0) { if(last_entry && last_entry->child) last_entry->flags |= PLAY_TREE_RND; else last_parent->flags |= PLAY_TREE_RND; } else if(strcasecmp(opt,"noshuffle") == 0) { if(last_entry && last_entry->child) last_entry->flags &= ~PLAY_TREE_RND; else last_parent->flags &= ~PLAY_TREE_RND; } else { const m_option_t* mp_opt = NULL; play_tree_t* entry = NULL; tmp = is_entry_option(opt,(i+1<argc) ? argv[i + 1] : NULL,&entry); if(tmp > 0) { // It's an entry if(entry) { add_entry(&last_parent,&last_entry,entry); if((last_parent->flags & PLAY_TREE_RND) && entry->child) entry->flags |= PLAY_TREE_RND; UNSET_GLOBAL; } else if(mode == LOCAL) // Entry is empty we have to drop his params mode = DROP_LOCAL; } else if(tmp == 0) { // 'normal' options mp_opt = m_config_get_option(config,opt); if (mp_opt != NULL) { // Option exist if(mode == GLOBAL || (mp_opt->flags & M_OPT_GLOBAL)) tmp = (i+1<argc) ? m_config_set_option(config, opt, argv[i + 1]) : m_config_set_option(config, opt, NULL); else { tmp = m_config_check_option(config, opt, (i+1<argc) ? argv[i + 1] : NULL); if(tmp >= 0 && mode != DROP_LOCAL) { play_tree_t* pt = last_entry ? last_entry : last_parent; play_tree_set_param(pt,opt, argv[i + 1]); } } } else { tmp = M_OPT_UNKNOWN; mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_UnknownOptionOnCommandLine, opt); } } } if (tmp <= M_OPT_EXIT) { opt_exit = 1; tmp = M_OPT_EXIT - tmp; } else if (tmp < 0) { mp_msg(MSGT_CFGPARSER, MSGL_FATAL, MSGTR_ErrorParsingOptionOnCommandLine, opt); goto err_out; } i += tmp; } else /* filename */ { int is_dvdnav = strstr(argv[i],"dvdnav://") != NULL; play_tree_t* entry = play_tree_new(); mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]); // if required expand DVD filename entries like dvd://1-3 into component titles if ( strstr(argv[i],"dvd://") != NULL || is_dvdnav) { int offset = is_dvdnav ? 9 : 6; splitpos=strstr(argv[i]+offset,"-"); if(splitpos != NULL) { start_title=strtol(argv[i]+offset,NULL,10); if (start_title<0) { //entries like dvd://-2 start title implied 1 end_title=abs(start_title); start_title=1; } else { end_title=strtol(splitpos+1,NULL,10); } if (dvd_range(start_title) && dvd_range(end_title) && (start_title<end_title)) { for (j=start_title;j<=end_title;j++) { if (j!=start_title) entry=play_tree_new(); snprintf(entbuf,sizeof(entbuf),is_dvdnav ? "dvdnav://%d" : "dvd://%d",j); play_tree_add_file(entry,entbuf); add_entry(&last_parent,&last_entry,entry); last_entry = entry; } } else { mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_InvalidPlayEntry, argv[i]); } } else { // dvd:// or dvd://x entry play_tree_add_file(entry,argv[i]); } } else { play_tree_add_file(entry,argv[i]); } // Lock stdin if it will be used as input if(strcasecmp(argv[i],"-") == 0) m_config_set_option(config,"noconsolecontrols",NULL); add_entry(&last_parent,&last_entry,entry); UNSET_GLOBAL; // We start entry specific options } } if (opt_exit) goto err_out; if(last_parent != root) mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n"); return root; err_out: play_tree_free(root,1); return NULL; }
int get_url_info() { char temp[MAX_WEB_LEN + MAX_FOLDER_LEN], *temp1, *temp2, web[MAX_WEB_LEN], folder[MAX_FOLDER_LEN]; //<< [BCMBG-NTWK-102] Jim Lin: Fix issue as if web A with port A and web B with port B are only allowed rules in URL filter, web A with port B will get bypassed, 20131018 char *ptr1; //>> [BCMBG-NTWK-102] end FILE *f = fopen("/var/url_list", "r"); if (f != NULL) { while (fgets(temp,96, f) != '\0') { //<< [BCMBG-NTWK-102] Jim Lin: Fix issue as if web A with port A and web B with port B are only allowed rules in URL filter, web A with port B will get bypassed, 20131018 if(ptr1=strstr(temp,"###")) { *ptr1 = '\0'; ptr1+=3; } //>> [BCMBG-NTWK-102] end if (temp[0]=='h' && temp[1]=='t' && temp[2]=='t' && temp[3]=='p' && temp[4]==':' && temp[5]=='/' && temp[6]=='/') { temp1 = temp + 7; } else { temp1 = temp; } if ((*temp1=='w') && (*(temp1+1)=='w') && (*(temp1+2)=='w') && (*(temp1+3)=='.')) { temp1 = temp1 + 4; } if ((temp2 = strchr(temp1, '\n'))) { *temp2 = '\0'; } sscanf(temp1, "%[^/]", web); temp1 = strchr(temp1, '/'); if (temp1 == NULL) { strcpy(folder, "\0"); } else { strcpy(folder, ++temp1); } //<< [BCMBG-NTWK-102] Jim Lin: Fix issue as if web A with port A and web B with port B are only allowed rules in URL filter, web A with port B will get bypassed, 20131018 #if 0 add_entry(web, folder); #else add_entry(web, folder, ptr1); #endif //>> [BCMBG-NTWK-102] end list_count ++; } fclose(f); } #ifdef UFD_DEBUG else { printf("/var/url_list isn't presented.\n"); return 1; } #endif return 0; }
/* * We use a simple lookup table to simulate manual enrollment * of certs by the CA. This is the case where an operator * needs to review each cert request and approve it (e.g. * auto-enrollment is off). * * Return 1 if a match was found and the enrollment operation * should proceed. Return 0 if no match was found, in which * case we'll add the public key from the cert request into * our lookup table so it can be correlated later. * * Windows: Rewriting to forgo the use of search.h API * lookup table will be implemented as a basic linked list */ static int lookup_pkcs10_request(unsigned char *pkcs10, int p10_len) { X509_REQ *req = NULL; BIO *in = NULL; BIO *out = NULL; BIO *b64; EVP_PKEY *pkey = NULL; BUF_MEM *bptr; int rv; LOOKUP_ENTRY *l; LOOKUP_ENTRY *n; /* * Decode the request into an X509_REQ structure */ b64 = BIO_new(BIO_f_base64()); in = BIO_new_mem_buf(pkcs10, p10_len); in = BIO_push(b64, in); if ((req = d2i_X509_REQ_bio(in, NULL)) == NULL) { /* Unable to parse the request, just let this fall through * and the enrollment will fail */ rv = 1; goto DONE; } /* * Get the public key from the request, this will be our index into * the lookup table. Frankly, I'm not sure how a real CA * would do this lookup. But this should be good enough for * testing the retry-after logic. */ pkey = X509_PUBKEY_get(req->req_info->pubkey); if (!pkey) { rv = 1; goto DONE; } out = BIO_new(BIO_s_mem()); PEM_write_bio_PUBKEY(out, pkey); BIO_get_mem_ptr(out, &bptr); /* * see if we can find a match for this public key */ n = malloc(sizeof(LOOKUP_ENTRY)); n->data = malloc(bptr->length); n->length = bptr->length; memcpy(n->data, bptr->data, n->length); n->next = NULL; l = search_list(lookup_root, n); if (l) { /* We have a match, allow the enrollment */ rv = 1; lookup_root = delete_lookup_entry(lookup_root, n); printf("\nRemoving key from lookup table:\n"); dumpbin((char*)n->data, n->length); free(n->data); free(n); } else { /* Not a match, add it to the list and return */ if (lookup_root == NULL) { /* * Initialize the list */ lookup_root = n; } else { add_entry(lookup_root, n); } rv = 0; printf("\nAdding key to lookup table:\n"); dumpbin((char*)n->data, n->length); } DONE: if (out) BIO_free_all(out); if (in) BIO_free_all(in); if (req) X509_REQ_free(req); if (pkey) EVP_PKEY_free(pkey); return (rv); }
/* * The actual main function. */ int sntp_main ( int argc, char **argv ) { register int c; struct kod_entry *reason = NULL; int optct; /* boolean, u_int quiets gcc4 signed overflow warning */ u_int sync_data_suc; struct addrinfo **bcastaddr = NULL; struct addrinfo **resh = NULL; struct addrinfo *ai; int resc; int kodc; int ow_ret; int bcast = 0; char *hostname; optct = optionProcess(&sntpOptions, argc, argv); argc -= optct; argv += optct; /* Initialize logging system */ init_logging(); if (HAVE_OPT(LOGFILE)) open_logfile(OPT_ARG(LOGFILE)); msyslog(LOG_NOTICE, "Started sntp"); /* IPv6 available? */ if (isc_net_probeipv6() != ISC_R_SUCCESS) { ai_fam_pref = AF_INET; #ifdef DEBUG printf("No ipv6 support available, forcing ipv4\n"); #endif } else { /* Check for options -4 and -6 */ if (HAVE_OPT(IPV4)) ai_fam_pref = AF_INET; else if (HAVE_OPT(IPV6)) ai_fam_pref = AF_INET6; } /* Parse config file if declared TODO */ /* * If there's a specified KOD file init KOD system. If not use * default file. For embedded systems with no writable * filesystem, -K /dev/null can be used to disable KoD storage. */ if (HAVE_OPT(KOD)) kod_init_kod_db(OPT_ARG(KOD)); else kod_init_kod_db("/var/db/ntp-kod"); if (HAVE_OPT(KEYFILE)) auth_init(OPT_ARG(KEYFILE), &keys); #ifdef EXERCISE_KOD_DB add_entry("192.168.169.170", "DENY"); add_entry("192.168.169.171", "DENY"); add_entry("192.168.169.172", "DENY"); add_entry("192.168.169.173", "DENY"); add_entry("192.168.169.174", "DENY"); delete_entry("192.168.169.174", "DENY"); delete_entry("192.168.169.172", "DENY"); delete_entry("192.168.169.170", "DENY"); if ((kodc = search_entry("192.168.169.173", &reason)) == 0) printf("entry for 192.168.169.173 not found but should have been!\n"); else free(reason); #endif /* Considering employing a variable that prevents functions of doing anything until * everything is initialized properly */ resc = resolve_hosts((void *)argv, argc, &resh, ai_fam_pref); if (resc < 1) { printf("Unable to resolve hostname(s)\n"); return -1; } bcast = ENABLED_OPT(BROADCAST); if (bcast) { const char * myargv[2]; myargv[0] = OPT_ARG(BROADCAST); myargv[1] = NULL; bcast = resolve_hosts(myargv, 1, &bcastaddr, ai_fam_pref); } /* Select a certain ntp server according to simple criteria? For now * let's just pay attention to previous KoDs. */ sync_data_suc = FALSE; for (c = 0; c < resc && !sync_data_suc; c++) { ai = resh[c]; do { hostname = addrinfo_to_str(ai); if ((kodc = search_entry(hostname, &reason)) == 0) { if (is_reachable(ai)) { ow_ret = on_wire(ai, bcast ? bcastaddr[0] : NULL); if (0 == ow_ret) sync_data_suc = TRUE; } } else { printf("%d prior KoD%s for %s, skipping.\n", kodc, (kodc > 1) ? "s" : "", hostname); free(reason); } free(hostname); ai = ai->ai_next; } while (NULL != ai); freeaddrinfo(resh[c]); } free(resh); if (!sync_data_suc) return 1; return 0; }
int handle_pkt ( int rpktl, struct pkt *rpkt, struct addrinfo *host ) { struct timeval tv_dst; int sw_case, digits; char *hostname = NULL, *ref, *ts_str = NULL; double offset, precision, root_dispersion; char addr_buf[INET6_ADDRSTRLEN]; char *p_SNTP_PRETEND_TIME; if(rpktl > 0) sw_case = 1; else sw_case = rpktl; switch(sw_case) { case SERVER_UNUSEABLE: return -1; break; case PACKET_UNUSEABLE: break; case SERVER_AUTH_FAIL: break; case KOD_DEMOBILIZE: /* Received a DENY or RESTR KOD packet */ hostname = addrinfo_to_str(host); ref = (char *)&rpkt->refid; add_entry(hostname, ref); if (ENABLED_OPT(NORMALVERBOSE)) printf("sntp handle_pkt: Received KOD packet with code: %c%c%c%c from %s, demobilizing all connections\n", ref[0], ref[1], ref[2], ref[3], hostname); msyslog(LOG_WARNING, "Received a KOD packet with code %c%c%c%c from %s, demobilizing all connections", ref[0], ref[1], ref[2], ref[3], hostname); break; case KOD_RATE: /* Hmm... probably we should sleep a bit here */ break; case 1: if (ENABLED_OPT(NORMALVERBOSE)) { getnameinfo(host->ai_addr, host->ai_addrlen, addr_buf, sizeof(addr_buf), NULL, 0, NI_NUMERICHOST); printf("sntp handle_pkt: Received %i bytes from %s\n", rpktl, addr_buf); } GETTIMEOFDAY(&tv_dst, (struct timezone *)NULL); p_SNTP_PRETEND_TIME = getenv("SNTP_PRETEND_TIME"); if (p_SNTP_PRETEND_TIME) { long long input_time; sscanf(p_SNTP_PRETEND_TIME, "%lld", &input_time); tv_dst.tv_sec = (time_t)input_time; } offset_calculation(rpkt, rpktl, &tv_dst, &offset, &precision, &root_dispersion); for (digits = 0; (precision *= 10.) < 1.; ++digits) /* empty */ ; if (digits > 6) digits = 6; ts_str = tv_to_str(&tv_dst); printf("%s ", ts_str); if (offset > 0) printf("+"); printf("%.*f", digits, offset); if (root_dispersion > 0.) printf(" +/- %f secs", root_dispersion); printf("\n"); free(ts_str); if (p_SNTP_PRETEND_TIME) return 0; if (ENABLED_OPT(SETTOD) || ENABLED_OPT(ADJTIME)) return set_time(offset); return 0; } return 1; }
void multiply_CSRMat_CSRMat(const CSRMat& A, const CSRMat& B, CSRMat& C, bool storeResultZeros) { //This function is unit-tested in fei/utest_cases/fei_unit_CSRMat_CSVec.cpp fei::FillableMat fc; const std::vector<int>& Arows = A.getGraph().rowNumbers; const std::vector<int>& Brows = B.getGraph().rowNumbers; if (Arows.size() < 1 || Brows.size() < 1) { C = fc; return; } const int* Arowoffs = &(A.getGraph().rowOffsets[0]); const int* Acols = &(A.getGraph().packedColumnIndices[0]); const double* Acoefs = &(A.getPackedCoefs()[0]); const int* Browoffs = &(B.getGraph().rowOffsets[0]); const std::vector<int>& Bcols = B.getGraph().packedColumnIndices; const double* Bcoefs = &(B.getPackedCoefs()[0]); static double fei_min = std::numeric_limits<double>::min(); int jbeg = *Arowoffs++; for(size_t i=0; i<Arows.size(); ++i) { int row = Arows[i]; int jend = *Arowoffs++; fei::CSVec* fc_row = NULL; if (storeResultZeros) { fc_row = fc.create_or_getRow(row); } else { fc_row = fc.hasRow(row) ? fc.create_or_getRow(row) : NULL; } while(jbeg<jend) { ++jbeg; int Acol = *Acols++; double Acoef = *Acoefs++; int Brow_offset = fei::binarySearch(Acol, &Brows[0], Brows.size()); if (Brow_offset < 0) { continue; } if (!storeResultZeros) { if (std::abs(Acoef) < fei_min) { continue; } } const int* Brow_cols = &(Bcols[Browoffs[Brow_offset]]); const double* Brow_coefs = &(Bcoefs[Browoffs[Brow_offset]]); int Brow_len = Browoffs[Brow_offset+1]-Browoffs[Brow_offset]; for(int k=0; k<Brow_len; ++k) { double resultCoef = Acoef*Brow_coefs[k]; int resultCol = Brow_cols[k]; if (!storeResultZeros) { if (std::abs(resultCoef) < fei_min) { continue; } } if (fc_row == NULL) { fc_row = fc.create_or_getRow(row); } add_entry(*fc_row, resultCol, resultCoef); } } } C = fc; }
static int verify_clean_subdirectory(const struct cache_entry *ce, enum unpack_trees_error_types error_type, struct unpack_trees_options *o) { /* * we are about to extract "ce->name"; we would not want to lose * anything in the existing directory there. */ int namelen; int i; struct dir_struct d; char *pathbuf; int cnt = 0; unsigned char sha1[20]; if (S_ISGITLINK(ce->ce_mode) && resolve_gitlink_ref(ce->name, "HEAD", sha1) == 0) { /* If we are not going to update the submodule, then * we don't care. */ if (!hashcmp(sha1, ce->sha1)) return 0; return verify_clean_submodule(ce, error_type, o); } /* * First let's make sure we do not have a local modification * in that directory. */ namelen = ce_namelen(ce); for (i = locate_in_src_index(ce, o); i < o->src_index->cache_nr; i++) { struct cache_entry *ce2 = o->src_index->cache[i]; int len = ce_namelen(ce2); if (len < namelen || strncmp(ce->name, ce2->name, namelen) || ce2->name[namelen] != '/') break; /* * ce2->name is an entry in the subdirectory to be * removed. */ if (!ce_stage(ce2)) { if (verify_uptodate(ce2, o)) return -1; add_entry(o, ce2, CE_REMOVE, 0); mark_ce_used(ce2, o); } cnt++; } /* * Then we need to make sure that we do not lose a locally * present file that is not ignored. */ pathbuf = xmalloc(namelen + 2); memcpy(pathbuf, ce->name, namelen); strcpy(pathbuf+namelen, "/"); memset(&d, 0, sizeof(d)); if (o->dir) d.exclude_per_dir = o->dir->exclude_per_dir; i = read_directory(&d, pathbuf, namelen+1, NULL); if (i) return o->gently ? -1 : add_rejected_path(o, ERROR_NOT_UPTODATE_DIR, ce->name); free(pathbuf); return cnt; }
/* We have a new comand from the server. 'emit' a signal. */ void TTCP::newCommand(const QStringList &list) { if (list[0] == "auto") { if (list.size() == 12) { emit add_autoentry(list[1], list[2].toInt(), list[3].toInt(), list[4], list[5], list[6], list[7], list[8], list[9], list[10], list[11]); /* user project auto_id host name class role desk title flags enabled */ } else if (list.size() == 11) { emit add_autoentry(list[1], list[2].toInt(), list[3].toInt(), list[4], list[5], list[6], list[7], list[8], list[9], list[10], "t"); /* user project auto_id host name class role desk title flags enabled */ } } else if (list[0] == "entry") { emit add_entry(list[2], list[3].toInt(), list[4].toInt(), totime(list[5]), totime(list[6])); } else if (list[0] == "timeslice") { if (list.size() == 8) { emit add_timeslice(list[1], list[2].toInt(), list[3].toInt(), list[4].toInt(), list[5], todatetime(list[6]), list[7]); } else { qWarning("timeslice: wrong # of arguments %d", list.size()); } } else if (list[0] == "current") { emit current(list[2].toInt()); } else if (list[0] == "disable") { emit disable(list[2].toInt()); } else if (list[0] == "error") { emit error(list[1]); } else if (list[0] == "update") { emit update_all(); } else if (list[0] == "update_time") { if (list.count() == 5) { emit settime(list[2].toInt(), totime(list[3]), totime(list[4])); } else { printf("Error in update_time\n"); } } else if (list[0] == "accept_note") { qWarning("%s %s", qPrintable(list[0]), qPrintable(list[1])); emit accept_note(list[1]); } else if (list[0] == "accept_task") { emit accept_project(list[1]); } else if (list[0] == "accept_select") { emit accept_select(list[1]); } else if (list[0] == "alert") { emit alert_message(list[1].toInt(), list[2], list[3]); } else if (list[0] == "alert_end") { emit alert_end_message(list[1].toInt()); } else if (list[0] == "hourly") { qWarning("Hourly"); emit hourly(); } else if (list[0] == "recentproject") { emit recentproject( list[2].toInt(), // project ID list[3].toInt(), // index list[4].toInt(), // max index QString("A comment") ); } else if (list[0] == "recentprojects") { QStringList plist(list.mid(2)); QList<int> pilist; QStringList::iterator i; for (i = plist.begin(); i != plist.end(); ++i) pilist.append((*i).toInt()); emit recentprojects( pilist ); } else { qWarning("TTCP Unknown: '%s'/%d\n", qPrintable(list[0]), list.size() - 1); } }
void Item_group::add_item_entry(const Item_tag &itemid, int probability) { std::unique_ptr<Item_spawn_data> ptr(new Single_item_creator(itemid, Single_item_creator::S_ITEM, probability)); add_entry(ptr); }
void Item_group::add_group_entry(const Group_tag &groupid, int probability) { std::unique_ptr<Item_spawn_data> ptr(new Single_item_creator(groupid, Single_item_creator::S_ITEM_GROUP, probability)); add_entry(ptr); }
GuiListboxEntry *GuiListbox::add_entry(const std::string& text) { return add_entry(GuiListboxEntry::Column(text, 0)); }
/* * this is where we finally load the file and create segments and other processing */ void idaapi load_file(linput_t *li, ushort neflags, const char *fileformatname) { /* reset file position to 0 - accept_file changed it? */ qlseek(li, 0); /* add header structures */ add_types(); create_filename_cmt(); /* process header and create its own segment */ EFI_IMAGE_TE_HEADER teHeader = {0}; if (qlread(li, &teHeader, sizeof(EFI_IMAGE_TE_HEADER)) != sizeof(EFI_IMAGE_TE_HEADER)) { warning("Failed to read TE header\n"); return; } /* read the data to the database */ /* header starts at 0 */ ea_t delta = teHeader.StrippedSize - sizeof(EFI_IMAGE_TE_HEADER); ea_t header_start = teHeader.ImageBase - delta; /* header total size is the TE header plus all sections that follow */ ea_t header_end = teHeader.ImageBase - delta + sizeof(EFI_IMAGE_TE_HEADER) + teHeader.NumberOfSections * sizeof(EFI_IMAGE_SECTION_HEADER); #if 1 msg("Header start: 0x%llx\n", header_start); msg("Header end: 0x%llx\n", header_end); msg("Delta: 0x%llx\n", delta); #endif file2base(li, 0, header_start, header_end, 1); /* create the HEADER segment */ add_segm(0, header_start, header_end, "HEADER", "DATA"); /* set header structures */ doStruct(teHeader.ImageBase - delta, sizeof(EFI_IMAGE_TE_HEADER), efi_image_te_header_struct); for (uint8_t i = 0; i < teHeader.NumberOfSections; i++) { doStruct(teHeader.ImageBase - delta + sizeof(EFI_IMAGE_TE_HEADER) + i * sizeof(EFI_IMAGE_SECTION_HEADER), sizeof(EFI_IMAGE_SECTION_HEADER), efi_image_section_header_struct); } int headerPosition = sizeof(EFI_IMAGE_TE_HEADER); /* read sections */ for (uint8_t i = 0; i < teHeader.NumberOfSections; i++) { qlseek(li, headerPosition); EFI_IMAGE_SECTION_HEADER sectionHeader = {0}; qlread(li, §ionHeader, sizeof(EFI_IMAGE_SECTION_HEADER)); msg("Section name: %s\n", sectionHeader.Name); /* ok */ uint32_t position = sectionHeader.PointerToRawData - delta; msg("Position %x\n", position); qlseek(li, position); ea_t section_start = sectionHeader.VirtualAddress + teHeader.ImageBase - delta; ea_t section_end = 0; if (sectionHeader.Misc.VirtualSize > sectionHeader.SizeOfRawData) { section_end = sectionHeader.VirtualAddress + teHeader.ImageBase - delta + sectionHeader.Misc.VirtualSize; } else { section_end = sectionHeader.VirtualAddress + teHeader.ImageBase - delta + sectionHeader.SizeOfRawData; } msg("Section start: 0x%llx\n", section_start); msg("Section end: 0x%llx\n", section_end); file2base(li, position, section_start, section_end, 1); int bitness = -1; switch (teHeader.Machine) { case IMAGE_FILE_MACHINE_I386: bitness = 1; break; case IMAGE_FILE_MACHINE_X64: bitness = 2; break; default: bitness = 0; } const char *classType; if (qstrcmp((const char*)sectionHeader.Name, ".text") == 0) { classType = "CODE"; } else { classType = "DATA"; } add_segm(0, section_start, section_end, (const char*)sectionHeader.Name, classType); set_segm_addressing(get_segm_by_name((const char *)sectionHeader.Name), bitness); /* try to find the GUIDs in data section */ if (qstrcmp((const char *)sectionHeader.Name, ".data") == 0) { find_guids(section_start, section_end); } /* advance to next section */ headerPosition += sizeof(EFI_IMAGE_SECTION_HEADER); } /* configure the entrypoint address */ add_entry(teHeader.AddressOfEntryPoint + teHeader.ImageBase - delta, teHeader.AddressOfEntryPoint + teHeader.ImageBase - delta, "_start", 1); /* all done */ }
GuiListboxEntry *GuiListbox::add_entry(const std::string& text, int width) { return add_entry(GuiListboxEntry::Column(text, width)); }
static int keep_entry(const struct cache_entry *ce, struct unpack_trees_options *o) { add_entry(o, ce, 0, 0); return 1; }
int main(int argc, char **argv) { unsigned long long vaddr; char *endp; addrxlat_ctx *ctx; addrxlat_pgt_t *pgt; int opt; addrxlat_status status; unsigned long refcnt; int rc; pgt = NULL; ctx = NULL; pgt = addrxlat_pgt_new(); if (!pgt) { perror("Cannot initialize page table translation"); rc = TEST_ERR; goto out; } while ((opt = getopt_long(argc, argv, "he:f:l:pr:", opts, NULL)) != -1) { switch (opt) { case 'f': rc = set_paging_form(optarg); if (rc != TEST_OK) return rc; break; case 'r': rc = set_root(optarg, pgt); if (rc != TEST_OK) return rc; break; case 'e': rc = add_entry(optarg); if (rc != TEST_OK) return rc; break; case 'l': rc = set_linear(optarg); if (rc != TEST_OK) return rc; break; case 'p': xlatdef.method = ADDRXLAT_PGT; xlatdef.pgt = pgt; break; case 'h': default: usage(argv[0]); rc = (opt == 'h') ? TEST_OK : TEST_ERR; goto out; } } if (argc - optind != 1 || !*argv[optind]) { fprintf(stderr, "Usage: %s <addr>\n", argv[0]); return TEST_ERR; } vaddr = strtoull(argv[optind], &endp, 0); if (*endp) { fprintf(stderr, "Invalid address: %s\n", argv[optind]); return TEST_ERR; } ctx = addrxlat_new(); if (!ctx) { perror("Cannot initialize address translation context"); rc = TEST_ERR; goto out; } status = addrxlat_pgt_set_form(pgt, &paging_form); if (status != addrxlat_ok) { fprintf(stderr, "Cannot set paging form\n"); rc = TEST_ERR; goto out; } addrxlat_cb_read32(ctx, read32); addrxlat_cb_read64(ctx, read64); rc = do_xlat(ctx, vaddr); out: if (pgt && (refcnt = addrxlat_pgt_decref(pgt)) != 0) fprintf(stderr, "WARNING: Leaked %lu pgt references\n", refcnt); if (ctx && (refcnt = addrxlat_decref(ctx)) != 0) fprintf(stderr, "WARNING: Leaked %lu addrxlat references\n", refcnt); return rc; }