Coder Social home page Coder Social logo

Comments (2)

rowingdude avatar rowingdude commented on June 4, 2024 1

Hello, I would like to take a stab at this.

I'd like to propose using a single map and a key of the folder.

First, we modify the original "walk" function to get rid of the if statements which cause obscurity. This eliminates one map and established a directory of composite keys, which are much faster to look up than re-traversing.

func chromiumWalkFunc(items []item.Item, itemPaths map[string]map[item.Item]string) filepath.WalkFunc {
	return func(path string, info fs.FileInfo, err error) error {
		if !isValidItem(path, info, items) {
			return nil
		}
		
		profileFolder := fileutil.ParentBaseDir(path)
		if strings.Contains(filepath.ToSlash(path), "/Network/Cookies") {
			profileFolder = fileutil.BaseDir(strings.ReplaceAll(filepath.ToSlash(path), "/Network/Cookies", ""))
		}
	
		for _, v := range items {
			if info.Name() == v.Filename() {
				itemPaths[composeKey(profileFolder, v)] = path
				break 
			}
		}
		
		return nil
	}
}
func composeKey(profileFolder string, item item.Item) string {
	return fmt.Sprintf("%s|%s", profileFolder, item.Filename())
}

We then write up a function to test if the item is what we're looking for:

func isValidItem(path string, info fs.FileInfo, items []item.Item) bool {
	if info.IsDir() || strings.Contains(path, "System Profile") {
		return false
	}
	for _, v := range items {
		if info.Name() == v.Filename() {
			return true
		}
	}
	return false
}

I have not bench marked this yet but present it here as a possible alternative to your original idea.

from hackbrowserdata.

moonD4rk avatar moonD4rk commented on June 4, 2024

Thanks for your suggestion @rowingdude, The following structure is defined in the new version. Use the KeyFile of Chromium to determine the location of RootPath .

There are still some bugs that need to be fixed. I will submit the code in the next few days and look forward to your review at that time.

type BrowserProfile struct {
	// Name name like 'Default', 'BrowserProfile 1', etc.
	Name string
	// Path to the master key file (e.g., 'Local State', 'key4.db',
	KeyPath string
	// MasterKey is the key used to decrypt the browser data.
	MasterKey []byte
	// Map of data types to file paths
	DataFiles map[types.DataType][]string
}

func (bd *BrowserData) findChromiumProfiles(rootPath string, dataTypes []types.DataType) (map[string]*BrowserProfile, error) {
	profiles := make(map[string]*BrowserProfile)
	var sharedKeyPath string
	err := filepath.WalkDir(rootPath, func(path string, entry fs.DirEntry, err error) error {
		if err != nil {
			return err
		}
		normalizedPath := filepath.ToSlash(path)
		// Skip directories that should not be included
		if entry.IsDir() && skipDirs(normalizedPath, defaultExcludeDirs) {
			return fs.SkipDir
		}
		for _, dataType := range dataTypes {
			if entry.Name() != dataType.Filename() {
				continue
			}
			// Calculate relative path from Chrome baseDir path
			profileName := extractProfileNameFromPath(rootPath, path)
			// handle shard key
			if profileName == "" && dataType == types.ChromiumKey {
				sharedKeyPath = path
			}
			if profileName == "" {
				continue
			}
			if _, exists := profiles[profileName]; !exists {
				profiles[profileName] = newProfile(profileName)
				profiles[profileName].DataFiles[dataType] = []string{path}
			} else {
				profiles[profileName].DataFiles[dataType] = append(profiles[profileName].DataFiles[dataType], path)
			}
		}
		return nil
	})
	// Assign the shared key path to all profileNames
	for _, profile := range profiles {
		profile.KeyPath = sharedKeyPath
	}
	return profiles, err
}

from hackbrowserdata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.