# How do I edit an existing program

**URL:** https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600
**Category:** Factual Questions
**Created:** [June 23, 2005, 10:21pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600 "2005-06-23T22:21:52Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Ficer67](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@Ficer67](https://boards.straightdope.com/u/Ficer67)
#### Post date: [June 23, 2005, 10:21pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/1 "2005-06-23T22:21:52Z")

</div>

I have bought some GPS recieving equipment for my Pocket PC. It does most of what I want it to do, but there are some things that I just can’t get it to do. So, I would like to decompile the program, see what that program does, and then modify it to do what I want it to do.

If I could get it to a programming level, I could trace it and make the changes that I want. Anyone want to help me on this?

---

<div class="post-metadata">

### Author: ![mks57](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mks57](https://boards.straightdope.com/u/mks57)
#### Post date: [June 23, 2005, 10:46pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/2 "2005-06-23T22:46:17Z")

</div>

What you are asking is possible, but not practical. It usually takes a great deal of work to decompile a program, and the result does not have the original programmer’s comments that explain how the program works. It would be much cheaper to buy a product that does what you want out-of the-box.

---

<div class="post-metadata">

### Author: ![Kevbo](https://avatars.discourse-cdn.com/v4/letter/k/e47774/32.png) [@Kevbo](https://boards.straightdope.com/u/Kevbo)
#### Post date: [June 23, 2005, 10:59pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/3 "2005-06-23T22:59:38Z")

</div>

Not just comments are missing, but the variable names will be totally arbitrary (non distcriptive in any sense)

The only time I’ve done this successfully is when I had a paper copy of the source code as a reference. In this case my customer had paid another developer to design a product, then developer decided they weren’t interested in production. 5 yrs later all electronic copies of source code have been lost.

Note that this was assembly code, so the output of the dis-assembler looked a lot like the source, structure wise. A de-compiler would be much worse.

---

<div class="post-metadata">

### Author: ![TimeWinder](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@TimeWinder](https://boards.straightdope.com/u/TimeWinder)
#### Post date: [June 23, 2005, 11:04pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/4 "2005-06-23T23:04:55Z")

</div>

Decompiling isn’t something that’s done much any more. mainly because processor architectures and compilers do such a good job of optimizing (read “mangling”) the code that post-compiled code is usually considerably more complicated than the original. Machine generated RISC code, for example, is often all-but-uninitelligible after compilation, as the order of instructions gets moved around to assist branch prediction, pipelining, and vectorization.  
So **mks57** is right - it’s not practical unless you’re an unbelievably good programmer in the specific architecture of the program.

However, all is not necessarily lost. “Open Source” is trendy these days, especially on embedded systems like GPS units. If the one you chose is based on open source code, you might be able to just download the original source code for the system. Check with the manufacturer of the system.

---

<div class="post-metadata">

### Author: ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)
#### Post date: [June 23, 2005, 11:05pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/5 "2005-06-23T23:05:17Z")

</div>

Doing this on a piece of commercial software will also quite likely be a violation of the User Licensing Agreement.

---

<div class="post-metadata">

### Author: ![DougC](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@DougC](https://boards.straightdope.com/u/DougC)
#### Post date: [June 23, 2005, 11:09pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/6 "2005-06-23T23:09:26Z")

</div>

- 
  - 
    - It is generally not possible to “translate” a runtime (executable) program back into source code, because of the different ways that different compilers apply optimizations. Different compilers (written by different people) place different priorities on different types of optimizations, and perform multiple optimization-passes, and so the end result is that there’s no way to really know how to backtrack and undo everything properly, in the reverse order it was done originally. If you compile the exact same source code in several different compilers for example, all their results will _function_, but they will very-probably not be the same exact file-sizes, and some will run faster than others, some will use less RAM than others, and so on.  
So then-  
…The most you can do is disassemble it into ASM and then edit it in a hex editor, but for most people that’s not much help, as there’s no comments contained therein and usefully doing complex revisions on uncommented asm is pretty baffling. Perhaps there is some human with the brains to do that sort of business, but it sure as heck ain’t me.

- If you are capable of programming, you could look for any open-source projects on the equipment you have. I have read elsewhere that most GPS receivers can be accessed and polled with simple commands through a regular terminal window.  
~

---

<div class="post-metadata">

### Author: ![galt](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@galt](https://boards.straightdope.com/u/galt)
#### Post date: [June 24, 2005, 1:06am UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/7 "2005-06-24T01:06:46Z")

</div>

The problem is that the compiled code is built of extremely simple instructions. Move a byte from here to there. Test a condition and jump to a different address if it’s true, etc. Basic building block stuff. The software was generally written in a higher level language that has more complicated constructs like loops, subroutines, control blocks, and the compiler translates these complicated constructs into huge chains of really simple instructions. Translating back is simply not something you can do in an automated way. It takes an expert a lot of time of poring over low-level code to see patterns and try to discern what higher-level code led to the instructions he’s looking at.

Here’s an analogy. I’ll give you a sequence of basic arithmetic chores, and you have to figure out what was the ultimate task I wanted completed:

```auto

add 1 and 2
integer divide by 10, storing the remainder in A
add 6 to the result
add 9 to that result
integer divide by 10, adding 10 times the remainder to A
add 3 to the result
add 1 to the result
add 100 times the result to A
A is your answer

```

What did you just do?

you added 361 and 192 one digit at a time. Note that this isn’t really how computers do math, but it’s analogous to the simplistic instructions complex programs are reduced to when they get compiled.

---

<div class="post-metadata">

### Author: ![Stan\_Doubt](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@Stan\_Doubt](https://boards.straightdope.com/u/Stan_Doubt)
#### Post date: [June 24, 2005, 2:43am UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/8 "2005-06-24T02:43:46Z")

</div>

If you bought it recently and it works with a PocketPC, the GPS most likely has a SiRF chip and can use the NMEA 0183 protocol; The software you recieved when you bought the GPS device is not the only solution, as all the programs support NMEA0183. If your GPS device has this format, you will probably be better served finding an off-the-shelf solution rather than trying to decompile the program you have.

---

<div class="post-metadata">

### Author: ![Stan\_Doubt](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@Stan\_Doubt](https://boards.straightdope.com/u/Stan_Doubt)
#### Post date: [June 24, 2005, 3:19am UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/9 "2005-06-24T03:19:25Z")

</div>

You might also check out [this site](http://www.pocketgps.co.uk/modules.php?name=Downloads)

---

<div class="post-metadata">

### Author: ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)
#### Post date: [June 24, 2005, 9:10am UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/10 "2005-06-24T09:10:35Z")

</div>

No offence but if you don’t understand the basic principles of compilation, then it’s highly unlikely that you would have the skills to make whatever changes are neccesary, even if you had the source code.

---

<div class="post-metadata">

### Author: ![Ficer67](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@Ficer67](https://boards.straightdope.com/u/Ficer67)
#### Post date: [June 24, 2005, 4:46pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/11 "2005-06-24T16:46:36Z")

</div>

Thanks for all of the great responses guys. Turns out that the code I am looking for is open source code. So kudos to TimeWinder for clueing me in about open source code.

Thanks again everyone

---

<div class="post-metadata">

### Author: ![TimeWinder](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@TimeWinder](https://boards.straightdope.com/u/TimeWinder)
#### Post date: [June 26, 2005, 6:48am UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/12 "2005-06-26T06:48:48Z")

</div>

> [@Shalmanese](#):
>
> No offence but if you don’t understand the basic principles of compilation, then it’s highly unlikely that you would have the skills to make whatever changes are neccesary, even if you had the source code.

Not necessarily. I won’t go off on a rant about CS education these days, but the basic principles of compilation are often omitted for modern programmers.

For one thing, Java, VB, and other bytecode languages–very popular for beginners–have a somewhat different set of rules altogether. The basic principles still apply, whether your target is bytecode or machine language, but knowing what’s happening is less important. (From a standpoint of successfully programming – I’d argue it’s still quite important.)

For another, an awful lot of this stuff is purely high-level nowadays. I’ve met professional programmers who couldn’t even READ assembly, much less write it. Doesn’t hold 'em back a bit; the tools are reliable enough that you can just assume the low level stuff works. Especially in the increasing number of places where you can overwhelm performance issues with hardware (or patience).

For comparison, when I went through school, they taught about the compiler, the linker, and the loader? Loader? When’s the last time you thought about that in any real sense? Or the whole issue of absolute vs. relocatable addressing? It just isn’t relevant. Virtual memory (as in, how it works)? Paging in general?

Please note that I’m not saying any of this is good. But the field of “computer knowledge” has grown enormously, to the point where you can’t know it all. You choose what’s important, and for many of today’s young’uns, the magic that happens when you hit “build” doesn’t make it past the “importance threshold.”

---

<div class="post-metadata">

### Author: ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)
#### Post date: [June 26, 2005, 11:58am UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/13 "2005-06-26T11:58:59Z")

</div>

Yes, but unless you were purely a Perl or PHP or other interpreted language programmer, you must surely have the notion of “source files” which are plain, ASCII text files and “object files” which are filled with gibberish and are what the computer actually runs. It seems that this is basic enough that it would be hard to miss, no matter how spotty your education was.

---

<div class="post-metadata">

### Author: ![RaftPeople](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@RaftPeople](https://boards.straightdope.com/u/RaftPeople)
#### Post date: [June 26, 2005, 6:44pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/14 "2005-06-26T18:44:35Z")

</div>

**TimeWinder** , given that the result of dis-assembly is going to be some ugly assembly code that needs to get assembled after being modified, I have to agree with **Shalmanese**. It’s unlikely that a programmer would be un-aware of compilation, but would be comfortable with assembly language and running the assembler to produce machine code.

---

<div class="post-metadata">

### Author: ![TimeWinder](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@TimeWinder](https://boards.straightdope.com/u/TimeWinder)
#### Post date: [June 27, 2005, 9:46pm UTC](https://boards.straightdope.com/t/how-do-i-edit-an-existing-program/309600/15 "2005-06-27T21:46:40Z")

</div>

Point taken. However, based on that exact reasoning and the vagueness of the OP, I was assuming that he wanted a decompiler that decompiled to his language of choice (Java, say), rather than assembly.
