Proton BASIC Community

Proton (Positron) => Proton8 threads => Topic started by: TimB on Feb 23, 2023, 09:25 PM

Title: Lost code extracting data from ASM
Post by: TimB on Feb 23, 2023, 09:25 PM

Hi all

Horrors of horrors I lost a bas file.

I have the asm which has all the lines of code in it. Is there a code stripper around

Example of what I need F1_001131 equ $ ; in [OPTOBOARD 13K22 I2C V1.BAS] Inc bVelAvePntr

The bit in bold is what I need. Is there any utility's to help? Basically remove any line not starting with F1 then remove all upto ]

Thanks

Tim


Title: Re: Lost code extracting data from ASM
Post by: Gary Scott on Feb 24, 2023, 12:33 AM
I ask chatGPT and here is one answer, and it recommends sed, and it supplies the expressions to make it happen.  https://gnuwin32.sourceforge.net/packages/sed.htm

IDA Pro and Ghidra may do what you want but both have one hell of a learning curve and probably not worth the effort unless you know one of them already
Title: Re: Lost code extracting data from ASM
Post by: Gary Scott on Feb 24, 2023, 02:56 AM
This Python script should also do what you want (not tested) if you prefer Python over sed. You will need python installed on your computer.

Make back up! before trying any procedure!!!!!!!!!!!

I ran Python with Powershell on Windows to run python

import re

# read in the input file
with open('input_file.txt', 'r') as f:
    input_lines = f.readlines()

# filter out lines that do not start with F1
filtered_lines = [line for line in input_lines if line.startswith('F1')]

# remove everything on each line up to and including the first ']' character
output_lines = []
for line in filtered_lines:
    output_lines.append(re.sub(r'^.*\]', '', line))

# write the output to a new file
with open('output_file.txt', 'w') as f:
    f.writelines(output_lines)

QuoteTo run this code, you'll need to save it to a Python file (e.g., my_script.py) and make sure you have a text file with the input data in the same directory. Then, follow these steps:

Open a command prompt or terminal window.
Navigate to the directory where your Python file and input data file are located using the cd command. For example, if they are both located in a directory called "my_project", you could navigate there with the command cd my_project.
Once you are in the correct directory, you can run the Python script by typing python my_script.py (replace "my_script.py" with the name of your Python file).
After running the script, you should see a new file in the same directory called "output_file.txt", which will contain the processed output data.
Note that you will need to have Python installed on your system in order to run this script. If you don't have Python installed, you can download it from the official website (https://www.python.org/downloads/).
Title: Re: Lost code extracting data from ASM
Post by: JohnB on Feb 24, 2023, 03:13 AM
You could do the same thing using Regular Expressions.
Title: Re: Lost code extracting data from ASM
Post by: TimB on Feb 24, 2023, 07:27 AM
Quote from: Gary Scott on Feb 24, 2023, 12:33 AMI ask chatGPT and here is one answer, and it recommends sed, and it supplies the expressions to make it happen.  https://gnuwin32.sourceforge.net/packages/sed.htm

IDA Pro and Ghidra may do what you want but both have one hell of a learning curve and probably not worth the effort unless you know one of them already

LOL I asked Chat GPT and it wrote me a script as well

with open('input.txt', 'r') as input_file, open('output.txt', 'w') as output_file:
    for line in input_file:
        if line.startswith('F1'):
            output_file.write(line)

Only issue is I cannot make it run. No idea if it is real code or it pulled it from its.. I will ask Son as he writes python..

Title: Re: Lost code extracting data from ASM
Post by: atomix on Feb 24, 2023, 07:51 AM
use Notepad++

Menu -> Search -> Replace -> Press button "Replace All"

use the following regular expressions


Title: Re: Lost code extracting data from ASM
Post by: TimB on Feb 24, 2023, 09:07 AM

Thanks atomix

I'm not sure what I'm doing wrong. It just says no matches

searchreplace.png
Title: Re: Lost code extracting data from ASM
Post by: Stephen Moss on Feb 24, 2023, 09:54 AM
Quote from: TimB on Feb 24, 2023, 07:27 AMLOL I asked Chat GPT and it wrote me a script as well

with open('input.txt', 'r') as input_file, open('output.txt', 'w') as output_file:
    for line in input_file:
        if line.startswith('F1'):
            output_file.write(line)

Only issue is I cannot make it run. No idea if it is real code or it pulled it from its.. I will ask Son as he writes python..
Looks like pseudocode to me and one that would not do the job anyway as it appears to be reading and then writing out the entire line.

In VB if ] is always the last character before the BASIC code then I would do something like...
FileOpen(1, FilenName, OpenMode.Input)        'Open Source File
FileOpen(2, FileName, OpenMode.Output)        'Open Destination file

Do Until EOF(1)                               'Loop until the end of the source File is reached
X = Lineinput(1)                              'Get Next Line of Data from the Source File
Y = InstrRev("]", X, 1, CompareMethod.Text)   'Get Location of ] staring from Right side of String
X = Strings.Right(X, Y-1)                     'Strip out everything left of ] to leave just the BASIC code
Print(2, X)                                   'Write BASIC Code to the new file
Loop

FileClose(1)                                  'Close Source File
FileClose(2)                                  'Close Destination File

It may not be 100% working code as it is a quick lash-up but it would not be far off, I know using stream readers/writes in the modern way but for something so simple the classic LineInput, Print & FileOpen/Close method would be sufficient.
Title: Re: Lost code extracting data from ASM
Post by: JohnB on Feb 24, 2023, 12:39 PM
@TimB

I will send you a version of studio which will let you do this.  Studio relies heavily on Regular Expression and I have all the code in there to generate the file, it would be quicker than building a new app.  I couldn't find an easy way to do this using the RegEx in notepad++

This is the RegEx ^\s*(?:F\d{1}_\d{6}\sequ\s\$\s;\s[a-z\s[0-9.]+)](.)
Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 24, 2023, 01:27 PM
I created a program to generate the .bas file from the .asm missing still some things runs asm_bas xxx where xxx is the name of the asm file but without the extension and creates a file xxx_.bas
Look #26
Title: Re: Lost code extracting data from ASM
Post by: atomix on Feb 24, 2023, 01:47 PM
You may have copied a space character while copying
Title: Re: Lost code extracting data from ASM
Post by: TimB on Feb 24, 2023, 05:13 PM

Thanks everyone the support is fantastic. Some results

After removing the " " as was pointed out the Notepad++ worked a treat.

The Python code worked when run properly (it was only to leave the F1.... Lines)

Not tried the .exe yet as have to do that from a command line I think

In the mean time I also did it the hard way with note pad and loads of highlight + deletes
Personally I like the Notepad++ results as it left spaces and made it look easier to add the comments back in etc

What it did highlight though is my backups were not running properly. Google Back up on that file had not changed in months and would have just overwritten the files any case. I thought I had Windows backup running but it will not enable it unless I use of machine storage so non of the usual previous version stuff was working.
I'm investing now in a 3rd party backup to my G cloud account and going to see why backup in Positron IDE is not running.

Thanks again everyone
Title: Re: Lost code extracting data from ASM
Post by: John Lawton on Feb 24, 2023, 05:35 PM
Good to hear you've managed to get your source code back.

I don't use Backup in Positron Studio, but I notice it only creates a .zip text file of the file names, and no actual source code is backed up... I don't know whether this is a known problem.

For my general company data backup, I store everything on a small file server which has an overnight 'snapshot' backup to another drive. As a result I have 30 days of file backup with that system which I can restore from if required, which I occasionally have to do. It has saved me a number of times.
Title: Re: Lost code extracting data from ASM
Post by: keytapper on Feb 24, 2023, 05:41 PM
Quote from: JohnB on Feb 24, 2023, 12:39 PMThis is the RegEx ^\s*(?:F\d{1}_\d{6}\sequ\s\$\s;\s[a-z\s[0-9.]+)](.)
This is the rightest. It takes in account whether there are more than a file included on the assembly file.
Title: Re: Lost code extracting data from ASM
Post by: TimB on Feb 24, 2023, 06:04 PM
Quote from: John Lawton on Feb 24, 2023, 05:35 PMknow whether this is a known problem.

For my general company data backup, I store everything on a small file server which has an overnight 'snapshot' backup to another drive. As a result I have 30 days of file backup with that system which I can restore from if required, which I occasionally have to do. It has saved me a number of times.

I actually have a NAS hidden away but its a power hog and can warm a room. Since I pay G money for storage I might as well use it.
Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 24, 2023, 08:07 PM
Mira el #26
Title: Re: Lost code extracting data from ASM
Post by: rick.curl on Feb 25, 2023, 12:54 PM
Quote from: TimB on Feb 24, 2023, 05:13 PMI'm investing now in a 3rd party backup to my G cloud account and going to see why backup in Positron IDE is not running.
Hi Tim- I'm using Insync (https://www.insynchq.com) to keep files and libraries backed up and sync'ed across multiple computers.  It's affordable and the support is very good.

-Rick
Title: Re: Lost code extracting data from ASM
Post by: Dompie on Feb 25, 2023, 03:23 PM
@Pepe When I download your asm_bas.zip I got a "serious" warning from Microsoft Defender.
Message: Trojan:Win32/Wacatac.B!ml

I haven't investigated further, I want to report it (since I almost never get notifications from Microsoft Defender)

Johan
Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 25, 2023, 04:09 PM
look #21
Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 25, 2023, 04:15 PM
Try another antivirus, it can be a false positive, I have Windows Defender and does not report any virus
Title: Re: Lost code extracting data from ASM
Post by: Dompie on Feb 25, 2023, 04:22 PM
@Pepe Hmmm, I use the same one as you, Windows Defender (I called it accidentally Microsoft Defender).
Doesn't matter.

Johan
Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 26, 2023, 12:15 AM
new version, added dimension variables and symbols, can not be correctly melted type, must be verified by the user look #26
Title: Re: Lost code extracting data from ASM
Post by: John Drew on Feb 26, 2023, 07:36 AM
Pepe, BitDefender also suggested a Virus in the latest file. There must be a match to some sections of code. The Virus checker wouldn't let me proceed. I see I'm not the only one.
Cheers
John
Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 26, 2023, 12:58 PM
Avg reports nothing
Title: Re: Lost code extracting data from ASM
Post by: JohnB on Feb 26, 2023, 04:34 PM
@John Lawton Positron Backup zips the source files up and you can unzip them from the application.  You can either restore over the original or create a new file.  If you open the zip files using windows only the info.txt file will be visible.

@TimB If you want automatic backup, go to Tools, Options, Miscellaneous. Make sure Backup on Successful compile is checked.  Otherwise you will have to make manual backups using the backup wizard.
Title: Re: Lost code extracting data from ASM
Post by: TimB on Feb 26, 2023, 07:04 PM

Hi John

As J Lawton was eluding to the issue is that the zip file is essentially empty with just a file called Zipinfoo.txt in it and that just says the file name and location etc

Tim
Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 26, 2023, 08:34 PM
Look #31
Title: Re: Lost code extracting data from ASM
Post by: TimB on Feb 27, 2023, 08:00 AM

Pepe

Can you give an explnation on how to run the code?

I tried opening command prompt. changing directory to where the asm then running the exe followed by the asm name and path

C:\Users\timbo\Documents\Test code\ASM> asm_bas.exe C:\Users\timbo\Documents\Test code\ASM\OptoBoard 13k22 i2c v1.asm

but it does nothing

Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 27, 2023, 01:18 PM
Put the file asm_bas.exe where the 13k22 i2c v1.asm file is

and the name of the file without the .asm extension.

write asm_bas 13k22 i2c v1

redownload the file because bugs were fixed

I clarify that the type of variables must be verified by the user because it does not detect variables of the type with sign and with decimal point, and vectors consider them of type byte.
Tested for some 12f, 16f and 18f pics.

look #31
Title: Re: Lost code extracting data from ASM
Post by: TimB on Feb 27, 2023, 03:20 PM


Just as feed back it generated vars and Symbols for the code but did not extract the basic code

Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 27, 2023, 05:32 PM
You could send me the.asm file to see if I can fix anything.
Title: Re: Lost code extracting data from ASM
Post by: Pepe on Feb 27, 2023, 08:37 PM
Could you try now
Title: Re: Lost code extracting data from ASM
Post by: Dompie on Feb 28, 2023, 08:34 AM
@Pepe No Windows Defender messages this time any more

Johan
Title: Re: Lost code extracting data from ASM
Post by: top204 on Feb 28, 2023, 12:12 PM
Also remember, the "F1" refers to the ".bas" code listing's file, and any include files used in the program will be referenced as "F2" and "F3" and "F4" etc... With "Fx_SOF equ $" to signal the start of a file and "Fx_EOF equ $" to signal the end of a file, where "Fx" is either the ".bas" code listing's "F" value or an include file's code listing "F" value. These were placed in the compiler for the ISIS simulator.

As a test, I used my old friend UltraEdit with its search and regular expressions enabled on a simple program's assembler listing and I got a block of text that included the "F" directive, then after a few search/replace passes of start of line character removals with regular expressions, I got:


Dim MyTable8[10]  As byte Heap = 10, 20, 30, 40, 50, 60, 70
Dim MyTable16[10] As Word Heap = 100, 200, 300, 400, 500, 600, 700
Dim MyTable24[10] As Long Heap = 10000, 20000, 30000, 40000, 50000, 60000, 70000
Dim MyTable32[10] As Dword Heap = 100000, 200000, 300000, 400000, 500000, 600000, 700000
Dim MyTableFloat[10] As Float Heap = 3.14, 6.28, 12.56, 25.12, 50.24, 100.48, 200.96
wFSR0 = AddressOf(MyTable8)
MyByte.Byte0 = POSTINC0
HRsout Dec MyByte, ","
MyByte.Byte0 = POSTINC0
HRsout Dec MyByte, ","
MyByte.Byte0 = POSTINC0
HRsout Dec MyByte, ","
yByte.Byte0 = POSTINC0
HRsout Dec MyByte, ","
MyByte.Byte0 = POSTINC0
HRsoutLn Dec MyByte
wFSR0 = AddressOf(MyTable16)
MyWord.Byte0 = POSTINC0
HRsout Dec MyWord, ","
MyWord.Byte0 = POSTINC0
HRsout Dec MyWord, ","
MyWord.Byte0 = POSTINC0
HRsout Dec MyWord, ","
MyWord.Byte0 = POSTINC0
HRsout Dec MyWord, ","
MyWord.Byte0 = POSTINC0
HRsoutLn Dec MyWord
wFSR0 = AddressOf(MyTable24)
MyLong.Byte0 = POSTINC0
HRsout Dec MyLong, ","
MyLong.Byte0 = POSTINC0
HRsout Dec MyLong, ","
MyLong.Byte0 = POSTINC0
HRsout Dec MyLong, ","
MyLong.Byte0 = POSTINC0
HRsout Dec MyLong, ","
MyLong.Byte0 = POSTINC0
HRsoutLn Dec MyLong
wFSR0 = AddressOf(MyTable32)
MyDword.Byte0 = POSTINC0
HRsout Dec MyDword, ","
MyDword.Byte0 = POSTINC0
HRsout Dec MyDword, ","
MyDword.Byte0 = POSTINC0
HRsout Dec MyDword, ","
MyDword.Byte0 = POSTINC0
HRsout Dec MyDword, ","
MyDword.Byte0 = POSTINC0
HRsoutLn Dec MyDword
wFSR0 = AddressOf(MyTableFloat)
MyFloat.Byte0 = POSTINC0
HRsout Dec2 MyFloat, ","
MyFloat.Byte0 = POSTINC0
HRsout Dec2 MyFloat, ","
MyFloat.Byte0 = POSTINC0
HRsout Dec2 MyFloat, ","
MyFloat.Byte0 = POSTINC0
HRsout Dec2 MyFloat, ","
MyFloat.Byte0 = POSTINC0
HRsoutLn Dec2 MyFloat
Stop

And it took abput 5 minutes, and is, essentially, the original ".bas" code. However, if there is assembler in the .bas file it will not have the preceeding Fx directives, and neither will variable declarations or preprocessor meta-macros, so they will need to be extracted seperately, but they are all listed in the asm code.

If you also have the ".lst" file, the variables and include files are listed at the top of it, for example, the above program's ".lst" file has:

                      00002         LIST
                      00003 ;{
                      00004 ;FILE F1 = C:\USERS\LES\PDS\TESTS\TEST_18F25K20.BAS
                      00005 ;}
;[Variable Listing]
                      00007 ;MyByte,0028,DT_BYTE,1
                      00008 ;MyWord,0029,DT_WORD,2
                      00009 ;MyLong,002B,DT_LONG,3
                      00010 ;MyDword,002E,DT_DWORD,4
                      00011 ;MyFloat,0032,DT_MCHP_FLOAT,4
                      00012 ;MyTable8,0036,DT_BYTE,10
                      00013 ;MyTable16,0040,DT_WORD,20
                      00014 ;MyTable24,0054,DT_LONG,30
                      00015 ;MyTable32,0072,DT_DWORD,40
                      00016 ;MyTableFloat,009A,DT_MCHP_FLOAT,40
                      00017 ;wFSR0,0FE9,DT_WORD,2
;[End Listing]
                      00019 ;[TOTAL VARS] 194

These give the include file names and the variable names and the variable types and address' and array sizes etc... And are what the Proteus simulator actually reads for its simulation of a BASIC program.
Title: Re: Lost code extracting data from ASM
Post by: Gary Scott on Mar 25, 2023, 02:14 PM
Quote from: rick.curl on Feb 25, 2023, 12:54 PM
Quote from: TimB on Feb 24, 2023, 05:13 PMI'm investing now in a 3rd party backup to my G cloud account and going to see why backup in Positron IDE is not running.
Hi Tim- I'm using Insync (https://www.insynchq.com) to keep files and libraries backed up and sync'ed across multiple computers.  It's affordable and the support is very good.

-Rick

Sale at the moment:
QuoteSpring is here!🌸

Get 40% off on your Insync license until March 28, 2023!

How to get the discount:

    Head to our pricing page and click Buy Insync now, or click "BUY NOW" below.
    Enter the code SPRING40 where it says Click here to add a voucher.
    Enter your payment details. Make sure to type in the correct email you want the license for.
    Proceed to checkout.
Title: Re: Lost code extracting data from ASM
Post by: Yves on Mar 25, 2023, 03:54 PM
I use OneDrive but not in sync mode but always save my work in in desktop OneDrive folder after regulars code improvement.
Also save files in separate hard drive. Sound parano but I have learn my lesson in the past.

Yves 
Title: Re: Lost code extracting data from ASM
Post by: joesaliba on Mar 27, 2023, 05:42 AM
Quote from: Yves on Mar 25, 2023, 03:54 PMI use OneDrive but not in sync mode but always save my work in in desktop OneDrive folder after regulars code improvement.
Also save files in separate hard drive. Sound parano but I have learn my lesson in the past.

Yves

Same here.

Joe
Title: Re: Lost code extracting data from ASM
Post by: SeanG_65 on Mar 31, 2023, 02:22 AM
For backups in real time, try this;

https://www.tgrmn.com/web/viceversa.pro/?camp=goog_bac_p&t=backup&gclid=CjwKCAjw5pShBhB_EiwAvmnNV4kR8cQIefJTLxEgh01pfhSen3TtmT2P5yEa0YWfMhVVDg5bn_dQExoCHvoQAvD_BwE

When you write a file to one directory, it mirrors the contents of theat directory into another one, better if this is done on a cloud drive maybe?
Title: Re: Lost code extracting data from ASM
Post by: TimB on Mar 31, 2023, 07:01 AM


If you use a mirroring system then the changes made are just mirrored, 1 day later you just have 2 copies of the damaged file.

I now use EaseUs ToDo Backup and the backup in the IDE. The main backup sticks it in my Gdrive and is sequential so I have versions based on dates.



Title: Re: Lost code extracting data from ASM
Post by: top204 on Mar 31, 2023, 09:49 AM
Over the years, I have gotten in the habit of saving the project I am working on, then backing up any modified files in it at the end of each day. And every week I backup complete folders, zipped and with version numbers and dates as the file name. That means I still have the unmodified project files, and the modified files in case there was something incorrect with the code or circuit, and I have only a day's work to go back into and correct if a problem is found.

I have never trusted any cloud based novelty for important files, and never will, and I always use external hard drives. I have a few 2tb hard drives and back up to each of them. They are now only about £48 each, so I save up and buy one when I can, so my backups are also backed up. Better safe than sorry. :-)