forked from AlexeySoshin/smali2java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smali2java.go
76 lines (58 loc) · 1.25 KB
/
smali2java.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"bufio"
"flag"
"fmt"
"github.com/alexeysoshin/smali2java/parser"
"log"
"os"
"path/filepath"
"sync"
)
const smaliExtension = ".smali"
func main() {
pathToSmali := flag.String("path_to_smali", "./test_data/s.smali", "Path to your smali files")
flag.Parse()
parseSmaliFiles(*pathToSmali)
}
func parseSmaliFiles(path string) {
var wg = sync.WaitGroup{}
filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
if f.IsDir() {
//log.Printf("Skipping directory: %s\n", path)
} else if filepath.Ext(path) != smaliExtension {
//log.Printf("Not a smali file, skipping: %s\n", path)
} else {
convertSmali(path, &wg)
}
return nil
})
wg.Wait()
}
func convertSmali(path string, wg *sync.WaitGroup) {
/*defer func() {
if r := recover(); r != nil {
fmt.Printf("%s %v\n", path, r)
}
}()*/
fmt.Printf("Processing %s\n", path)
wg.Add(1)
//go func() {
file, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
defer file.Close()
javaFile := parser.JavaFile{}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
//fmt.Println(scanner.Text())
javaFile.ParseLine(scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
javaFile.Print()
wg.Done()
//}()
}