-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelfDecrypt.go
66 lines (50 loc) · 1.36 KB
/
SelfDecrypt.go
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
package main
import (
"encoding/binary"
"fmt"
"os"
"path/filepath"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: cob_selfdec.exe <file_path>")
return
}
filePath := os.Args[1]
data, err := os.ReadFile(filePath)
if err != nil {
fmt.Println("Error reading file:", err)
return
}
// Xorkey
xorKey := uint32(0x3493D9DE)
// Decrypt the data
for i := 0; i < len(data); i += 4 {
var dword uint32
if i+4 <= len(data) {
dword = binary.LittleEndian.Uint32(data[i : i+4])
} else {
padLen := 4 - (len(data) - i)
paddedData := append(data[i:], make([]byte, padLen)...)
dword = binary.LittleEndian.Uint32(paddedData)
}
// XOR the DWORD with the XOR key
dword ^= xorKey
// Rotate the XOR key left by 1 bit
xorKey = rotateLeft(xorKey)
binary.LittleEndian.PutUint32(data[i:i+4], dword)
}
inputFileName := filepath.Base(filePath)
fileNameWithoutExt := inputFileName[:len(inputFileName)-len(filepath.Ext(inputFileName))]
outputFilePath := fileNameWithoutExt + "_dec" + filepath.Ext(inputFileName)
err = os.WriteFile(outputFilePath, data, 0644)
if err != nil {
fmt.Println("Error writing decrypted data to file:", err)
return
}
fmt.Printf("Decryption complete. Decrypted data saved to %s\n", outputFilePath)
}
// rotates the bits of a uint32 left by 1 bit
func rotateLeft(x uint32) uint32 {
return (x << 1) | (x >> 31)
}