home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / LordLucifer / win32asm / files / win32asm.exe / Win32ASM / ASMInc / UnicAnsi.equ < prev    next >
Encoding:
Text File  |  1997-09-02  |  12.5 KB  |  375 lines

  1. ;   ANSI / UniCode strings handling.
  2. ;  19.JUN.96 : Philippe Auphelle.
  3. ;        LARGE Portions from 03-14-1996 Sven B. Schreiber sbs@orgon.com
  4.  
  5. ; $Id: UnicAnsi.equ 1.1 1997/09/02 09:50:53 Philippe Exp $
  6.  
  7. ; $Log: /Win32Equ/UnicAnsi.equ $
  8. ; 1     18/09/97 14:24 Philippe
  9. ; Initial checkin into SourceSafe.
  10. ; Revision 1.1  1997/09/02 09:50:53  Philippe
  11. ; Initial revision
  12. ;
  13.  
  14.  
  15. ;==============================================================================
  16. ;
  17. ;               ANSI / UniCode strings.
  18. ;
  19. ; This include file should be included ahead of any other one.
  20. ; It defines various equates, textequates and macros used to handle
  21. ; Unicode or ANSI string encoding definitions.
  22. ; This include assumes the UniCode equate is clear (0) or set (1) according
  23. ; to the coding system to be used.
  24. ; But of course, Win95 doesn't support UniCode...
  25. ; So if nothing's defined, we default to ASCII. Not the best, but works
  26. ; for both Win95 and NT.
  27. ;==============================================================================
  28.  
  29.  
  30.                 IFNDEF UniCode
  31. UniCode         = 0                     ;Default to ASCII (always works)
  32.                 ENDIF
  33.  
  34. ; Takes care of Win32syscalls that are encoding dependant:
  35. ; These have a generic name that, by a typical Microsoft kludge, is
  36. ; transformed at compile time in the real target name.
  37. ; The real target name is composed by postfixing the generic name by an
  38. ; "A" (ANSI/ASCII) or "W" (Wide, for Unicode).
  39. ; The great thing with the wonderful MS approach is that you have to handle
  40. ; two different sets of object files when building libraries for both
  41. ; Unicode and ANSI. How nice... This, IMHO, should have been handled at
  42. ; link time and/or runtime. Anyway.
  43. ; The following macro simply generates a text equate that replaces the
  44. ; generic procedure name by its encoded (postfixed) form.
  45. ; Any procedure that's encoding dependant should have a UnicAnsiExtern macro
  46. ; coded ahead of its PROTO definition to resolve its name to something defined
  47. ; in the Microsoft import libraries.
  48. ; There are other implications to the use of Unicode, as the Unicode uses
  49. ; double bytes. For instance, the CHAR typedef is assigned to either a BYTE
  50. ; (for ANSI) or a WORD (for UniCode).
  51. ; An 80 character string can thus be up to 160 bytes long when coded in
  52. ; UniCode.
  53. ; I haven't look at this problem yet, but I expect Sven's macros below to
  54. ; solve the problem...
  55.  
  56.  
  57. UnicAnsiExtern  MACRO Procedure
  58.                 LOCAL Procedure
  59.                   IF UniCode EQ 0
  60. Procedure         TEXTEQU @CatStr(Procedure,A)
  61.                   ELSE
  62. Procedure         TEXTEQU @CatStr(Procedure,W)
  63.                   ENDIF
  64.                 ENDM
  65.  
  66.  
  67.  
  68. ; Alternate to Sven's STRING macro (see below) for generating ANSI or
  69. ; Unicode strings:
  70.  
  71. ; Supported convenience Escape Sequences:
  72.  
  73. ; \n
  74. ; \t
  75. ; \0
  76. ; \1
  77.  
  78. ; Note: The convenience escape letters are case sensitive.
  79.  
  80. ; MASM macro forcing character ("!") only required for "!", ">" and "<".
  81. ; Other characters OK, including "'", '"', etc...
  82.  
  83.  
  84. $String         MACRO Parm1:REQ
  85. ;; For some undetermined reason, declaring StrChar as LOCAL to the macro
  86. ;; generates errors. MASM macro language truly STINKS.
  87.                 LOCAL CharType, ParmSize, _ESC_, Start, NumChar
  88.  
  89.                 IF UniCode
  90. CharType        TEXTEQU <WORD>
  91.                 ELSE
  92. CharType        TEXTEQU <BYTE>
  93.                 ENDIF
  94.  
  95. ParmSize        SIZESTR <Parm1>
  96.         _ESC_   = 0                             ;;Not in escape seq.
  97.         Start   = 2                             ;;Skip leading "'",
  98.                   REPEAT ParmSize-2             ;;For each char in parm but "'"
  99. StrChar           SUBSTR <Parm1>,Start,1        ;;extract current char as TEXTEQU,
  100.                     IFIDNI StrChar,<">          ;;Because we use " already
  101.                     NumChar = '"'               ;;in the %NumChar assign. below.
  102.                     ELSE
  103. %NumChar            = "&StrChar"                ;;Convert it to numeric value,
  104.                     ENDIF
  105.  
  106.                     IF _ESC_                    ;;Second byte of Escape sequence
  107. _ESC_               = 0
  108.                       if     NumChar eq 06Eh    ;;"n"
  109.                         CharType 0Dh, 0Ah
  110.                       elseif NumChar eq 074h    ;;"t"
  111.                         CharType 09h
  112.                       elseif NumChar eq 030h    ;;"0"
  113.                         CharType 0
  114.                       elseif NumChar eq 031h    ;;"1"
  115.                         CharType 1
  116.                       else                      ;; None of these,
  117.                         CharType "\", NumChar   ;; purge out \<whatever>.
  118.                       endif                     ;;if NumChar eq ...
  119.  
  120.                     else                        ;; Not in Escape sequence.
  121.  
  122.                       if NumChar eq 05Ch        ;;"\" : Esc character?
  123. _ESC_                   = 1
  124.                       else
  125. _ESC_                   = 0
  126.                         CharType NumChar
  127.                       endif                     ;; (if "\").
  128.                     endif                       ;;(if _ESC_)
  129.  
  130.                   Start = Start + 1             ;;Bump string index.
  131.                   ENDM
  132.                 ENDM
  133.  
  134.  
  135. ; The rest are original Walk32 macros.
  136.  
  137.  
  138. ASTRING         macro _STRING_
  139. _ESC_           = 0
  140.  
  141.                   forc _CHAR_,<_STRING_>
  142.  
  143.                     if _ESC_
  144. _ESC_               = 0
  145. ;
  146.                       if "&_CHAR_" eq "/"
  147.                         BYTE "/"
  148.                       elseif "&_CHAR_" eq "n"
  149.                         BYTE 0Dh, 0Ah
  150.                       elseif "&_CHAR_" eq "t"
  151.                         BYTE 09h
  152.                       elseif "&_CHAR_" eq ":"
  153.                         BYTE "!"
  154.                       elseif "&_CHAR_" eq "-"
  155.                         BYTE "'"
  156.                       elseif "&_CHAR_" eq "="
  157.                         BYTE '"'
  158.                       elseif "&_CHAR_" eq "|"
  159.                         BYTE "\"
  160.                       elseif "&_CHAR_" eq "#"
  161.                         BYTE "%"
  162.                       elseif "&_CHAR_" eq "+"
  163.                         BYTE "&"
  164.                       elseif "&_CHAR_" eq "("
  165.                         BYTE "<"
  166.                       elseif "&_CHAR_" eq ")"
  167.                         BYTE ">"
  168.                       elseif "&_CHAR_" eq "0"
  169.                         BYTE 0
  170.                       elseif "&_CHAR_" eq "1"
  171.                         BYTE 1
  172.                       else
  173.                         BYTE "/", "&_CHAR_"
  174.                       endif             ;if "&_CHAR_" eq ...
  175.  
  176.                     else
  177.                                         ;if _ESC_
  178.                       if "&_CHAR_" eq "/"
  179. _ESC_                   = 1
  180.                       else
  181. _ESC_                   = 0
  182.                         BYTE "&_CHAR_"
  183.                       endif
  184.                     endif               ;if _ESC_
  185.                   endm                  ;forc _CHAR_,<_STRING_>
  186.                 endm                    ;ASTRING macro.
  187.  
  188. ;------------------------------------------------------------------------------
  189.  
  190. WSTRING         macro          _STRING_
  191. _ESC_           = 0
  192.  
  193.                   forc _CHAR_,<_STRING_>
  194.  
  195.                     if _ESC_
  196. _ESC_               = 0
  197.  
  198.                       if "&_CHAR_" eq "/"
  199.                         WORD "/"
  200.                       elseif "&_CHAR_" eq "n"
  201.                         WORD 0Dh, 0Ah
  202.                       elseif "&_CHAR_" eq "t"
  203.                         WORD 09h
  204.                       elseif "&_CHAR_" eq ":"
  205.                         WORD "!"
  206.                       elseif "&_CHAR_" eq "-"
  207.                         WORD "'"
  208.                       elseif "&_CHAR_" eq "="
  209.                         WORD '"'
  210.                       elseif "&_CHAR_" eq "|"
  211.                         WORD "\"
  212.                       elseif "&_CHAR_" eq "#"
  213.                         WORD "%"
  214.                       elseif "&_CHAR_" eq "+"
  215.                         WORD "&"
  216.                       elseif "&_CHAR_" eq "("
  217.                         WORD "<"
  218.                       elseif "&_CHAR_" eq ")"
  219.                         WORD ">"
  220.                       elseif "&_CHAR_" eq "0"
  221.                         WORD 0
  222.                       elseif "&_CHAR_" eq "1"
  223.                         WORD 1
  224.                       else
  225.                         WORD "/", "&_CHAR_"
  226.                       endif             ;if "&_CHAR_"
  227.  
  228.                     else                ;if _ESC_
  229.  
  230.                       if "&_CHAR_" eq "/"
  231. _ESC_                   = 1
  232.                       else
  233. _ESC_                   = 0
  234.                         WORD "&_CHAR_"
  235.                       endif
  236.                     endif               ;if _ESC_
  237.                   endm                  ;forc _CHAR_,<_STRING_>
  238.                 endm
  239.  
  240. ;------------------------------------------------------------------------------
  241.  
  242.  
  243. WCHAR           TYPEDEF WORD            ;unicode character
  244. ACHAR           TYPEDEF BYTE            ;ansi character
  245.  
  246.                   IF UniCode
  247. CHAR              TYPEDEF WCHAR
  248.                   ELSE
  249. CHAR              TYPEDEF ACHAR
  250.                   ENDIF
  251.  
  252. ;------------------------------------------------------------------------------
  253.  
  254.  
  255. STRING          macro _STRING_:REQ
  256.                   if UniCode
  257.                   WSTRING <_STRING_>
  258.                   else
  259.                   ASTRING <_STRING_>
  260.                   endif
  261.                 endm
  262.  
  263.  
  264.  
  265. ;------------------------------------------------------------------------------
  266.  
  267. lodczx          macro _from
  268.                   if UniCode
  269.                     movzx eax,word ptr _from
  270.                   else
  271.                     movzx eax,byte ptr _from
  272.                   endif
  273.                 endm
  274.  
  275. ;------------------------------------------------------------------------------
  276.  
  277. lodc            macro _from
  278.                   if UniCode
  279.                     mov ax,_from
  280.                   else
  281.                     mov al,_from
  282.                   endif
  283.                 endm
  284.  
  285. ;------------------------------------------------------------------------------
  286.  
  287. stoc            macro _to
  288.                   if UniCode
  289.                     mov _to,ax
  290.                   else
  291.                     mov _to,al
  292.                   endif
  293.                 endm
  294.  
  295. ;------------------------------------------------------------------------------
  296.  
  297. xchc            macro _with
  298.                   if UniCode
  299.                     xchg ax,_with
  300.                   else
  301.                     xchg al,_with
  302.                   endif
  303.                 endm
  304.  
  305. ;------------------------------------------------------------------------------
  306.  
  307. cmpc            macro _against
  308.                   if UniCode
  309.                     cmp ax,_against
  310.                   else
  311.                     cmp al,_against
  312.                   endif
  313.                 endm
  314.  
  315. ;------------------------------------------------------------------------------
  316.  
  317. subc            macro _what
  318.                   if UniCode
  319.                     sub ax,_what
  320.                   else
  321.                     sub al,_what
  322.                   endif
  323.                 endm
  324.  
  325. ;------------------------------------------------------------------------------
  326.  
  327. addc            macro _what
  328.                   if UniCode
  329.                     add ax,_what
  330.                   else
  331.                     add al,_what
  332.                   endif
  333.                 endm
  334.  
  335. ;------------------------------------------------------------------------------
  336.  
  337. incc            macro _what
  338.                   if UniCode
  339.                     inc _what
  340.                   inc _what
  341.                     else
  342.                   inc _what
  343.                   endif
  344.                 endm
  345.  
  346. ;------------------------------------------------------------------------------
  347.  
  348. decc            macro _what
  349.                   if UniCode
  350.                     dec _what
  351.                     dec _what
  352.                   else
  353.                     dec _what
  354.                   endif
  355.                 endm
  356.  
  357. ;------------------------------------------------------------------------------
  358.  
  359. cc2bc           macro _location
  360.                   if UniCode
  361.                     shl _location,1
  362.                   endif
  363.                 endm
  364.  
  365. ;------------------------------------------------------------------------------
  366.  
  367. bc2cc           macro _location
  368.                   if UniCode
  369.                     shr _location,1
  370.                   endif
  371.                 endm
  372.  
  373. ;------------------------------------------------------------------------------
  374.