明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1243|回复: 5

[源码] 用于试探函数参数工具

[复制链接]
发表于 2022-8-26 15:03:27 | 显示全部楼层 |阅读模式

大佬们研究怎么挖内部函数,我只能试怎么用函数所以做了这个东东出来,原理是买彩票一样大包围,我这里只0-4位参数测试,每测试一次都会打开一个“dwg”,只要不出错就会记录在“ff.lsp”里,每个函数大概会试4000+多次所以比较费事,如果有大佬能优化一下更好,测试好结果请到http://bbs.mjtd.com/thread-186120-1-1.html记录
  1. (defun lyt_type (item i_类型 / xx TN)
  2.   (if (= (type i_类型) 'list)
  3.     (foreach xx i_类型
  4.       (if TN
  5.         (setq TN T)
  6.         (setq TN (lyt_type item xx))
  7.       ) ;_ 结束if
  8.     ) ;_ 结束foreach
  9.     (setq TN (= (type item) i_类型))
  10.   ) ;_ 结束if
  11.   TN
  12. ) ;_

  13. ;(defun try-load-hide-fun (qqq lujing / dat file fo fun len)
  14. ;  (setq fun qqq)
  15. ;  (setq len (+ (strlen (car fun)) (strlen (car fun)) 28))
  16. ;  (setq file (strcat lujing "\\" (vl-princ-to-string (read (cadr FUN))) ".fas"))
  17. ;  (setq dat
  18. ;    (append
  19. ;      '(266 70 65 83 52 45 70 73 76 69 32 59 98 121 58 116 114 121 104 105 32 13 266 49 13 266 49 32 36 32 36 13 266)
  20. ;      (vl-string->list (itoa len))
  21. ;      '(32 52 32 36 20 1 1 1 256 219)
  22. ;      (vl-string->list (car fun))
  23. ;      '(256 256 214)
  24. ;      (vl-string->list (car fun))
  25. ;      '(256 256 1 67 256 256 2 256 266 266 131 1 256 160 134 256 256 1 22 36 59 98 121 58 180 243 186 163 )
  26. ;      '(59 213 251 186 207 98 121 195 217 211 234 227 229 186 219 81 81 49 49 50 54 57 49 53 57 53 56 44 188 164 187 238 186 175 202 253 98 121 32 116 114 121 104 105)
  27. ;    )
  28. ;  )
  29. ;  (setq fo (open file "w"))
  30. ;  (foreach x dat (write-char x fo))
  31. ;  (close fo)
  32. ;  (load file)
  33. ;  (if (eval(car (atoms-family 1 (list (car fun)))))
  34. ;    ()
  35. ;    (vl-file-delete file)
  36. ;  )
  37. ;)

  38. (defun try-load-hide-fun1 (qqq lujing / dat file fo fun len)
  39.   (setq fun qqq)
  40.   (setq len (+ (strlen fun) (strlen fun) 28))
  41.   (setq file lujing);(strcat lujing "\\" "temp" ".fas")
  42.   (setq dat
  43.     (append
  44.       '(266 70 65 83 52 45 70 73 76 69 32 59 98 121 58 116 114 121 104 105 32 13 266 49 13 266 49 32 36 32 36 13 266)
  45.       (vl-string->list (itoa len))
  46.       '(32 52 32 36 20 1 1 1 256 219)
  47.       (vl-string->list fun)
  48.       '(256 256 214)
  49.       (vl-string->list fun)
  50.       '(256 256 1 67 256 256 2 256 266 266 131 1 256 160 134 256 256 1 22 36 59 98 121 58 180 243 186 163 )
  51.       '(59 213 251 186 207 98 121 195 217 211 234 227 229 186 219 81 81 49 49 50 54 57 49 53 57 53 56 44 188 164 187 238 186 175 202 253 98 121 32 116 114 121 104 105)
  52.     )
  53.   )
  54.   (if (findfile file)
  55.     (vl-file-delete file)
  56.   )
  57.   (setq fo (open file "w"))
  58.   (foreach x dat (write-char x fo))
  59.   (close fo)
  60.   (load file)
  61.   (if (eval(car (atoms-family 1 (list fun))))
  62.     ()
  63.     (vl-file-delete file)
  64.   )
  65. )


  66. (defun JiHuoYinCangHanShu ()
  67.   (setq n 1)
  68.   (setq lujing (vl-filename-directory (getfiled "指定一个fas文件保存路径" "" "fas" 1)))
  69.   (while (setq aaa (eval (read (strcat "NeiBuJZ" (itoa n)))))
  70.     (if (car (atoms-family 1 (list (car aaa))))
  71.       ()
  72.       (try-load-hide-fun1 aaa lujing)
  73.     )
  74.     (setq n (1+ n))
  75.   )
  76. )


  77. ;(lyt_get_subr"d:/available - 副本.lsp")
  78. (defun lyt_get_subr (na_f / file ls_f lst_str str_1)
  79.   (if (setq  na_f(findfile na_f))
  80.     (progn
  81.       (setq file    (open na_f "R")
  82.         ;lst_str '()
  83.       ) ;_ 结束setq
  84.       (while (setq str_1 (read-line file))
  85.         (setq lst_str (cons str_1 lst_str))
  86.       ) ;_ 结束while
  87.       (CLOSE file)
  88.     )
  89.   )
  90.   (foreach ii lst_str
  91.     (if (and (/= "." ii)(/= "'" ii) (not(wcmatch ii "LYT_*,TFUN*,YQ*,VLA*,VLX*,VL-*,MAI*")) (lyt_type(eval(read ii)) '('SUBR 'UBR)))
  92.       (progn
  93.         (setq ls_f (cons ii ls_f))
  94.         ;(princ (strcat "\n" ii))
  95.       )
  96.     )
  97.   )
  98.   ls_f
  99. )



  100. (defun c:tt (/ doc dwg fc file file1 file2 ls1 ls12 ls2 ls3 str t_list2str write0)
  101.   (defun fc (na_f / file)
  102.     (setq file (open na_f "W"))
  103.     (CLOSE file)
  104.   )
  105.   (defun write0 (na_f str)
  106.     (progn
  107.       (if (lyt_type na_f 'STR)
  108.         (setq file (open na_f "W"))
  109.       ) ;_ 结束if
  110.       (WRITE-LINE str file)
  111.       (CLOSE file)
  112.     )
  113.   )
  114.   (defun T_list2str (lst / str)
  115.     (cond
  116.       ((lyt_type lst 'list)
  117.         (progn
  118.           (setq lst (mapcar
  119.                       '(lambda (x) (cond
  120.                                      ((lyt_type x 'list)(T_list2str x))
  121.                                      (T x)
  122.                                    )) lst))
  123.           (setq str(strcat "(list"(apply 'strcat (mapcar '(lambda (x) (strcat " " x))lst))")"))
  124.         ))
  125.       ((lyt_type lst 'list) (setq str lst))
  126.     )
  127.     str
  128.   )
  129.   (setq ls1 '("\"e:/1.dwg\"" "1" "(entlast)" "(vlax-ename->vla-object (entlast))"))
  130.   (setq ls2 (mapcar '(lambda (x) (T_list2str (list x)))ls1))
  131.   (setq ls12 (cons "" (append ls1 ls2)))
  132.   (setq ls3 (lyt_get_subr"d:/available - 副本.lsp"))
  133.   (setq file (getfiled "指定一个fas文件保存路径" "" "fas" 1))
  134.   (if (not(findfile file))
  135.     (fc file)
  136.   )
  137.   (setq file1 (strcat(vl-filename-directory file) "/" "fun.lsp"))
  138.   (if (not(findfile file1))
  139.     (fc file1)
  140.   )
  141.   (setq file2 (strcat(vl-filename-directory file) "/" "ff.lsp"))
  142.   (if (not(findfile file2))
  143.     (fc file2)
  144.   )
  145.   (setq dwg (getfiled "测试用dwg" "" "dwg" 0));;用于执行试探命令,至少要有一条线在里
  146.   (vl-load-all file)
  147.   (vl-load-all file1)
  148.   (foreach ii ls3
  149.     (try-load-hide-fun1 ii file)
  150.     (foreach iy (reverse(lyt_xx1 ii ls12 file2))
  151.       (setq str (strcat"(defun-q MYSTARTUP()(defun jo (str na_f / file l_st ln nn str_1)(setq file (open na_f \"R\"))(while (setq str_1 (read-line file))(setq l_st (cons str_1 l_st)))(CLOSE file)(setq file (open na_f \"W\"))(setq ln (reverse (cons str l_st)))(setq nn 0)(repeat (LENGTH ln)(WRITE-LINE (nth nn ln) file)(setq nn (1+ nn)))(CLOSE file))" iy ")(setq S::STARTUP (append S::STARTUP MYSTARTUP))"))
  152.       (write0 file1 str)
  153.       (setq doc(vla-Open (vla-get-documents (vlax-get-acad-object)) dwg))
  154.       (vla-close doc :vlax-false)
  155.     )
  156.   )
  157.   
  158. )

  159. ;;生成参数试探
  160. (defun lyt_xx1 (fun lst file / f1 f2 f3 gv ls1 st v1 v2 v3)
  161.   (defun st (f0 st1 va / fx)
  162.     ;;;;;;;;;;;(progn (setq fi (open na_f "W")))
  163.     (setq ls1 (cons(strcat (setq fx(strcat f0 " " st1)) ")" (if va (strcat "(jo \"" fun " " va")\"" "\"" (SS-STR_SUBST "\\\\" "\\" file) "\")") ""))ls1));(strcat"(princ " (strcat "\""fun " " va "\"") ")")
  164.     fx
  165.   )
  166.   ;;参数类型
  167.   (defun Gv (ii / vaR)
  168.     (if (= 'list (type (eval(read ii))))
  169.       (cond
  170.         ((= 'str (type(car(eval(read ii))))) (setq vaR "ls_str"))
  171.         ((= 'int (type(car(eval(read ii))))) (setq vaR "ls_int"))
  172.         ((= 'ename (type(car(eval (read ii))))) (setq vaR "ls_ent"))
  173.         ((= 'VLA-OBJECT (type(car (eval (read ii))))) (setq vaR "ls_obj"))
  174.       )
  175.       (setq vaR (vl-prin1-to-string (type (eval(read ii)))))  
  176.     )
  177.     vaR
  178.   )
  179.   (setq fun (strcat "(" fun))
  180.   (foreach ii lst
  181.     (if (/= "" ii)
  182.       (progn
  183.         (setq v1 (Gv ii))
  184.         ;(setq ls1 (cons(strcat (setq f1(strcat fun " " ii)) ")")ls1))
  185.         (setq f1 (st fun ii v1))
  186.         (foreach iy lst
  187.           (if (/= "" iy)
  188.             ;(setq ls1 (cons(strcat (setq f2(strcat f1 " " iy)) ")")ls1))
  189.             (progn
  190.               (setq v2 (strcat v1 " " (Gv iy)))(setq f2 (st f1 iy v2))
  191.               (foreach io lst
  192.                 (if (/= "" io)
  193.                   ;(setq ls1 (cons(strcat (setq f3(strcat f2 " " io)) ")")ls1))
  194.                   (progn (setq v3 (strcat v2 " " (Gv io)))(setq f3 (st f2 io v3))
  195.                     (foreach ir lst
  196.                       (if (/= "" ir)
  197.                         ;(setq ls1 (cons(strcat f3 " " ir ")")ls1))
  198.                         (st f3 ir (strcat v3 " " (Gv ir)))
  199.                       )
  200.                     )
  201.                   )
  202.                   ;(setq f3 f2)
  203.                 )
  204.               )
  205.             )
  206.             ;(setq f2 f1)
  207.           )
  208.         )
  209.       )
  210.       (setq ls1 (cons(strcat (setq f1 fun) ")")ls1))
  211.     )  
  212.   )
  213.   (list_delsame ls1)
  214. )

  215. ;(SS-STR_SUBST "\\\\" "\\" "C:\\Users\\Administrator\\Documents/ff.lsp")
  216. (DEFUN SS-STR_SUBST (NEWCHAR CURCHAR STR / RETURN N CHAR)
  217.   (setq RETURN "")
  218.   (setq N 1)
  219.   (REPEAT (STRLEN STR)
  220.     (setq CHAR (SUBSTR STR N 1))
  221.     (if (= CHAR CURCHAR)
  222.       (PROGN (setq RETURN (STRCAT RETURN NEWCHAR)))
  223.       (PROGN (setq RETURN (STRCAT RETURN CHAR)))
  224.     )
  225.     (setq N (1+ N))
  226.   )
  227.   RETURN
  228. )

  229. ;(jo "1" (getfiled "测试用dwg" "" "txt" 0))
  230. (defun jo (str na_f / file l_st ln nn str_1)
  231.   (setq file (open na_f "R"))
  232.   (while (setq str_1 (read-line file))
  233.     (setq l_st (cons str_1 l_st))
  234.   )
  235.   (CLOSE file)
  236.   (setq file (open na_f "W"))
  237.   (setq ln (reverse (cons str l_st)))
  238.   (setq nn 0)
  239.   (repeat (LENGTH ln)
  240.     (WRITE-LINE (nth nn ln) file)
  241.     (setq nn (1+ nn))
  242.   )
  243.   (CLOSE file)
  244. )

  245. (defun list_delsame (l)
  246.   (if l
  247.     (cons (car l) (list_delsame (vl-remove (car l) l)))
  248.   ) ;_ 结束if
  249. )


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 2明经币 +1 金钱 +5 收起 理由
tigcat + 5
jltx123456 + 1 赞一个!

查看全部评分

发表于 2022-8-27 08:16:18 | 显示全部楼层
感觉像挖矿啊

评分

参与人数 1明经币 +1 收起 理由
jltx123456 + 1 赞一个!

查看全部评分

回复 支持 1 反对 0

使用道具 举报

发表于 2022-8-26 15:56:15 | 显示全部楼层
这些内部函数中,有没有针对三维实体进行操作的函数呢?
 楼主| 发表于 2022-8-26 16:08:55 | 显示全部楼层
mokson 发表于 2022-8-26 15:56
这些内部函数中,有没有针对三维实体进行操作的函数呢?

要试出来才知道
发表于 2022-8-26 23:47:45 | 显示全部楼层
这个功能挺好的,能测出来怎么用函数
发表于 2022-8-27 08:25:54 | 显示全部楼层
不错,楼主牛。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-2-23 17:47 , Processed in 0.184489 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表