Extension Prometheus

Hello everybody,

I don’t quite understand how this module works. In Flash,
the code obfuscation software would take the SWF file and create a version of the SWF with the obfuscated code.

When I installed the package in a simple test example and compiled
for the HTML5 version I got errors like this:

image

Do I understand correctly that in Defold code obfuscation works similarly, ie.

  1. I add a Prometheus package to a project
  2. I compile the project (and code obfuscation occurs during compilation)
  3. The compiled version of the project already has the code obfuscated
    Is this how it works?

Is it possible to obfuscate 1 selected script ?

Yes, during the build process the Lua code gets obfuscated.

No, the extension currently obfuscates all scripts in the project.

2 Likes

Thank you.
And what is the reason for this error during compilation ? The project has only one script with “Hello Word”

This error only appears when compiling for the HTML version

Which error?

You mean when you do “Project->Bundle->HTML5” or “Project->Build HTML5”?

errors on the following screen
image

YES

Ok, so it happens in both cases? But not when you bundle for other platforms?

My first guess is that the files in builtins are not processed, but it looks like it isn’t able to process any file…

Sorry, the error appears when compiling for all platforms. It does not appear only when run Project-Build.

I have added an example and a Prometheus module that I download from the local server

Ah, I see what’s going on. The obfuscator works when run using bob.jar from the project root, but when run from the unpack folder of the editor it obviously can’t find the prometheus.lua config file.

@FredZX there’s a new release which fixes the path issue when run from the editor: Release Fix path issue when run from the editor · defold/extension-prometheus · GitHub

2 Likes

Great, thanks a lot !

Attempting to use this on our game, there were a few problems obfuscating narrator by @astrochili
e.g

in test/runtime/jumping.lua line 18:
local paragraphs = story:continue()
unexpected token <Keyword> “continue”, expected <Identifier>

and narrator/narrator/parser.lua line 56:
local address = id * ('.' * id) ^ -2
Parsing Error at Position 56:36, Unexpected Token “-”. Expected a Expression!

The first I thought wouldn’t occur given that the configuration file specifies LuaVersion = “Lua51”, and the second (and others) are presumably also errors, if we assume the code is valid Lua.

Is the best course of action for me to raise issues at https://github.com/prometheus-lua/Prometheus ?

Wow, sorry, just interesting in the context of using a narrator. What is the game? Is there public screenshots/videos or is it in-house yet? :slight_smile:

1 Like

Is there any easy way to temporary disable this plugin instead of removing it from game.project? Removing then adding is quite annoying, I must copy the dependency url for backup. Sometimes I just want to have a quick build for Android testing but I’m not happy to remove it, reopen the editor.

Is there anything I can add to prometheus.lua to make it disabled?

No I don’t think so.

Ok, one more question. Does this extension affect Live Update? I mean whether it makes the unchanged files hexDigest value changed at every build?

Good question! I’m not sure if if the obfuscated code for a file is the same every time or if there is some randomness to them. You would have to try yourself and check the checksum of the file between attempts (or do a simple file comparison).

It depend. Look at prometheus git. And prometheus.lua file.

If you use only minification I think you will get same files.

If you use obfuscation, it can contains some random. But you can set seed value.

1 Like

Also ,i use fork of extension. It much easy to work with not minified code in development.

@britzl is it possible to read here game.project? mb it is not hard to add game.project-> prometheus → enable = 1 flag?

@Override
	public String obfuscate(String input, String path, String buildVariant) throws Exception {
		if(buildVariant.equals(Bob.VARIANT_RELEASE)) {
			try {
				Bob.initLua();
				unpackPrometheusSource();

				File inputFile = writeToTempFile(input);
				File outputFile = createTempFile();

				// command line arguments to launch prometheus
				List<String> options = new ArrayList<String>();
				options.add(Bob.getExe(Platform.getHostPlatform(), "luajit-64"));
				options.add(getCliPath().toString());
				options.add("--config");
				options.add("prometheus.lua");
				options.add("--out");
				options.add(outputFile.getAbsolutePath());
				options.add(inputFile.getAbsolutePath());

				// launch the process
				ProcessBuilder pb = new ProcessBuilder(options).redirectErrorStream(true);
				java.util.Map<String, String> env = pb.environment();
				env.put("LUA_PATH", Bob.getPath("share/luajit/") + "/?.lua");
				Process p = pb.start();
				int ret = p.waitFor();

				// get all of the output from the process
				InputStream is = p.getInputStream();
				byte[] output_bytes = new byte[is.available()];
				is.read(output_bytes);
				is.close();

				if (ret != 0) {
					System.err.println(new String(output_bytes));
					throw new Exception("Unable to run prometheus, return code: " + ret);
				}
				return readFile(outputFile);
			} catch (Exception e) {
				e.printStackTrace();
				throw new Exception("Unable to run prometheus, ", e);
			}
		}else{
			return input;
		}
	}
2 Likes

Another way is to use different settings files for building with bob. E.g. “–settings release.ini” which uses the complete list of dependencies (e.g. prometheus)

2 Likes