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

Upgrade the NWScript disassembler to a decompiler #16

Open
DrMcCoy opened this issue Jun 7, 2018 · 3 comments
Open

Upgrade the NWScript disassembler to a decompiler #16

DrMcCoy opened this issue Jun 7, 2018 · 3 comments

Comments

@DrMcCoy
Copy link
Member

DrMcCoy commented Jun 7, 2018

Currently, we have a disassembler for NWScript bytecode, ncsdis. For an explanation for what NWScript is and how it works internally, please see here: https://xoreos.org/blog/2016/01/12/disassembling-nwscript-bytecode/

What we could use is a full-fledged decompiler. For that, the existing NWScript IR produced by the disassembler could be leveraged. More analysis on said IR would be necessary, of course.

The IR itself might also need to be modified, to bring it more in line with usual compiler IR. And the disassembler could probably also profit from this task.

Owning the different BioWare games would be useful here, since more functionality was added to the script over the years. And testing the decompiler over a wide variety of scripts is paramount. As a starter, though, a few (Neverwinter-Nights-era) script sources and their bytecode are here: scripts.zip

Like the rest of the xoreos-tool, the decompiler should be written in C++. xoreos-tools is currently fully C++03, but I'm opening it up to C++11 now. I don't necessarily want to see a PR with thousands line diffs changing everything in xoreos-tools the C++11 way, but feel free to use C++11 features in new code.

@DrMcCoy
Copy link
Member Author

DrMcCoy commented Mar 24, 2019

UPDATE: @Nostritius started on a decompiler (see #34 and #35), but there's a lot still to be done.

  • Variable deduplication
  • vector/structs
  • Not all opcodes are handled
  • loops, break and continue
  • Moving comparisons into conditionals
  • Local variable declarations
  • ...

There's probably also a lot of transforms that can/should be done to make the code more readable.

@lachjames
Copy link

lachjames commented Jul 24, 2020

As discussed with @DrMcCoy several times (including in issue #57), I've been working on an implementation of an ncs2nss compiler. I've made the repository public at https://github.com/lachjames/ncs2nss.

My ultimate goal is certainly to integrate this into xoreos-tools (I already rely on ncsdis to disassemble the files). However, it's written in Python and xoreos-tools is (of course) C++. So there are several options here:

  • As discussed on DeadlyStream, I'd be happy to work with AmanoJyaku on a decompiler that could eventually be integrated into xoreos-tools.
  • I'd also be very happy to discuss/help anybody who wants to implement a C++ version of my tool, using my implementation as a guide.
  • I could have a go at implementing the decompiler myself for xoreos-tools in C++, though I admit I've never really used C++ for any serious project before (however, I'm confident I could do it if necessary).
  • There's always the possibility of integrating my Python code with xoreos-tools directly, though I imagine @DrMcCoy wouldn't want to go that route, (quite reasonably) preferring a pure C++ implementation. That said, I'd be happy to work with you on creating an integration if you'd like.

What do you think?

@DrMcCoy
Copy link
Member Author

DrMcCoy commented Jul 24, 2020

I imagine @DrMcCoy wouldn't want to go that route, (quite reasonably) preferring a pure C++ implementation.

Yup.

As for the rest, I'm happy to have whatever's coming my way. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants