Parsing Hack code into Abstract Syntax Tree - abstract-syntax-tree

I would like my Hack code to be broken down to Abstract Syntax Tree. Please advise me on available tools/libraries/github repositories which will help me to parse Hack code into AST.
I have found "h2tp" (hack to php transpiler written by Facebook), however it doesn't parse the code into AST. I also tried this project which does what I want however it is not recognising many of the operators and requires a significant rework, which will quite a lot of time to do.

hhast (HHAST: Low-Level AST Library) lets you do that, you may invoke hh_parse like this : hh_parse --full-fidelity-json $file | jq
taken from (https://github.com/hhvm/hhast/blob/master/docs/ast-lib.md)

The HHVM itself provides a lot of tools to dump the structure of a PHP file. However, the AST dump was removed: https://github.com/facebook/hhvm/issues/1268
What you can do is dump the HHVM assembly language: http://hhvm.com/blog/6323/the-journey-of-a-thousand-bytecodes
HHVM also has a PHP transpiler which may help:https://docs.hhvm.com/hack/tools/transpiler
You could also try to port this extension over to the HHVM: https://github.com/nikic/php-ast

Related

How to use Domain_builder module?

I would like to implement a simple abstract domain using functors provided by module Domain_builder (documented in section EVA->Domains), but I am not able to open the module. A simple ocaml file x.ml:
open Domain_builder
and command frama-c -load-script x.ml produce error Unbound module Domain_builder. I am, however, able to import other modules documented in this section (e.g. Cvalue).
It seems that module Domain_builder is not exported by EVA's .mli file (https://git.frama-c.com/pub/frama-c/-/blob/master/src/plugins/value/Eva.mli), but neither is Cvalue module.
Am I doing something wrong, or is Domain_builder module really missing in EVA's signature?
Sadly, you're right, Domain_builder cannot be used outside of Eva for now
(NB: if it was exported, you'd have to open Eva.Domain_builder in any case).
As for why Cvalue is available: for historical reasons, this module, together with all files within src/plugins/value_types are in fact considered as kernel modules.

How to include the application's version number in a Scala.js program?

Basically, I'm curious if something like SBT including the version number in a program is possible for Scala.js. The proposed solution doesn't work in scala.js, apparently due the the absence of the getPackage method:
[error] Referring to non-existent method java.lang.Class.getPackage()java.lang.Package
Use sbt-buildinfo for that. The Usage section of the readme contains everything you need.

Ioncube - obfuscation error

Currently I am evaluating ioncube for products developed by our company.
When running the encoded product I'm getting
PHP Fatal error: Class '[obfuscated]'
If I have anything like DomDocument in my code I get this error. I feel like if I have any php package installed and used Ioncube throws a error. I contacted Ioncube support and I'm unable to get a solution.
Does anybody know how to use Ioncube with a code contain DomDocument, imagick like package usages?
Obfuscation renames latent symbolic information in the compiled code of ionCube files, using names that are nonsense, or in the case of functions, names that would not even be valid were they used in PHP source. The corollary of this is that any non-encoded context will fail that attempts to use a symbol that has been obfuscated, as expected.
To bridge between the encoded and non-encoded world, an obfuscation exclusion list can be specified to name the symbols that should not be obfuscated. Due to the nature of PHP, in code such as $a->foo(), it is in general unknown what class $a is an instance of, and therefore if excluding foo() from being obfuscated, foo() used in any class context (i.e. all foo()s) would need not to be obfuscated. This isn't really a problem as symbol renaming is much less important than new features such as code encryption with dynamic algorithmic keys, but it is still preferable not to blindly exclude from obfuscation every method that happens to share the same name as a method from a module, which is why methods of module classes are not excluded by default.
The upshot of this is that you should prepare an exclusion file of just the methods that you want to exclude. It would be useful to have pre-prepared lists of functions for all known modules, and this is likely to be available in a future release, but it is easy to produce this oneself either manually or automatically.
Disclosure: I am associated with ionCube.

Flyway Mysql multiline comment directive not parsed

I am wondering if there is any news for multi line comment directive support for MySql.
I believe the problem is related to:
Mysql dump comments directives and simple comments
Basically it seems SqlScript/MySQLSqlStatementBuilder fail in recognizing as directive a statement in the format:
/*!50001 <STATEMENT SPLITTED IN
MULTI
LINES> */;
I am using version 2.2.1
Additional notes:
the same goes for previous versions (2.1.1), and issues are multiple and not only related to comment directives; theu are also hard to debug because of missing exception trace.
Basically I think parser cannot currently handle pretty standard mysql scripts created with mysqldump; this IMO is a necessary feature for any usage in existing projects at least.
If anybody has suggestions to overcome these issues, it would be highly appreciated.
I am using Flyway 2.1.1 API in Java.
What I am doing is parsing a dump file (only the schema structure) and replace the version dependant comments.
This solution is pretty bad, but waiting for a better support of MySQL dump in Flyway, I didn't find anything else...

How to create a directory in Lua?

Is it possible to create a directory in lua ? If so, how ?
You may find the LuaFileSystem library useful. It has a mkdir function.
require "lfs"
lfs.mkdir("/path/to/dir")
There's a "system" call (or something like that, this is from memory) which you should be able to use to run an arbitrary program, which could include the mkdir command.
EDIT: I found my Programming in Lua book. On page 203, it mentions how you could use an
os.execute("mkdir " .. dirname)
to "fake" a directory creation command.
EDIT 2: Take note of Jonas Thiem's warning that this command can be abused if the directory name comes from an untrusted source!
You may also want to look at Lua/APR, the Apache Portable Runtime binding for Lua. The docs can be found at here
One of the reasons I use Lua is that I can write code that runs across multiple OSes. I was using LFS for some time, but have found that using Lua/APR provides a more platform-neutral library. And there are lots of other useful routines in the APR.
You can use the paths package instead. Then you can simply do:
require 'paths'
paths.mkdir('your/dir')

Resources