| 1 | #!/bin/sh -x |
| 2 | |
| 3 | # sed -i -e '/.model flat/i\ |
| 4 | # \t\t.xmm\r' StarCraft.asm |
| 5 | |
| 6 | usyms="copy_start ___from_strstr_to_strchr unknown_libname_36 unknown_libname_41 unknown_libname_58" |
| 7 | |
| 8 | f=/tmp/sedcmd_ |
| 9 | echo -n "sed -i -e '/.model flat/i\\\t\t.xmm\r' -e '" > $f |
| 10 | for sym in $usyms; do |
| 11 | echo -n "s/^\<$sym\>:\([^:]\)/$sym::\1/g;" >> $f |
| 12 | done |
| 13 | |
| 14 | echo "\ |
| 15 | s/^\([ +-]\?loc[r_].*[0-9A-F]:\)[^:]\(.*\;\)/\1:\t\2/g;\ |
| 16 | s/dd[[:blank:]]rva/dd/;\ |
| 17 | s/\<fldcw\>\t\[esp+4+var_4\]/fldcw\tword ptr \[esp\]/;\ |
| 18 | s/\<large \(.*fs:\)/\1/;\ |
| 19 | s/lea\t\(e.[px]\), \[\1+0\]/align 10h/;\ |
| 20 | s/\[\(e..\)+\(e.p\)\]/\[\2+\1\]/;\ |
| 21 | s/\<lea\t\(e..\), \[\(e.p\)+\(e.x\)+/lea\t\1, \[\3+\2+/;\ |
| 22 | s/\[\(e.p\)+\(e.i\)+/\[\2+\1+/;\ |
| 23 | s/\<pushf\>/pushfd/;\ |
| 24 | s/\<popf\>/popfd/;\ |
| 25 | s/\(\<j[mn]\?[abceglopszp]e\?\>\)\tloc_/\1\tnear ptr loc_/;\ |
| 26 | s/\<jmp\tsub_/jmp\tnear ptr sub_/;\ |
| 27 | ' $1" >> $f |
| 28 | . $f |
| 29 | |
| 30 | # manual fixup: |
| 31 | # - 'end start' -> 'end' |
| 32 | # - 'mov edi, edi', 'lea ...' -> align |
| 33 | # - add 'near ptr' to some jumps |
| 34 | # - 'cmp [ebp+edx+0], cl' -> 'cmp [ebp+edx*1+0], cl' |
| 35 | # - 0FFxxh constants - masm treats a byte, ONLY sometimes prefix with 'word ptr' |
| 36 | # - jmp near: |
| 37 | # - jmp _strchr |
| 38 | # - search for 'dword_xx+N', make byte/word, also word->byte |
| 39 | # - get rid of type propagation, regenerate as 'simple' var_ |
| 40 | # - convert ds:0[eax*4] -> [eax*4+0] (h hotkey) |
| 41 | # - rm function chunks - they're funcs reached by tailcalls (usually) |