Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types: add more missing atomic types and fix structure format size calculation #4624

Merged
merged 2 commits into from
Sep 9, 2024

Conversation

XVilka
Copy link
Member

@XVilka XVilka commented Sep 9, 2024

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've documented or updated the documentation of every function and struct this PR changes. If not so I've explained why.
  • I've added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the rizin book with the relevant information (if needed)

Detailed description

After testing Rizin on some firmwares I found these two problems:

  • Missing some relatively rare atomic types
  • Wrong calculation of the format size for relatively complex structured data types.

Test plan

CI is green

uint16_t=type
type.uint16_t=w
type.uint16_t.size=16
type.uint16_t.typeclass=Unsigned Integral

uint_fast16_t=type
type.uint_fast16_t=w
Copy link
Member

@Rot127 Rot127 Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w for word? Isn't this again architecture specific if it is a word or half-word? Also below with potentially w = 32bit, d == 64bit, q == 128bit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find anything in the C standard (looked briefly). But I find 16 = halfword more intuitive nowadays. The bit-widths don't get smaller in the end.

Copy link
Member Author

@XVilka XVilka Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's how it's defined in the pf, see the pf?:

Formats:
| b # byte (unsigned)
| B # resolve enum bitfield (see t?)
| c # char (signed byte)
| C # byte in decimal
| d # 0xHEX value (4 bytes) (see 'i' and 'x' formats)
| D # disassemble one opcode
| e # temporarily swap endian
| E # resolve enum name (see t?)
| f # float value (4 bytes)
| F # double float value (8 bytes)
| i # signed integer value (4 bytes) (see 'd' and 'x' formats)
| n # next char specifies size of signed value (1, 2, 4, or 8 byte(s))
| N # next char specifies size of unsigned value (1, 2, 4, or 8 byte(s))
| o # octal value (4 bytes)
| p # pointer reference (2, 4, or 8 bytes)
| q # quadword (8 bytes)
| Q # octoword (uint128_t) (16 bytes)
| r # CPU register (`pf r (eax)plop`)
| s # 32 bit pointer to string (4 bytes)
| s # 32 bit pointer to string (4 bytes)
| t # 32 bit UNIX timestamp (4 bytes)
| T # show ten first bytes of buffer
| u # uleb128 (variable length)
| w # word (2 bytes unsigned short in hex)

@@ -1682,7 +1688,7 @@ RZ_API int rz_type_format_struct_size(const RzTypeDB *typedb, const char *f, int
free(o);
return 0;
}
int newsize = rz_type_format_struct_size(typedb, format, mode, n + 1);
int newsize = format_struct_size(typedb, f, format, mode, depth + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename f to something descriptive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't because it would require renaming in many places, I try to keep changes in the formatting code to the minimum.

@XVilka XVilka merged commit 26eb226 into dev Sep 9, 2024
47 checks passed
@XVilka XVilka deleted the asan-type-atomics branch September 9, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants