Author Topic: [original works] adds GOTO instruction to AutoLisp language  (Read 1277 times)

0 Members and 1 Guest are viewing this topic.

baitang36

  • Newt
  • Posts: 51
[original works] adds GOTO instruction to AutoLisp language
« on: March 21, 2020, 01:27:12 AM »
As we all know, lisp has no unconditional jump instructions, and programs can only be executed sequentially. Fas supports unconditional jump instructions, but normal compilers cannot generate them. We can do this indirectly. In the LSP source code to write a special string, compiled into the normal fas program after modification, so you can achieve the purpose of unconditional jump between functions.
See the source code:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:zhuce()
  2.   (setq zcm (getint "Please enter the registration code:"))
  3.   (if (= zcm 3637)(setq syz_goto 959461169)(princ "Registration code error!"));Jump if the registration code is correct
  4.   (princ)
  5. )
  6. (defun t1 ()(princ "Check registration code")
  7. (setq syz_loc1 959461170 ) ;Let the program jump here to start execution
  8. (princ "The registration code is correct. Welcome to use")
  9.   ;Insert the program you want to run here
  10.   (princ)
  11. )
Here (setq syz_goto 959461169) and (setq syz_loc1 959461170) are two tokens, the unconditional jump instruction of fas is 57h (decimal 87),
as long as we find the two tokens, calculate the size of the interval between the two tokens, we can modify the jump,
to achieve our purpose.959461169 in hexadecimal in fas is 31709,959461170 is 32709, which is easy to find.
Using winhex to see  tmp.fas is like this:
Offset           0  1  2  3  4  5  6  7            8  9  A  B  C  D  E  F
00000000   0D 0A 20 46 41 53 34 2D  46 49 4C 45 20 3B 20 44      FAS4-FILE ; D
00000010   6F 20 6E 6F 74 20 63 68  61 6E 67 65 20 69 74 21   o not change it!
00000020   0D 0A 31 31 31 0D 0A 31  32 20 24 14 00 00 00 00     111  12 $     
00000030   09 0B 00 35 01 0A 00 03  06 09 00 03 09 00 33 35      5          35
00000040   0E 00 00 35 02 08 00 03  67 0D 00 00 00 33 31 37      5    g    317
00000050   30 39 06 07 00 57 09 00  00 00 09 06 00 35 01 05   09   W       5 
00000060   00 03 0A 35 00 05 00 03  16 14 00 00 00 00 09 04      5           
00000070   00 35 01 05 00 03 0A 35  00 03 00 03 0A 33 32 37    5     5     327
00000080   30 39 06 02 00 09 01 00  35 01 05 00 03 0A 35 00   09      5     5
00000090   05 00 03 0A 35 00 05 00  03 16 24 0D 0A 32 38 30       5     $  280
The modified tmp.fas is as follows:
Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F
00000000   0D 0A 20 46 41 53 34 2D  46 49 4C 45 20 3B 20 44      FAS4-FILE ; D
00000010   6F 20 6E 6F 74 20 63 68  61 6E 67 65 20 69 74 21   o not change it!
00000020   0D 0A 31 31 31 0D 0A 31  32 20 24 14 00 00 00 00     111  12 $     
00000030   09 0B 00 35 01 0A 00 03  06 09 00 03 09 00 33 35      5          35
00000040   0E 00 00 35 02 08 00 03  67 0D 00 00 00 57 33 00      5    g    W3
00000050   00 00 20 20 20 57 09 00  00 00 09 06 00 35 01 05        W       5 
00000060   00 03 0A 35 00 05 00 03  16 14 00 00 00 00 09 04      5           
00000070   00 35 01 05 00 03 0A 35  00 03 00 03 0A 33 32 37    5     5     327
00000080   30 39 06 02 00 09 01 00  35 01 05 00 03 0A 35 00   09      5     5
00000090   05 00 03 0A 35 00 05 00  03 16 24 0D 0A 32 38 30       5     $  280
A modified program cannot be decomcompiled correctly because normal lisp does not have goto.
« Last Edit: April 02, 2020, 08:59:36 PM by baitang36 »

VovKa

  • Swamp Rat
  • Posts: 1210
  • Ukraine
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #1 on: March 21, 2020, 09:41:22 AM »
nice research, baitang36, as always

you often mention 'a popular decompiler', i'm not sure what exactly it is
but how will uncoditional jumping protect your code?
the 'hacker' will simply delete c:zhuce function from the decompiled lsp.

baitang36

  • Newt
  • Posts: 51
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #2 on: March 22, 2020, 10:56:30 PM »
Fas to LSP program is a commercial software written by my friend. It can be converted almost perfectly, and most of the LSP generated can be loaded and run normally. He sells the software for 200 dollars. You can provide an fas file and I will decompile it for you to see

Rod

  • Newt
  • Posts: 129
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #3 on: March 22, 2020, 11:50:19 PM »
Takes me back.
I remember GOTO and GOSUB from the first program I wrote as a kid on the apple IIe.
"All models are wrong, some models are useful" - George Box

MP

  • Seagull
  • Posts: 17577
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #4 on: March 23, 2020, 12:13:20 AM »
Coolio! I took my first programming course on a IIC. The instructor was aghast and extremely apologetic at course end as he couldnít assign the final grade I had achieved - his grades app would only accept values 0-99. It was then when I knew I was on to something, lol. :lol:
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

baitang36

  • Newt
  • Posts: 51
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #5 on: March 23, 2020, 01:04:00 AM »
Takes me back.
I remember GOTO and GOSUB from the first program I wrote as a kid on the apple IIe.
GOTO is more free, you can jump anywhere you want, there are no restrictions.

Did you learn the poems of Petofi Sandor?
<Freedom and love>

Life is precious,

Love costs more.

For freedom's sake,

Both can be thrown!

baitang36

  • Newt
  • Posts: 51
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #6 on: March 23, 2020, 01:09:48 AM »
Coolio! I took my first programming course on a IIC. The instructor was aghast and extremely apologetic at course end as he couldnít assign the final grade I had achieved - his grades app would only accept values 0-99. It was then when I knew I was on to something, lol. :lol:
The programming language I learned in school was Fortran77, and I learned it on an apple ii, which had a green screen and a series of English letters. I didn't understand English then

d2010

  • Newt
  • Posts: 42
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #7 on: March 23, 2020, 04:39:10 AM »
Coolio! I took my first programming course on a IIC. Th

Yesterday, I compile this source to (fas for Autocad)  and (des for BrisCad)
The programe Decompilator-exe can restore, reveal 100%autolisp-source?
Code: [Select]
       len=php_strlen(utmZone);
       // Changed from utmZone.Last as the Linq version is much slower than simply indexing
       // the last position in the string's array of characters
       if (len>1)
              {   isNorthHemisphere = substr(utmZone,len,1),
                  diflat = -0.00066286966871111111111111111111111111,
  diflon = -0.0003868060578,
                  utmZone = substr(utmZone,1,len-1);
  c_sa = 6378137.000000;
  c_sb = 6356752.314245;
  e2 = math_pow((math_Pow(c_sa, 2) - Math_Pow(c_sb, 2)), 0.5) / c_sb;
  e2cuadrada = Math_Pow(e2, 2);
  c = math_pow(c_sa, 2) / c_sb;
  x = utmX - 500000;
                  isNorthHemisphere =(isNorthHemisphere >"N")?T:nil;
  y = isNorthHemisphere ? utmY : utmY - 10000000;
                  zone=atoi(utmZone);
  s = ((zone * 6.0) - 183.0);
  lat = y / (6366197.724 * 0.9996); // Change c_sa for 6366197.724
  v = (c / math_pow(1 + (e2cuadrada * math_pow(cos(lat), 2)), 0.5)) * 0.9996;
  a = x / v;
  a1 = sin(2 * lat);
  a2 = a1 * math_pow((cos(lat)), 2);
  j2 = lat + (a1 / 2.0);
  j4 = ((3 * j2) + a2) / 4.0;
                  j6 = (5 * j4 + a2 * math_pow((cos(lat)), 2)) / 3.0; // saque a2 de multiplicar por el coseno de lat y elevar al cuadrado
  alfa = (3.0 / 4.0) * e2cuadrada;
  beta = (5.0 / 3.0) * math_pow(alfa, 2);
  gama = (35.0 / 27.0) * math_pow(alfa, 3);
  bm = 0.9996 * c * (lat - alfa * j2 + beta * j4 - gama * j6);
  b = (y - bm) / v;
                  epsi = ((e2cuadrada * math_pow(a, 2)) / 2.0) * math_pow((cos(lat)), 2);
                  eps = a * (1 - (epsi / 3.0));
  nab = (b * (1 - epsi)) + lat;
  senoheps = (math_exp(eps) - Math_Exp(-eps)) / 2.0;
  delt = atan(senoheps / (cos(nab)));
  tao = atan(cos(delt) * sin(nab) / cos(nab));
                  longitude = (delt / Math_PI) * 180 + s;
  latitude = (((lat + (1 + e2cuadrada * math_pow(cos(lat), 2) - (3.0 / 2.0) * e2cuadrada * sin(lat) * cos(lat) * (tao - lat)) * (tao - lat))) / Math_PI) * 180.0; // era incorrecto el calculo
  rr=strcat("\nLatitud: " ,rtos(latitude,2,12),"\tLongitud: " , rtos(longitude,2,12));

« Last Edit: March 23, 2020, 05:28:15 AM by d2010 »

snownut2

  • Swamp Rat
  • Posts: 968
  • Bricscad 20 Ultimate
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #8 on: March 23, 2020, 06:28:48 AM »
D2010 what about lsp as a bricscad compiled file?

MP

  • Seagull
  • Posts: 17577
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #9 on: March 23, 2020, 08:05:51 AM »
The programming language I learned in school was Fortran77, and I learned it on an apple ii, which had a green screen and a series of English letters. I didn't understand English then

There was a time when I wanted to learn Fortran but there was no use in my field (civil eng. design) at the time. I canít image learning a programming language whilst simultaneously translating back and forth to another spoken language; yeow. As for the green screens, remember them well. When I bought my first PC (Zenith Z150) I had to choose between green and amber. I went amber as it was unusual at the time and text appeared much crisper.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MP

  • Seagull
  • Posts: 17577
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #10 on: March 23, 2020, 08:48:04 AM »
Yesterday, I compile this source to (fas for Autocad)  and (des for BrisCad)
The programe Decompilator-exe can restore ...

Non trivial accomplishment but I have no interest.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

BIGAL

  • Bull Frog
  • Posts: 425
  • 30 + years of using Autocad
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #11 on: March 23, 2020, 09:06:29 PM »
Why do you say there is no GOTO you can use defun statements, I wrote a bubble sort that required dual defuns for the testing part and looping through the data set. Took a BASIC version and rewrote in lisp.

Ps here is my GOTO Autocad command.

A man who never made a mistake never made anything

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9380
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #12 on: March 23, 2020, 09:49:19 PM »
Why do you say there is no GOTO you can use defun statements, I wrote a bubble sort that required dual defuns for the testing part and looping through the data set. Took a BASIC version and rewrote in lisp.

Ps here is my GOTO Autocad command.

GOTO is a very old programming concept and/or "thing". GOTO is for compiled languages and it is translated by the compiler as a "statement to jump to a specific memory address".  ...stack/heap discussions abound.

NOTE: you can also use GOTOs in windows command scripts too for a good visual aid of how they were used (made code messy and yucky).


The example used in the first post is quite interesting but I agree with VovKa.

TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

baitang36

  • Newt
  • Posts: 51
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #13 on: March 23, 2020, 10:06:54 PM »
Coolio! I took my first programming course on a IIC. Th

Yesterday, I compile this source to (fas for Autocad)  and (des for BrisCad)
The programe Decompilator-exe can restore, reveal 100%autolisp-source?
Code: [Select]
       len=php_strlen(utmZone);
       // Changed from utmZone.Last as the Linq version is much slower than simply indexing
       // the last position in the string's array of characters
       if (len>1)
              {   isNorthHemisphere = substr(utmZone,len,1),
                  diflat = -0.00066286966871111111111111111111111111,
  diflon = -0.0003868060578,
                  utmZone = substr(utmZone,1,len-1);
  c_sa = 6378137.000000;
  c_sb = 6356752.314245;
  e2 = math_pow((math_Pow(c_sa, 2) - Math_Pow(c_sb, 2)), 0.5) / c_sb;
  e2cuadrada = Math_Pow(e2, 2);
  c = math_pow(c_sa, 2) / c_sb;
  x = utmX - 500000;
                  isNorthHemisphere =(isNorthHemisphere >"N")?T:nil;
  y = isNorthHemisphere ? utmY : utmY - 10000000;
                  zone=atoi(utmZone);
  s = ((zone * 6.0) - 183.0);
  lat = y / (6366197.724 * 0.9996); // Change c_sa for 6366197.724
  v = (c / math_pow(1 + (e2cuadrada * math_pow(cos(lat), 2)), 0.5)) * 0.9996;
  a = x / v;
  a1 = sin(2 * lat);
  a2 = a1 * math_pow((cos(lat)), 2);
  j2 = lat + (a1 / 2.0);
  j4 = ((3 * j2) + a2) / 4.0;
                  j6 = (5 * j4 + a2 * math_pow((cos(lat)), 2)) / 3.0; // saque a2 de multiplicar por el coseno de lat y elevar al cuadrado
  alfa = (3.0 / 4.0) * e2cuadrada;
  beta = (5.0 / 3.0) * math_pow(alfa, 2);
  gama = (35.0 / 27.0) * math_pow(alfa, 3);
  bm = 0.9996 * c * (lat - alfa * j2 + beta * j4 - gama * j6);
  b = (y - bm) / v;
                  epsi = ((e2cuadrada * math_pow(a, 2)) / 2.0) * math_pow((cos(lat)), 2);
                  eps = a * (1 - (epsi / 3.0));
  nab = (b * (1 - epsi)) + lat;
  senoheps = (math_exp(eps) - Math_Exp(-eps)) / 2.0;
  delt = atan(senoheps / (cos(nab)));
  tao = atan(cos(delt) * sin(nab) / cos(nab));
                  longitude = (delt / Math_PI) * 180 + s;
  latitude = (((lat + (1 + e2cuadrada * math_pow(cos(lat), 2) - (3.0 / 2.0) * e2cuadrada * sin(lat) * cos(lat) * (tao - lat)) * (tao - lat))) / Math_PI) * 180.0; // era incorrecto el calculo
  rr=strcat("\nLatitud: " ,rtos(latitude,2,12),"\tLongitud: " , rtos(longitude,2,12));

What language is this?

baitang36

  • Newt
  • Posts: 51
Re: [original works] adds GOTO instruction to AutoLisp language
« Reply #14 on: March 23, 2020, 10:18:33 PM »
Why do you say there is no GOTO you can use defun statements, I wrote a bubble sort that required dual defuns for the testing part and looping through the data set. Took a BASIC version and rewrote in lisp.

Ps here is my GOTO Autocad command.

GOTO is a very old programming concept and/or "thing". GOTO is for compiled languages and it is translated by the compiler as a "statement to jump to a specific memory address".  ...stack/heap discussions abound.

NOTE: you can also use GOTOs in windows command scripts too for a good visual aid of how they were used (made code messy and yucky).


The example used in the first post is quite interesting but I agree with VovKa.
made code messy and yucky.That's the purpose
Standard fas is equivalent to source code
You can send me an Fas, I give you its LSP source code