-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer_truncator.go
More file actions
146 lines (125 loc) · 3.33 KB
/
container_truncator.go
File metadata and controls
146 lines (125 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"encoding/base64"
"flag"
"fmt"
"io"
"os"
"path/filepath"
"strings"
)
// version
var version = "v1.0.1, 2026-01-16\nhttps://github.com/cyclone-github/container_truncator"
func versionFunc() {
fmt.Fprintln(os.Stderr, version)
}
func welcome() {
fmt.Println(" ----------------------------------- ")
fmt.Println("| Cyclone's Container Truncater |")
fmt.Println("| Bestcrypt / Truecrypt / Veracrypt |")
fmt.Println(" ----------------------------------- ")
fmt.Println(version)
fmt.Println()
fmt.Println("Program will truncate a Bestcrypt, Truecrypt or Veracrypt Container")
fmt.Println("and save a new file as 'truncated_orginal_filename'")
fmt.Println("You can then run .tc & .vc files with hashcat")
fmt.Println("Program only supports .jbc .tc & .vc container files")
fmt.Println()
}
func truncate() {
// get all supported container files in current dir
extensions := []string{".jbc", ".tc", ".vc"}
var files []string
for _, ext := range extensions {
matches, err := filepath.Glob("*" + ext)
if err != nil {
fmt.Println("Error:", err)
return
}
files = append(files, matches...)
}
if len(files) == 0 {
fmt.Println("No files found with extension .jbc .tc or .vc")
return
}
// filter files that have already been truncated
var truncatedFiles []string
for _, file := range files {
if !strings.HasPrefix(file, "truncate_") {
truncatedFiles = append(truncatedFiles, file)
}
}
if len(truncatedFiles) == 0 {
fmt.Println("All files have already been truncated.")
return
}
// print list of files and prompt user to select one
fmt.Println("Select a container file to truncate:")
for i, file := range truncatedFiles {
fmt.Printf("%d) %s\n", i+1, file)
}
var selected int
fmt.Scan(&selected)
// get selected file
inputFile := truncatedFiles[selected-1]
// get output file name by prepending "_truncate" to input file name
outputFile := "truncate_" + inputFile
// check if output file already exists
if _, err := os.Stat(outputFile); !os.IsNotExist(err) {
fmt.Println("Error: Output file already exists.")
return
}
// open input file
in, err := os.Open(inputFile)
if err != nil {
fmt.Println("Error:", err)
return
}
defer in.Close()
// open output file
out, err := os.Create(outputFile)
if err != nil {
fmt.Println("Error:", err)
return
}
defer out.Close()
// determine header size based on container type
var headerSize int64 = 512 // default for .tc / .vc
if strings.HasSuffix(strings.ToLower(inputFile), ".jbc") {
headerSize = 4096 // BestCrypt v8/9
}
// copy header bytes from input file to output file
_, err = io.CopyN(out, in, headerSize)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("File truncated successfully.")
}
}
func main() {
version := flag.Bool("version", false, "Program version:")
cyclone := flag.Bool("cyclone", false, "dev info")
help := flag.Bool("help", false, "Prints help:")
flag.Parse()
// run sanity checks for special flags
if *version {
versionFunc()
os.Exit(0)
}
if *cyclone {
decodedStr, err := base64.StdEncoding.DecodeString("Q29kZWQgYnkgY3ljbG9uZSA7KQo=")
if err != nil {
fmt.Fprintln(os.Stderr, "--> Cannot decode base64 string. <--")
os.Exit(1)
}
fmt.Fprintln(os.Stderr, string(decodedStr))
os.Exit(0)
}
if *help {
welcome()
os.Exit(0)
}
welcome()
truncate()
}
// end of program