popraw ten kod o błąd: .\hyb.go:86:27: cannot use strconv.ParseInt(argv[index], 16, 64)…
- User
popraw ten kod o błąd: .\hyb.go:86:27: cannot use strconv.ParseInt(argv[index], 16, 64) (value of type int64) as int value in assignment
package main
import ( "fmt" "os" "strconv" "strings" )
type PlatformType int
const ( PlatformX86 PlatformType = iota PlatformX64 )
type PROGRAM_ARGUMENTS struct { HasPlatform bool Platform PlatformType HasMajorVersion bool MajorVersion int HasMinorVersion bool MinorVersion int HasDataOffset bool DataOffset int FileName string OutFileName string }
const COMAE_TOOLKIT_VERSION string = "3.0.0.undefined"
func Help() { fmt.Printf("Usage: Hibr2Bin [Options] /INPUT /OUTPUT \n\n") fmt.Printf("Description:\n Enables users to uncompress Windows hibernation file.\n\n") fmt.Printf("Options:\n /PLATFORM, /P Select platform (X64 or X86)\n") fmt.Printf(" /MAJOR, /V Select major version (e.g. 6 for NT 6.1\n") fmt.Printf(" /MINOR, /M Select minor version (e.g. 1 for NT 6.1)\n") fmt.Printf(" /OFFSET, /L Data offset in hexadecimal (optional)\n") fmt.Printf(" /INPUT, /I Input hiberfil.sys file.\n") fmt.Printf(" /OUTPUT, /O Output hiberfil.sys file.\n\n") fmt.Printf("Versions:\n") fmt.Printf(" /MAJOR 5 /MINOR 1 Windows XP\n") fmt.Printf(" /MAJOR 5 /MINOR 2 Windows XP x64, Windows 2003 R2\n") fmt.Printf(" /MAJOR 6 /MINOR 0 Windows Vista, Windows Server 2008\n") fmt.Printf(" /MAJOR 6 /MINOR 1 Windows 7, Windows Server 2008 R2\n") fmt.Printf(" /MAJOR 6 /MINOR 2 Windows 8, Windows Server 2012\n") fmt.Printf(" /MAJOR 6 /MINOR 3 Windows 8.1, Windows Server 2012 R2\n") fmt.Printf(" /MAJOR 10 /MINOR 0 Windows 10, Windows Server 2017\n\n") fmt.Printf("Examples:\n\n") fmt.Printf(" Uncompress a Windows 7 (NT 6.1) x64 hibernation file:\n") fmt.Printf(" Hibr2Bin /PLATFORM X64 /MAJOR 6 /MINOR 1 /INPUT hiberfil.sys /OUTPUT uncompressed.bin\n\n") fmt.Printf(" Uncompress a Windows 10 (NT 10.0) x86 hibernation file:\n") fmt.Printf(" Hibr2Bin /PLATFORM X86 /MAJOR 10 /MINOR 0 /INPUT hiberfil.sys /OUTPUT uncompressed.bin\n") }
func Parse(argv []string) (PROGRAM_ARGUMENTS, bool) { arguments := PROGRAM_ARGUMENTS{} maxArg := len(argv) index := 1
for index < maxArg { if strings.HasPrefix(argv[index], "/") || strings.HasPrefix(argv[index], "-") { option := strings.ToUpper(argv[index]) switch option { case "/PLATFORM", "/P": index++ arguments.HasPlatform = true switch strings.ToUpper(argv[index]) { case "X86": arguments.Platform = PlatformX86 case "X64": arguments.Platform = PlatformX64 default: arguments.HasPlatform = false } case "/MAJOR", "/V": index++ arguments.MajorVersion, _ = strconv.Atoi(argv[index]) arguments.HasMajorVersion = true case "/MINOR", "/M": index++ arguments.MinorVersion, _ = strconv.Atoi(argv[index]) arguments.HasMinorVersion = true case "/OFFSET", "/L": index++ arguments.DataOffset, _ = strconv.ParseInt(argv[index], 16, 64) arguments.HasDataOffset = true case "/INPUT", "/I": index++ arguments.FileName = argv[index] case "/OUTPUT", "/O": index++ arguments.OutFileName = argv[index] case "/?", "/HELP": return arguments, false default: fmt.Printf("Error: Invalid parameter.\n") return arguments, false } }
index++ }
// Validate parameters. if !arguments.HasPlatform { fmt.Printf("Error: Please provide a platform type using /P.\n") } if !arguments.HasMajorVersion { fmt.Printf("Error: Please provide a major version using /V parameter.\n") } if !arguments.HasMinorVersion { fmt.Printf("Error: Please provide a minor version using /M parameter.\n") }
if !arguments.HasMajorVersion || !arguments.HasMinorVersion || !arguments.HasPlatform { return arguments, false }
// Known versions of Windows: http://www.codeproject.com/Articles/678606/Part-Overcoming-Windows-s-deprecation-of-GetVe if arguments.MajorVersion == 10 { // NT 10.0 if arguments.MinorVersion != 0 { fmt.Printf("Error: Unsupported target version.") return arguments, false } } else if arguments.MajorVersion == 6 { // NT 6.3, NT 6.2, NT 6.1, NT 6.0 if arguments.MinorVersion != 3 && arguments.MinorVersion != 2 && arguments.MinorVersion != 1 && arguments.MinorVersion != 0 { fmt.Printf("Error: Unsupported target version.") return arguments, false } } else if arguments.MajorVersion == 5 { // NT 5.2 (X64), NT 5.1 (x86) if (arguments.MinorVersion != 2 && arguments.Platform != PlatformX64) || (arguments.MinorVersion != 1 && arguments.Platform != PlatformX86) { fmt.Printf("Error: Unsupported target version.") return arguments, false } }
return arguments, true }
func IsLicenseValid() bool { // Placeholder for GetLocalTime and SYSTEMTIME
// GetLocalTime(&SystemTime) // if !((SystemTime.wYear == 2017) && (SystemTime.wMonth == 6)) { // return false // } return true }
func GetPlatformType(Type PlatformType) string { switch Type { case PlatformX86: return "X86" case PlatformX64: return "X64" }
return "Unknown" }
func processHiberfil(arguments *PROGRAM_ARGUMENTS) ([]string, bool) { // Placeholder for processHiberfil function return []string{}, true }
func writeMemoryBlocksToDisk(memoryBlocks []string, arguments *PROGRAM_ARGUMENTS) bool { // Placeholder for writeMemoryBlocksToDisk function return true }
func main() { fmt.Printf("\n Hibr2Bin %s\n", COMAE_TOOLKIT_VERSION) fmt.Printf(" Copyright © 2007 - 2021, Matthieu Suiche http://www.msuiche.net\n") fmt.Printf(" Copyright © 2012 - 2014, MoonSols Limited http://www.moonsols.com\n") fmt.Printf(" Copyright © 2016 - 2021, Comae Technologies DMCC http://www.comae.io\n") fmt.Printf(" Copyright © 2022, Magnet Forensics, Inc. https://www.magnetforensics.com/\n\n")
args := os.Args if len(args) < 2 { Help() return }
arguments, parsed := Parse(args) if !parsed { Help() return }
if !IsLicenseValid() { fmt.Printf(" Error: Beta program expired. Get the latest version on www.comae.io \n") return }
fmt.Printf(" In File: %s\n", arguments.FileName) fmt.Printf(" Out File: %s\n", arguments.OutFileName) fmt.Printf(" Target Version: Microsoft Windows NT %d.%d (%s)\n", arguments.MajorVersion, arguments.MinorVersion, GetPlatformType(arguments.Platform))
memoryBlocks, success := processHiberfil(&arguments) if success { success = writeMemoryBlocksToDisk(memoryBlocks, &arguments) }
// Placeholder for return value return }
- Assistant
package main
import ( "fmt" "os" "strconv" "strings" )
type PlatformType int
const ( PlatformX86 PlatformType = iota PlatformX64 )
type PROGRAM_ARGUMENTS struct { HasPlatform bool Platform PlatformType HasMajorVersion bool MajorVersion int HasMinorVersion bool MinorVersion int HasDataOffset bool DataOffset int64 // Changed type to int64 FileName string OutFileName string }
const COMAE_TOOLKIT_VERSION string = "3.0.0.undefined"
func Help() { // ... same code as before ... }
func Parse(argv []string) (PROGRAM_ARGUMENTS, bool) { // ... same code as before ... }
func IsLicenseValid() bool { // ... same code as before ... }
func GetPlatformType(Type PlatformType) string { // ... same code as before ... }
func processHiberfil(arguments *PROGRAM_ARGUMENTS) ([]string, bool) { // ... same code as before ... }
func writeMemoryBlocksToDisk(memoryBlocks []string, arguments *PROGRAM_ARGUMENTS) bool { // ... same code as before ... }
func main() { // ... same code as before ... }