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

Add tests for typedef'd structs with parameters #98

Closed
13 tasks done
d0c-s4vage opened this issue Jan 2, 2020 · 0 comments · Fixed by #99
Closed
13 tasks done

Add tests for typedef'd structs with parameters #98

d0c-s4vage opened this issue Jan 2, 2020 · 0 comments · Fixed by #99
Assignees
Labels
bug concrete-issue An actionable, concrete issue that includes stack trace & technical details. Usually post-triage

Comments

@d0c-s4vage
Copy link
Owner

d0c-s4vage commented Jan 2, 2020

After creating the issue, checkboxes will appear where [] label exist in the
markdown. You can check/uncheck them to fill out the environment section.

Checklist

  • I have included the [relevant portions of the] 010 template used that caused the bug
  • I have filled out the environment section

Environment

Platform

  • Windows
  • Mac
  • Linux
  • Other (please specify)

Python Version

  • Python 2.7
  • Python 3.4
  • Python 3.5
  • Python 3.6
  • Python 3.7
  • Python 3.8
  • Other (please specify)

Describe the bug

It is unclear if typedefd structs with parameters currently work. This is blocked by d0c-s4vage/py010parser#31. Once that is fixed, this test case should pass:

    def test_typedefd_struct_with_parameters(self):
        dom = self._test_parse_build(
            "\x01\x02\x03\x04\x01\x02\x03",
            """
                struct TEST_STRUCT(int arraySize, int arraySize2)
                {
                    uchar b[arraySize];
                    uchar c[arraySize2];
                };
                local int bytes = 4;
                typedef struct TEST_STRUCT NEW_STRUCT;
                NEW_STRUCT l(bytes, 3);
            """,
        )
        self.assertEqual(len(dom.l.b), 4)
        self.assertEqual(dom.l.b[0], 1)
        self.assertEqual(dom.l.b[1], 2)
        self.assertEqual(dom.l.b[2], 3)
        self.assertEqual(dom.l.b[3], 4)
        self.assertEqual(len(dom.l.c), 3)
        self.assertEqual(dom.l.c[0], 1)
        self.assertEqual(dom.l.c[1], 2)
        self.assertEqual(dom.l.c[2], 3)

    def test_typedefd_struct_with_parameters(self):
        dom = self._test_parse_build(
            "\x01\x02\x03\x04\x01\x02\x03",
            """
                struct TEST_STRUCT(int arraySize, int arraySize2)
                {
                    uchar b[arraySize];
                    uchar c[arraySize2];
                };
                local int bytes = 4;
                typedef struct TEST_STRUCT NEW_STRUCT;
                NEW_STRUCT l(bytes, 3);
            """,
        )
        self.assertEqual(len(dom.l.b), 4)
        self.assertEqual(dom.l.b[0], 1)
        self.assertEqual(dom.l.b[1], 2)
        self.assertEqual(dom.l.b[2], 3)
        self.assertEqual(dom.l.b[3], 4)
        self.assertEqual(len(dom.l.c), 3)
        self.assertEqual(dom.l.c[0], 1)
        self.assertEqual(dom.l.c[1], 2)
        self.assertEqual(dom.l.c[2], 3)

Implementation/Fix Notes/Thoughts

This may work out-of-the-box once the py010parser issue is fixed. This test case needs to be added though, as pfp is not currently testing this specific setup.

The potential problem that needs to be tested is the resolving of struct parameter fields when creating a struct using the new StructUnionTypeRef function.

@d0c-s4vage d0c-s4vage added bug concrete-issue An actionable, concrete issue that includes stack trace & technical details. Usually post-triage labels Jan 2, 2020
@d0c-s4vage d0c-s4vage self-assigned this Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug concrete-issue An actionable, concrete issue that includes stack trace & technical details. Usually post-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant