diff --git a/commands/commands.go b/commands/commands.go index 978f55c..f9a6224 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -4,6 +4,7 @@ type BaseCommand struct { Help HelpCommand `command:"help" description:"Print this help message"` DecryptDBF DecryptDBFCommand `command:"decrypt-dbf" description:"decrypt dbf-data"` + EncryptDBF EncryptDBFCommand `command:"encrypt-dbf" description:"encrypt dbf-data"` DecryptDES DecryptDESCommand `command:"decrypt-des" description:"decrypt des-data"` //CodePlugModify diff --git a/commands/dbf-encrypt.go b/commands/dbf-encrypt.go new file mode 100644 index 0000000..5b84a85 --- /dev/null +++ b/commands/dbf-encrypt.go @@ -0,0 +1,46 @@ +package commands + +import ( + "io" + "os" + + "git.cheetah.cat/cheetah/moto-flash-data/motolol/cpe" +) + +type EncryptDBFCommand struct { + SourceFileName string `long:"src" alias:"i" required:"true" description:"input-filename"` + DestFileName string `long:"dest" alias:"o" required:"true" description:"output-filename"` +} + +func (command *EncryptDBFCommand) Execute(args []string) error { + inputFile, err := os.Open(command.SourceFileName) + if err != nil { + return err + } + defer inputFile.Close() + outputFile, err := os.Create(command.DestFileName) + if err != nil { + return err + } + defer outputFile.Close() + + inputFileStat, err := inputFile.Stat() + if err != nil { + return err + } + + pdata := make([]byte, inputFileStat.Size()) + _, err = io.ReadFull(inputFile, pdata) + if err != nil { + return err + } + + decrypted := cpe.EncryptDBFFile(pdata) + + _, err = outputFile.Write(decrypted) + if err != nil { + return err + } + + return nil +}