Real Blitz3d Decompiler?

Blitz3D Forums/Blitz3D Programming/Real Blitz3d Decompiler?

Caton(Posted 2014) [#1]
is there a real blitz3d decompiler?


xlsior(Posted 2014) [#2]
No.


Caton(Posted 2014) [#3]
is there anyway to get the source code from a blitz3d program exe file?


RemiD(Posted 2014) [#4]
Is it not simpler to take the time to understand how something works and then to code your own version ? (and also more beneficial on the long term for you)


xlsior(Posted 2014) [#5]
is there anyway to get the source code from a blitz3d program exe file?


You can't uncook an omelet, or turn a hamburger back into a cow.


Yasha(Posted 2014) [#6]
is there anyway to get the source code from a blitz3d program exe file?


Actually there's an easy way - you can ask the person who wrote it.

If they aren't providing the source, consider that maybe they don't want you to look at it. Whether you succeed in decompiling it or not doesn't matter - using it without permission is copyright infringement and will land you in trouble.


Actually decompiling Blitz3D is technically possible (learn x86 and then look into objdump), but not easy. I can't think of any situations where it would be easier to decompile a program than to just write it again from nothing - especially since if you do the latter, you'll be able to actually use the resulting information!

The thing about decompiling is that it requires a lot of interpretation on the part of the reader because most of the context has been lost. You effectively have to already know what you're looking at to understand it. This means that in practice, you already have to know e.g. how to write a physics engine, in order to recognise that you're looking at what was once physics code in the first place. It is much easier to learn how to write a new physics engine, no matter your starting level, than it is to try to pick apart someone else's like this.


RGR(Posted 2014) [#7]
Well, one of the reasons why you cannot turn a hamburger back into a cow is because a hamburger is only a very little part of a cow and consists of some additional ingredients, while the cow consists of even many more components which do not find its way into the hamburger ... ;-)

Of course you can decompile a Blitz3D program.
I wrote my first decompiler about 25 years ago and there were several decompilers available.
I made a version for Blitz3D some 10 years ago, which was able to find all Basic functions and many Blitz3D functions by comparing asm sequences, compiled sample sequences and final exe sequences.

I did it to find out what I am able to do, looking for challenges.

Anyway. Don't ask. No-one who got that far will give you any software. You will find decompilers which produce assembler code - and if you are able to understand that code you can figure out, how Blitz3D (which is quite simple to understand) works ... good luck.

Plus what Yasha wrote same time while I wrote this ...


Caton(Posted 2014) [#8]
can you give me your decompiler? RGR


xlsior(Posted 2014) [#9]
while the cow consists of even many more components which do not find its way into the hamburger ... ;-)


...you hope.


Caton(Posted 2014) [#10]
is there a porgram that can get all the functions,Globals,dims?


Matty(Posted 2014) [#11]
Unlikely....once it is converted to machine code you lose all your nice function names....converting it back to the function name you wanted is basically.....impossible....


Caton(Posted 2014) [#12]
function,Global,dim,type names are still there I found them in the hex editor.


_PJ_(Posted 2014) [#13]
Whilst largely irrelevant to the topic, strangely I have found that there are some function names even kept in the compiled code. Not sure why or what criteria allows some to be maintained in the executable or why they are there.
I also know that B3D compiles the complete libary of internal functions even if they are not used in the code itself, but either way, it doesn't necessarily make any decompilation directly understandable.


Matty(Posted 2014) [#14]
Interesting that this came up ... a few days ago I had to decompile one of the android.jar files on one of our devices...it gets converted to a thing called "smali" - in the end though I didn't bother making any changes....


virtlands(Posted 2014) [#15]
Here's an interesting decompiler :
IDA v5.o Free Edition :: https://www.hex-rays.com/products/ida/support/download_freeware.shtml

It has Graph views & Text Views.
You can resize (zoom In/Out) the graph views by using Ctrl+mouse wheel .

[ Here's a sample screenshot I took, as I de-compiled Blitzcc.exe ]



The typical downside to decompiling EXEs is that you'll be staring
at millions of lines of code.

I'm confident that someone (in future) will create a special
"self-decompile" FUNCTION (DLL) for Blitz3D eventually, one where
you can choose to decompile a small range of code, perhaps 10 lines or so, (between 2 instruction points).


Who was John Galt?(Posted 2014) [#16]
I'm confident that someone (in future) will create a special
"self-decompile" FUNCTION (DLL) for Blitz3D eventually, one where
you can choose to decompile a small range of code, perhaps 10 lines or so, (between 2 instruction points).
I would be surprised to say the least if anyone went to so much effort for an outdated language bound to an old version of DX.


Floyd(Posted 2014) [#17]
And the resulting uncommented source would be incomprehensible in all but the simplest cases.


Kryzon(Posted 2014) [#18]
What do you want to decompile? Maybe someone has the source.


Yasha(Posted 2014) [#19]
What would be the point of inserting decompilation directives into the source of your own program? That seems backwards.

I can't imagine any situation where decompilation is useful if you also have access to the original code.


virtlands(Posted 2014) [#20]
What would be the point of inserting decompilation directives into the source of your own program? That seems backwards.
Hi Y.
There is the possibility for a running Blitz3D program to self-decompile portions of itself for ...

(a) would make an excellent opportunity to learn assembly language, [to see how Blitz3D get translated into assembly].
(b) would allow us to learn & make special (DLL) Function interfaces that take advantage of the low-level workings,
such as, for example, knowing how the STACK & FUNCTIONS connect with "Blitz" code.

(c) Believe it or not, this assembly knowledge can lead to the development of code
that does not need to use "GOTO Skip1" nor
If SETUP_FUNCS=0
; *** function body goes here!!!
Print "This works!!!!"
EndIf

style of coding when fetching pointers to FUNCTIONs and variables.

(d) Will allow us to develop usable pointers to Functions with MORE than ONE parameter, as well as create weird VAR-ARGS FUNCTIONs.
(e) Will help us with concurrent & parallel programming too.

Here is a recent snapshot of a program I made that decompiles perfectly. In this case, it decompiles " c = a * b " .

eip1 = getEIP() ;;;; = returns the (32-bit) instruction pointer.
c = a * b
eip2 = getEIP()-10



Update: (Jan 26,2015):

I plan to start working on some "decompiler" code in February. Have been sort of busy, and haven't had time to start yet.


Zethrax(Posted 2014) [#21]
@VirtLands - That's pretty cool. But I think what Caton wants is for people to give him info on how to steal other people's code and assets.

Frankly, I'm starting to think that Caton is Puki's love child.


cyanic(Posted 2015) [#22]
I think anyone making a decompiler would be having an easier time now, considering how the compiler is now open-source. It would basically come down to finding patterns in the disassembly and mapping them back to BB code. Sort of like the way you can decompile MSIL back into C# or VB, except you'd be translating x86 assembly instead of MSIL. I'd make one if I wasn't busy.

As for assets, well, mesh loading code is open source too. Even without source code, it didn't stop me from messing with this one game that I was fixing the translations on. That said, compiled BB code is difficult to analyze statically because it's stored as a blob in the runtime's resource section, and all the offsets are table IDs or something instead of actual addresses.

Someone should make a better compiler. There's so much redundancy and inefficiency in current generated code.


Caton(Posted 2015) [#23]
resone because I lost my source code...


Caton(Posted 2015) [#24]
mov ecx, [esi+4]
what does this mean in blitz code?


GfK(Posted 2015) [#25]
mov ecx, [esi+4]
what does this mean in blitz code?
It moves a value into register ECX. It doesn't mean anything in Blitz. It does nothing by itself.

If you're trying to go through assembly code and translate it line-for-line back to Blitz - forget it. It isn't going to work.


*(Posted 2015) [#26]
This is the daftest idea I have seen in ages, if you disassemble a program you will only get the assembly from it. Translating back to blitz code is pretty much impossible as you would have to work out how each command is arranged in the game engine and hat it does and where.

As Yasha said if you want the source from someone elses code ask them for the source code as once its compiled into machine code its nearly impossible to transfer back the other way.


Who was John Galt?(Posted 2015) [#27]
Bottom line, it would take much more skill and effort to reverse engineer compiled code back to Blitz than it would take to just learn to program to a decent level and recreate whatever game you want from scratch.


jfk EO-11110(Posted 2015) [#28]
As Caton said, he'd need it cause he lost his source code, this may be a legite reason, tho if he wrote it in the first place, it would be much easier to simply rewrite it (usually it turns out to be better code when rewritten). Even if he didn't write it in the 1st place, it would still be easier to learn about and then write it. And if it's a huge piece of code, it would be nightmareish to read the bloody disassembled code. On the other hand, if it's few code, it will be rewritten quickly.

However, it may be useful to disassemble an exe to optimize it in Asm, like some timecritical loops, if you can manage to handle an algorithm entirely within registers, it may run about ten times faster.

But this is done much easier by writing a userlib with a language that supports inline asm, eg. purebasic.


Matty(Posted 2015) [#29]
Given Caton doesn't even know how to read from a file I doubt he wrote it in the first place....(see his other threads).


jfk EO-11110(Posted 2015) [#30]
Guess we all begun one day. Rehi btw.


RemiD(Posted 2015) [#31]
[offtopic]
jfk is alive \o/
Welcome back !
I thought that you were gone forever, your website is down...
[/offtopic]


jfk EO-11110(Posted 2015) [#32]
Hi. Yeah, it produced costs only, so there was no point in keeping it.

Rumors concerning my recent death are way exaggerated tho. :°)