How does blitz3d compile this?

Blitz3D Forums/Blitz3D Programming/How does blitz3d compile this?

Matty(Posted 2013) [#1]
If I create a function and never reference it in my code will blitz3d include it in the final exe...and if so is it possible with a bit of jiggery-pokery to access it.

For example (pseudo code):


various processing here

End

function myfunction()

processing here

end function 


Is it possible to trigger the myfunction() function with the compiled exe even though it is never referenced before meeting the "End" statement?


Bobysait(Posted 2013) [#2]
if you dump your exe file you'll found your unused function (as a "function-name.ToLower") so it is compiled even though it is not used in the main program. I can't assume the core of the function is fully compiled somewherein the exe file, but name mangling seems to be there.

for the jiggery thing, I have no idea as I don't use this kind of stuff.
but if you don't run an exception (violation) What kind of thing do you expect to do ?


Yasha(Posted 2013) [#3]
If you want to remove unused code (seriously doesn't make a huge difference most of the time), IDEal has a feature that will list these functions for you. More usefully it also lists variables which are more likely to matter.

If you never reference the function... Well, how could it be called?

Unless you mess about with the dark magic unlocked by function pointers and system DLLs, which is not a model for anything safe anyway, it will never run, and in fact B3D would be a pretty terrible compiler - to the point of being unusable - if there was any way it could run without ever being referenced! (Note that even taking the function pointer still requires you to consciously write it in your code in some fashion.)


EDIT: wait - are you concerned about unknown effects, or are you trying to produce unusual effects? If it's the latter, check out FastPointer. It's a really solid way of getting and using function pointers. Even works with debugging.


Matty(Posted 2013) [#4]
Hi Yasha - I'm more asking a hypothetical question. What I have is a game that I wrote which was multiplayer. I've converted it to a single player game though the network code is all still part of the source, though not referenced anymore (I've removed references to the networking funcionality but the functions are still all there). My thought (not a concern at all just a curiousity) was whether it would be possible for someone to take the final executable and reactivate the network code without having seen the source.

As I said it is more a hypothetical question - I'm curious whether a person could actually reactivate code that is no longer referenced.

To give some background, the reason I'm curious about this that I've noticed with monkey (not blitz3d) that if I write classes and functions that are not referenced anywhere they are not even included in the final source at all - and there is no error checking on those parts of the code when compiling which seems a very different way of compiling compared to blitz3d which will check for errors in code that is not actually referenced.


Yasha(Posted 2013) [#5]
Well the short answer is no. Executables don't export symbols, so there's simply no way to hook into functions the way you would with a DLL.

The long answer is that of course they could if they knew how to use a hex editor or decompiler... but in general I really, really don't think that's something you need to consider since logically once a person can do that, they can do literally anything anyway. (Besides, that sort of work is waaay beyond the ability of most mortals.)

So no, there is no reasonable way to do that.


That seems like an odd decision on the part of Monkey though. I can actually think of lots of reasons why I would want code to be compiled even if it's unused, mainly because checking that code compiles is the first stage of testing (and fun with static assertions is the second...).