void show_ext2_inode(const struct ext2_inode *inode) { int i; print_sep(60); pr_bold_info("ext2 inode %p", inode); println("mode = 0x%05o", inode->mode); println("uid = %d", inode->uid); println("size = %d", inode->size); println("atime = %d", inode->atime); println("ctime = %d", inode->ctime); println("mtime = %d", inode->mtime); println("dtime = %d", inode->dtime); println("gid = %d", inode->gid); println("links_count = %d", inode->links_count); println("blocks = %d", inode->blocks); println("flags = 0x%08x", inode->flags); println("version = %d", inode->version); println("file_acl = %d", inode->file_acl); println("dir_acl = %d", inode->dir_acl); println("faddr = %d", inode->faddr); if ((inode->flags & EXT2_INODE_FLAG_EXTENTS) == 0) { for (i = 0; i < EXT2_N_BLOCKS; i++) { println("inode->block[%d] = %d", i, inode->block[i]); } } }
void show_ext4_extent_index(const struct ext4_extent_index *index) { print_sep(60); pr_bold_info("ext4 extent index %p", index); println("block = %d", index->block); println("leaf = %" PRINT_FORMAT_INT64, (u64) index->leaf_hi << 32 | index->leaf_lo); }
void print_l(list *l){ assert(l != NULL); if(l->first == NULL){ print_sep('-'); printf("Empty list\n"); }else{ node_l *n = l->first; while(n != NULL){ print_sep('-'); print_c(n->c); n = n->next; } } print_sep('-'); }
void show_ext4_extent_leaf(const struct ext4_extent_leaf *leaf) { print_sep(60); pr_bold_info("ext4 extent leaf %p", leaf); println("block = %d", leaf->block); println("length = %d", leaf->length); println("start = %" PRINT_FORMAT_INT64, (u64) leaf->start_hi << 32 | leaf->start_lo); }
void show_ext4_extent_header(const struct ext4_extent_header *header) { print_sep(60); pr_bold_info("ext4 extent header %p", header); println("magic = 0x%04x", header->magic); println("entries = %d", header->entries); println("max_entries = %d", header->max_entries); println("depth = %d", header->depth); println("generations = %d", header->generations); }
void show_ext2_directory_entry(const struct ext2_directory_entry *dir_entry) { print_sep(60); pr_bold_info("ext2 directory entry %p", dir_entry); println("file_type = %d", dir_entry->file_type); println("inode = %d", dir_entry->inode); println("name = %s", dir_entry->name); println("name_len = %d", dir_entry->name_len); println("rec_len = %d", dir_entry->rec_len); }
void show_ext2_group_desc(const struct ext2_group_desc *group_desc) { print_sep(60); pr_bold_info("ext2 group desc %p", group_desc); println("block_bitmap = %d", group_desc->block_bitmap); println("inode_bitmap = %d", group_desc->inode_bitmap); println("inode_table = %d", group_desc->inode_table); println("free_blocks_count = %d", group_desc->free_blocks_count); println("free_inodes_count = %d", group_desc->free_inodes_count); println("used_dirs_count = %d", group_desc->used_dirs_count); println("pad = %d", group_desc->pad); }
void show_ext2_desc(const struct ext2_desc *desc) { unsigned int i; print_sep(60); pr_bold_info("ext2 desc %p", desc); println("block_shift = %" PRINT_FORMAT_SIZE, desc->block_shift); println("block_size = %" PRINT_FORMAT_SIZE, desc->block_size); println("flex_count = %" PRINT_FORMAT_SIZE, desc->flex_count); println("group_count = %" PRINT_FORMAT_SIZE, desc->group_count); println("groups_per_flex = %" PRINT_FORMAT_SIZE, desc->groups_per_flex); println("group_flex_shift = %" PRINT_FORMAT_SIZE, desc->group_flex_shift); show_ext2_super_block(&desc->super_block); for (i = 0; i < desc->group_count; i++) { show_ext2_group_desc(desc->gdt + i); println("gdt_index = %d", i); } }
int sql_query ( dbref player, char *q_string, char *buff, char **bufc, const Delim *row_delim, const Delim *field_delim ) { PGresult *pgres; ExecStatusType pgstat; PGconn *pgsql; char *pg_data; int num_rows, got_rows, got_fields; int i, j; int retries; /* * If we have no connection, and we don't have auto-reconnect on (or * we try to auto-reconnect and we fail), this is an error generating * a #-1. Notify the player, too, and set the return code. */ pgsql = pgsql_struct; if ( ( !pgsql ) && ( mod_db_sql_config.reconnect != 0 ) ) { /* * Try to reconnect. */ retries = 0; while ( ( retries < PGSQL_RETRY_TIMES ) && !pgsql ) { sleep ( 1 ); sql_init ( 0, 0, NULL, NULL ); pgsql = pgsql_struct; retries++; } } if ( !pgsql ) { notify ( player, "No SQL database connection." ); if ( buff ) safe_str ( "#-1", buff, bufc ); return -1; } if ( !q_string || !*q_string ) return 0; /* * Send the query. */ pgres = PQexec ( pgsql, q_string ); pgstat = PQresultStatus ( pgres ); if ( pgstat != PGRES_COMMAND_OK && pgstat != PGRES_TUPLES_OK ) { notify ( player, PQresultErrorMessage ( pgres ) ); if ( buff ) safe_str ( "#-1", buff, bufc ); PQclear ( pgres ); return -1; } /* * A number of affected rows greater than 0 means it wasn't a SELECT */ num_rows = atoi ( PQcmdTuples ( pgres ) ); if ( num_rows > 0 ) { notify_check ( player, player, MSG_PUP_ALWAYS | MSG_ME_ALL | MSG_F_DOWN, "SQL query touched %d %s.", num_rows, ( num_rows == 1 ) ? "row" : "rows" ); PQclear ( pgres ); return 0; } /* * Check to make sure we got rows back. */ got_rows = PQntuples ( pgres ); if ( got_rows == 0 ) { PQclear ( pgres ); return 0; } /* * Construct properly-delimited data. */ if ( buff ) { for ( i = 0; i < got_rows; i++ ) { if ( i > 0 ) { print_sep ( row_delim, buff, bufc ); } got_fields = PQnfields ( pgres ); if ( got_fields ) { for ( j = 0; j < got_fields; j++ ) { pg_data = PQgetvalue ( pgres, i, j ); if ( j > 0 ) { print_sep ( field_delim, buff, bufc ); } if ( pg_data && *pg_data ) safe_str ( pg_data, buff, bufc ); } } } } else { for ( i = 0; i < got_rows; i++ ) { got_fields = PQnfields ( pgres ); if ( got_fields ) { for ( j = 0; j < got_fields; j++ ) { pg_data = PQgetvalue ( pgres, i, j ); if ( pg_data && *pg_data ) { notify_check ( player, player, MSG_PUP_ALWAYS | MSG_ME_ALL | MSG_F_DOWN, "Row %d, Field %d: %s", i + 1, j + 1, pg_data ); } else { notify_check ( player, player, MSG_PUP_ALWAYS | MSG_ME_ALL | MSG_F_DOWN, "Row %d, Field %d: NULL", i + 1, j + 1 ); } } } else { notify_check ( player, player, MSG_PUP_ALWAYS | MSG_ME_ALL | MSG_F_DOWN, "Row %d: NULL", i + 1 ); } } } PQclear ( pgres ); return 0; }
void show_ext2_super_block(const struct ext2_super_block *super_block) { print_sep(60); pr_bold_info("ext2 super block %p", super_block); println("inodes_count = %d", super_block->inodes_count); println("blocks_count = %d", super_block->blocks_count); println("reserved_blocks_count = %d", super_block->reserved_blocks_count); println("free_blocks_count = %d", super_block->free_blocks_count); println("free_inodes_count = %d", super_block->free_inodes_count); println("first_data_block = %d", super_block->first_data_block); println("log_block_size = %d", super_block->log_block_size); println("log_frag_size = %d", super_block->log_frag_size); println("blocks_per_group = %d", super_block->blocks_per_group); println("frags_per_group = %d", super_block->frags_per_group); println("inodes_per_group = %d", super_block->inodes_per_group); println("mtime = %d", super_block->mtime); println("wtime = %d", super_block->wtime); println("mnt_count = %d", super_block->mnt_count); println("max_mnt_count = %d", super_block->max_mnt_count); println("magic_number = 0x%04x", super_block->magic_number); println("state = %d", super_block->state); println("errors = %d", super_block->errors); println("minor_rev_level = %d", super_block->minor_rev_level); println("lastcheck = %d", super_block->lastcheck); println("checkinterval = %d", super_block->checkinterval); println("creator_os = %d", super_block->creator_os); println("rev_level = %d", super_block->rev_level); println("def_resuid = %d", super_block->def_resuid); println("def_resgid = %d", super_block->def_resgid); println("first_inode = %d", super_block->first_inode); println("inode_size = %d", super_block->inode_size); println("block_group_nr = %d", super_block->block_group_nr); println("feature_compat = 0x%08x", super_block->feature_compat); println("feature_incompat = 0x%08x", super_block->feature_incompat); println("feature_ro_compat = 0x%08x", super_block->feature_ro_compat); println("uuid[16] = %s", text_header((char *) super_block->uuid, 16)); println("volume_name[16] = %s", text_header(super_block->volume_name, 16)); println("last_mounted[64] = %s", text_header(super_block->last_mounted, 64)); println("algorithm_usage_bitmap = %d", super_block->algorithm_usage_bitmap); println("prealloc_blocks = %d", super_block->prealloc_blocks); println("prealloc_dir_blocks = %d", super_block->prealloc_dir_blocks); println("reserved_gdt_blocks = %d", super_block->reserved_gdt_blocks); // println("journal_uuid[16] = %d", super_block->journal_uuid[16]); println("journal_inum = %d", super_block->journal_inum); println("journal_dev = %d", super_block->journal_dev); println("last_orphan = %d", super_block->last_orphan); // println("hash_seed[4] = %d", super_block->hash_seed[4]); println("def_hash_version = %d", super_block->def_hash_version); println("jnl_backup_type = %d", super_block->jnl_backup_type); println("desc_size = %d", super_block->desc_size); println("default_mount_opts = %d", super_block->default_mount_opts); println("first_meta_bg = %d", super_block->first_meta_bg); println("mkfs_time = %d", super_block->mkfs_time); // println("jnl_blocks[17] = %d", super_block->jnl_blocks[17]); println("blocks_count_hi = %d", super_block->blocks_count_hi); println("r_blocks_count_hi = %d", super_block->r_blocks_count_hi); println("free_blocks_hi = %d", super_block->free_blocks_hi); println("min_extra_isize = %d", super_block->min_extra_isize); println("want_extra_isize = %d", super_block->want_extra_isize); println("flags = %d", super_block->flags); println("raid_stride = %d", super_block->raid_stride); println("mmp_update_interval = %d", super_block->mmp_update_interval); println("mmp_block = %" PRINT_FORMAT_INT64, super_block->mmp_block); println("raid_stripe_width = %d", super_block->raid_stripe_width); println("log_groups_per_flex = %d", super_block->log_groups_per_flex); println("reserved_char_pad = %d", super_block->reserved_char_pad); println("reserved_pad = %d", super_block->reserved_pad); println("kbytes_written = %" PRINT_FORMAT_INT64, super_block->kbytes_written); println("snapshot_inum = %d", super_block->snapshot_inum); println("snapshot_id = %d", super_block->snapshot_id); println("snapshot_r_blocks_count = %" PRINT_FORMAT_INT64, super_block->snapshot_r_blocks_count); println("snapshot_list = %d", super_block->snapshot_list); println("error_count = %d", super_block->error_count); println("first_error_time = %d", super_block->first_error_time); println("first_error_ino = %d", super_block->first_error_ino); println("first_error_block = %" PRINT_FORMAT_INT64, super_block->first_error_block); // println("first_error_func[32] = %d", super_block->first_error_func[32]); println("first_error_line = %d", super_block->first_error_line); println("last_error_time = %d", super_block->last_error_time); println("last_error_ino = %d", super_block->last_error_ino); println("last_error_line = %d", super_block->last_error_line); println("last_error_block = %" PRINT_FORMAT_INT64, super_block->last_error_block); // println("last_error_func[32] = %d", super_block->last_error_func[32]); // println("mount_opts[64] = %d", super_block->mount_opts[64]); println("usr_quota_inum = %d", super_block->usr_quota_inum); println("grp_quota_inum = %d", super_block->grp_quota_inum); println("overhead_blocks = %d", super_block->overhead_blocks); // println("backup_bgs[2] = %d", super_block->backup_bgs[2]); // println("reserved[106] = %d", super_block->reserved[106]); println("checksum = %d", super_block->checksum); }
int sql_query(dbref player, char *q_string, char *buff, char **bufc, const Delim *row_delim, const Delim *field_delim) { sqlite3 *sqlite; const unsigned char *col_data; int num_rows, got_rows, got_fields; int i, j; int retries; int retval; sqlite3_stmt *stmt; const char *rest; /* * If we have no connection, and we don't have auto-reconnect on (or * we try to auto-reconnect and we fail), this is an error generating * a #-1. Notify the player, too, and set the return code. */ sqlite = sqlite3_struct; if ((!sqlite) && (mod_db_sql_config.reconnect != 0)) { /* * Try to reconnect. */ retries = 0; while ((retries < SQLITE_RETRY_TIMES) && !sqlite) { sleep(1); sql_init(0,0,NULL,NULL); sqlite = sqlite3_struct; retries++; } } if (!sqlite) { notify_quiet(player, "No SQL database connection."); if (buff) safe_str("#-1", buff, bufc); return -1; } if (!q_string || !*q_string) return 0; /* * Prepare the query. */ retval = sqlite3_prepare_v2(sqlite, q_string, -1, &stmt, &rest); if (retval != SQLITE_OK) { notify_quiet(player, sqlite3_errmsg(sqlite)); if (buff) safe_str("#-1", buff, bufc); sqlite3_finalize(stmt); return -1; } /* * Construct properly-delimited data. */ if (buff) { i = 0; while (sqlite3_step(stmt) == SQLITE_ROW) { if (i++ > 0) { print_sep(row_delim, buff, bufc); } got_fields = sqlite3_column_count(stmt); if (got_fields) { for (j = 0; j < got_fields; j++) { col_data = sqlite3_column_text(stmt, j); if (j > 0) { print_sep(field_delim, buff, bufc); } if (col_data && *col_data) safe_str((char *)col_data, buff, bufc); } } } } else { i = 0; while (sqlite3_step(stmt) == SQLITE_ROW) { if (i++ > 0) { print_sep(row_delim, buff, bufc); } got_fields = sqlite3_column_count(stmt); if (got_fields) { for (j = 0; j < got_fields; j++) { col_data = sqlite3_column_text(stmt, j); if (j > 0) { notify_check(player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "Row %d, Field %d: %s", i, j + 1, col_data); } if (col_data && *col_data) { notify_check(player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "Row %d, Field %d: NULL", i, j + 1); } } } } } if (i == 0) { num_rows = sqlite3_changes(sqlite); if (num_rows > 0) { notify_check(player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "SQL query touched %d %s.", num_rows, (num_rows == 1) ? "row" : "rows"); } } sqlite3_finalize(stmt); return 0; }
/* * Go through the whole list, stopping if you find a match. Process all * the continuations of that match before returning. * * We support multi-level continuations: * * At any time when processing a successful top-level match, there is a * current continuation level; it represents the level of the last * successfully matched continuation. * * Continuations above that level are skipped as, if we see one, it * means that the continuation that controls them - i.e, the * lower-level continuation preceding them - failed to match. * * Continuations below that level are processed as, if we see one, * it means we've finished processing or skipping higher-level * continuations under the control of a successful or unsuccessful * lower-level continuation, and are now seeing the next lower-level * continuation and should process it. The current continuation * level reverts to the level of the one we're seeing. * * Continuations at the current level are processed as, if we see * one, there's no lower-level continuation that may have failed. * * If a continuation matches, we bump the current continuation level * so that higher-level continuations are processed. */ static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, size_t nbytes, int mode) { ut32 magindex = 0; unsigned int cont_level = 0; int need_separator = 0; int returnval = 0; /* if a match is found it is set to 1*/ int firstline = 1; /* a flag to print X\n X\n- X */ int printed_something = 0; if (file_check_mem (ms, cont_level) == -1) return -1; for (magindex = 0; magindex < nmagic; magindex++) { int flush; struct r_magic *m = &magic[magindex]; if ((m->flag & BINTEST) != mode) { /* Skip sub-tests */ while (magic[magindex + 1].cont_level != 0 && ++magindex < nmagic - 1) continue; continue; /* Skip to next top-level test*/ } ms->offset = m->offset; ms->line = m->lineno; /* if main entry matches, print it... */ flush = !mget(ms, s, m, nbytes, cont_level); if (flush) { if (m->reln == '!') flush = 0; } else { int ret = magiccheck (ms, m); if (ret == -1) return -1; if (!ret) flush++; } if (flush) { /* * main entry didn't match, * flush its continuations */ while (magindex < nmagic - 1 && magic[magindex + 1].cont_level) magindex++; continue; } /* * If we are going to print something, we'll need to print * a blank before we print something else. */ if (*R_MAGIC_DESC) { need_separator = 1; printed_something = 1; if (print_sep(ms, firstline) == -1) return -1; } if ((ms->c.li[cont_level].off = mprint(ms, m)) == -1) return -1; /* and any continuations that match */ if (file_check_mem(ms, ++cont_level) == -1) return -1; while (++magindex < nmagic - 1 && magic[magindex].cont_level != 0) { m = &magic[magindex]; ms->line = m->lineno; /* for messages */ if (cont_level < m->cont_level) continue; if (cont_level > m->cont_level) { /* * We're at the end of the level * "cont_level" continuations. */ cont_level = m->cont_level; } ms->offset = m->offset; if (m->flag & OFFADD) ms->offset += ms->c.li[cont_level - 1].off; if (m->cond == COND_ELSE || m->cond == COND_ELIF) { if (ms->c.li[cont_level].last_match == 1) continue; } flush = !mget(ms, s, m, nbytes, cont_level); if (flush && m->reln != '!') continue; switch (flush ? 1 : magiccheck(ms, m)) { case -1: return -1; case 0: ms->c.li[cont_level].last_match = 0; break; default: ms->c.li[cont_level].last_match = 1; if (m->type != FILE_DEFAULT) ms->c.li[cont_level].got_match = 1; else if (ms->c.li[cont_level].got_match) { ms->c.li[cont_level].got_match = 0; break; } /* * If we are going to print something, * make sure that we have a separator first. */ if (*R_MAGIC_DESC) { printed_something = 1; if (print_sep(ms, firstline) == -1) return -1; } /* * This continuation matched. Print * its message, with a blank before it * if the previous item printed and * this item isn't empty. */ /* space if previous printed */ if (need_separator && ((m->flag & NOSPACE) == 0) && *R_MAGIC_DESC) { if (file_printf (ms, " ") == -1) return -1; need_separator = 0; } if ((ms->c.li[cont_level].off = mprint(ms, m)) == -1) return -1; if (*R_MAGIC_DESC) need_separator = 1; /* * If we see any continuations * at a higher level, * process them. */ if (file_check_mem(ms, ++cont_level) == -1) return -1; break; } } if (printed_something) { firstline = 0; returnval = 1; } if ((ms->flags & R_MAGIC_CONTINUE) == 0 && printed_something) return 1; /* don't keep searching */ } return returnval; /* This is hit if -k is set or there is no match */ }
int main(int argc, char **argv) { char id[UUID_STR_LEN + 1]; int cf_index, ret, type; Octstr *os, *store_type, *store_location, *status; Msg *msg; CfgGroup *grp; conf_file = NULL; gwlib_init(); //This can be overwritten with the -v flag at runtime log_set_output_level(DEFAULT_LOG_LEVEL); cf_index = get_and_set_debugs(argc, argv, check_args); if (argv[cf_index] == NULL) { print_usage(argv[0]); goto error; } if (conf_file == NULL) conf_file = octstr_create("kannel.conf"); cfg = cfg_create(conf_file); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(conf_file)); info(0, "1"); grp = cfg_get_single_group(cfg, octstr_imm("core")); if (grp == NULL) { printf("FATAL: Could not load Kannel's core group. Exiting.\n"); return 2; } store_location = cfg_get(grp, octstr_imm("store-location")); store_type = cfg_get(grp, octstr_imm("store-type")); store_init(store_type, store_location, -1, msg_pack, msg_unpack_wrapper); switch (command) { case COMMAND_LIST: printf("Listing records %d -> %d\n", list_from+1, list_limit); print_header(); store_load(print_msg); if (counter == 0) { printf("|%60s%14s%60s|\n", "", "Store is Empty", ""); } print_sep(); break; case COMMAND_DELETE: store_load(msg_count); msg = msg_create(ack); msg->ack.nack = ack_failed; msg->ack.time = time(NULL); uuid_parse(octstr_get_cstr(param_1), msg->ack.id); ret = store_save(msg); if (ret == 0) { printf("Deleted message %s\n", octstr_get_cstr(param_1)); counter--; } else { printf("Could not delete message %s\n", octstr_get_cstr(param_1)); } msg_destroy(msg); break; case COMMAND_EXPORT: counter = 0; type = 0; list = gwlist_create(); store_load(msg_push); printf("Exporting %ld messages...\n", gwlist_len(list)); if ((octstr_compare(param_1, octstr_imm("file")) == 0) || (octstr_compare(param_1, octstr_imm("spool")) == 0)) { store_shutdown(); store_init(param_1, param_2, -1, msg_pack, msg_unpack_wrapper); store_load(msg_count); while ((os = gwlist_extract_first(list)) != NULL) { msg = msg_unpack_wrapper(os); if (msg != NULL) { ret = store_save(msg); if (ret == 0) { counter++; } else { printf("Error saving message\n"); } } else { printf("Error extracting message\n"); } msg_destroy(msg); } status = NULL; } else if (octstr_compare(param_1, octstr_imm("text")) == 0) { status = store_status(BBSTATUS_TEXT); } else if (octstr_compare(param_1, octstr_imm("html")) == 0) { status = store_status(BBSTATUS_HTML); } else if (octstr_compare(param_1, octstr_imm("xml")) == 0) { status = store_status(BBSTATUS_XML); } else { status = NULL; } if (status != NULL) { file = fopen(octstr_get_cstr(param_2), "w"); if (file == NULL) { error(errno, "Failed to open '%s' for writing, cannot create output file", octstr_get_cstr(param_2)); return -1; } octstr_print(file, status); fflush(file); if (file != NULL) fclose(file); //printf("%s", octstr_get_cstr(status)); } gwlist_destroy(list, octstr_destroy_item); break; default: break; } octstr_destroy(store_type); octstr_destroy(store_location); cfg_destroy(cfg); store_shutdown(); error: gwlib_shutdown(); return 1; }
/* * Prints a nicely formatted header */ void print_header() { print_sep(); PRINT_COLUMNS("|", " ", "message id", "from", "to", "smsc", "text"); print_sep(); }
static int vobjdump(void) { p = vobj; if (vlen>4 && p[0]==0x56 && p[1]==0x4f && p[2]==0x42 && p[3]==0x4a) { int endian,nsecs,nsyms,i; const char *cpu_name; struct vobj_symbol *vsymbols = NULL; struct vobj_section *vsect = NULL; p += 4; /* skip ID */ endian = (int)*p++; /* endianess */ if (endian<1 || endian>2) { fprintf(stderr,"Wrong endianess: %d\n",endian); return 1; } bpb = (int)read_number(0); /* bits per byte */ if (bpb != 8) { fprintf(stderr,"%d bits per byte not supported!\n",bpb); return 1; } bpt = (int)read_number(0); /* bytes per taddr */ if (bpt > sizeof(taddr)) { fprintf(stderr,"%d bytes per taddr not supported!\n",bpt); return 1; } bptmask = makemask(bpt*bpb); cpu_name = p; skip_string(); /* skip cpu-string */ nsecs = (int)read_number(0); /* number of sections */ nsyms = (int)read_number(0); /* number of symbols */ /* print header */ print_sep(); printf("VOBJ %s (%s endian), %d bits per byte, %d bytes per word.\n" "%d symbol%s.\n%d section%s.\n", cpu_name,endian_name[endian-1],bpb,bpt, nsyms,nsyms==1?emptystr:sstr,nsecs,nsecs==1?emptystr:sstr); /* read symbols */ if (nsyms) { if (vsymbols = malloc(nsyms * sizeof(struct vobj_symbol))) { for (i=0; i<nsyms; i++) read_symbol(&vsymbols[i]); } else { fprintf(stderr,"Cannot allocate %ld bytes for symbols!\n", (long)(nsyms * sizeof(struct vobj_symbol))); return 1; } } /* read and print sections */ if (vsect = malloc(nsecs * sizeof(struct vobj_section))) { for (i=0; i<nsecs; i++) read_section(&vsect[i],vsymbols,nsyms); } else { fprintf(stderr,"Cannot allocate %ld bytes for sections!\n", (long)(nsecs * sizeof(struct vobj_section))); return 1; } /* print symbols */ for (i=0; i<nsyms; i++) { struct vobj_symbol *vs = &vsymbols[i]; if (i == 0) { printf("\n"); print_sep(); printf("SYMBOL TABLE\n" "file offs bind size type def value name\n"); } if (!strncmp(vs->name," *current pc",12)) continue; printf("%08llx: %-4s %08x %-4s %8.8s %8llx %s\n", BPTMASK(vs->offs),bind_name(vs->flags),(unsigned)vs->size, type_name[TYPE(vs)],def_name(vs,vsect,nsecs), BPTMASK(vs->val),vs->name); } } else { fprintf(stderr,"Not a VOBJ file!\n"); return 1; } return 0; }
static void read_section(struct vobj_section *vsect, struct vobj_symbol *vsym,int nsyms) { const char *attr; unsigned long flags; int align,nrelocs,i; vsect->offs = p - vobj; vsect->name = p; skip_string(); attr = p; skip_string(); flags = (unsigned long)read_number(0); align = (int)read_number(0); vsect->dsize = read_number(0); nrelocs = (int)read_number(0); vsect->fsize = read_number(0); print_sep(); printf("%08llx: SECTION \"%s\" (attributes=\"%s\")\n" "Flags: %-8lx Alignment: %-6d " "Total size: %-9lld File size: %-9lld\n", BPTMASK(vsect->offs),vsect->name,attr,flags,align, vsect->dsize,vsect->fsize); if (nrelocs) printf("%d Relocation%s present.\n",nrelocs,nrelocs==1?emptystr:sstr); p += vsect->fsize; /* skip section contents */ /* read and print relocations for this section */ for (i=0; i<nrelocs; i++) { ubyte type; if (i == 0) { /* print header */ printf("\nfile offs sectoffs pos sz mask type symbol+addend\n"); } printf("%08llx: ",BPTMASK(p-vobj)); type = (ubyte)read_number(0); if (type<sizeof(reloc_name)/sizeof(reloc_name[0])) { /* standard relocation */ taddr offs,mask,addend; int bpos,bsiz,sym; const char *basesym; offs = read_number(0); bpos = (int)read_number(0); bsiz = (int)read_number(0); mask = read_number(1); addend = read_number(1); sym = (int)read_number(0) - 1; /* symbol index */ if (offs<0 || offs>=vsect->dsize) { printf("offset 0x%llx is outside of section!\n",BPTMASK(offs)); continue; } if (sym<0 || sym>=nsyms) { printf("symbol index %d is illegal!\n",sym+1); continue; } if (bsiz<0 || bsiz>bpt*bpb) { printf("size of %d bits is illegal!\n",bsiz); continue; } if (bpos<0 || bpos+bsiz>bpt*bpb) { printf("bit field start=%d, size=%d doesn't fit into target address " "type (%d bits)!\n",bpos,bsiz,bpt*bpb); continue; } basesym = vsym[sym].name; if (!strncmp(basesym," *current pc",12)) { basesym = vsect->name; /*addend += offs;*/ } printf("%08llx %02d %02d %8llx %-8s %s%+lld\n", BPTMASK(offs),bpos,bsiz,BPTMASK(mask), reloc_name[type],basesym,addend); } else { /* non-standard relocation */ taddr rsize; rsize = read_number(0); /* size of special relocation entry */ p += rsize; printf("special relocation type %-3d with a size of %d bytes\n", (int)type,(int)rsize); } } }