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

[WIP] Rewrite PDB parser #1498

Closed
wants to merge 17 commits into from
Closed

[WIP] Rewrite PDB parser #1498

wants to merge 17 commits into from

Conversation

Basstorm
Copy link
Member

@Basstorm Basstorm commented Aug 21, 2021

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 added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the documentation and the rizin book with the relevant information (if needed)

Detailed description

Undone:
1: Fix bugs in symbols parsing(done)
2: update test and unit test(cmd test done)
3: switch to new rz_buf_xxx API(done)
4: update doxygen comments(done)
5: use bit mask when parsing bitfields(done)

Test plan

...

Closing issues

...

Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

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

I thought the API for rz_buf_ access has been changed by @08a to separate the return value from the error.

librz/analysis/type_pdb.c Show resolved Hide resolved
librz/analysis/type_pdb.c Outdated Show resolved Hide resolved
librz/analysis/type_pdb.c Show resolved Hide resolved
librz/analysis/type_pdb.c Outdated Show resolved Hide resolved
librz/analysis/type_pdb.c Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.h Outdated Show resolved Hide resolved
librz/bin/pdb/stream_pe.c Outdated Show resolved Hide resolved
librz/bin/pdb/tpi.c Show resolved Hide resolved
librz/bin/pdb/tpi.h Outdated Show resolved Hide resolved
librz/type/base.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/tpi.c Outdated Show resolved Hide resolved
librz/bin/pdb/tpi.c Outdated Show resolved Hide resolved
librz/bin/pdb/tpi.c Outdated Show resolved Hide resolved
librz/bin/pdb/tpi.c Show resolved Hide resolved
@XVilka
Copy link
Member

XVilka commented Aug 23, 2021

In fact, I can see there is rz_core_pdb_info() in librz/core/cbin.c. I suggest to create new file called librz/core/cpdb.c and put that function here, also rename it to rz_core_bin_pdb_info_print() and put your RZ_API rz_core_bin_pdb_*() functions as well. Like it's done to DWARF - librz/core/cdwarf.c.

librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Show resolved Hide resolved
librz/bin/pdb/tpi.c Outdated Show resolved Hide resolved
@wargio wargio changed the title [WIP] Totally rewrite PDB parser [WIP] Rewrite PDB parser Aug 23, 2021
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/bin/pdb/pdb.c Outdated Show resolved Hide resolved
librz/core/cpdb.c Outdated Show resolved Hide resolved
Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

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

Also seems too many tests marked as BROKEN. Why?

ut32 blocks = count_blocks(stream_size, pdb->super_block->block_size);
total_blocks += blocks;
}
// NumStreams StreamsSizes StreamsBlockMap
Copy link
Member

Choose a reason for hiding this comment

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

What does this comment mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indicate the meaning of each sizeof(ut32)


/**
* \brief Parse pdb from the buffer
Copy link
Member

Choose a reason for hiding this comment

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

pdb -> PDB

return lf_enum ? lf_enum->substructs : NULL;
}
default:
return NULL;
}
}

static char *get_type_name(void *type) {
/**
* \brief Get the name of the givin type
Copy link
Member

Choose a reason for hiding this comment

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

Get the name of the type

return lf_union->name.name;
}
default:
return NULL;
}
}

static ut64 get_type_val(void *type) {
/**
* \brief Get the numric inside the givin type
Copy link
Member

Choose a reason for hiding this comment

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

Get the numeric value inside the type

* \param mode Output Mode
* \return bool
*/
RZ_API bool rz_core_pdb_info(RzCore *core, const char *file, RzOutputMode mode) {
Copy link
Member

Choose a reason for hiding this comment

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

Rename it into rz_core_pdb_info_print()

@Basstorm
Copy link
Member Author

Also seems too many tests marked as BROKEN. Why?

They are flags(were added by rz_cons_printf("f xx=0x1234"), I removed it.) or classes(We don't support yet)

@wargio
Copy link
Member

wargio commented Aug 24, 2021

Also seems too many tests marked as BROKEN. Why?

They are flags(were added by rz_cons_printf("f xx=0x1234"), I removed it.) or classes(We don't support yet)

i think this is fine, as long as the C apis does the same (actually much better if is via C)

Copy link
Member

@ret2libc ret2libc left a comment

Choose a reason for hiding this comment

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

Also seems too many tests marked as BROKEN. Why?

They are flags(were added by rz_cons_printf("f xx=0x1234"), I removed it.) or classes(We don't support yet)

i think this is fine, as long as the C apis does the same

If they don't show up with fi @ 0xXXXXX it means the C API does not do the same, thus I think it is not fine to completely remove them. The purpose of loading PDB is to get more information about the binary, and for example knowing where the main function is is a valuable info that we lose if we don't put a flag in the right address.

@@ -24,6 +24,7 @@
#include <rz_type.h>
#include <rz_arch.h>
#include <rz_cmd.h>
#include "../bin/pdb/pdb.h"
Copy link
Member

Choose a reason for hiding this comment

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

Why this??? I think it should not be done.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have RZ_API void rz_parse_pdb_types(const RzTypeDB *typedb, const RzPdb *pdb); in this module.

@@ -12,25 +12,6 @@ extern "C" {

struct RZ_PDB7_ROOT_STREAM;

typedef struct rz_pdb_t {
Copy link
Member

Choose a reason for hiding this comment

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

is this file even necessary now? it seems there's not much inside..

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I forgot this file..

@XVilka
Copy link
Member

XVilka commented Aug 24, 2021

I agree that we should keep this f ... output. Even if we might remove it in the future, it's crucial for testing and backward compatibility for now.

@Basstorm
Copy link
Member Author

Move to #1517

@Basstorm Basstorm closed this Aug 24, 2021
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.

4 participants