Shop OBEX P1 Docs P2 Docs Learn Events
Extracting codes from a BS2P40 — Parallax Forums

Extracting codes from a BS2P40

GabeGabe Posts: 24
edited 2005-10-20 20:52 in BASIC Stamp
Hi guys

I was wondering if it is possible to extract out programme codes from the internal EEPROM and RAM of a BS2P40 via the serial port into the computer?

Regards,
Gabe

·

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-10-17 04:04
    Gabe -

    The answer to your question depends on what you mean by "programme codes". If you're asking if the tokenized code which was downloaded to the Stamp by the Editor/Compiler is accessible, the answer is yes, but I'm not sure what you might want to do with it, once you've extracted it.

    If you're asking if the human readable source code can be downloaded from the Stamp, the answer is no, since that form of the program never exists on the Stamp per se. It only exists on your hard drive, and in the Editor/Compiler during processing.

    If your interest is in cloning one Stamp program from another existing one, this applications note may be helpful to you, although it only addresses the Stamp BS-2:
    http://www.emesystems.com/BS2clone.htm

    Regards,

    Bruce Bates
  • GabeGabe Posts: 24
    edited 2005-10-17 04:54
    Hi Bruce,

    I am referring to the tokenized code. with regards to "but I'm not sure what you might want to do with it, once you've extracted it.", I actually need to extract this code to modify it. Its actually from a BS2P40 chip that is in a finished artefact. What I'm worried about is, does the Stamp makes a copy of it and sents it to the PC or does it just send whatever that's inside the Stamp, thus effectively leaving it empty?

    The 2nd scenerio is something I rather do without.

    Regards,
    Gabe
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-10-17 05:39
    Gabe -

    I'm not sure we're quite communicating yet. Let me see if I can ferret out what's causing the problem.

    First, do you realize that the tokenized code is NOT human readable?

    Do you also understand that there is almost NO documentation on how the tokenization is actually done, and how it's created or interpreted? The reason is that such information is proprietary to Parallax, and rightfully so.

    Do you realize that the Stamp uses an onboard interpreter to cause this tokenized code to effect or produce results at program execution time, and thus it's not truly executable in the sense that·machine language code is executable as a native computer language form? Said differently, PBASIC is an interpretive Basic Language.

    Finally, given all that above, how, or in what way, were you planning on modifying it? Were you hoping to (say) change the instruction sequence in some way?

    Also, in your sentence "What I'm worried about is, does the Stamp makes a copy of it and sents it to the PC or does it just send whatever that's inside the Stamp, thus effectively leaving it empty?" there are more unidentified "it or its" than I'm able to cope with. Could you perhaps make that sentence a bit more qualified and specific. Otherwise, the question is a bit difficult to answer.

    Perhaps I'm way off base here. Is this a security or potential program piracy issue you're concerned about? That's a somewhat different matter, but there are very distinct answers to those sorts of questions.

    You might want to explain exactly what it is you're trying to accomplish, as there may be an alternate way of doing it, other than the method you seem to be proposing. Just by way of example:

    I'm trying to find a way to change a table stored in EEPROM on the Stamp, on the fly. Is there any practical way of accomplishing that?

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 10/17/2005 5:43:27 AM GMT
  • GabeGabe Posts: 24
    edited 2005-10-17 07:00
    Hi Bruce,

    Sorry for the mistake. I guess i misunderstood the meaning of 'tokenised codes'...and yes I want the human readable source code.

    Okay, what i wanted to do is, there is a completed program done by a previous group, now I'm interested to get their codes directly from the BS2P40, because I suspect they did not leave the entire finalised codes inside any report that they have submitted. I was just wondering if there's a way to get those human readable source code that were originally downloaded into the Stamp from the PC?

    I want to take a look at their codes and try to think of alternatives ways to modify the program so to make it more efficient and see if I am able to incorporate more functions.

    I shall rephrase what I meant by "What I'm worried about is, does the Stamp makes a copy of it and sents it to the PC or does it just send whatever that's inside the Stamp, thus effectively leaving it empty?".

    I wanted to ask if the BS2P40 would actually make a copy of the·human readable source codes·that is inside the Stamp·before sending out/extracted out·to the PC? I mean, if the Stamp doesn't make a copy of the human readable source code, does that means, after the codes were extracted out, the Stamp is effectively empty?

    Sorry again for the misunderstanding,
    Gabe

    Post Edited (Gabe) : 10/17/2005 7:05:50 AM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-10-17 07:27
    Gabe -

    I'd go looking on the computer they were using, rather than looking at the Stamp they were using. There is no easy method to do what you want to do, since by the time the Stamp "sees" the program, the human readable source code is LONG gone.

    To answer your question directly - Can the EEPROM be read out, and the tokenized codes retrieved, and de-compiled into human readable source code? The answer is yes, BUT. The BUT is that all of the variable names are gone, all of the program labels (GOTO and GOSUB destinations) are gone, none of the constants have their appropriate labels, and all you're left with is a very difficult to read or understand "skeleton" program which represents, in rudimentry but true form, the original program which was subsequently tokenized and loaded into the Stamp. Needless to say, none of the program comments are kept either.

    If you've ever seen a machine language program dis-assembled back into assembler source code, without the use of the original program name and address table, then you know what kind of mess you'd have to deal with. GOTO (branch) designations often look like this: RTN#001, variable names look like this: VAR#001, constant names (if they can be so identified) look like this: CON#001 and unless you were intimately familiar with what the program did, you'd be much better off re-writing it from scratch.

    Sorry!

    Regards,

    Bruce Bates
  • GabeGabe Posts: 24
    edited 2005-10-17 07:42
    Hi Bruce,

    Thanks for the constant quick replies. Really appreciated it. Stopped me from doing anything stupid with the Stamp. Heh. =)

    Regards,

    Gabe
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-10-17 16:02
    Yes, Gabe, when the IDE starts to program the BS2, the FIRST thing it does is erase EVERYTHING that was originally in the BS2 EEPROM. Then it makes a whole new version of the code from the source in the PC. Then it downloads the program tokens from the PC to the BS2.

    So, there's very little information coming back to the PC from the BS2 -- basically a short string saying what kind of BS2 it is (SX, E, plain, etc) and then probably some check-byte for each 'record' sent to the BS2 from the PC to reassure the PC the data actually got there.

    Reading the program from the BS2 itself is really a non-starter. It can be done, with great pains, by de-soldering the eeprom and putting it in an eeprom reader. But even then, you just have the program tokens. You'll still have to reverse-engineer the source code that generated those tokens.

    It's SO much easier to get the source off the PC that made it. Oh, and the little 'memory map' the IDE generates is STILL not read from the chip -- it's generated by the IDE by compiling the source.
  • FlyingFishFingerFlyingFishFinger Posts: 461
    edited 2005-10-17 22:37
    Is it possible to electronically read the memory map to get the ASCII characters without attaching a Stamp, downloading the code and useing the read command?
    Rafael
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-10-17 23:10
    Yes, but then you'll only have the ascii codes of the just-compiled source program. And you had to have the source program to generate the ascii codes.

    So, using the ascii codes to regenerate the program makes absolutely no sense in that case.
  • ChipCircuitChipCircuit Posts: 23
    edited 2005-10-20 20:52
    Steve Parkis has a for fee service that will pull the program from the stamp and then offer it in a revised format.

    it is readable as stamp code, comments and any and everything that is not downloaded to the Stamp is gone.

    but, if you have a clue what you did in the first place, the recovered code makes getting back to where you were a much easier task.

    http://home.earthlink.net/~parkiss/recovery.txt

    Dave
Sign In or Register to comment.