Giter VIP home page Giter VIP logo

jvm-parser's Introduction

JVM Parser
----------

This package implements a simple parser for JVM bytecode (.class and .jar)
files in Haskell.  It also implements some basic control-flow graph
manipulations.

jvm-parser's People

Contributors

acfoltzer avatar atomb avatar langston-barrett avatar ntc2 avatar robdockins avatar ryanglscott avatar travitch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jvm-parser's Issues

Parsing failure for JVM bytecode generated from Scala

Trivial Scala code which compiles to only simple Java works. Slightly more interesting Scala which depends on the scala-library for collections fails with a parse error:

saw: Index 587 is not a method reference.
CallStack (from HasCallStack):
  error, called at src/Language/JVM/Parser.hs:387:12 in jvm-parser-0.3.0.0-8vikjDDT9aZHOxrZiDNeeN:Language.JVM.Parser

screen shot 2019-02-05 at 11 37 11 am

This example was produced with the nightly build of SAW: saw-0.2-2019-01-29-MacOSX-64

`Invokespecial` and `Invokevirtual` should include `ClassName` instead of `Type`

In the Instruction datatype, constructors Invokeinterface and Invokestatic both take ClassName and MethodKey arguments, while the related Invokespecial and Invokevirtual constructors take Type instead of ClassName.

| Invokeinterface ClassName MethodKey -- ^ Invoke interface method
| Invokespecial Type MethodKey -- ^ Invoke instance method; special handling for
-- superclass, private, and instance initialization
-- method invocations
| Invokestatic ClassName MethodKey -- ^ Invoke a class (@static@) method
| Invokevirtual Type MethodKey -- ^ Invoke instance method; dispatch based on class

According to the JVM spec, all invoke instruction variants require a reference to a class or interface; they do not say that they work with a "class, array, or interface type" like some other instructions do (e.g. new, checkcast, anewarray, etc).

The crucible-jvm package fails during translation if either Invokespecial or Invokevirtual uses a Type that is not a class. The jvm-verifier package handles invoke instructions on array types by substituting in class java/lang/Object for the array type; however, I can't find any such behavior documented in any version of the JVM spec, so I expect that it's just wrong.

We should replace Type arguments with ClassName in the Invokespecial and Invokevirtual constructors so that all four invoke instructions are treated uniformly in accordance with the JVM spec.

Argument of `Newarray` instruction should be the element type, not the array type

As the docstring for Newarray points out, the Type argument is the type of the array itself, and not the element type.

| Newarray Type -- ^ Create new array (The type is the type of the array.)

This is both confusing and inconvenient. No code in the library ever produces a Newarray constructor with anything other than an ArrayType argument, so its presence conveys no information. And every function that consumes Instruction values must deal with the possibility of Newarray with a non-ArrayType argument, and implement some error handling for that case (which actually never arises in practice).

It would be much cleaner to change the convention so that Newarray has the element type as its argument.

This change should probably go along with bumping the package version number, as it breaks backward compatibility in a subtle way that is not reflected in the type signatures. We will have to make sure that downstream packages like crucible-jvm are adapted appropriately.

Descriptor parsing functions call `error`

Functions parseTypeDescriptor and parseMethodDescriptor both call the haskell error function in the case of a parse error. This makes them not useful for parsing user-provided strings.

These functions should be changed to return Maybe types, so that a parse error can be indicated with Nothing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.