Scriptable scope = cx.initStandardObjects(doc);
cx.putThreadLocal("topscope", scope);
cx.putThreadLocal("scrutinizer", scrutinizer);
//set up API
App app = new App(scrutinizer, doc);
ScriptableObject.putProperty(scope, "app", Context.javaToJS(app, scope));
ScriptableObject.putProperty(scope, "Collab", Context.javaToJS(new Collab(scrutinizer), scope));
ScriptableObject.putProperty(scope, "util", Context.javaToJS(new Util(scrutinizer), scope));
ScriptableObject.putProperty(scope, "event", Context.javaToJS(new Event(scrutinizer, doc), scope));
ScriptableObject.putProperty(scope, "media", Context.javaToJS(new Media(scrutinizer), scope));
ScriptableObject.putProperty(scope, "XMLData", Context.javaToJS(new XMLData(scrutinizer), scope));
ScriptableObject.putProperty(scope, "display", Context.javaToJS(new display(), scope));
ScriptableObject.putProperty(scope, "console", Context.javaToJS(doc.console, scope));
ScriptableObject.putProperty(scope, "info", Context.javaToJS(doc.info, scope));
ScriptableObject.putProperty(scope, "spell", Context.javaToJS(new Spell(scrutinizer), scope));
// redirect String.eval() and app.eval() to eval()
ScriptableObject.putProperty((Scriptable) scope.get("String", scope), "eval", (Scriptable) scope.get("eval", scope));
ScriptableObject.putProperty((Scriptable) scope.get("app", scope), "eval", (Scriptable) scope.get("eval", scope));
/* these are deprecated but still used in malicious samples */
ScriptableObject.putProperty(scope, "subject", Context.javaToJS(doc.info.Subject, scope));
ScriptableObject.putProperty(scope, "producer", Context.javaToJS(doc.info.Producer, scope));
ScriptableObject.putProperty(scope, "creator", Context.javaToJS(doc.info.Creator, scope));
ScriptableObject.putProperty(scope, "author", Context.javaToJS(doc.info.Author, scope));
ScriptableObject.putProperty(scope, "keywords", Context.javaToJS(doc.info.Keywords, scope));
ScriptableObject.putProperty(scope, "creationDate", Context.javaToJS(doc.info.CreationDate, scope));
ScriptableObject.putProperty(scope, "modDate", Context.javaToJS(doc.info.ModDate, scope));
ScriptableObject.putProperty(scope, "title", Context.javaToJS(doc.info.Title, scope));
ScriptableObject.putProperty(scope, "zoom", Context.javaToJS(doc.zoom, scope));
ScriptableObject.putProperty(scope, "URL", Context.javaToJS(doc.URL, scope));
ScriptableObject.putProperty(scope, "numPages", Context.javaToJS(doc.numPages, scope));
// if document catalog contains custom metadata we have to put them into the context.
if (scrutinizer.getDocumentAdapter() != null) {
PDDocumentInformation info = scrutinizer.getDocumentAdapter().getDocument().getDocumentInformation();
if (info != null) {
String[] docinfokeys = {"Author", "Creator", "CreationDate", "Subject", "Title", "Keywords", "ModDate", "Producer", "Trapped"};
Set<String> metadataKeys = info.getMetadataKeys();
metadataKeys.removeAll(Arrays.asList(docinfokeys)); // remove non-custom keys
for (String metadataKey : metadataKeys) {
log.debug(String.format("adding custom info metadata: %s value: %s", "info." + metadataKey, info.getCustomMetadataValue(metadataKey)));
ScriptableObject.putProperty((Scriptable) scope.get("info", scope), metadataKey, Context.javaToJS(info.getCustomMetadataValue(metadataKey), scope));
}
}
}
app.viewerVersion = Double.parseDouble(viewerVersion);
plugIn plugin = app.getPlugin();
plugin.version = Double.parseDouble(pluginVersion);
app.setPlugin(plugin);
log.info("using viewerVersion " + app.viewerVersion);
for (String str : codes) {
doExecute(str, cx, scope);
}
List<Timeout> timeouts = app.getTimeouts();
synchronized (timeouts) {
for (Timeout timeout : timeouts) {
timeout.stop();
}
}