Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Miscellaneous > Archive > Off-Topic-Archive > Programming Question
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!

bottom of page
  
Author
Thread    < Last Thread     Next Thread > Post New Thread     Post A Reply
Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:30
  Old Post 30-08-2003 19:41 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
Programming Question Support Apolyton, buy Civilization: The Boardgame

I could definitely use input from Asher or someone else here.

Obviously, it's possible to write a disassembler that would disassemble another executable and provide the code for it.

The question stands, is it possible for a program to disassemble itself. Dunno, maybe with first creating a copy of my program first, but somehow. The disassembled code doesn't have to be changing - I'm not aiming for a self-changing program here. Merely viewing the code, and that's it.

Help or links to material much appreciated.

Sir Ralph is offline Sir Ralph
Emperor
Long live teh Schwampel!
Dec 2001
time: 06:30
  Old Post 30-08-2003 20:14
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Re: Programming Question Remove this text

quote:
Originally posted by Solver
The question stands, is it possible for a program to disassemble itself.


Only if the program is a disassembler. But I fear that's not the answer you're looking for.

quote:
Dunno, maybe with first creating a copy of my program first, but somehow. The disassembled code doesn't have to be changing - I'm not aiming for a self-changing program here. Merely viewing the code, and that's it.


Some programs contain debug information, which provide information about symbols like function, class and variable names. Together with a debugger you can reverse engineer the program then. But all you get is the assembler code with label names. But that's not enough to analyze complex programs. You can't, for instance, reverse engineer C++ code this way.

Debug information are usually not in the release version of the programs, though.

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:30
  Old Post 30-08-2003 20:16 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Get a bigger avatar today!

But what if in my program, I build in also the code of a disassembler? That is, let it do its normal work, and the hidden disassembler work - so that it could provide the disassembler data for itself.

Debug information... yep, good stuff, but doesn't suit me. I need the program to provide full disassembler output for itself.

If only I knew how exactly does one make a disassembler ?

Inverse Icarus is offline Inverse Icarus
Emperor
flying too low to the ground
May 2001
time: 00:30
  Old Post 30-08-2003 20:21 Visit Inverse Icarus's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

i have never seen a "perfect" disassembler, every time i have used one, a lot of code was "lost" in the translation.

but, that was a long time ago, perhaps things have improved.

as for links, a quick search of my fav coding sites and a googling yeilding nothing of major intrest.

i'm also assuming you mean a C disassembler.

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:30
  Old Post 30-08-2003 20:35 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Help yourself to an AD-FREE life

quote:
i'm also assuming you mean a C disassembler.


Indeed, C or C++ stuff...

Sir Ralph is offline Sir Ralph
Emperor
Long live teh Schwampel!
Dec 2001
time: 06:30
  Old Post 30-08-2003 21:46
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Support Apolyton, pre-order Civilization IV

quote:
Originally posted by Solver
If only I knew how exactly does one make a disassembler ?


To write a disassembler is pretty easy, but for the modern processors it would be a hell lot of work. Just take the whole numeric instruction set and write a program, which uses the numerical codes and addressing schemes to restore assembler code. I've done that for several processors of the 65xx series and the Z80. In theory, you can write a disassembler for the Pentium IV too, this way. But nobody would do so.

To reverse engineer C or C++ code this way is not possible, because the process of compilation is not unambiguous reversible. A lot of modern compilers optimize code, rewrite functions by changing the instruction order, keep variables in registers instead of memory, make inline macros out of functions and eliminate unused code and data at all. You can't restore the program as it was. Forget it. All you can is do a compromise. Take variables like EAX, EBX, ECX, EDX, ESI, EDI, EBP and so on, which correspond with the processor registers, keep track of memory addresses used and try to find a nomenklatura to symbolize them (like SYM_001234AB for address 001234AB hex). You'd get C code this way, which could compile back into the program, but that code has absolutely nothing to do with the original code the program was written in.

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:30
  Old Post 30-08-2003 22:37 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Inflate your Upload Space

Yup, the Halting Problem is of disturbance there.

The good stuff is this, though, any decompiler will get the MOV, CALL, PUSH and NOP commands from the executable... basically all I need.

Looked at a few thingies that try to make C code that way... nahh... let the kids play with them, I'll go with my ASM commands .

Angelo Scotto is offline Angelo Scotto
Warlord
Milan, Italy
Oct 1999
time: 05:30
  Old Post 31-08-2003 00:27
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

An interesting request, i'm unsure to have understood it correctly, so forgive me if my suggestions are not appliable to your case.

Usually scripting languages always offer this feature (i don't know if you need an compiled exe program).
To write self-modify code (you don't need it, i know, but if it can modify itself, it can also read itself) the king is always LISP.
Anyway if i remember correctly also Rexx was very good in that:
Yes, i checked, it has a builtin function called Sourceline(int) which returns a string containing the Rexx program source line you requested.
And with the Interpret(String) command Rexx will do the other thing, get a line (or more) of Rexx code and execute it.

If you don't want to use scripting languages you could always look at VM-based languages (Java and .NET), since the code produced by compilation is developed to be interpreted if needed (bytecode for Java and MSIL for .NET) the decompilation phase is always feasible.

Particularly .NET comes with some interesting Reflection features, aside from letting you inspecting everything about your assemblies such as types contained in it with its methods, fields, properties, etc (but this can be done with Java Reflection too), .NET goes further allowing you to add metadata to an assembly and inspect it afterwards (using the so-called attributes), Attributes are user-defined and can contain everything you want, so a solution could be signing every method with a "SourceAttribute" containing its source code.
Another feature of .NET Reflection is the Emit which allows to dynamically invoke C# (or VB) compiler to compile source-files at runtime (a sort of Rexx Interpret) to obtain an assembly as output; you could use it in this way: the exe is a small startup-code with a C# source file (containing the true application) embedded in the exe, the startup-code just compile the source file and launch it; in this way you can always request source files of the program directly from the program.

What else to add, from my experience C/C++ Decompilers are just a joke but extract the code section from an executable (at least on Windows and from a PE-Executable) is (relatively) easy, the difficult part is to decompile correctly what you extract.

I hope this helps,

quote:
Originally posted by Solver
Indeed, C or C++ stuff...


Maybe not...

Greetings,
Angelo

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:30
  Old Post 31-08-2003 00:32 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Support Apolyton, buy GURPS/ Alpha Centauri

Angelo - excellent thoughts. Very helpful .

I took a look at the few C/C++ decompilers and really found them to be weak. Extraction of merely the code segment from PE files seems much better of an idea.

Didn't know about rexx... gotta do some research on that.

Thanks again, just the reply I was looking forward to .

This can be closed now...

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:30.
Apolyton Time is 00:30.
    top of page
Rate This Thread:
archivepost
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0468 seconds (89.74% PHP - 10.26% MySQL) with 31 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net