Skip to content

Commit 055c38e

Browse files
committed
feat: use new frida-go compiler options
1 parent f1ae54e commit 055c38e

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
github.com/fatih/color v1.18.0
7-
github.com/frida/frida-go v0.12.1
7+
github.com/frida/frida-go v0.13.0
88
github.com/spf13/cobra v1.9.1
99
)
1010

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
33
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
44
github.com/frida/frida-go v0.12.1 h1:dHOdJU3wuQkvlb7Lan0RFSm0lpCJH6cW8IbYOxt9C0E=
55
github.com/frida/frida-go v0.12.1/go.mod h1:OyRIp58wuTcGggI6ztakXcHkTXrt5WfD9yi3pq6QyGw=
6+
github.com/frida/frida-go v0.13.0 h1:ocEnnj3+87EXrxRXaFPCCT/WxoDvwFW+wPEFx6IfEEQ=
7+
github.com/frida/frida-go v0.13.0/go.mod h1:O8Dg1YBGfQsBEL1a8x3GURw/JllJrcuvg78ga2OgdM4=
68
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
79
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
810
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=

main.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ var rootCmd = &cobra.Command{
206206

207207
os.MkdirAll(tempDir, os.ModePerm)
208208

209-
// save current directory because we might change it to compile the script
210-
currentDir, _ := os.Getwd()
211-
212209
if _, err = os.Stat(filepath.Join(tempDir, "script.ts")); os.IsNotExist(err) {
213210
for fl, data := range tempFiles {
214211
os.WriteFile(filepath.Join(tempDir, fl), data, os.ModePerm)
@@ -217,26 +214,36 @@ var rootCmd = &cobra.Command{
217214

218215
if _, err = os.Stat(filepath.Join(tempDir, "node_modules")); os.IsNotExist(err) {
219216
// Install modules
217+
pwd, _ := os.Getwd()
218+
os.Chdir(tempDir)
220219
command := exec.Command("npm", "install")
221220
if err := command.Run(); err != nil {
222221
logger.Errorf("Error installing modules: %v", err)
223222
}
223+
os.Chdir(pwd)
224224
}
225225

226226
agentPath := filepath.Join(tempDir, agentFilename)
227227
var scriptBody string
228228

229229
// check if we have script.ts already compiled
230230
if _, err = os.Stat(agentPath); os.IsNotExist(err) {
231-
os.Chdir(tempDir)
232-
233231
comp := frida.NewCompiler()
234232

235233
comp.On("finished", func() {
236234
logger.Infof("Done compiling script")
237235
})
238236

239-
bundle, err := comp.Build("script.ts")
237+
comp.On("diagnostics", func(diag string) {
238+
logger.Errorf("compilation error: %v", diag)
239+
})
240+
241+
buildOptions := frida.NewCompilerOptions()
242+
buildOptions.SetProjectRoot(tempDir)
243+
buildOptions.SetJSCompression(frida.JSCompressionTerser)
244+
buildOptions.SetSourceMaps(frida.SourceMapsOmitted)
245+
246+
bundle, err := comp.Build("script.ts", buildOptions)
240247
if err != nil {
241248
return fmt.Errorf("error compiling script: %v", err)
242249
}
@@ -246,8 +253,6 @@ var rootCmd = &cobra.Command{
246253
}
247254

248255
scriptBody = bundle
249-
250-
os.Chdir(currentDir)
251256
} else {
252257
data, err := os.ReadFile(agentPath)
253258
if err != nil {

0 commit comments

Comments
 (0)