Skip to content

Commit

Permalink
add more info to list output
Browse files Browse the repository at this point in the history
  • Loading branch information
JLaferri committed Nov 19, 2022
1 parent dabb7ef commit d63f7e3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

type injectionDetails struct {
InjectionAddress string
Name string
Codetype string
Annotation string
Tags string
Expand All @@ -33,7 +34,7 @@ func listInjections(input, output string, isRecursive bool) {
}

if loc.IsDir() {
populateInjectionsFromFolder(input, isRecursive, &result)
populateInjectionsFromFolder("N/A", input, isRecursive, &result)
} else {
populateInjectionsFromFile(input, &result)
}
Expand Down Expand Up @@ -85,6 +86,7 @@ func populateInjectionsFromFile(input string, list *injectionList) {
}

list.Details = append(list.Details, injectionDetails{
Name: code.Name,
InjectionAddress: address,
Codetype: codetype,
Annotation: lineAnnotation,
Expand All @@ -97,22 +99,23 @@ func populateInjectionsFromFile(input string, list *injectionList) {
}

list.Details = append(list.Details, injectionDetails{
Name: code.Name,
InjectionAddress: address,
Codetype: "06",
Annotation: geckoCode.Annotation,
})
case Binary:
populateInjectionsFromBinary(geckoCode.SourceFile, list)
populateInjectionsFromBinary(code.Name, geckoCode.SourceFile, list)
case InjectFolder:
populateInjectionsFromFolder(geckoCode.SourceFolder, geckoCode.IsRecursive, list)
populateInjectionsFromFolder(code.Name, geckoCode.SourceFolder, geckoCode.IsRecursive, list)
default:
log.Panicf("Unsupported build type: %s\n", geckoCode.Type)
}
}
}
}

func populateInjectionsFromBinary(file string, list *injectionList) {
func populateInjectionsFromBinary(name, file string, list *injectionList) {
contents, err := ioutil.ReadFile(file)
if err != nil {
log.Panicf("Failed to read binary file %s\n%s\n", file, err.Error())
Expand All @@ -136,6 +139,7 @@ func populateInjectionsFromBinary(file string, list *injectionList) {
address[0] = (address[0] & 1) + 0x80

list.Details = append(list.Details, injectionDetails{
Name: name,
InjectionAddress: strings.ToUpper(hex.EncodeToString(address)),
Codetype: codetype,
})
Expand Down Expand Up @@ -168,16 +172,23 @@ func populateInjectionsFromBinary(file string, list *injectionList) {
}
}

func populateInjectionsFromFolder(input string, isRecursive bool, list *injectionList) {
func populateInjectionsFromFolder(name, input string, isRecursive bool, list *injectionList) {
asmFilePaths := collectFilesFromFolder(input, isRecursive)

for _, filePath := range asmFilePaths {
header := parseAsmFileHeader(filePath)
address := parseAddressFromFile(header.Address, filePath)

lineAnnotation := filepath.ToSlash(filePath)
if header.Annotation != "" {
lineAnnotation = fmt.Sprintf("%s | %s", header.Annotation, lineAnnotation)
}

list.Details = append(list.Details, injectionDetails{
Name: name,
InjectionAddress: address,
Codetype: header.Codetype,
Annotation: header.Annotation,
Annotation: lineAnnotation,
Tags: header.Tags,
})
}
Expand Down

0 comments on commit d63f7e3

Please sign in to comment.