Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chkerr(msg) {
- global title
- if ((a_lasterror !== 0) && (a_lasterror !== 80)) {
- varsetcapacity(str, 1024)
- dllcall("FormatMessage", "uint", 0x1000, "uint", 0, "uint", a_lasterror, "uint", 0, "str", str, "uint", 1024, "str", "")
- msgbox 16, %title%, %msg%`n%str%
- return false
- }
- return true
- }
- title:= "GUI to Console EXE Converter"
- if (a_args.length() < 2) {
- msgbox 64, %title%, Usage: gui2con.ahk {source exe} {dest exe}
- exitapp
- }
- ok:= false
- file:= fileopen(a_args[1], "r -wd")
- if (!chkerr("Can not open source file."))
- exitapp
- if ((file.read(2) == "MZ") && file.seek(0x3c)) {
- ofs:= file.readuint()
- if (ofs && file.seek(ofs) && (file.read(2) == "PE") && file.seek(0x5a, 1)) {
- dt:= file.readushort()
- ok:= true
- }
- }
- if (!ok) {
- msgbox 16, %title%, Invalid EXE source file.
- exitapp
- }
- if (dt == 3) {
- msgbox 16, %title%, EXE source file is already a console version.
- exitapp
- } else if (dt !== 2) {
- msgbox 16, %title%, EXE source file is not a GUI version.
- exitapp
- }
- file.close()
- if (fileexist(a_args[2])) {
- msgbox 52, %title%, % "Destination file """ a_args[2] """ is already exist and will be overwritten.`n`nDo you want to proceed?"
- ifmsgbox no
- exitapp
- }
- filecopy % a_args[1], % a_args[2], true
- if (!chkerr("Can not create/overwrite destination file."))
- exitapp
- file:= fileopen(a_args[2], "rw -rwd")
- if (!chkerr("Can not write destination file."))
- exitapp
- file.seek(ofs + 0x5c)
- if (file.writeushort(3) == 2) {
- msgbox 64, %title%, File created.
- } else {
- chkerr("Can not write destination file.")
- }
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement