QuickBeのCソース化1

QuickBeの逆アセンブルコードは非常にシンプルで美しい。
特にWinMainより前のスタートアップコードはVC++BCCでのコンパイルでは得られないものになっている。
これらコンパイラが提供するオブジェクトファイルを結合すると、それだけで大きなファイルになってしまうようなので、この部分はそのままいただき
オブジェクトファイルとしてアセンブルして、メインのコードに結合することにする。

00401000 >/$  sub     esp,44
00401003  |.  push    esi
00401004  |.  call    [ds:<&KERNEL32.GetCommandLineA>]       ; [GetCommandLineA
0040100A  |.  mov     esi,eax
0040100C  |.  mov     al,[ds:eax]
0040100E  |.  cmp     al,22
00401010  |.  jnz     short 0040102B
00401012  |.  inc     esi
00401013  |.  cmp     [byte ds:esi],0
00401016  |.  je      short 00401023
00401018  |>  /cmp     [byte ds:esi],22
0040101B  |.  |je      short 00401028
0040101D  |.  |inc     esi
0040101E  |.  |cmp     [byte ds:esi],0
00401021  |.^ \jnz     short 00401018
00401023  |>  cmp     [byte ds:esi],22
00401026  |.  jnz     short 00401035
00401028  |>  inc     esi
00401029  |.  jmp     short 00401035
0040102B  |>  cmp     al,20
0040102D  |.  jle     short 00401035
0040102F  |>  /inc     esi
00401030  |.  |cmp     [byte ds:esi],20
00401033  |.^ \jg      short 0040102F
00401035  |>  cmp     [byte ds:esi],0
00401038  |.  je      short 00401045
0040103A  |>  /cmp     [byte ds:esi],20
0040103D  |.  |jg      short 00401045
0040103F  |.  |inc     esi
00401040  |.  |cmp     [byte ds:esi],0
00401043  |.^ \jnz     short 0040103A
00401045  |>  mov     [dword ss:esp+30],0
0040104D  |.  lea     eax,[ss:esp+4]
00401051  |.  push    eax                                    ; /pStartupinfo
00401052  |.  call    [ds:<&KERNEL32.GetStartupInfoA>]       ; \GetStartupInfoA
00401058  |.  test    [byte ss:esp+30],1
0040105D  |.  mov     eax,0A
00401062  |.  je      short 0040106D
00401064  |.  mov     eax,[ss:esp+34]
00401068  |.  and     eax,0FFFF
0040106D  |>  push    eax                                    ; /ShowState
0040106E  |.  push    esi                                    ; |CmdLine
0040106F  |.  push    0                                      ; |hPrevInstance = NULL
00401071  |.  push    0                                      ; |/pModule = NULL
00401073  |.  call    [ds:<&KERNEL32.GetModuleHandleA>]      ; |\GetModuleHandleA
00401079  |.  push    eax                                    ; |hCurrInstance
0040107A  |.  call    00401090                               ; \Assumed WinMain
0040107F  |.  push    eax                                    ; /ExitCode
00401080  \.  call    [ds:<&KERNEL32.ExitProcess>]           ; \ExitProcess
00401086   .  pop     esi
00401087   .  add     esp,44
0040108A   .  retn

MASM

.386
.model flat,stdcall
option casemap:none

GetModuleHandleA PROTO :DWORD
GetCommandLineA  PROTO
GetStartupInfoA  PROTO :DWORD
ExitProcess      PROTO :DWORD
WinMain          PROTO :DWORD,:DWORD,:DWORD,:DWORD

.CODE
start:
  sub     esp,44h
  push    esi
  call    GetCommandLineA
  mov     esi,eax
  mov     al,[eax]
  cmp     al,022h
  jnz     @label1
  inc     esi
  cmp     byte ptr [esi],0
  je      @label2
@label4:
  cmp     byte ptr [esi],022h
  je      @label3
  inc     esi
  cmp     byte ptr [esi],0
  jnz     @label4
@label2:
  cmp     byte ptr [esi],022h
  jnz     @label5
@label3:
  inc     esi
  jmp     @label5
@label1:
  cmp     al,20h
  jle     @label5
@label6:
  inc     esi
  cmp     byte ptr [esi],020h
  jg      @label6
@label5:
  cmp     byte ptr [esi],0
  je      @label7
@label8:
  cmp     byte ptr [esi],020h
  jg      @label7
  inc     esi
  cmp     byte ptr [esi],0
  jnz     @label8
@label7:
  mov     dword ptr [esp+030h],0
  lea     eax,[esp+04h]
  push    eax
  call    GetStartupInfoA
  test    byte ptr [esp+030h],1
  mov     eax,0Ah
  je      @label9
  mov     eax,[esp+034h]
  and     eax,0FFFFh
@label9:
  push    eax                 ; ShowState
  push    esi                 ; CmdLine
  push    0                   ; hPrevInstance
  push    0                   ; pModule
  call    GetModuleHandleA
  push    eax                 ; hCurrInstance
  call    WinMain
  push    eax
  call    ExitProcess
  pop     esi
  add     esp,044h
  retn
end start

問題あるかもしれないけど、とりあえずってことで。