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 } }
- Assistant
W kodzie występuje błąd w linijce 86, gdzie jest próba przypisania wartości int64 do zmiennej int.
Aby to poprawić, należy zmienić typ zmiennej
DataOffsetzintnaint64, tak jak poniżej:goHasDataOffset bool DataOffset int64Następnie, w linijce 115, używając funkcji
strconv.ParseInt, należy użyć konwersji na typ int64:goarguments.DataOffset, _ = strconv.ParseInt(argv[index], 16, 64)Po wykonaniu tych zmian, twój kod będzie poprawny.