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

Support for custom output #25

Open
Cubxity opened this issue Sep 23, 2019 · 11 comments
Open

Support for custom output #25

Cubxity opened this issue Sep 23, 2019 · 11 comments

Comments

@Cubxity
Copy link
Contributor

Cubxity commented Sep 23, 2019

I am currently working on a RE tool that would like to use CFR as a decompilation backend. I would like support for custom output for writing type references, method references, etc. This would be useful for making hyperlinks in the frontend, etc.

An example could be found here: ITextOutput.java

@Col-E
Copy link
Contributor

Col-E commented Sep 23, 2019

This would be pretty useful. I've been using JavaParser's SymbolSolver for this so far. If this isn't in-scope you can always try that out.

@Cubxity
Copy link
Contributor Author

Cubxity commented Sep 23, 2019

@Col-E it is possible for the classes to have some weird characters that could potentially affect the symbol solver like { for example

@Col-E
Copy link
Contributor

Col-E commented Sep 23, 2019

As long as the AST is built it should work. I've not tested on obfuscated code if that's what you're asking.

@leibnitz27
Copy link
Owner

FWIW - the current internal api is https://github.com/leibnitz27/cfr/blob/master/src/org/benf/cfr/reader/util/output/Dumper.java

which is more of a literal string stream than ITextOutput. It wouldn't be too tricky to convert usages to a similar api. (note that there's some state which is used to handle how types are viewed etc).

However .....

I have a sneaky (ENTIRELY UNJUSTIFIED) feeling that the next logical step is basically to export a parse tree, rather than something like a string stream.

The issue there (yak shaving time!) is that I don't want to use standard JDK parse tree types, because I am very attached to 'any version of java' with forwards compatibility. And I don't want to export the internal AST types, because they contain a great deal of hackery that isn't locked down.

I'm tempted to bypass the intermediate stage.

@Cubxity
Copy link
Contributor Author

Cubxity commented Sep 28, 2019

@leibnitz27 Would it be possible for you to add an option to set a custom dumper factory in CfrDriverImpl as seen here?
image

@Cubxity
Copy link
Contributor Author

Cubxity commented Sep 30, 2019

@leibnitz27 could you add methods like "writeComment", "writeKeyword", "writeDelimiter", etc. like procyon's ITextOutput? This would be very useful for syntax highlighting

@Cubxity
Copy link
Contributor Author

Cubxity commented Sep 30, 2019

@leibnitz27 also would it be possible to make objects for identifier like method, fields, variables instead of string?
image

@Cubxity
Copy link
Contributor Author

Cubxity commented Sep 30, 2019

Alright, I'm making a fork for my attempt at this https://github.com/bytespy/cfr

@leibnitz27
Copy link
Owner

Cool - please bear in mind a few small things:

I massively prefer not to expose internal APIs, because I really appreciate the freedom to screw with them (you might have noticed). So either implement an externally visible API in dumper, or expose to the outside world via an adaptor please.

Also note that the dumper (effctively) carries a type registration burden, which really doesn't want to be exposed to the outside world.

@leibnitz27
Copy link
Owner

I ended up going for a 'token-stream-with-semantic-info' rather than an explicit interface. I don't want to expose the internal interface, and this fits better with my aim of keeping the external API compatible in both directions.

There's an example in https://github.com/leibnitz27/cfr_client/blob/master/src/org/benf/cfr_client_example/WithTokenSink.java

@NKU915
Copy link

NKU915 commented Nov 4, 2019

How can dump the original bytecode of method code attribute when CFR failed to decompile? As Procyon decompiler does(pls refer the attachement), thanks.
Jietu20191104-121139

leibnitz27 added a commit that referenced this issue Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants