Skip to content

Commit

Permalink
fix: fix not writing crashes in some edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
NSEcho committed Feb 19, 2024
1 parent 7da5ccf commit 103f167
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
17 changes: 3 additions & 14 deletions cmd/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,6 @@ var fuzzCmd = &cobra.Command{
var script *frida.Script = nil
hasCrashed := false

go func() {
<-m.DetachCH
sendStats(p, "Unloading script")
if script != nil {
script.Unload()
}
sendStats(p, "Detaching session")
if sess != nil {
sess.Detach()
}

}()

go func() {
if base == "" {
sendErr(p, "Base cannot be empty")
Expand Down Expand Up @@ -154,6 +141,8 @@ var fuzzCmd = &cobra.Command{
var lastInput string

sess.On("detached", func(reason frida.SessionDetachReason, crash *frida.Crash) {
// Add sleep here so that we can wait for the context to get cancelled
time.Sleep(3 * time.Second)
if hasCrashed {
sendStats(p, fmt.Sprintf("Session detached; reason=%s", reason.String()))
out := fmt.Sprintf("fcrash_%s_%s", app, crashSHA256(lastInput))
Expand Down Expand Up @@ -185,6 +174,7 @@ var fuzzCmd = &cobra.Command{
sendStats(p, "Written session file")
}
}
p.Send(tui.SessionDetached{})
})

script, err = sess.CreateScript(scriptContent)
Expand Down Expand Up @@ -216,7 +206,6 @@ var fuzzCmd = &cobra.Command{
ctx, _ := context.WithTimeout(context.Background(), 1*time.Second)
if err := script.ExportsCallWithContext(ctx, "fuzz", method, mutated.Input); err == frida.ErrContextCancelled {
hasCrashed = true
sess.Detach()
break
}
if timeout > 0 {
Expand Down
6 changes: 3 additions & 3 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type Model struct {
Base string
Input string
ValidInputs []string
DetachCH chan struct{}

exiting bool
start time.Time
Expand Down Expand Up @@ -55,7 +54,6 @@ func NewModel() Model {

m.seconds = 5
m.start = time.Now()
m.DetachCH = make(chan struct{})
return m
}

Expand All @@ -68,7 +66,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "q":
m.DetachCH <- struct{}{}
m.exiting = true
return m, m.Tick()
}
Expand All @@ -90,6 +87,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit
}
return m, m.Tick()
case SessionDetached:
m.exiting = true
return m, m.Tick()
}

return m, nil
Expand Down

0 comments on commit 103f167

Please sign in to comment.