Valhalla Legends Forums Archive | General Programming | Extracting Machine Code

AuthorMessageTime
Win32
It's been decided that we'll be using dynamic code execution (machine code is loaded at run-time) for our "Monster AI".

Thus, we need some way for this AI to be written. I figure the most practical way would be to let people use their favourite compiler/IDE to write a Static Library, which would then have the encapsuled machine code migrated to the server database.

Now for the problem, how to extract the machine code from a library? I've been looking for awhile now, and cannot seem to find any technical documentation on the library format (have found some on the COFF, but it doesn't explain what I need) or any programs that enable such functionality.

Does anyone know of such a program, or some detailed documentation the static library format?


Cheers,

Matt.
August 7, 2007, 5:05 AM
Myndfyr
[quote author=Win32 link=topic=16928.msg171418#msg171418 date=1186463116]
I figure the most practical way would be to let people use their favourite compiler/IDE to write a Static Library, which would then have the encapsuled machine code migrated to the server database.
[/quote]
How did you come to this conclusion?
August 7, 2007, 6:24 AM
Win32
[quote]
How did you come to this conclusion?
[/quote]
I cannot see any other way to do it. No matter what, the code is going to have to be compiled.
August 7, 2007, 8:03 AM
Yegg
[quote author=Win32 link=topic=16928.msg171420#msg171420 date=1186473839]
[quote]
How did you come to this conclusion?
[/quote]
I cannot see any other way to do it. No matter what, the code is going to have to be compiled.
[/quote]

Why does it need to be compiled to machine code?
August 7, 2007, 12:05 PM
Win32
[quote]
Why does it need to be compiled to machine code?
[/quote]
Because I'm not interested in having a 'scripting language', one of the server's primary focuses is on performance.
August 7, 2007, 3:29 PM
Myndfyr
Why couldn't you use a dynamically-linked library that contains a predefined protocol or contract for being extended?  You know, like pretty much every other plugin system in the world uses?

I highly recommend taking a look at this book.  I have the first edition of it, and at least one entire chapter is about architecting your code so that it's extensible and you can use plugins.  The approach it uses for C++ is almost identical to how I create plugins in C# and .NET.
August 7, 2007, 10:41 PM
St0rm.iD
yeah just do it like any other plugin api, except strap a web based interface on it to upload the dll to the server and use loadlibrary/getprocaddress to manipulate it.
August 8, 2007, 4:20 AM
iago
It sounds like you're suggesting allowing artibrary users to run machine code on your server. Isn't there something about that that sounds like a Bad Idea?
August 8, 2007, 1:02 PM
Win32
[quote]
Why couldn't you use a dynamically-linked library that contains a predefined protocol or contract for being extended?  You know, like pretty much every other plugin system in the world uses?

I highly recommend taking a look at this book.  I have the first edition of it, and at least one entire chapter is about architecting your code so that it's extensible and you can use plugins.  The approach it uses for C++ is almost identical to how I create plugins in C# and .NET.
[/quote]
If it were intended to be used by the public, then I would've opted for using a DLL. The method I've chosen fits in well with the rest of the program's design, which itself is very strict.


[quote]
It sounds like you're suggesting allowing artibrary users to run machine code on your server. Isn't there something about that that sounds like a Bad Idea?
[/quote]
Only a few people will be allowed to use this feature.
August 8, 2007, 3:53 PM
Myndfyr
[quote author=Win32 link=topic=16928.msg171450#msg171450 date=1186588416]
[quote]
Why couldn't you use a dynamically-linked library that contains a predefined protocol or contract for being extended?  You know, like pretty much every other plugin system in the world uses?

I highly recommend taking a look at this book.  I have the first edition of it, and at least one entire chapter is about architecting your code so that it's extensible and you can use plugins.  The approach it uses for C++ is almost identical to how I create plugins in C# and .NET.
[/quote]
If it were intended to be used by the public, then I would've opted for using a DLL. The method I've chosen fits in well with the rest of the program's design, which itself is very strict.
[/quote]

It doesn't really mean anything whether you're using a strict design or being used by the public.  By choosing to dynamically link to a static library, you're going through a lot of extra effort.  You're going to have to dynamically map exports, relocate pointers, potentially rebase addresses; you might as well re-implement the entire Win32 program loader.  Do you think you can rewrite all that effectively?

By using a DLL, all you need to do is called LoadLibrary() and GetProcAddress() to map functions.  If you're smart, and if you're using C++, you only need to map one or two functions.

But hey, do whatever.
August 8, 2007, 5:05 PM

Search