Page 1 of 2

Compile x86 programs from x64 IDE (windows only)

Posted: Sun Jan 25, 2009 8:14 am
by lexvictory
If you're anything like me, you hate having to open the x86 IDE to test or compile something in x86 (me especially because the x86 IDE runs with /noext).
So I made this little (relatively anyway) program to call the x86 compiler from an x64 IDE tool.

Theoretically it could also be used to call an earlier PB version, or compile x64 from the x86 IDE (on an x64 windows install - but this would require disabling of the wow64 emulation iirc).

Just edit the variable/constants at the top of the file, and you're ready to compile as exe (compile in x64 IDE).
#windowwidth/height is the width and height of the compiler output window opened.
#dontcloseonOKcompile will keep the compiler output window open even if the compile had no errors.
Set #droopyslibisinstalled if you have droopy's lib installed, or the compiler will complain.

It will only set compiler command line options that are available as Environment Variables to a tool, if you require other options, add the option(s) to the end of the tools's command line; they should be passed on.

Code: Select all

purebasicx86path.s = "C:\Program Files (x86)\PureBasic4.30"
#windowwidth = 550
#windowheight = 250
#dontcloseonOKcompile = 0
#droopyslibisinstalled = 0


Procedure Error(error.s)
  MessageRequester("Error", error, #MB_ICONERROR)
EndProcedure

CompilerIf #droopyslibisinstalled = 0
  Procedure WaitUntilWindowIsClosed()
    Repeat
    Until WaitWindowEvent()= #PB_Event_CloseWindow
    ProcedureReturn 1
  EndProcedure
  Procedure.s GetTempDirectory() ; Return the temp directory 
  Protected WinTemp.s 
  WinTemp  = Space(255) 
  GetTempPath_(255, WinTemp) 
  If Right(WinTemp, 1) <> "\" : WinTemp = WinTemp + "\" : EndIf 
  ProcedureReturn WinTemp 
EndProcedure 
CompilerEndIf

Debugger = Val(GetEnvironmentVariable("PB_TOOL_Debugger"))
inlineasm = Val(GetEnvironmentVariable("PB_TOOL_InlineASM"))
unicode = Val(GetEnvironmentVariable("PB_TOOL_Unicode"))
threadsafe = Val(GetEnvironmentVariable("PB_TOOL_Thread"))
xpskin = Val(GetEnvironmentVariable("PB_TOOL_XPSkin"))
onerror = Val(GetEnvironmentVariable("PB_TOOL_OnError"))
subsys.s = Trim(GetEnvironmentVariable("PB_TOOL_SubSystem"))
theexe.s = GetEnvironmentVariable("PB_TOOL_Executable")

 ;EnableExplicit
 Define compileroptions.s = "",x.i, progparam.s,properfile.s,tempfile.s

If debugger : compileroptions+"/DEBUGGER " : EndIf
If inlineasm : compileroptions+"/INLINEASM " : EndIf
If unicode : compileroptions+"/UNICODE " : EndIf
If threadsafe : compileroptions+"/THREAD " : EndIf
If xpskin : compileroptions+"/XP " : EndIf
If onerror : compileroptions+"/LINENUMBERING " : EndIf
If subsys <> "" : compileroptions+"/SUBSYSTEM "+Chr(34)+subsys+Chr(34)+" " : EndIf

For x = 0 To CountProgramParameters()-1
  progparam = ProgramParameter(x)
  Debug progparam
  If FindString(UCase(progparam), "/FILE:", 0)
    properfile = RemoveString(progparam,"/FILE:",#PB_String_NoCase)
    Debug properfile
    ;properfile = progparam
    ;properfile = Right(progparam, Len(progparam)-6)
  ElseIf FindString(UCase(progparam), "/TEMPFILE:", 0)
    tempfile = RemoveString(progparam,"/TEMPFILE:",#PB_String_NoCase)
  ElseIf FindString(UCase(progparam), "/EXE", 0)
    makeexe.s = SaveFileRequester("Create cross compiled exe", theexe, "*.exe,*.dll|*.exe;*.dll", 0)
    If makeexe
      If (LCase(Right(makeexe, 4)) <> ".exe") And (LCase(Right(makeexe, 4)) <> ".dll")
        makeexe+".exe"
      EndIf
      compileroptions+"/EXE "+Chr(34)+makeexe+Chr(34)+" "
      If LCase(Right(makeexe, 4)) = ".dll"
        compileroptions+"/DLL "
      EndIf
      disablethedebugger = 1
    Else
      End
    EndIf
  Else
    compileroptions+progparam+" "
  EndIf
Next x

OpenWindow(0,0,0,#windowwidth,#windowheight,"PB compiler output", #PB_Window_SystemMenu)
ListViewGadget(0,0,0,#windowwidth,#windowheight)
AddGadgetItem(0,-1, "Compiler Options:")
AddGadgetItem(0,-1, compileroptions)

If properfile <> ""
  compileroptions+Chr(34)+properfile+Chr(34)
ElseIf tempfile <> ""
  compileroptions+Chr(34)+tempfile+Chr(34)
  SetCurrentDirectory(GetTempDirectory())
Else
  Error("You need to specify a file (with /FILE:) or a temp file (with /TEMPFILE:)")
  End
EndIf

If disablethedebugger : compileroptions=RemoveString(compileroptions, "/DEBUGGER ") : EndIf ;for compiling as exe

wasanerror = 0

prog = RunProgram(purebasicx86path+"\compilers\PBCompiler.exe", compileroptions, GetCurrentDirectory(), #PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
If prog
  While ProgramRunning(prog)
    If AvailableProgramOutput(prog)
      progoutput.s = ReadProgramString(prog)
      If FindString(LCase(progoutput), "error",0)
        wasanerror = 1
        Error(progoutput)
        SetForegroundWindow_(WindowID(0))
      EndIf
      AddGadgetItem(0,-1, progoutput)
    Else
      WaitWindowEvent(0)
    EndIf
  Wend
  CloseProgram(prog)
  AddGadgetItem(0,-1, "Compiler Closed")
Else
  Error("Could Not execute PB compiler")
EndIf


CompilerIf #dontcloseonOKcompile = 1
  WaitUntilWindowIsClosed()
CompilerElse
  If wasanerror
    WaitUntilWindowIsClosed()
  EndIf
CompilerEndIf
Create an IDE tool with the arguments set to the following:
"/FILE:%FILE" "/TEMPFILE:%TEMPFILE"
You can also create another tool and add /EXE to the command arguments to create an exe/dll (you have to add .dll to the SaveFileRequester file field manually)


If you spot any problems (especially relating to Vista usage), or have any suggestions/requests, let me know! :)

Posted: Sun Jan 25, 2009 6:22 pm
by Thunder93
Hey lexvictory!

This just became a vital part of my work, I'm usually running PureBasic x64, and I'm always needing to open PureBasic x86 to test my code to make sure there's no unforseen anomalies.


I'm running Vista x64, and it's working beautifully here, thank you very much!


Bests Regards,
Thunder93

Posted: Mon Jan 26, 2009 4:49 am
by lexvictory
Updated: fixed access denied linker error when pb file not saved (changes current dir to temp dir)

To Do: do cleanup of temp dir and erasure of made purebasic.exe in source dir.

Posted: Mon Jan 26, 2009 12:06 pm
by Thunder93
"Sign of "Win32:KdCrypt [Cryp]" has been found in "C:\Users\Phant0m``\AppData\Local\Temp\PureBasic.exe" file. "

When using this here method, it causes my Avast! Home AntiVirus system to go off with the message above. I noticed if I enabled '* XP skin support' via Compiler \ Compiler Options... it doesn't trigger my Avast!. If I merely do up a blank template even, and with "Enabled XP skin support" disabled, it happens.

I found it doesn't always bring up an alert depending what path I'm working in, I done some investigation and created some example paths that triggers Avast! Home AntiVirus when compiling in them using this here method.

"C:\Users\Thunder93\Documents\abcdefghi\abcdefghijk\abcdefghis\abcdefghijklomnp\"
"C:\ab\abcdefghi\abcdefghijk\abcdefghis\abcdefghijklomnp\"

I'm not observing this when I run manually the PureBasic x86 and compile in those locations.


Regards,
Thunder93

Posted: Mon Jan 26, 2009 12:13 pm
by lexvictory
No problem with my avast with anything compiled with this tool.

Click 'Report False Positive' (I think that's what the text is anyway) in the bottom right of the alert window.
Describe what your compiled file does - and explain that the XP style manifest does it.


I got an false alert from them when compiling one of my programs from cmd.exe recently - no problem when done from the IDE nor when using this tool.


But really, why the big red text? YOU compiled it, you can see that it does exactly what it was intended for and nothing more.
Look around on the forum, there are many topics about false positives.

Posted: Mon Jan 26, 2009 12:26 pm
by Thunder93
Hi lexvictory,

No.., I know it's just a false positive! and I have already reported it.

But it's not just specific to XP style manifest, it also has something to-do also with paths.. If you were to create the location "C:\ab\abcdefghi\abcdefghijk\abcdefghis\abcdefghijklomnp\" and run your tool to compile something from there, it'll cause Avast! Home to alert. Even if the pb templete is emptied and compiled from such locations (which I think depends on certain length of characters used in a path).

I also know it only happens while using your tool, and not when compiling manually. I know something is slightly different, feature included or something that wouldn't be by default.

Posted: Mon Jan 26, 2009 12:36 pm
by lexvictory
It's just annoying to see the red text.
Most users on the forum know random things will cause false positives - most programmers have problems with heuristics
So I see the emphasis as unnecessary... (and would appreciate it if the colour was removed - but that's up to you)

But yes, not every compiler option is enabled using this tool as would be when compiling with the IDE - only the ones available as environment variables, see the help topic about external tools.
For example if you have User/Administrator Vista modes ticked, they won't be added to the exe with this tool.

Posted: Mon Jan 26, 2009 12:44 pm
by Thunder93
heh, sorry .. It's been removed. ;P

Just a freshly created template with only 'Enable Debugger' checked by default in Compiler Options.

Posted: Mon Jan 26, 2009 12:49 pm
by lexvictory
Thunder93 wrote:heh, sorry .. It's been removed. ;P
Thank you :)
Thunder93 wrote:Just a freshly created template with only 'Enable Debugger' checked by default in Compiler Options.
You mean that triggers it too? :shock:
I'm glad I don't have Vista :lol:

Posted: Mon Jan 26, 2009 12:58 pm
by Thunder93
Not at the time, but yes ... disabling this feature, and compiling using your tool, not a problem.

Posted: Wed Jan 28, 2009 12:00 pm
by Thunder93
I e-mailed Avast! to better explain things..

I pretty much explained that when I manually ran an PureBasic template file through the PureBasic Compiler (32-bit) file (pbcompiler.exe) using the /DEBUGGER as an parameter to be passed, the compiled files triggers Avast! about a virus found - "Win32:KdCrypt [Cryp]".

I have said a few things but I also again mentioned about Avast! sensitivity when compiling PureBasic template files from certain paths, and the PureBasic template files can be entirely emptied and compiled and still cause the Avast! alert.

If your interested..., I'll keep you updated.


Regards,
Thunder93

Posted: Wed Jan 28, 2009 12:26 pm
by lexvictory
Well, its quite surprising the many ways you can trigger it on your computer.
Just let me know if you ever get a reply! :lol:

But Avast has started picking up on things it never used to - it picks up 'piracy' things even if they can be used with legally purchased software.

Posted: Wed Jan 28, 2009 1:54 pm
by Thunder93
Well with Avast! v4.8 came new support, anti-virus built-in, and anti-rootkit was also built-in...

It's not surprising to me..., I only noticed this when I used your program... And your program calls the PureBasic 32-bit compiler (pbcompiler.exe) and passes /DEBUGGER parameter if set, and if you happen to have your PureBasic template files stored in certain locations, it's enough to cause Avast! to alert with parameter /DEBUGGER set, on the actual compiled files. Doesn't matter if you simply compile an empty PureBasic template file...

This only specific to the PureBasic 32-bit compiler compiled files, and doesn't happen when I'm compiling from PureBasic.

Posted: Fri Feb 06, 2009 12:50 pm
by Thunder93
Hi lexvictory,

I received a reply from them shortly after having e-mailed them, but I didn't bother updating you until after they corrected this, which they have.


Avast! Home Edition 4.8.1335 (Released Today, February, 06 2009)
* improvements in some unpackers (WinExec, Installer, ZIP)
* improved memory scan, especially under 64-bit operating systems
* fixed a possible deadlock condition when copying system files from some removable media
* fixed a possible problem with access rights when deleting infected files on reboot
* Web Shield: minor stability fixes
* Internet Mail: smtp.gmail.com and smtp.live.com now ignored on port 25 (as these are SSL only)
* improved healing of some infected files
* various fixes and improvements in the scanning engine
* Web Shield now scans pages compressed with the "deflate" algorithm
* performance optimization of Standard Shield under Windows Vista
* improvements in the automatic sample submission system
* improvements in the URL blocker



And so now ... everything is perfect :)


Regards,
Thunder93

Posted: Fri Feb 06, 2009 12:56 pm
by lexvictory
Excellent news, thank you for the update