Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; --------------------------------------------------------------------------
  2. ; FILE: TMsgTable.Asm
  3. ; DATE: September 28, 2008
  4. ; --------------------------------------------------------------------------
  5.  
  6. ; --------------------------------------------------------------------------
  7. align PROC_ALIGN
  8. TMsgTable_CountItems:
  9.     mov     esi, [glb_pRawMsgBuffer]
  10.     mcZeroBits eax
  11.     mcZeroBits ecx
  12.     mcZeroBits edx
  13.  
  14. .load_char:
  15.     lodsb
  16.     mcOnRegZero eax, .done
  17.  
  18.     cmp     al, 0Dh
  19.     sete    dl
  20.     add     ecx, edx
  21.     jmp     .load_char
  22.  
  23. .done:
  24.     mov     [glb_NumMsgItems], ecx
  25.     ret
  26.  
  27. ; --------------------------------------------------------------------------
  28. align PROC_ALIGN
  29. TMsgTable_Parse:
  30.     mov     ecx, [glb_NumMsgItems]
  31.     shl     ecx, 2
  32.     invoke  HeapAlloc, [glb_Allocator], HEAP_NO_SERIALIZE, ecx
  33.     mov     [glb_pMsgItems], eax
  34.  
  35.     mov     edi, eax
  36.     mov     esi, [glb_pRawMsgBuffer]
  37.     mcZeroBits eax
  38.     mov     [glb_NumMsgItems], eax
  39.  
  40. .load_char:
  41.     lodsb
  42.     mcOnRegZero eax, .done
  43.  
  44.     mcOnRegEqu al, '{', .begin_item
  45.     mcOnRegEqu al, '}', .end_item
  46.     jmp     .load_char
  47.  
  48. .begin_item:
  49.     mov     [edi], esi
  50.     add     edi, 4
  51.     inc     [glb_NumMsgItems]
  52.     jmp     .load_char
  53.  
  54. .end_item:
  55.     lea     edx, [esi - 1]
  56.     mov     byte [edx], 0
  57.     jmp     .load_char
  58.  
  59. .done:
  60.     ret
  61.  
  62. ; --------------------------------------------------------------------------
  63. ; Input:
  64. ;   EDI = buffer address
  65. ;   ECX = buffer size in bytes
  66. ; --------------------------------------------------------------------------
  67. align PROC_ALIGN
  68. TMsgTable_Decrypt:
  69.     pushad
  70.  
  71. .reset_key:
  72.     mov     esi, TMsgTable_GetItem
  73.     mcLoad8bitsToReg32 edx, 27
  74.  
  75. .next:
  76.     lodsb
  77.     xor     [edi], al
  78.     inc     edi
  79.  
  80.     dec     ecx
  81.     jz      .done
  82.  
  83.     dec     edx
  84.     jz      .reset_key
  85.     jmp     .next
  86.  
  87. .done:
  88.     popad
  89.     ret
  90.  
  91. ; --------------------------------------------------------------------------
  92. virtual at 0
  93. loc4:
  94.     .hFile HFILE ?
  95.     .dwSize UINT32 ?
  96.     .dwLoaded UINT32 ?
  97.     .size = $
  98. end virtual
  99. ; --------------------------------------------------------------------------
  100. align PROC_ALIGN
  101. TMsgTable_Load:
  102.     mcBeginLocals loc4.size
  103.  
  104.     invoke  CreateFile, str_MsgFileName, GENERIC_READ, \
  105.             0, 0, OPEN_EXISTING, FILE_FLAG_SEQ_SCAN, 0
  106.  
  107.     mcStoreLocal loc4.hFile, eax
  108.     cmp     eax, -1
  109.     je      .done
  110.  
  111.     mov     ebx, esp
  112.     invoke  GetFileSize, [ebx + loc4.hFile], 0
  113.     mcStoreLocal loc4.dwSize, eax
  114.     mcOnRegZero eax, .close
  115.  
  116.     inc     eax
  117.     invoke  HeapAlloc, [glb_Allocator], HEAP_NO_SERIALIZE, eax
  118.     mov     [glb_pRawMsgBuffer], eax
  119.     mcOnRegZero eax, .close
  120.  
  121.     mcLoadMemberRef edi, loc4.dwLoaded
  122.  
  123.     invoke  ReadFile, [ebx + loc4.hFile], eax, \
  124.             [ebx + loc4.dwSize], edi, 0
  125.  
  126.     mov     edi, [glb_pRawMsgBuffer]
  127.     mcLoadLocal ecx, loc4.dwLoaded
  128.     mcZeroBits eax
  129.     mov     [edi + ecx], al
  130.  
  131.     call    TMsgTable_Decrypt
  132.     call    TMsgTable_CountItems
  133.     call    TMsgTable_Parse
  134.  
  135. .close:
  136.     mov     ebx, esp
  137.     invoke  CloseHandle, [ebx + loc4.hFile]
  138.  
  139. .done:
  140.     mcEndLocals loc4.size
  141.     ret
  142.  
  143. ; --------------------------------------------------------------------------
  144. ; Input:
  145. ;   ECX = item index (1-based)
  146. ; Output:
  147. ;   ESI = points to ANSI text at specified index or empty string
  148. ; --------------------------------------------------------------------------
  149. align PROC_ALIGN
  150. TMsgTable_GetItem:
  151.     cmp     ecx, [glb_NumMsgItems]
  152.     ja      .empty
  153.  
  154.     dec     ecx
  155.     push    edx
  156.     mov     edx, [glb_pMsgItems]
  157.     mov     esi, [edx + ecx*4]
  158.     pop     edx
  159.     ret
  160.  
  161. .empty:
  162.     mov     esi, str_CharSizeText + 4
  163.     ret
  164.  
  165. ; --------------------------------------------------------------------------
  166. ; Input:
  167. ;   ECX = item index (1-based)
  168. ; Output:
  169. ;   EAX = string length
  170. ; --------------------------------------------------------------------------
  171. align PROC_ALIGN
  172. TMsgTable_GetLength:
  173.     push    esi ecx
  174.     call    TMsgTable_GetItem
  175.  
  176.     mcZeroBits eax
  177.     mcZeroBits ecx
  178.  
  179. .next_char:
  180.     lodsb
  181.     mcOnRegZero eax, .done
  182.  
  183.     inc     ecx
  184.     jmp     .next_char
  185.  
  186. .done:
  187.     mov     eax, ecx
  188.     pop     ecx esi
  189.     ret
  190.  
  191. ; --- EOF ---
  192.