;;by tryhi http://bbs.mjtd.com/forum.php?mod=viewthread&tid=182474&highlight=%CF%C2%D4%D8
(vl-Load-COM)
(defun try-file-ReadBinary (FileName / node size str stream xmldom)
(setq xmldom (vlax-create-object "Microsoft.XMLDOM"))
(setq node (vlax-invoke-method xmldom 'CreateElement "binary"))
(vlax-put-Property node 'DataType "bin.hex")
(setq stream (vlax-create-object "ADODB.Stream"))
(vlax-put-Property stream 'type 1)
(Vlax-Invoke stream 'open)
(vlax-invoke-method
stream
'LoadFromFile
FileName
)
(setq size(vlax-get-Property stream 'size))
(vlax-put-Property node 'NodeTypedValue (Vlax-Invoke-Method stream 'Read size))
(Vlax-Invoke-Method stream 'close)
(setq str (vlax-get-Property node 'text))
(vlax-release-object xmldom)
str
)
(defun try-file-WriteBinary (file str / node stream xmldom)
(setq xmldom (vlax-create-object "Microsoft.XMLDOM"))
(setq node (vlax-invoke-method xmldom 'CreateElement "binary"))
(vlax-put-Property node 'DataType "bin.hex")
(vlax-put-Property node 'Text str)
(setq stream (vlax-create-object "ADODB.Stream"))
(vlax-put-Property stream 'type 1)
(Vlax-Invoke stream 'open)
(vlax-invoke-method stream 'write
(vlax-get-Property node 'NodeTypedValue)
)
(vlax-invoke-method stream 'saveToFile file 2)
(Vlax-Invoke-Method stream 'close)
(vlax-release-object xmldom)
(vlax-release-object stream)
)
(defun c:tt (/ file h16 h16-2 newfile)
(setq file(getfiled "选择一个文件" "" "*" 0))
(or file (exit))
(setq
h16(try-file-ReadBinary file)
h16-2(substr h16 5)
)
(setq newfile (strcat(vl-filename-directory file)"\\"(vl-filename-base file)"_new"(vl-filename-extension file)))
(try-file-WriteBinary newfile h16-2)
(princ(strcat"\n处理完成,生成新文件"newfile))(princ)
)