Skip to content

Commit

Permalink
v2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrofroes committed Mar 24, 2021
1 parent e4da668 commit 95fd790
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GOCMD=go
all: build

build:
$(GOCMD) build manw
$(GOCMD) build

clean:
rm -f manw
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ BOOL CreateProcessA(
LPPROCESS_INFORMATION lpProcessInformation
);
Return value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Note that the function returns before the process has finished initialization. If a required DLL cannot be located or fails to initialize, the process is terminated.
Return value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
Example code:
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ OPTIONS:

flag.Parse()

if(len(os.Args) < 2){
if len(os.Args) < 2{
fmt.Fprintf(os.Stderr, usage)
os.Exit(1)
}

var cachePath string

if(!cacheFlag){
if !cacheFlag{
cachePath = config.Load()
}

Expand Down
12 changes: 8 additions & 4 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func addFunctionCache(search, cachePath string, api *utils.API) (entry string){
utils.CheckError(err)

f.WriteString(api.Title + "\n\n")
f.WriteString("Exported by: " + api.DLL + "\n\n")

if api.DLL != ""{
f.WriteString("Exported by: " + api.DLL + "\n\n")
}

f.WriteString(api.Description + "\n\n")
f.WriteString(api.CodeA + "\n")

Expand Down Expand Up @@ -58,12 +62,12 @@ func addStructureCache(search, cachePath string, api *utils.API) (entry string){

func parseSyscallJson(data *map[string]interface{}, search string, f *os.File){
for k, v := range *data {
if(strings.HasPrefix(k, "Windows")){
if strings.HasPrefix(k, "Windows"){
f.WriteString(k + "\n")
} else if(!strings.Contains(k, "Nt")){
} else if !strings.Contains(k, "Nt"){
f.WriteString("\t- " + k + ": ")
}
if(strings.ToLower(k) == strings.ToLower(search)){
if strings.ToLower(k) == strings.ToLower(search){
switch v.(type){
case float64:
s := fmt.Sprintf("%2.f\n", v)
Expand Down
24 changes: 16 additions & 8 deletions pkg/scrapy/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ParseMSDNFunction(search, url string) *utils.API{
if e.Attr("property") == "og:title"{
funcTitle := strings.Split(strings.ToLower(e.Attr("content")), " ")[0]

if(!strings.Contains(funcTitle, search)){
if !strings.Contains(funcTitle, search){
utils.Warning("Unable to find this Windows function.")
}

Expand All @@ -42,8 +42,16 @@ func ParseMSDNFunction(search, url string) *utils.API{

collector.OnHTML("meta", func(e *colly.HTMLElement){
if e.Attr("name") == "req.dll"{
api.DLL = e.Attr("content")
return
if e.Attr("content") != ""{
api.DLL = e.Attr("content")
return
}
}
if e.Attr("name") == "APILocation"{
if strings.Contains(e.Attr("content"), ".dll"){
api.DLL = e.Attr("content")
return
}
}
})

Expand All @@ -59,12 +67,12 @@ func ParseMSDNFunction(search, url string) *utils.API{
})

collector.OnHTML("p", func(e *colly.HTMLElement){
re, err := regexp.Compile(".*(no error occurs|succeeds|fails|failure|returns|return value|returned).*(no error occurs|succeeds|fails|failure|returns|return value|returned)[^.]+")
re, err := regexp.Compile("^(If the function succeeds|The return value|Returns|This function does|If the function fails|If no error occurs)[^.]+.*[.]")
utils.CheckError(err)
match := re.FindString(e.Text)

if match != ""{
api.Return += match + ". "
api.Return += match
api.Return = strings.ReplaceAll(api.Return, "\n", " ",)
}
})
Expand All @@ -81,8 +89,8 @@ func ParseMSDNFunction(search, url string) *utils.API{
func RunFunctionScraper(search, cachePath string){
search = strings.ToLower(search)

if(cachePath != ""){
if(!cache.CheckCache(search, cachePath)){
if cachePath != ""{
if !cache.CheckCache(search, cachePath){
searchAux := "+api+function+msdn"

url := GoogleMSDNSearch(search, searchAux)
Expand Down
8 changes: 4 additions & 4 deletions pkg/scrapy/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func GoogleMSDNSearch(search, searchAux string) string{
item := sellector.Eq(node)
link, _ := item.Attr("href")

re, err := regexp.Compile("https://docs.microsoft.com/en-us/windows+")
re, err := regexp.Compile("https://docs.microsoft.com/en-us/+")
utils.CheckError(err)

if(re.MatchString(link)) {
if re.MatchString(link) {
tmpUrl := strings.Split(link, "=")[5]
result = strings.Split(tmpUrl, "&")[0]
return
Expand All @@ -49,7 +49,7 @@ func GoogleMSDNSearch(search, searchAux string) string{
func GoogleKernelSearch(search, searchAux string) string{
baseUrl := "https://www.google.com/search?q="

if(!strings.HasPrefix(search, "_")){
if !strings.HasPrefix(search, "_"){
search = "_" + search
}

Expand All @@ -71,7 +71,7 @@ func GoogleKernelSearch(search, searchAux string) string{
re, err := regexp.Compile("https://www.nirsoft.net/kernel_struct/+")
utils.CheckError(err)

if(re.MatchString(link)) {
if re.MatchString(link) {
tmpUrl := strings.Split(link, "=")[5]
result = strings.Split(tmpUrl, "&")[0]
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/scrapy/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ParseMSDNStructure(search, url string) *utils.API{
if e.Attr("property") == "og:title"{
strucTitle := strings.Split(strings.ToLower(e.Attr("content")), " ")[0]

if(!strings.Contains(strucTitle, search)){
if !strings.Contains(strucTitle, search){
utils.Warning("Unable to find this Windows structure.")
}

Expand Down Expand Up @@ -78,8 +78,8 @@ func ParseMSDNStructure(search, url string) *utils.API{
func RunStructureScraper(search, cachePath string){
search = strings.ToLower(search)

if(cachePath != ""){
if(!cache.CheckCache(search, cachePath)){
if cachePath != ""{
if !cache.CheckCache(search, cachePath){
searchAux := "+structure+msdn"

url := GoogleMSDNSearch(search, searchAux)
Expand Down
10 changes: 5 additions & 5 deletions pkg/scrapy/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func parseSyscallRepo(search, url string) map[string]interface{}{
utils.CheckError(err)
match := re.FindString(strings.ToLower(string(body)))

if(match == ""){
if match == ""{
utils.Warning("Unable to find this Windows Syscall ID.")
}

Expand All @@ -39,18 +39,18 @@ func RunSyscallScraper(search, arch, cachePath string){

search = strings.ToLower(search)

if(arch == "x64" || arch == "amd64" || arch == "x86_64" ){
if arch == "x64" || arch == "amd64" || arch == "x86_64" {
url = "https://raw.githubusercontent.com/j00ru/windows-syscalls/master/x64/json/nt-per-system.json"
arch = "_x64"
} else if(arch == "x86" || arch == "i386" || arch == "80386"){
} else if arch == "x86" || arch == "i386" || arch == "80386"{
url = "https://raw.githubusercontent.com/j00ru/windows-syscalls/master/x86/json/nt-per-system.json"
arch = "_x86"
} else {
utils.Warning("Missing architecture (-a) value.")
}

if(cachePath != ""){
if(!cache.CheckSyscallCache(search, arch, cachePath)){
if cachePath != ""{
if !cache.CheckSyscallCache(search, arch, cachePath){
jsonData := parseSyscallRepo(search, url)
cache.RunSyscallCache(&jsonData, search, arch, cachePath)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/scrapy/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func parseMSDNDataType(search, url string) string{
strSlice := strings.Split(e.Text, "\n")
dataTypeInfo += "\nData Type: "
for i, str := range strSlice{
if(i > 0 && i < len(strSlice) -1){
if i > 0 && i < len(strSlice) - 1{
dataTypeInfo += str + "\n\n"
}
}
Expand All @@ -48,8 +48,8 @@ func parseMSDNDataType(search, url string) string{
func RunTypeScraper(search, cachePath string){
search = strings.ToLower(search)

if(cachePath != ""){
if(!cache.CheckCache(search, cachePath)){
if cachePath != ""{
if !cache.CheckCache(search, cachePath){
searchAux := "+windows+data+type+msdn"

url := GoogleMSDNSearch(search, searchAux)
Expand All @@ -60,7 +60,7 @@ func RunTypeScraper(search, cachePath string){

dataTypeInfo := parseMSDNDataType(search, url)

if(dataTypeInfo == ""){
if dataTypeInfo == ""{
utils.Warning("Unable to find this Windows data type.")
}

Expand All @@ -77,7 +77,7 @@ func RunTypeScraper(search, cachePath string){

dataTypeInfo := parseMSDNDataType(search, url)

if(dataTypeInfo == ""){
if dataTypeInfo == ""{
utils.Warning("Unable to find this Windows data type.")
}

Expand Down
14 changes: 9 additions & 5 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type API struct {
}

func CheckError(err error){
if(err != nil){
if err != nil{
log.Fatal(err)
}
}
Expand All @@ -40,7 +40,11 @@ func GenericPrint(data string){

func PrintMSDNFunc(api *API){
fmt.Printf(api.Title + "\n\n")
fmt.Printf("Exported by: " + api.DLL + "\n\n")

if api.DLL != ""{
fmt.Printf("Exported by: " + api.DLL + "\n\n")
}

fmt.Printf(api.Description + "\n\n")
fmt.Printf(api.CodeA + "\n")

Expand Down Expand Up @@ -73,12 +77,12 @@ func PrintMSDNStructure(api *API){

func PrintSyscallJson(data *map[string]interface{}, search string){
for k, v := range *data {
if(strings.HasPrefix(k, "Windows")){
if strings.HasPrefix(k, "Windows"){
fmt.Printf("%s\n", k)
} else if(!strings.Contains(k, "Nt")){
} else if !strings.Contains(k, "Nt"){
fmt.Printf("\t- %s: ", k)
}
if(strings.ToLower(k) == strings.ToLower(search)){
if strings.ToLower(k) == strings.ToLower(search){
switch v.(type){
case float64:
fmt.Printf("%2.f\n", v)
Expand Down

0 comments on commit 95fd790

Please sign in to comment.