5 Cent tip for today [ DELINK.LSP ]

Featuring the Dragonfly web framework
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

5 Cent tip for today [ DELINK.LSP ]

Post by newdep »

;;
;; Delink extracts the newlisp code from the linked newlisp binary file.
;;
;; Version 1.0
;; Date: 03/16/04
;;
;; How it works:
;; =============
;; Opens the linked newlisp binary file.
;; Seeks for a pointer "@@@@@@@@" (originaly!)
;; Cuts the NewlispSourceCode off from the linked binary.
;; Will overwrite/create the sourcecode in "mySource.lsp"
;;
;; How to use on CYGWIN WIN32:
;; ===========================
;; example: to delink the source from program.exe to mySource.lsp
;;
;; (delink "program.exe" "mySource.lsp")
;;
;; then i.e: c:\>edit mySource.lsp
;;
;; On Linux/freeBSD implementations:
;; =================================
;; (delink "program" "mySource.lsp")
;;
;; the mySource.lsp is saved in the current directory.
;; No write permission check is done and the mySource.lsp
;; will be overwritten when it already exists.
;;
;; Enjoy,
;; Norman.


(define (delink orgExe LispSourceName )

;; open linked newlisp file
(set 'infile (open orgExe "r"))

;; start seeking for the light..
(seek infile (+ (search infile "reserved") 10))
(read-buffer infile 'buff 4)
(set 'bin (unpack "ld" buff))
(read-buffer infile 'buff 4)
(set 'code (unpack "ld" buff))
(seek infile (first bin))
(read-buffer infile 'buff (first code))
(set 'buff (encrypt buff (string (first code))))

;; create a new and write-to LispSourcefile
(set 'outfile (open LispSourceName "w"))
(write-buffer outfile 'buff (length buff))
(close infile)
(close outfile))
-- (define? (Cornflakes))

Locked