You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.8 KiB
84 lines
1.8 KiB
3 years ago
|
package extension
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
2 years ago
|
"github.com/tidwall/gjson"
|
||
2 years ago
|
|
||
|
"github.com/moond4rk/HackBrowserData/item"
|
||
|
"github.com/moond4rk/HackBrowserData/log"
|
||
|
"github.com/moond4rk/HackBrowserData/utils/fileutil"
|
||
3 years ago
|
)
|
||
|
|
||
|
type ChromiumExtension []*extension
|
||
|
|
||
|
type extension struct {
|
||
|
Name string
|
||
|
Description string
|
||
|
Version string
|
||
|
HomepageURL string
|
||
|
}
|
||
|
|
||
|
const (
|
||
|
manifest = "manifest.json"
|
||
|
)
|
||
|
|
||
|
func (c *ChromiumExtension) Parse(masterKey []byte) error {
|
||
|
files, err := fileutil.FilesInFolder(item.TempChromiumExtension, manifest)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer os.RemoveAll(item.TempChromiumExtension)
|
||
|
for _, f := range files {
|
||
|
file, err := fileutil.ReadFile(f)
|
||
|
if err != nil {
|
||
|
log.Error("Failed to read file: %s", err)
|
||
|
continue
|
||
|
}
|
||
|
b := gjson.Parse(file)
|
||
|
*c = append(*c, &extension{
|
||
|
Name: b.Get("name").String(),
|
||
|
Description: b.Get("description").String(),
|
||
|
Version: b.Get("version").String(),
|
||
|
HomepageURL: b.Get("homepage_url").String(),
|
||
|
})
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (c *ChromiumExtension) Name() string {
|
||
|
return "extension"
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
func (c *ChromiumExtension) Length() int {
|
||
|
return len(*c)
|
||
|
}
|
||
|
|
||
3 years ago
|
type FirefoxExtension []*extension
|
||
|
|
||
|
func (f *FirefoxExtension) Parse(masterKey []byte) error {
|
||
|
s, err := fileutil.ReadFile(item.TempFirefoxExtension)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer os.Remove(item.TempFirefoxExtension)
|
||
|
j := gjson.Parse(s)
|
||
|
for _, v := range j.Get("addons").Array() {
|
||
|
*f = append(*f, &extension{
|
||
|
Name: v.Get("defaultLocale.name").String(),
|
||
|
Description: v.Get("defaultLocale.description").String(),
|
||
|
Version: v.Get("version").String(),
|
||
|
HomepageURL: v.Get("defaultLocale.homepageURL").String(),
|
||
|
})
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (f *FirefoxExtension) Name() string {
|
||
|
return "extension"
|
||
|
}
|
||
3 years ago
|
|
||
|
func (f *FirefoxExtension) Length() int {
|
||
|
return len(*f)
|
||
|
}
|