• Welcome to Valhalla Legends Archive.
 

Extracting Machine Code

Started by Win32, August 07, 2007, 12:05 AM

Previous topic - Next topic

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.

MyndFyre

Quote from: Win32 on August 07, 2007, 12:05 AM
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.
How did you come to this conclusion?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Win32

Quote
How did you come to this conclusion?
I cannot see any other way to do it. No matter what, the code is going to have to be compiled.

Yegg

Quote from: Win32 on August 07, 2007, 03:03 AM
Quote
How did you come to this conclusion?
I cannot see any other way to do it. No matter what, the code is going to have to be compiled.

Why does it need to be compiled to machine code?

Win32

Quote
Why does it need to be compiled to machine code?
Because I'm not interested in having a 'scripting language', one of the server's primary focuses is on performance.

MyndFyre

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Banana fanna fo fanna

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.

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?
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


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.
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?
Only a few people will be allowed to use this feature.

MyndFyre

Quote from: Win32 on August 08, 2007, 10:53 AM
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.
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.

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.