diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2022-12-17 12:45:03 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2022-12-22 10:11:08 +0100 |
| commit | 9867c87359492308a169e6da6e007082e299ac3a (patch) | |
| tree | ae304695ecce329ef882711f2be7e42fdc5c457e /prog/analysis.go | |
| parent | 8482d3c1035095c89d112c75bfcc2e4095b486bf (diff) | |
prog: move image extraction from sys/linux
Now that images are not linux-specific,
we can move all image-related logic directly into prog package
and significantly simplify the logic.
Diffstat (limited to 'prog/analysis.go')
| -rw-r--r-- | prog/analysis.go | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/prog/analysis.go b/prog/analysis.go index b4a30dbe8..fec43e1bd 100644 --- a/prog/analysis.go +++ b/prog/analysis.go @@ -9,8 +9,11 @@ package prog import ( + "bytes" "fmt" "io" + + "github.com/google/syzkaller/pkg/image" ) type state struct { @@ -340,39 +343,27 @@ func checkMaxCallID(id int) { } } -type ExtractedAssetType int +type AssetType int const ( - MountInRepro ExtractedAssetType = iota + MountInRepro AssetType = iota ) -type ExtractedAsset struct { - Call int - Type ExtractedAssetType - Reader io.Reader - Error error -} - -func (p *Prog) ExtractAssets() []*ExtractedAsset { - handler := p.Target.ExtractMountedImage - if handler == nil { - // Such an operation is not supported by the target. - return nil - } - ret := []*ExtractedAsset{} +func (p *Prog) ForEachAsset(cb func(name string, typ AssetType, r io.Reader)) { for id, c := range p.Calls { - // So far we only support the MountInRepro asset. - reader, err := handler(c) - if reader == nil && err == nil { - // This is not the call that contains the mount image. - continue - } - ret = append(ret, &ExtractedAsset{ - Type: MountInRepro, - Call: id, - Reader: reader, - Error: err, + ForeachArg(c, func(arg Arg, _ *ArgCtx) { + a, ok := arg.(*DataArg) + if !ok || a.Type().(*BufferType).Kind != BufferCompressed { + return + } + data, err := image.Decompress(a.Data()) + if err != nil { + panic(err) + } + if len(data) == 0 { + return + } + cb(fmt.Sprintf("mount_%v", id), MountInRepro, bytes.NewReader(data)) }) } - return ret } |
