fix: allow ipswd route /dsc/a2s to stream output vs. waiting until done

This commit is contained in:
blacktop
2023-04-27 17:39:45 -06:00
parent e6f00279d5
commit c7fdf3b19b
4 changed files with 79 additions and 134 deletions
+39 -33
View File
@@ -8,7 +8,6 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"github.com/blacktop/go-macho"
@@ -20,7 +19,7 @@ import (
"github.com/gin-gonic/gin"
)
// swagger:parameters postDscAddrToOff postDscAddrToSym
// swagger:parameters postDscAddrToOff
type dscAddrToOffParams struct {
// path to dyld_shared_cache
// in:query
@@ -29,7 +28,7 @@ type dscAddrToOffParams struct {
// address to convert
// in:query
// required: true
Addr string `json:"addr" binding:"required"`
Addr uint64 `json:"addr" binding:"required"`
}
// swagger:response
@@ -53,12 +52,7 @@ func dscAddrToOff(c *gin.Context) {
}
defer f.Close()
addr, err := strconv.ParseUint(params.Addr, 10, 64)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, types.GenericError{Error: fmt.Sprintf("invalid param 'addr' %s: %v", params.Addr, err)})
}
off, err := cmd.ConvertAddressToOffset(f, addr)
off, err := cmd.ConvertAddressToOffset(f, params.Addr)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, types.GenericError{Error: err.Error()})
return
@@ -67,15 +61,26 @@ func dscAddrToOff(c *gin.Context) {
c.IndentedJSON(http.StatusOK, dscAddrToOffResponse{*off})
}
// swagger:response
// swagger:parameters postDscAddrToSym
type dscAddrsToSymsParams struct {
// path to dyld_shared_cache
// in:query
// required: true
Path string `json:"path" binding:"required"`
// address to convert
// in:query
// required: true
Addrs []uint64 `json:"addrs" binding:"required"`
}
// swagger:response dscAddrToSymResponse
type dscAddrToSymResponse struct {
// The DSC symbol
// in:body
cmd.SymbolLookup
Body []cmd.SymbolLookup `json:"body"`
}
func dscAddrToSym(c *gin.Context) {
var params dscAddrToOffParams
var params dscAddrsToSymsParams
if err := c.ShouldBindJSON(&params); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, types.GenericError{Error: err.Error()})
return
@@ -88,21 +93,27 @@ func dscAddrToSym(c *gin.Context) {
}
defer f.Close()
addr, err := strconv.ParseUint(params.Addr, 10, 64)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, types.GenericError{Error: fmt.Sprintf("invalid param 'addr' %s: %v", params.Addr, err)})
w := c.Writer
enc := json.NewEncoder(w)
header := w.Header()
header.Set("Transfer-Encoding", "chunked")
header.Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
var syms []cmd.SymbolLookup
for _, addr := range params.Addrs {
sym, err := cmd.LookupSymbol(f, addr)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, types.GenericError{Error: err.Error()})
return
}
sym.Demanged = demangle.Do(sym.Symbol, false, false)
sym.Demanged = swift.DemangleBlob(sym.Demanged)
enc.Encode(sym)
w.(http.Flusher).Flush()
}
sym, err := cmd.LookupSymbol(f, addr)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, types.GenericError{Error: err.Error()})
return
}
sym.Demanged = demangle.Do(sym.Symbol, false, false)
sym.Demanged = swift.DemangleBlob(sym.Demanged)
c.IndentedJSON(http.StatusOK, dscAddrToSymResponse{*sym})
c.IndentedJSON(http.StatusOK, syms)
}
// swagger:response
@@ -202,7 +213,7 @@ type dscOffToAddrParams struct {
// offset to convert
// in:query
// required: true
Offset string `json:"off" binding:"required"`
Offset uint64 `json:"off" binding:"required"`
}
// swagger:response
@@ -227,12 +238,7 @@ func dscOffToAddr(c *gin.Context) {
}
defer f.Close()
off, err := strconv.ParseUint(params.Offset, 10, 64)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, types.GenericError{Error: fmt.Sprintf("invalid param 'off' %s: %v", params.Offset, err)})
}
addr, err := cmd.ConvertOffsetToAddress(f, off)
addr, err := cmd.ConvertOffsetToAddress(f, params.Offset)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, types.GenericError{Error: err.Error()})
return
+14 -46
View File
@@ -190,7 +190,8 @@
"required": true
},
{
"type": "string",
"type": "integer",
"format": "uint64",
"x-go-name": "Addr",
"description": "address to convert",
"name": "addr",
@@ -229,10 +230,14 @@
"required": true
},
{
"type": "string",
"x-go-name": "Addr",
"type": "array",
"items": {
"type": "integer",
"format": "uint64"
},
"x-go-name": "Addrs",
"description": "address to convert",
"name": "addr",
"name": "addrs",
"in": "query",
"required": true
}
@@ -372,7 +377,8 @@
"required": true
},
{
"type": "string",
"type": "integer",
"format": "uint64",
"x-go-name": "Offset",
"description": "offset to convert",
"name": "off",
@@ -1386,10 +1392,6 @@
"description": "Symbol is a struct that contains information about a dyld_shared_cache symbol",
"x-go-package": "github.com/blacktop/ipsw/internal/commands/dsc"
},
"SymbolLookup": {
"description": "SymbolLookup is a struct that contains information about a dyld_shared_cache symbol lookup",
"x-go-package": "github.com/blacktop/ipsw/internal/commands/dsc"
},
"address": {
"x-go-package": "github.com/blacktop/ipsw/internal/commands/dsc"
},
@@ -1431,43 +1433,9 @@
},
"dscAddrToSymResponse": {
"description": "",
"headers": {
"demanged": {
"type": "string",
"description": "The demangled symbol name"
},
"ext": {
"type": "string",
"description": "The DSC sub-cache file extension"
},
"image": {
"type": "string",
"description": "The containing image name"
},
"mapping": {
"type": "string",
"description": "The DSC mapping name"
},
"section": {
"type": "string",
"description": "The containing image section"
},
"segment": {
"type": "string",
"description": "The containing image segment"
},
"stub_island": {
"type": "boolean",
"description": "Is the symbol in a DSC stub island"
},
"symbol": {
"type": "string",
"description": "The symbol name"
},
"uuid": {
"type": "string",
"description": "The DSC sub-cache UUID"
}
"schema": {
"type": "array",
"items": {}
}
},
"dscImportsResponse": {
+12 -9
View File
@@ -65,8 +65,9 @@ type Symbol struct {
}
// SymbolLookup is a struct that contains information about a dyld_shared_cache symbol lookup
// swagger:model
type SymbolLookup struct {
// The address of the symbol
Address uint64 `json:"address,omitempty"`
// The symbol name
Symbol string `json:"symbol,omitempty"`
// The demangled symbol name
@@ -248,13 +249,12 @@ func ConvertOffsetToAddress(f *dyld.File, offset uint64) (*Address, error) {
UUID: uuid.String(),
},
}
uuid, m, err := f.GetMappingForVMAddress(addr)
if err != nil {
a.Cache = nil
return a, nil
}
a.Cache.SubCache.Mapping = m.Name
if _, m, err := f.GetMappingForVMAddress(addr); err == nil {
a.Cache.SubCache.Mapping = m.Name
} else {
a.Cache.SubCache.Mapping = "?"
}
if f.IsDyld4 {
a.Cache.SubCache.Extension, _ = f.GetSubCacheExtensionFromUUID(uuid)
@@ -271,7 +271,9 @@ func ConvertOffsetToAddress(f *dyld.File, offset uint64) (*Address, error) {
func LookupSymbol(f *dyld.File, addr uint64) (*SymbolLookup, error) {
var secondAttempt bool
sym := &SymbolLookup{}
sym := &SymbolLookup{
Address: addr,
}
uuid, mapping, err := f.GetMappingForVMAddress(addr)
if err != nil {
@@ -349,7 +351,8 @@ retry:
}
if secondAttempt {
return sym, fmt.Errorf("no symbol found")
sym.Symbol = "?"
return sym, nil
}
ptr, err := f.ReadPointerAtAddress(addr)
+14 -46
View File
@@ -190,7 +190,8 @@
"required": true
},
{
"type": "string",
"type": "integer",
"format": "uint64",
"x-go-name": "Addr",
"description": "address to convert",
"name": "addr",
@@ -229,10 +230,14 @@
"required": true
},
{
"type": "string",
"x-go-name": "Addr",
"type": "array",
"items": {
"type": "integer",
"format": "uint64"
},
"x-go-name": "Addrs",
"description": "address to convert",
"name": "addr",
"name": "addrs",
"in": "query",
"required": true
}
@@ -372,7 +377,8 @@
"required": true
},
{
"type": "string",
"type": "integer",
"format": "uint64",
"x-go-name": "Offset",
"description": "offset to convert",
"name": "off",
@@ -1386,10 +1392,6 @@
"description": "Symbol is a struct that contains information about a dyld_shared_cache symbol",
"x-go-package": "github.com/blacktop/ipsw/internal/commands/dsc"
},
"SymbolLookup": {
"description": "SymbolLookup is a struct that contains information about a dyld_shared_cache symbol lookup",
"x-go-package": "github.com/blacktop/ipsw/internal/commands/dsc"
},
"address": {
"x-go-package": "github.com/blacktop/ipsw/internal/commands/dsc"
},
@@ -1431,43 +1433,9 @@
},
"dscAddrToSymResponse": {
"description": "",
"headers": {
"demanged": {
"type": "string",
"description": "The demangled symbol name"
},
"ext": {
"type": "string",
"description": "The DSC sub-cache file extension"
},
"image": {
"type": "string",
"description": "The containing image name"
},
"mapping": {
"type": "string",
"description": "The DSC mapping name"
},
"section": {
"type": "string",
"description": "The containing image section"
},
"segment": {
"type": "string",
"description": "The containing image segment"
},
"stub_island": {
"type": "boolean",
"description": "Is the symbol in a DSC stub island"
},
"symbol": {
"type": "string",
"description": "The symbol name"
},
"uuid": {
"type": "string",
"description": "The DSC sub-cache UUID"
}
"schema": {
"type": "array",
"items": {}
}
},
"dscImportsResponse": {