int typedef_dissect_from_buffer( types_t *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent, gboolean new_line) { int length = 0; char cbuf[50 + (type->name ? strlen (type->name) : 0)]; types_t *type_child = NULL; DISPLAY_PARSE_INFO("typedef", type->name, offset, parent_offset); if (type->child != NULL) { /* Ignore TYPEDEF children */ for (type_child = type->child; type_child != NULL && type_child->type == TYPE_TYPEDEF; type_child = type_child->child) { } } if ((type_child == NULL) || (type_child->type != TYPE_FUNDAMENTAL)) { INDENTED_STRING(cbuf, new_line ? indent : 0, length = sprintf (cbuf, "%s, ", type->name)); ui_set_signal_text_cb(user_data, cbuf, length); new_line = FALSE; } /* Simply call next_type */ if (type->child != NULL) { type->child->parent = type; type->child->type_dissect_from_buffer( type->child, ui_set_signal_text_cb, user_data, buffer, offset, parent_offset, indent, new_line); } return 0; }
int enum_type_dissect_from_buffer ( types_t * type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data, buffer_t * buffer, uint32_t offset, uint32_t parent_offset, int indent, gboolean new_line) { uint32_t value = 0; types_t *values; DISPLAY_PARSE_INFO ("enum", type->name, offset, parent_offset); value = buffer_get_uint32_t (buffer, parent_offset + offset); for (values = type->child; values; values = values->next) { if (value == values->init_value) { values->parent = type; values->type_dissect_from_buffer (values, ui_set_signal_text_cb, user_data, buffer, offset, parent_offset, type->name == NULL ? indent : indent + DISPLAY_TAB_SIZE, FALSE); break; } } if (values == NULL) { int length = 0; char cbuf[50]; length = sprintf (cbuf, "(0x%08x) UNKNOWN;\n", value); ui_set_signal_text_cb (user_data, cbuf, length); } return 0; }
int fundamental_dissect_from_buffer( types_t *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent, gboolean new_line) { int length = 0; char cbuf[200]; int type_unsigned; uint8_t value8; uint16_t value16; uint32_t value32; uint64_t value64; DISPLAY_PARSE_INFO("fundamental", type->name, offset, parent_offset); memset (cbuf, 0, 200); type_unsigned = strstr (type->name, "unsigned") == NULL ? 0 : 1; value64 = fundamental_read_from_buffer(type, buffer, offset, parent_offset); indent = new_line ? indent : 0; if (indent > 0) { DISPLAY_TYPE("Fun"); } switch (type->size) { case 8: value8 = (uint8_t) value64; INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, type_unsigned ? "(0x%02" PRIx8 ") %3" PRIu8 ";\n" : "(0x%02" PRIx8 ") %4" PRId8 ";\n", value8, value8)); break; case 16: value16 = (uint16_t) value64; INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, type_unsigned ? "(0x%04" PRIx16 ") %5" PRIu16 ";\n" : "(0x%04" PRIx16 ") %6" PRId16 ";\n", value16, value16)); break; case 32: value32 = (uint32_t) value64; INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, type_unsigned ? "(0x%08" PRIx32 ") %9" PRIu32 ";\n" : "(0x%08" PRIx32 ") %10" PRId32 ";\n", value32, value32)); break; case 64: INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, type_unsigned ? "(0x%016" PRIx64 ") %20" PRIu64 ";\n" : "(0x%016" PRIx64 ") %20" PRId64 ";\n", value64, value64)); break; default: /* ??? */ break; } ui_set_signal_text_cb(user_data, cbuf, length); return 0; }
int pointer_dissect_from_buffer ( types_t * type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data, buffer_t * buffer, uint32_t offset, uint32_t parent_offset, int indent, gboolean new_line) { int length = 0, i; char cbuf[200]; DISPLAY_PARSE_INFO ("pointer", type->name, offset, parent_offset); memset (cbuf, 0, 200); uint8_t value[type->size / 8]; buffer_fetch_nbytes (buffer, parent_offset + offset, type->size / 8, value); indent = new_line ? indent : 0; if (indent > 0) { DISPLAY_TYPE ("Ptr"); } if (type->child && type->child->name) { /* * INDENTED(stdout, indent, fprintf(stdout, "<%s>0x%08x</%s>\n", * type->child->name, value, type->child->name)); */ INDENTED_STRING (cbuf, indent, length = sprintf (cbuf, "(%s *) 0x", type->child->name)); } else { /* * INDENTED(stdout, indent, fprintf(stdout, "<Pointer>0x%08x</Pointer>\n", * value)); */ INDENTED_STRING (cbuf, indent, length = sprintf (cbuf, "(void *) 0x")); } /* * Append the value */ for (i = type->size / 8 - 1; i >= 0; i--) { length += sprintf (&cbuf[length], "%02x", value[i]); } length += sprintf (&cbuf[length], ";\n"); ui_set_signal_text_cb (user_data, cbuf, length); return 0; }
int enum_value_dissect_from_buffer( types_t *type, ui_set_signal_text_cb_t ui_set_signal_text_cb, gpointer user_data, buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent, gboolean new_line) { types_t *type_parent = NULL; uint32_t value = 0; DISPLAY_PARSE_INFO("enum_value", type->name, offset, parent_offset); value = buffer_get_uint32_t(buffer, parent_offset + offset); if (type->name) { int length = 0; char cbuf[50 + strlen(type->name)]; /* Search for enum variable name and check if it is used in association with a union type */ { if (type->parent != NULL) { /* Ignore ENUMERATION and TYPEDEF parents */ for (type_parent = type->parent; (type_parent != NULL) && ((type_parent->type == TYPE_ENUMERATION) || (type_parent->type == TYPE_TYPEDEF)); type_parent = type_parent->parent) { } } if ((type_parent != NULL) && (type_parent->name != NULL) && (strcmp(type_parent->name, "present") == 0)) { /* ASN1 union, keep the "present" member */ last_enum_value = value; } else { last_enum_value = 0; } } length = sprintf(cbuf, "(0x%08x) %s;\n", value, type->name); ui_set_signal_text_cb(user_data, cbuf, length); } return 0; }