frida / frida-compile

Compile a Frida script comprised of one or more Node.js modules
Other
190 stars 48 forks source link

Files that start with an uppercase character overwrite the entry point (the file given to frida-compile at cli) #49

Closed leonitousconforti closed 2 years ago

leonitousconforti commented 2 years ago

When an agent imports a file that starts with an uppercase character, it becomes the 'entry point' of the frida script.

reproduction repo: https://github.com/leonitousconforti/frida-agent-no-frist-uppercase-filenames

I feel like this is a bug but please let me know if this is intended behavior.

leonitousconforti commented 2 years ago

Found what I think is the problem: https://github.com/frida/frida-compile/blob/700bd39432416360b8650e3638bbd99798294e5d/src/compiler.ts#L522-L523

Is there a reason why they are sorted? When compiling the 'good' agents the sorted array is

[
  '/agent/index.js',
  '/agent/index.js.map',
  '/agent/logger.js',
  '/agent/logger.js.map',
  '/agent/test.js',
  '/agent/test.js.map'
]

but when compiling the bad agent it is

[
  '/badAgent/Test.js',
  '/badAgent/Test.js.map',
  '/badAgent/index.js',
  '/badAgent/index.js.map',
  '/badAgent/logger.js',
  '/badAgent/logger.js.map'
]
leonitousconforti commented 2 years ago

I see that the next block of code tries to correct if the entry point is not at the top of the list, fixing the compare to normalize the paths puts them in the right order. Since I am on windows, it was trying to compare "\\badAgent\\index.js" to "/badAgent/index.js"