From d5f3384a13efe44b8407cbe55537e0bdc36a093c Mon Sep 17 00:00:00 2001 From: leandrofroes Date: Mon, 13 Feb 2023 17:14:27 -0300 Subject: [PATCH] Fix MS URL search bug; Add func argc counter to the output --- pkg/cache/cache.go | 2 ++ pkg/scrapy/function.go | 10 ++++++---- pkg/scrapy/google.go | 2 +- pkg/scrapy/structure.go | 5 ++--- pkg/scrapy/type.go | 3 +-- pkg/utils/utils.go | 3 +++ 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 7bde537..4cb8300 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -20,6 +20,8 @@ func addFunctionCache(search, cachePath string, api *utils.API) (entry string){ if api.DLL != ""{ f.WriteString("Exported by: " + api.DLL + "\n\n") } + + f.WriteString("Number of arguments: " + api.Argc + "\n\n") f.WriteString(api.Description + "\n\n") f.WriteString(api.CodeA + "\n") diff --git a/pkg/scrapy/function.go b/pkg/scrapy/function.go index 26d25a5..b808789 100644 --- a/pkg/scrapy/function.go +++ b/pkg/scrapy/function.go @@ -4,6 +4,7 @@ import ( "log" "regexp" "strings" + "strconv" "github.com/leandrofroes/manw/pkg/utils" "github.com/leandrofroes/manw/pkg/cache" @@ -15,7 +16,6 @@ func ParseMSDNFunction(search, url string) *utils.API{ api := utils.API{} collector := colly.NewCollector( - colly.AllowedDomains("docs.microsoft.com"), colly.UserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"), ) @@ -58,6 +58,8 @@ func ParseMSDNFunction(search, url string) *utils.API{ collector.OnHTML("pre", func(e *colly.HTMLElement){ if e.Index == 0 { api.CodeA = e.Text + api.Argc = strconv.Itoa(len(strings.Split(e.Text, "\n")) - 3) + return } if e.Index == 1{ @@ -91,10 +93,10 @@ func RunFunctionScraper(search, cachePath string){ if cachePath != ""{ if !cache.CheckCache(search, cachePath){ - searchAux := "+api+function+msdn" + searchAux := "+function+msdn" url := GoogleMSDNSearch(search, searchAux) - + if url == ""{ utils.Warning("Unable to find this Windows function.") } @@ -104,7 +106,7 @@ func RunFunctionScraper(search, cachePath string){ cache.RunFunctionCache(search, cachePath, api) } } else { - searchAux := "+api+function+msdn" + searchAux := "+function+msdn" url := GoogleMSDNSearch(search, searchAux) diff --git a/pkg/scrapy/google.go b/pkg/scrapy/google.go index 352376e..bcef3e0 100644 --- a/pkg/scrapy/google.go +++ b/pkg/scrapy/google.go @@ -26,7 +26,7 @@ func GoogleMSDNSearch(search, searchAux string) string{ item := sellector.Eq(node) link, _ := item.Attr("href") - re, err := regexp.Compile("https://docs.microsoft.com/en-us/+") + re, err := regexp.Compile(".microsoft.com/en-us/+") utils.CheckError(err) if re.MatchString(link) { diff --git a/pkg/scrapy/structure.go b/pkg/scrapy/structure.go index 4b63303..d4e2875 100644 --- a/pkg/scrapy/structure.go +++ b/pkg/scrapy/structure.go @@ -15,7 +15,6 @@ func ParseMSDNStructure(search, url string) *utils.API{ api := utils.API{} collector := colly.NewCollector( - colly.AllowedDomains("docs.microsoft.com"), colly.UserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"), ) @@ -80,7 +79,7 @@ func RunStructureScraper(search, cachePath string){ if cachePath != ""{ if !cache.CheckCache(search, cachePath){ - searchAux := "+api+msdn" + searchAux := "+msdn" url := GoogleMSDNSearch(search, searchAux) @@ -105,4 +104,4 @@ func RunStructureScraper(search, cachePath string){ utils.PrintMSDNStructure(api) } -} +} \ No newline at end of file diff --git a/pkg/scrapy/type.go b/pkg/scrapy/type.go index b684729..7934605 100644 --- a/pkg/scrapy/type.go +++ b/pkg/scrapy/type.go @@ -14,7 +14,6 @@ import( func parseMSDNDataType(search, url string) string{ var dataTypeInfo string collector := colly.NewCollector( - colly.AllowedDomains("docs.microsoft.com"), colly.UserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"), ) @@ -53,7 +52,7 @@ func RunTypeScraper(search, cachePath string){ searchAux := "+windows+data+type+msdn" url := GoogleMSDNSearch(search, searchAux) - + if url == ""{ utils.Warning("Unable to find this Windows data type.") } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index d245368..08edc1d 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -16,6 +16,7 @@ type API struct { Return string Source string DLL string + Argc string } func CheckError(err error){ @@ -44,6 +45,8 @@ func PrintMSDNFunc(api *API){ if api.DLL != ""{ fmt.Printf("Exported by: " + api.DLL + "\n\n") } + + fmt.Printf("Number of arguments: " + api.Argc + "\n\n") fmt.Printf(api.Description + "\n\n") fmt.Printf(api.CodeA + "\n")