Advertisement
jcunews

gui2con.ahk

Aug 23rd, 2019 (edited)
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. chkerr(msg) {
  2.   global title
  3.   if ((a_lasterror !== 0) && (a_lasterror !== 80)) {
  4.     varsetcapacity(str, 1024)
  5.     dllcall("FormatMessage", "uint", 0x1000, "uint", 0, "uint", a_lasterror, "uint", 0, "str", str, "uint", 1024, "str", "")
  6.     msgbox 16, %title%, %msg%`n%str%
  7.     return false
  8.   }
  9.   return true
  10. }
  11.  
  12. title:= "GUI to Console EXE Converter"
  13. if (a_args.length() < 2) {
  14.   msgbox 64, %title%, Usage: gui2con.ahk {source exe} {dest exe}
  15.   exitapp
  16. }
  17. ok:= false
  18. file:= fileopen(a_args[1], "r -wd")
  19. if (!chkerr("Can not open source file."))
  20.   exitapp
  21. if ((file.read(2) == "MZ") && file.seek(0x3c)) {
  22.   ofs:= file.readuint()
  23.   if (ofs && file.seek(ofs) && (file.read(2) == "PE") && file.seek(0x5a, 1)) {
  24.     dt:= file.readushort()
  25.     ok:= true
  26.   }
  27. }
  28. if (!ok) {
  29.   msgbox 16, %title%, Invalid EXE source file.
  30.   exitapp
  31. }
  32. if (dt == 3) {
  33.   msgbox 16, %title%, EXE source file is already a console version.
  34.   exitapp
  35. } else if (dt !== 2) {
  36.   msgbox 16, %title%, EXE source file is not a GUI version.
  37.   exitapp
  38. }
  39. file.close()
  40. if (fileexist(a_args[2])) {
  41.   msgbox 52, %title%, % "Destination file """ a_args[2] """ is already exist and will be overwritten.`n`nDo you want to proceed?"
  42.   ifmsgbox no
  43.     exitapp
  44. }
  45. filecopy % a_args[1], % a_args[2], true
  46. if (!chkerr("Can not create/overwrite destination file."))
  47.   exitapp
  48. file:= fileopen(a_args[2], "rw -rwd")
  49. if (!chkerr("Can not write destination file."))
  50.   exitapp
  51. file.seek(ofs + 0x5c)
  52. if (file.writeushort(3) == 2) {
  53.   msgbox 64, %title%, File created.
  54. } else {
  55.   chkerr("Can not write destination file.")
  56. }
  57. file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement