Example #1
0
    def __parseMethods(self):
        """
        Parse methods section.
        """

        assert  self.clsFile is not None

        methodCount = ByteToDec(self.clsFile.read(2))

        methods = []
        for index in range(methodCount):
            accessFlag = ByteToDec(self.clsFile.read(2))
            name = self.result.getUtf8(ByteToDec(self.clsFile.read(2)))
            descriptor = self.result.getUtf8(ByteToDec(self.clsFile.read(2)))

            method = Method(name, descriptor, accessFlag)

            attrCount = ByteToDec(self.clsFile.read(2))
            if attrCount > 0:
                for i in range(attrCount):
                    attributeName = self.result.getUtf8(ByteToDec(self.clsFile.read(2)))
                    attributeLength = ByteToDec(self.clsFile.read(4))

                    # for now, only parse the "Code Attribute
                    parser = Attribute.getParser(attributeName)

                    if parser is not None:
                        attribute = parser(self.clsFile, self.result)
                        method.addAttribute(attribute)
                    else:
                        self.clsFile.read(attributeLength)

            methods.append(method)

        self.result.setMethods(methodCount, methods)
Example #2
0
    def __parseAttribute(self):
        """
        Parse the attributes of class file.
        """

        attrCount = ByteToDec(self.clsFile.read(2))
        if attrCount > 0:
            for i in range(attrCount):
                attributeName = self.result.getUtf8(ByteToDec(self.clsFile.read(2)))
                attributeLength = ByteToDec(self.clsFile.read(4))

                parser = Attribute.getParser(attributeName)

                if parser is not None:
                    attribute = parser(self.clsFile, self.result)
                    self.result.addAttribute(attribute)
                else:
                    self.clsFile.read(attributeLength)