title: How to import multiple Frida JS files/functions into the runtime CLI?
body: <p>I'm putting together a Frida test bench for co-workers, and am unfamiliar with JavaScript and Node.JS. I would like to create a single JS file that imports several other JS files, each with several functions. But when I use frida-compile against some Node.JS code that imports other functions, the REPL interpreter is not pulling the functions/variables into scope. So, for example:</p>
  
  <p>I have a flat directory consisting of 3 JavaScript files:</p>
  
  <p>in1.js:</p>
  
  <pre><code>'use strict';
  var a = 'test';
  function b() { console.log("function b"); };
  </code></pre>
  
  <p>in2.js:</p>
  
  <pre><code>'use strict';
  var c = 'test2';
  var d = function () { console.log("function d"); };
  </code></pre>
  
  <p>in3.js:</p>
  
  <pre><code>'use strict';
  require('./in1.js');
  require('./in2.js');
  </code></pre>
  
  <p>Then I run frida-compile, on Windows 10 + Python 3.6 + Node.JS 9.5:</p>
  
  <pre><code>frida-compile in3.js -o out.js
  </code></pre>
  
  <p>Which results in the following output:</p>
  
  <pre><code>(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&amp;&amp;require;if(!u&amp;&amp;a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&amp;&amp;require;for(var o=0;o&lt;r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
  'use strict';
  
  var a = 'test';
  function b() {
    console.log("function b");
  };
  
  },{}],2:[function(require,module,exports){
  'use strict';
  
  var c = 'test2';
  var d = function () {
    console.log("function d");
  };
  
  },{}],3:[function(require,module,exports){
  'use strict';
  
  require('./in1.js');
  require('./in2.js');
  
  },{"./in1.js":1,"./in2.js":2}]},{},[3])
  //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJpbjEuanMiLCJpbjIuanMiLCJpbjMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTs7QUFDQSxJQUFJLElBQUksTUFBUjtBQUNBLElBQUksSUFBSSxZQUFZO0FBQUUsVUFBUSxHQUFSLENBQVksWUFBWjtBQUE0QixDQUFsRDs7O0FDRkE7O0FBQ0EsSUFBSSxJQUFJLE9BQVI7QUFDQSxJQUFJLElBQUksWUFBWTtBQUFFLFVBQVEsR0FBUixDQUFZLFlBQVo7QUFBNEIsQ0FBbEQ7OztBQ0ZBOztBQUNBLFFBQVEsVUFBUjtBQUNBLFFBQVEsVUFBUiIsImZpbGUiOiJnZW5lcmF0ZWQuanMiLCJzb3VyY2VSb290IjoiIn0=
  </code></pre>
  
  <p>Lastly, when I try importing it into the Frida CLI, using the OWASP iGoat project as an example, I cannot access any of those functions:</p>
  
  <pre><code>    frida -R -f com.swaroop.iGoat -l out.js
       ____
      / _  |   Frida 10.6.52 - A world-class dynamic instrumentation toolkit
     | (_| |
      &gt; _  |   Commands:
     /_/ |_|       help      -&gt; Displays the help system
     . . . .       object?   -&gt; Display information about 'object'
     . . . .       exit/quit -&gt; Exit
     . . . .
     . . . .   More info at http://www.frida.re/docs/home/
  Spawned `com.swaroop.iGoat`. Use %resume to let the main thread start executing!
  [Remote::com.swaroop.iGoat]-&gt; %resume
  [Remote::com.swaroop.iGoat]-&gt; a
  ReferenceError: identifier 'a' undefined
  [Remote::com.swaroop.iGoat]-&gt; b
  ReferenceError: identifier 'b' undefined
  [Remote::com.swaroop.iGoat]-&gt; c
  ReferenceError: identifier 'c' undefined
  [Remote::com.swaroop.iGoat]-&gt; d
  ReferenceError: identifier 'd' undefined
  [Remote::com.swaroop.iGoat]-&gt; module
  ReferenceError: identifier 'module' undefined
  [Remote::com.swaroop.iGoat]-&gt; require
  ReferenceError: identifier 'require' undefined
  [Remote::com.swaroop.iGoat]-&gt; exports
  ReferenceError: identifier 'exports' undefined
  [Remote::com.swaroop.iGoat]-&gt;
  </code></pre>
  
  <p>What am I missing... How do I access a,b,c, and d within the Frida CLI?</p>