rar to zip

This commit is contained in:
quackerd 2022-04-28 18:32:53 +08:00
parent 113cc82825
commit 6daa8e03fa
5 changed files with 17 additions and 16 deletions

View File

@ -2,7 +2,6 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
"fmt" "fmt"
"log" "log"
"os" "os"
@ -10,39 +9,35 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/mholt/archiver" "github.com/yeka/zip"
) )
func crack(tid int, file []byte, fn string, passwords []string, found **string, stop *bool, total *uint64, exited *int32) { func crack(tid int, file []byte, fn string, passwords []string, found **string, stop *bool, total *uint64, exited *int32) {
fmt.Println("Thread", tid, ": starting with", len(passwords), "passwords...") fmt.Println("Thread", tid, ": starting with", len(passwords), "passwords...")
rar := archiver.NewRar() r, err := zip.OpenReader(fn)
rar.ContinueOnError = false if err != nil {
rar.ImplicitTopLevelFolder = true log.Fatal(err)
rar.OverwriteExisting = true }
rar.MkdirAll = false
f := r.File[len(r.File)-1]
fmt.Println("Filename:", f.Name)
for i := 0; i < len(passwords); i++ { for i := 0; i < len(passwords); i++ {
if *stop { if *stop {
goto end goto end
} }
cur_pass := passwords[i] cur_pass := passwords[i]
rar.Password = cur_pass f.SetPassword(cur_pass)
reader := bytes.NewReader(file)
err := rar.Open(reader, 0) r, err := f.Open()
if err != nil {
log.Fatal(err)
}
_, err = rar.Read()
if err == nil { if err == nil {
*found = &passwords[i] *found = &passwords[i]
r.Close()
goto end goto end
} }
rar.Close()
atomic.AddUint64(total, 1) atomic.AddUint64(total, 1)
} }
end: end:

2
go.mod
View File

@ -10,4 +10,6 @@ require (
github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/ulikunitz/xz v0.5.10 // indirect github.com/ulikunitz/xz v0.5.10 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/yeka/zip v0.0.0-20180914125537-d046722c6feb // indirect
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect
) )

4
go.sum
View File

@ -16,3 +16,7 @@ github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/yeka/zip v0.0.0-20180914125537-d046722c6feb h1:OJYP70YMddlmGq//EPLj8Vw2uJXmrA+cGSPhXTDpn2E=
github.com/yeka/zip v0.0.0-20180914125537-d046722c6feb/go.mod h1:9BnoKCcgJ/+SLhfAXj15352hTOuVmG5Gzo8xNRINfqI=
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc=
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=

BIN
test.rar

Binary file not shown.

BIN
test.zip Normal file

Binary file not shown.