crx3

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: Apache-2.0 Imports: 21 Imported by: 3

README

go-crx3

Coverage Status Documentation Go Report Card Actions

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

Table of contents

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

if err := crx3.Extension("/path/to/file.zip").Pack(nil); err != nil {
    panic(err)
}
import crx3 "github.com/mediabuyerbot/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/mediabuyerbot/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/mediabuyerbot/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/mediabuyerbot/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/mediabuyerbot/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/mediabuyerbot/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/mediabuyerbot/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/mediabuyerbot/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/mediabuyerbot/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/mediabuyerbot/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 added in v1.3.0

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 CopyFile added in v1.4.0

func CopyFile(src, dst string) (int64, error)

CopyFile copies the contents of the source file 'src' to the destination file 'dst'. It returns the number of bytes copied and any encountered error. If the source file does not exist, is not a regular file, or other errors occur during the copy, it returns an error with a descriptive message.

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 added in v1.2.0

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

ID returns the extension ID extracted from a CRX (Chrome Extension) file specified by 'filename'. It checks if the file is in the CRX format, reads its header and signed data, and then converts the CRX ID into a string representation

func LoadPrivateKey

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

LoadPrivateKey loads the RSA private key from the specified 'filename' into memory. It returns the loaded private key or an error if the key cannot be loaded.

func NewPrivateKey

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

NewPrivateKey returns a new RSA private key with a bit size of 2048.

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. It takes the source 'src' (zip file or directory), target 'dst' CRX file path, and a private key 'pk' (optional). If 'pk' is nil, it generates a new private key. It creates a CRX extension from the source and writes it to the destination.

func SavePrivateKey

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

SavePrivateKey saves the provided 'key' private key to the specified 'filename'. If 'key' is nil, it generates a new private key and saves it to the file.

func SetWebStoreURL added in v1.3.0

func SetWebStoreURL(u string)

SetWebStoreURL sets the web store url to download extensions.

func Unpack

func Unpack(filename string) error

Unpack unpacks a CRX (Chrome Extension) file specified by 'filename' to its original contents. It checks if the file is in the CRX format, reads its header and signed data, and then extracts and decompresses the original contents. The unpacked contents are placed in a directory with the same name as the original file (without the '.crx' extension).

func UnpackTo added in v1.4.0

func UnpackTo(filename string, dirname string) error

UnpackTo unpacks a CRX (Chrome Extension) file specified by 'filename' to the directory 'dirname'. If 'dirname' does not exist, it creates the directory before unpacking.

func Unzip

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

Unzip extracts all files and directories from the provided ZIP archive. It takes an io.ReaderAt 'r', the size 'size' of the ZIP archive, and the target directory 'unpacked' for extraction. It iterates through the archive, creating directories and writing files as necessary.

func UnzipTo added in v1.4.0

func UnzipTo(basepath string, filename string) error

UnzipTo extracts the contents of a ZIP archive specified by 'filename' to the 'basepath' directory. It opens the ZIP file, creates the necessary directory structure, and extracts all files.

func Zip

func Zip(dst io.Writer, dirname string) error

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

func ZipTo added in v1.4.0

func ZipTo(filename string, dirname string) error

ZipTo creates a ZIP archive with the specified filename and adds all files from the given directory to it.

Types

type Extension

type Extension string

Extension represents an extension for google chrome.

func (Extension) Base64 added in v1.3.0

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

Base64 encodes an extension file to a base64 string.

func (Extension) ID added in v1.2.0

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

ID returns an extension id.

func (Extension) IsCRX3 added in v1.1.0

func (e Extension) IsCRX3() bool

IsCRX3 reports whether extension describes a crc file.

func (Extension) IsDir added in v1.1.0

func (e Extension) IsDir() bool

IsDir reports whether extension describes a directory.

func (Extension) IsEmpty added in v1.4.0

func (e Extension) IsEmpty() bool

IsEmpty checks if the extension is empty.

func (Extension) IsZip added in v1.1.0

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

String returns a string representation.

func (Extension) Unpack

func (e Extension) Unpack() error

Unpack unpacks the CRX3 extension into a 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