Skip to content

Commit

Permalink
Fix MS URL search bug; Add func argc counter to the output
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrofroes committed Feb 13, 2023
1 parent 5882ade commit d5f3384
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 6 additions & 4 deletions pkg/scrapy/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"log"
"regexp"
"strings"
"strconv"

"github.com/leandrofroes/manw/pkg/utils"
"github.com/leandrofroes/manw/pkg/cache"
Expand All @@ -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"),
)

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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.")
}
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pkg/scrapy/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/scrapy/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)

Expand Down Expand Up @@ -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)

Expand All @@ -105,4 +104,4 @@ func RunStructureScraper(search, cachePath string){

utils.PrintMSDNStructure(api)
}
}
}
3 changes: 1 addition & 2 deletions pkg/scrapy/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)

Expand Down Expand Up @@ -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.")
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type API struct {
Return string
Source string
DLL string
Argc string
}

func CheckError(err error){
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit d5f3384

Please sign in to comment.