crx3

package module
v0.0.0-...-4eaae31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

README

go-crx3

Coverage Status Documentation

Provides a sets of tools packing, unpacking, zip, unzip, download, gen id, etc...

Table of contents

Installation
go get -u github.com/akuz0/go-crx3/crx3
Dev commands
$ make proto 
$ make test/cover
Examples
Pack
Pack a zip file or unzipped directory into a crx extension
import crx3 "github.com/akuz0/go-crx3"

if err := crx3.Extension("/path/to/file.zip").Pack(nil); err != nil {
    panic(err)
}
import crx3 "github.com/akuz0/go-crx3"

pk, err := crx3.LoadPrivateKey("/path/to/key.pem")
if err != nil { 
    panic(err) 
}
if err := crx3.Extension("/path/to/file.zip").Pack(pk); err != nil {
    panic(err)
}
import crx3 "github.com/akuz0/go-crx3"

pk, err := crx3.LoadPrivateKey("/path/to/key.pem")
if err != nil { 
    panic(err) 
}
if err := crx3.Extension("/path/to/file.zip").PackTo("/path/to/ext.crx", pk); err != nil {
    panic(err)
}
$ crx3 pack /path/to/file.zip 
$ crx3 pack /path/to/file.zip -p /path/to/key.pem 
$ crx3 pack /path/to/file.zip -p /path/to/key.pem -o /path/to/ext.crx 
Unpack
Unpack chrome extension into current directory
import crx3 "github.com/akuz0/go-crx3"

if err := crx3.Extension("/path/to/ext.crx").Unpack(); err != nil {
   panic(err)
}
$ crx3 unpack /path/to/ext.crx 
Base64
Encode an extension file to a base64 string
import crx3 "github.com/akuz0/go-crx3"
import "fmt"

b, err := crx3.Extension("/path/to/ext.crx").Base64()
if err != nil {
   panic(err)
}
fmt.Println(string(b))
$ crx3 base64 /path/to/ext.crx [-o /path/to/file] 
Download
Download a chrome extension from the web store
import crx3 "github.com/akuz0/go-crx3"

extensionID := "blipmdconlkpinefehnmjammfjpmpbjk"
filepath := "/path/to/ext.crx"
if err := crx3.DownloadFromWebStore(extensionID,filepath); err != nil {
    panic(err)
}
$ crx3 download blipmdconlkpinefehnmjammfjpmpbjk [-o /custom/path]
$ crx3 download https://chrome.google.com/webstore/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk
Zip
Zip add an unpacked extension to the archive
import crx3 "github.com/akuz0/go-crx3"

if err := crx3.Extension("/path/to/unpacked").Zip(); err != nil {
    panic(err)
}
$ crx3 zip /path/to/unpacked [-o /custom/path] 
Unzip
Unzip an extension to the current directory
import crx3 "github.com/akuz0/go-crx3"

if err := crx3.Extension("/path/to/ext.zip").Unzip(); err != nil {
    panic(err)
}
$ crx3 unzip /path/to/ext.zip [-o /custom/path] 
Gen ID
Generate extension id (like dgmchnekcpklnjppdmmjlgpmpohmpmgp)
import crx3 "github.com/akuz0/go-crx3"

id, err := crx3.Extension("/path/to/ext.crx").ID()
if err != nil {
    panic(err)
}
$ crx3 id /path/to/ext.crx 
IsDir, IsZip, IsCRX3
import crx3 "github.com/akuz0/go-crx3"

crx3.Extension("/path/to/ext.zip").IsZip()
crx3.Extension("/path/to/ext").IsDir()
crx3.Extension("/path/to/ext.crx").IsCRX3()
NewPrivateKey, LoadPrivateKey, SavePrivateKey
import crx3 "github.com/akuz0/go-crx3"

pk, err := crx3.NewPrivateKey()
if err != nil {
    panic(err)
}
if err := crx3.SavePrivateKey("/path/to/key.pem", pk); err != nil {
    panic(err)
}
pk, err = crx3.LoadPrivateKey("/path/to/key.pem")
Keygen
$ crx3 keygen /path/to/key.pem 

License

go-crx3 is released under the Apache 2.0 license. See LICENSE.txt

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownFileExtension  = errors.New("crx3: unknown file extension")
	ErrUnsupportedFileFormat = errors.New("crx3: unsupported file format")
	ErrExtensionNotSpecified = errors.New("crx3: extension id not specified")
	ErrPathNotFound          = errors.New("crx3: filepath not found")
	ErrPrivateKeyNotFound    = errors.New("crx3: private key not found")
)

Functions

func Base64

func Base64(filename string) (b []byte, err error)

Base64 encodes an extension file to a base64 string. It returns a bytes and an error encountered while encodes, if any.

func DownloadFromWebStore

func DownloadFromWebStore(extensionID string, filename string) error

DownloadFromWebStore downloads a Chrome extension from the web store. ExtensionID can be an identifier or an url.

func ID

func ID(filename string) (id string, err error)

ID returns the extension id.

func LoadPrivateKey

func LoadPrivateKey(filename string) (*rsa.PrivateKey, error)

LoadPrivateKey loads the private key from a file into memory.

func NewPrivateKey

func NewPrivateKey() (*rsa.PrivateKey, error)

NewPrivateKey returns a new private key.

func Pack

func Pack(src string, dst string, pk *rsa.PrivateKey) (err error)

Pack packs a zip file or unzipped directory into a crx extension.

func SavePrivateKey

func SavePrivateKey(filename string, key *rsa.PrivateKey) error

SavePrivateKey saves private key to file.

func SetWebStoreURL

func SetWebStoreURL(u string)

SetWebStoreURL sets the web store url to download extensions.

func Unpack

func Unpack(filename string) error

Unpack unpacks Google Chrome extension.

func Unzip

func Unzip(r io.ReaderAt, size int64, unpacked string) error

Unzip extracts all files from the archive.

func Zip

func Zip(w io.Writer, unpacked string) error

Zip creates a *.zip archive and adds all the files to it.

Types

type Extension

type Extension string

func (Extension) Base64

func (e Extension) Base64() ([]byte, error)

Base64 encodes an extension file to a base64 string.

func (Extension) ID

func (e Extension) ID() (string, error)

ID returns an extension id.

func (Extension) IsCRX3

func (e Extension) IsCRX3() bool

IsCRX3 reports whether extension describes a crc file.

func (Extension) IsDir

func (e Extension) IsDir() bool

IsDir reports whether extension describes a directory.

func (Extension) IsZip

func (e Extension) IsZip() bool

IsZip reports whether extension describes a zip-archive.

func (Extension) Pack

func (e Extension) Pack(pk *rsa.PrivateKey) error

Pack packs zip file or an unpacked directory into a CRX3 file.

func (Extension) PackTo

func (e Extension) PackTo(dst string, pk *rsa.PrivateKey) error

PackTo packs zip file or an unpacked directory into a CRX3 file.

func (Extension) String

func (e Extension) String() string

func (Extension) Unpack

func (e Extension) Unpack() error

Unpack unpacks CRX3 extension to directory.

func (Extension) Unzip

func (e Extension) Unzip() error

Unzip extracts all files from the archive.

func (Extension) Zip

func (e Extension) Zip() error

Zip creates a *.zip archive and adds all the files to it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL