<div dir="ltr"><div>This might be a very beginner question, but I'm looking for an example for something that I have never done.</div><div><br></div>Suppose that I wanted to express actions with respect to lifted semantics of CPU instructions to an intermediate representation, BAP IL or LLVM IR. How might I go about providing a Backus Naur Form specification and then dynamically interpreting those lifted instructions by also specifying actions to be done with any given IL/IR primitive? I'm looking for any library that allows me to express BNF terms and actions on them.<div><br></div><div>Like, say I convert push ebp to Bap IL (here's a json representation from their live development branch):</div><div><br></div><div><div>{</div><div>  "move": {</div><div>    "lvar": { "name": "t", "id": 107, "typ": { "imm": 64 } },</div><div>    "rexp": { "var": { "name": "RBP", "id": 30, "typ": { "imm": 64 } } }</div><div>  }</div><div>},</div><div>{</div><div>  "move": {</div><div>    "lvar": { "name": "RSP", "id": 32, "typ": { "imm": 64 } },</div><div>    "rexp": {</div><div>      "binop": {</div><div>        "op": "minus",</div><div>        "lexp": {</div><div>          "var": { "name": "RSP", "id": 32, "typ": { "imm": 64 } }</div><div>        },</div><div>        "rexp": { "inte": { "int": "MHg4OjY0" } }</div><div>      }</div><div>    }</div><div>  }</div><div>},</div><div>{</div><div>  "move": {</div><div>    "lvar": {</div><div>      "name": "mem64",</div><div>      "id": 58,</div><div>      "typ": {</div><div>        "mem": {</div><div>          "index_type": { "r64": true },</div><div>          "element_type": { "r8": true }</div><div>        }</div><div>      }</div><div>    },</div><div>    "rexp": {</div><div>      "store": {</div><div>        "memory": {</div><div>          "var": {</div><div>            "name": "mem64",</div><div>            "id": 58,</div><div>            "typ": {</div><div>              "mem": {</div><div>                "index_type": { "r64": true },</div><div>                "element_type": { "r8": true }</div><div>              }</div><div>            }</div><div>          }</div><div>        },</div><div>        "address": {</div><div>          "var": { "name": "RSP", "id": 32, "typ": { "imm": 64 } }</div><div>        },</div><div>        "value": {</div><div>          "var": { "name": "t", "id": 107, "typ": { "imm": 64 } }</div><div>        },</div><div>        "endian": "little_endian",</div><div>        "size": { "r64": true }</div><div>      }</div><div>    }</div><div>  }</div><div>}</div></div><div><br></div><div>Then, for say, move, I could, in my interpreter specify some reasonable action that captures those semantics, like allocate a 64 bit space in which to store the value, and then also a SSA for the RSP variable value at such a point. In this way, I could possibly specify other things such as symbolic interpretation of specific memory regions for things like solving to find certain constraints and limitations on code blocks. Then, after some segments of code are lifted and interpreted, I provide some meaningful context in terms of state, registers and memory, and the representation gained could be executed upon in order to reach interesting path and state combinations.</div><div><br></div><div>But I've never written a language before... I'm afraid I'm new. But I'm very interested, and I want to learn so I'm looking to use infrastructure that's already there, and learn how to construct this properly.</div></div>