parent
							
								
									dc06b1d69b
								
							
						
					
					
						commit
						e0a3fd3ca2
					
				@ -1,116 +1,125 @@ | 
				
			|||||||
package firefox | 
					package firefox | 
				
			||||||
 | 
					
 | 
				
			||||||
// type firefox struct {
 | 
					import ( | 
				
			||||||
// 	name           string
 | 
						"fmt" | 
				
			||||||
// 	storage        string
 | 
						"io/fs" | 
				
			||||||
// 	profilePath    string
 | 
						"io/ioutil" | 
				
			||||||
// 	masterKey      []byte
 | 
						"path/filepath" | 
				
			||||||
// 	items          []item.Item
 | 
						"strings" | 
				
			||||||
// 	itemPaths      map[item.Item]string
 | 
					
 | 
				
			||||||
// 	multiItemPaths map[string]map[item.Item]string
 | 
						"hack-browser-data/internal/browingdata" | 
				
			||||||
// }
 | 
						"hack-browser-data/internal/item" | 
				
			||||||
//
 | 
						"hack-browser-data/internal/utils/fileutil" | 
				
			||||||
// // New
 | 
						"hack-browser-data/internal/utils/typeutil" | 
				
			||||||
// func New(info *browserInfo, items []item.Item) ([]*firefox, error) {
 | 
					) | 
				
			||||||
// 	f := &firefox{
 | 
					
 | 
				
			||||||
// 		browserInfo: info,
 | 
					type firefox struct { | 
				
			||||||
// 		items:       items,
 | 
						name        string | 
				
			||||||
// 	}
 | 
						storage     string | 
				
			||||||
// 	multiItemPaths, err := getFirefoxItemAbsPath(f.browserInfo.profilePath, f.items)
 | 
						profilePath string | 
				
			||||||
// 	if err != nil {
 | 
						masterKey   []byte | 
				
			||||||
// 		if strings.Contains(err.Error(), "profile path is not exist") {
 | 
						items       []item.Item | 
				
			||||||
// 			fmt.Println(err)
 | 
						itemPaths   map[item.Item]string | 
				
			||||||
// 			return nil, nil
 | 
					} | 
				
			||||||
// 		}
 | 
					
 | 
				
			||||||
// 		panic(err)
 | 
					// New returns a new firefox instance.
 | 
				
			||||||
// 	}
 | 
					func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) { | 
				
			||||||
// 	var firefoxList []*firefox
 | 
						f := &firefox{ | 
				
			||||||
// 	for name, value := range multiItemPaths {
 | 
							name:        name, | 
				
			||||||
// 		firefoxList = append(firefoxList, &firefox{
 | 
							storage:     storage, | 
				
			||||||
// 			browserInfo: &browserInfo{
 | 
							profilePath: profilePath, | 
				
			||||||
// 				name:      name,
 | 
							items:       items, | 
				
			||||||
// 				masterKey: nil,
 | 
						} | 
				
			||||||
// 			},
 | 
						if !fileutil.FolderExists(profilePath) { | 
				
			||||||
// 			items:     items,
 | 
							return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath) | 
				
			||||||
// 			itemPaths: value,
 | 
						} | 
				
			||||||
// 		})
 | 
					
 | 
				
			||||||
// 	}
 | 
						multiItemPaths, err := f.getMultiItemPath(f.profilePath, f.items) | 
				
			||||||
// 	return firefoxList, nil
 | 
						if err != nil { | 
				
			||||||
// }
 | 
							if strings.Contains(err.Error(), "profile path is not exist") { | 
				
			||||||
//
 | 
								fmt.Println(err) | 
				
			||||||
// func getFirefoxItemAbsPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
 | 
								return nil, nil | 
				
			||||||
// 	var multiItemPaths = make(map[string]map[item.Item]string)
 | 
							} | 
				
			||||||
// 	absProfilePath := path.Join(homeDir, filepath.Clean(profilePath))
 | 
							return nil, err | 
				
			||||||
// 	// TODO: Handle read file error
 | 
						} | 
				
			||||||
// 	if !isFileExist(absProfilePath) {
 | 
						var firefoxList []*firefox | 
				
			||||||
// 		return nil, fmt.Errorf("%s profile path is not exist", absProfilePath)
 | 
						for name, itemPaths := range multiItemPaths { | 
				
			||||||
// 	}
 | 
							firefoxList = append(firefoxList, &firefox{ | 
				
			||||||
// 	err := filepath.Walk(absProfilePath, firefoxWalkFunc(items, multiItemPaths))
 | 
								name:      name, | 
				
			||||||
// 	return multiItemPaths, err
 | 
								items:     typeutil.Keys(itemPaths), | 
				
			||||||
// }
 | 
								itemPaths: itemPaths, | 
				
			||||||
//
 | 
							}) | 
				
			||||||
// func (f *firefox) CopyItemFileToLocal() error {
 | 
						} | 
				
			||||||
// 	for item, sourcePath := range f.itemPaths {
 | 
						return firefoxList, nil | 
				
			||||||
// 		var dstFilename = item.TempName()
 | 
					} | 
				
			||||||
// 		locals, _ := filepath.Glob("*")
 | 
					
 | 
				
			||||||
// 		for _, v := range locals {
 | 
					func (f *firefox) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) { | 
				
			||||||
// 			if v == dstFilename {
 | 
						var multiItemPaths = make(map[string]map[item.Item]string) | 
				
			||||||
// 				err := os.Remove(dstFilename)
 | 
					
 | 
				
			||||||
// 				// TODO: Should Continue all iteration error
 | 
						err := filepath.Walk(profilePath, firefoxWalkFunc(items, multiItemPaths)) | 
				
			||||||
// 				if err != nil {
 | 
						return multiItemPaths, err | 
				
			||||||
// 					return err
 | 
					} | 
				
			||||||
// 				}
 | 
					
 | 
				
			||||||
// 			}
 | 
					func (f *firefox) copyItemToLocal() error { | 
				
			||||||
// 		}
 | 
						for i, path := range f.itemPaths { | 
				
			||||||
//
 | 
							// var dstFilename = item.TempName()
 | 
				
			||||||
// 		// TODO: Handle read file name error
 | 
							var filename = i.String() | 
				
			||||||
// 		sourceFile, err := ioutil.ReadFile(sourcePath)
 | 
							// TODO: Handle read file error
 | 
				
			||||||
// 		if err != nil {
 | 
							d, err := ioutil.ReadFile(path) | 
				
			||||||
// 			fmt.Println(err.Error())
 | 
							if err != nil { | 
				
			||||||
// 		}
 | 
								fmt.Println(err.Error()) | 
				
			||||||
// 		err = ioutil.WriteFile(dstFilename, sourceFile, 0777)
 | 
							} | 
				
			||||||
// 		if err != nil {
 | 
							err = ioutil.WriteFile(filename, d, 0777) | 
				
			||||||
// 			return err
 | 
							if err != nil { | 
				
			||||||
// 		}
 | 
								return err | 
				
			||||||
// 	}
 | 
							} | 
				
			||||||
// 	return nil
 | 
						} | 
				
			||||||
// }
 | 
						return nil | 
				
			||||||
//
 | 
					} | 
				
			||||||
// func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) filepath.WalkFunc {
 | 
					
 | 
				
			||||||
// 	return func(path string, info fs.FileInfo, err error) error {
 | 
					func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) filepath.WalkFunc { | 
				
			||||||
// 		for _, v := range items {
 | 
						return func(path string, info fs.FileInfo, err error) error { | 
				
			||||||
// 			if info.Name() == v.FileName() {
 | 
							for _, v := range items { | 
				
			||||||
// 				parentDir := getParentDir(path)
 | 
								if info.Name() == v.FileName() { | 
				
			||||||
// 				if _, exist := multiItemPaths[parentDir]; exist {
 | 
									parentDir := getParentDir(path) | 
				
			||||||
// 					multiItemPaths[parentDir][v] = path
 | 
									if _, exist := multiItemPaths[parentDir]; exist { | 
				
			||||||
// 				} else {
 | 
										multiItemPaths[parentDir][v] = path | 
				
			||||||
// 					multiItemPaths[parentDir] = map[item.Item]string{v: path}
 | 
									} else { | 
				
			||||||
// 				}
 | 
										multiItemPaths[parentDir] = map[item.Item]string{v: path} | 
				
			||||||
// 			}
 | 
									} | 
				
			||||||
// 		}
 | 
								} | 
				
			||||||
// 		return err
 | 
							} | 
				
			||||||
// 	}
 | 
							return err | 
				
			||||||
// }
 | 
						} | 
				
			||||||
//
 | 
					} | 
				
			||||||
// func getParentDir(absPath string) string {
 | 
					
 | 
				
			||||||
// 	return filepath.Base(filepath.Dir(absPath))
 | 
					func getParentDir(absPath string) string { | 
				
			||||||
// }
 | 
						return filepath.Base(filepath.Dir(absPath)) | 
				
			||||||
//
 | 
					} | 
				
			||||||
// func (f *firefox) GetMasterKey() ([]byte, error) {
 | 
					
 | 
				
			||||||
// 	return f.masterKey, nil
 | 
					func (f *firefox) GetMasterKey() ([]byte, error) { | 
				
			||||||
// }
 | 
						return f.masterKey, nil | 
				
			||||||
//
 | 
					} | 
				
			||||||
// func (f *firefox) Name() string {
 | 
					
 | 
				
			||||||
// 	return f.name
 | 
					func (f *firefox) Name() string { | 
				
			||||||
// }
 | 
						return f.name | 
				
			||||||
//
 | 
					} | 
				
			||||||
// func (f *firefox) GetBrowsingData() []browingdata.Source {
 | 
					
 | 
				
			||||||
// 	var browsingData []browingdata.Source
 | 
					func (f *firefox) GetBrowsingData() (*browingdata.Data, error) { | 
				
			||||||
// 	for item := range f.itemPaths {
 | 
						b := browingdata.New(f.items) | 
				
			||||||
// 		d := item.NewBrowsingData()
 | 
					
 | 
				
			||||||
// 		if d != nil {
 | 
						if err := f.copyItemToLocal(); err != nil { | 
				
			||||||
// 			browsingData = append(browsingData, d)
 | 
							return nil, err | 
				
			||||||
// 		}
 | 
						} | 
				
			||||||
// 	}
 | 
					
 | 
				
			||||||
// 	return browsingData
 | 
						masterKey, err := f.GetMasterKey() | 
				
			||||||
// }
 | 
						if err != nil { | 
				
			||||||
 | 
							return nil, err | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f.masterKey = masterKey | 
				
			||||||
 | 
						if err := b.Recovery(f.masterKey); err != nil { | 
				
			||||||
 | 
							return nil, err | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						return b, nil | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
				
			|||||||
					Loading…
					
					
				
		Reference in new issue