1. Detecting a C translated bound program

I have a couple of programs that refuse to behave when bound into C, but behave
just fine when simply bound with the interpreter. Specific reasons for failure
aren't important for this discussion. Occasionally I step on my own toes and
accidentally bind a program incorrectly. Is there a way I can tell from within
the bound program itself if it was translated into C so I can catch my own
mistake prior to deployment? BTW I'm still using Euphoria Version 2.4.

Yours, OtterDad

Don't sweat it -- it's not real life. It's only ones and zeroes. Gene Spafford

new topic     » topic index » view message » categorize

2. Re: Detecting a C translated bound program

OtterDad wrote:

> I have a couple of programs that refuse to behave when bound into C, but
> behave
> just fine when simply bound with the interpreter. Specific reasons for failure
> aren't important for this discussion. Occasionally I step on my own toes and
> accidentally bind a program incorrectly. Is there a way I can tell from within
> the bound program itself if it was translated into C so I can catch my own
> mistake
> prior to deployment? BTW I'm still using Euphoria Version 2.4.

You can for instance link a resource that contains version information
with your translated & compiled EXE programs. In contrast, a program that
is bound to the intepreter does not contain version information.

Later you can right-click on your EXE file and select "properties" from
the context menu. If you see a tab with version information, then it's
a translated & compiled executable -- if not, it's either a bound
executable, or you forgot to link the resource. smile

Regards,
   Juergen

new topic     » goto parent     » topic index » view message » categorize

3. Re: Detecting a C translated bound program

OtterDad wrote:
> 
> I have a couple of programs that refuse to behave when bound into C, but
> behave
> just fine when simply bound with the interpreter. Specific reasons for failure
> aren't important for this discussion. Occasionally I step on my own toes and
> accidentally bind a program incorrectly. Is there a way I can tell from within
> the bound program itself if it was translated into C so I can catch my own
> mistake
> prior to deployment? BTW I'm still using Euphoria Version 2.4.

I'll assume you mean translated, compiled and linked.  It's more difficult
(and probably impossible in 2.4) to do this if you're using a bound
executable.

You could define a constant and set it to zero.  Before running emake,
edit init.c (or wherever it gets assigned, maybe in one of the main*.c
files) to set the constant to 1.

Matt

new topic     » goto parent     » topic index » view message » categorize

4. Re: Detecting a C translated bound program

OtterDad wrote:
> 
> I have a couple of programs that refuse to behave when bound into C, but 
> behave just fine when simply bound with the interpreter.
> Is there a way I can tell from within the bound program itself if it was 
> translated into C so I can catch my own mistake prior to deployment?

> BTW I'm still using Euphoria Version 2.4.
If that last point is unlikely to change, you could use the entry point:
cl=command_line()
 if equal(cl[1],cl[2]) then  -- prog is bound or translated
   fn=open(cl[1],"rb")
   void = seek(fn,#A8)
   ep={getc(fn),getc(fn),getc(fn),getc(fn)}
   close(fn)
   if equal(ep,{#10,#0F,#03,#00}) then  -- Eu 2.4 exw entry point, I think
   else                    -- assume eu2c'd

The above is completely untested, btw.
Alternatively you could try patching a 1 at offset #7F into any .exe you create
via eu2c and assume that all versions of eu (/bound files) will have a 0 there,
or examine the PE headers (I use OllyDebug) and see if there is anything else
that sticks out, maybe an EC.LIB section, (I'm guessing now).

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

5. Re: Detecting a C translated bound program

Pete Lomax wrote:
> 
> OtterDad wrote:
> > 
> > I have a couple of programs that refuse to behave when bound into C, but 
> > behave just fine when simply bound with the interpreter.
> > Is there a way I can tell from within the bound program itself if it was 
> > translated into C so I can catch my own mistake prior to deployment?
> 
> > BTW I'm still using Euphoria Version 2.4.
> If that last point is unlikely to change, you could use the entry point:
> }}}
<eucode>
>  cl=command_line()
>  if equal(cl[1],cl[2]) then  -- prog is bound or translated
>    fn=open(cl[1],"rb")
>    void = seek(fn,#A8)
>    ep={getc(fn),getc(fn),getc(fn),getc(fn)}
>    close(fn)
>    if equal(ep,{#10,#0F,#03,#00}) then  -- Eu 2.4 exw entry point, I think
>    else                    -- assume eu2c'd
> </eucode>
{{{

> The above is completely untested, btw.
> Alternatively you could try patching a 1 at offset #7F into any .exe you
> create
> via eu2c and assume that all versions of eu (/bound files) will have a 0
> there,
> or examine the PE headers (I use OllyDebug) and see if there is anything else
> that sticks out, maybe an EC.LIB section, (I'm guessing now).
> 
> Regards,
> Pete

that's more what i was looking for. thanks pete. i'll try it and report back.

Yours, OtterDad

Don't sweat it -- it's not real life. It's only ones and zeroes. Gene Spafford

new topic     » goto parent     » topic index » view message » categorize

6. Re: Detecting a C translated bound program

OtterDad wrote:
> 
> Pete Lomax wrote:
> > 
> > OtterDad wrote:
> > > 
> > > I have a couple of programs that refuse to behave when bound into C, but 
> > > behave just fine when simply bound with the interpreter.
> > > Is there a way I can tell from within the bound program itself if it was 
> > > translated into C so I can catch my own mistake prior to deployment?
> > 
> > > BTW I'm still using Euphoria Version 2.4.
> > If that last point is unlikely to change, you could use the entry point:
> > }}}
<eucode>
> >  cl=command_line()
> >  if equal(cl[1],cl[2]) then  -- prog is bound or translated
> >    fn=open(cl[1],"rb")
> >    void = seek(fn,#A8)
> >    ep={getc(fn),getc(fn),getc(fn),getc(fn)}
> >    close(fn)
> >    if equal(ep,{#10,#0F,#03,#00}) then  -- Eu 2.4 exw entry point, I think
> >    else                    -- assume eu2c'd
> > </eucode>
{{{

> > The above is completely untested, btw.
> > Alternatively you could try patching a 1 at offset #7F into any .exe you
> > create
> > via eu2c and assume that all versions of eu (/bound files) will have a 0
> > there,
> > or examine the PE headers (I use OllyDebug) and see if there is anything
> > else
> > that sticks out, maybe an EC.LIB section, (I'm guessing now).
> > 
> > Regards,
> > Pete
> 
> that's more what i was looking for. thanks pete. i'll try it and report back.
> 
> Yours, OtterDad
> 
> Don't sweat it -- it's not real life. It's only ones and zeroes. Gene Spafford

include Win32lib.ew
without warning

--------------------------------------------------------------------------------
--  Window Window1
constant Window1 = createEx( Window, "Window1", 0, Default, Default, 283, 97, 0,
0 )
--------------------------------------------------------------------------------
object cl, void, ep atom fn
cl=command_line()
if equal(cl[1],cl[2]) then  -- prog is bound or translated
	fn=open(cl[1],"rb")
	void = seek(fn,#A8)
	ep={getc(fn),getc(fn),getc(fn),getc(fn)}
	close(fn)
	if equal(ep,{#10,#0F,#03,#00}) then  -- Eu 2.4 exw entry point, I think
		warnErr("bound with translator")
	else                    -- assume eu2c'd
		warnErr("bound with C")
	end if
else
	warnErr("executed with translator")
end if

WinMain( Window1,Normal )


on my machine bound with Eu 2.4, and translated using watcom, both bound
programs report Bound with C

Yours, OtterDad

Don't sweat it -- it's not real life. It's only ones and zeroes. Gene Spafford

new topic     » goto parent     » topic index » view message » categorize

7. Re: Detecting a C translated bound program

OtterDad wrote:
> > Pete Lomax wrote:
> > > The above is completely untested, btw.
On closer inspection it has a UPX0 section in there which changes size and entry
point every time, didn't realise that. On an equally unsure footing, you may be
able to check for the UPX0 section as an indicator, if eu2c applies upx then I'm
out of ideas. Anyway, fingers crossed:
> }}}
<eucode>
>-- 	void = seek(fn,#A8)
>       void = seek(fn,#178)
>-- 	if equal(ep,{#10,#0F,#03,#00}) then
> 	if equal(ep,"UPX0") then
> </eucode>
{{{

Seems to identify bound eu programs for me anyway.

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

8. Re: Detecting a C translated bound program

OtterDad wrote:
> 
> on my machine bound with Eu 2.4, and translated using watcom, both bound
> programs
> report Bound with C
> 
Here's a simple demonstration of how to implement my idea:
--translate.ex
include misc.e
integer interpreted
-- This if statement is to fool the tranlator's optimizer
if platform() = WIN32 then
	interpreted = 1
else
	interpreted = 0
end if

if not interpreted then
	puts(1, "I'm translated!\n")
else
	puts(1, "I'm interpreted!\n")
end if

After translating, I edited main-.c to make sure that _1interpreted was 
always set to 0.  Of course, your file may look a bit different, since
you're using 2.4 (and the optimizer might not be as aggressive, either), 
but the idea is the same.
// main-.c
// Euphoria To C version 3.1.1
#include <time.h>
#include "C:\EUPHORIA\include\euphoria.h"
#include "main-.h"

int Argc;
char **Argv;
unsigned default_heap;
__declspec(dllimport) unsigned __stdcall GetProcessHeap(void);
unsigned long *peek4_addr;
unsigned char *poke_addr;
unsigned long *poke4_addr;
struct d temp_d;
double temp_dbl;
char *stack_base;
int total_stack_size = 262144;

void __stdcall WinMain(void *hInstance, void *hPrevInstance, char *szCmdLine,
int iCmdShow)
{
    int _0, _1, _2;
    
    int argc;
    char **argv;
    
    default_heap = GetProcessHeap();
    argc = 1;
    Argc = 1;
    argv = make_arg_cv(szCmdLine, &argc);
    winInstance = hInstance;
    stack_base = (char *)&_0;

    _02 = (int**) malloc( 4 * 3 );
    _02[0] = (int*) malloc( 4 );
    _02[0][0] = 2;
    _02[1] = (int*) malloc( 4 * 2 );
    _02[1][0] = 1;
    _02[1][1] = 2;
    _02[2] = (int*) malloc( 4 * 1 );
    _02[2][0] = 0;

    eu_startup(_00, _01, _02, 1, (int)CLOCKS_PER_SEC, (int)CLK_TCK);
    init_literal();
    shift_args(argc, argv);
    RefDS(_150);
    _2PI = _150;
    _2PI_HALF = NewDouble(DBL_PTR(_2PI)->dbl / DBL_PTR(_151)->dbl);

    // if platform() = WIN32 then

    // 	interpreted = 1
    _1interpreted = 0;
    goto L1;
L2:

    // 	interpreted = 0
    _1interpreted = 0;
L1:

    // if not interpreted then
    if (_1interpreted != 0)
        goto L3;

    // 	puts(1, "I'm translated!\n")
    EPuts(1, _179);
    goto L4;
L3:

    // 	puts(1, "I'm interpreted!\n")
    EPuts(1, _180);
L4:
    Cleanup(0);
}

new topic     » goto parent     » topic index » view message » categorize

9. Re: Detecting a C translated bound program

Pete Lomax wrote:
> 
> OtterDad wrote:
> > > Pete Lomax wrote:
> > > > The above is completely untested, btw.
> On closer inspection it has a UPX0 section in there which changes size and
> entry
> point every time, didn't realise that. On an equally unsure footing, you may
> be able to check for the UPX0 section as an indicator, if eu2c applies upx
> then
> I'm out of ideas. Anyway, fingers crossed:
> > }}}
<eucode>
> >-- 	void = seek(fn,#A8)
> >       void = seek(fn,#178)
> >-- 	if equal(ep,{#10,#0F,#03,#00}) then
> > 	if equal(ep,"UPX0") then
> > </eucode>
{{{

> Seems to identify bound eu programs for me anyway.
> 
> Regards,
> Pete

Worked like a champ! Let me pretty up the code and I'll publish the function.
Maybe it will come in handy for somebody else. Does it also work with 3.1.1?

Thanks again! You saved me much embarrassment.

Yours, OtterDad

Don't sweat it -- it's not real life. It's only ones and zeroes. Gene Spafford

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu