Results 1 to 15 of 16

Thread: New Method to obtain opcodes with little effort

Threaded View

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    235

    New Method to obtain opcodes with little effort

    HOWTO find opcodes by examining eqgame.exe:

    It seems the opcodes change frequently and it is a rather involved hunt to find the new opcodes each patch, I decided we should investigate the possibility of determining opcodes just as we do with the decode.cpp file.

    Examining the code, I did not find any switch blocks of the proper size. I then decided to look for jmp to data located within the data segment:

    egrep 'jmp[ \t]*ds:off' = 147 hits (excluding switch jumps = 79)

    Add the last cmp before the jump:

    egrep '[ \t]cmp|jmp[ \t]*ds:off' disasm.txt | grep -v switch.jump | awk '/cmp/ {c = $0} /jmp/ {print c; print $0}'

    Looking thru the 158 lines produces only one likely target:
    .text:00421821 cmp eax, 2BAh
    .text:00421834 jmp ds:off_424F34[eax*4]

    This is the only spot with a cmp/ja combo used to skip a jump of this format. I examined several archives of previous code
    listings. They all only have one code clip of this type:

    .text:00421AF1 cmp eax, 2AFh
    .text:00421B07 jmp ds:off_42539C[eax*4]

    and

    .text:004910E2 cmp eax, 2A3h
    .text:004910FB jmp ds:off_494AEA[eax*4]

    OK, so we found the dispatcher for opcodes:

    .text:00421818 loc_421818: ; CODE XREF: sub_4217B0+1A^Xj
    .text:00421818 add eax, 0FFFFFFE9h
    .text:0042181B xor ebx, ebx
    .text:0042181D push esi
    .text:0042181E mov esi, [ebp+10h]
    .text:00421821 cmp eax, 2BAh
    .text:00421826 push edi
    .text:00421827 ja loc_423B3B
    .text:0042182D movzx eax, ds:byte_4251D0[eax]
    .text:00421834 jmp ds:off_424F34[eax*4]

    First subtract 0x17 (23) from the wire opcode (0x0017 becomes 0x0000), skip above 0x02BA, fetch from a hard code table located at byte_4251D0 with this value as the index. What you end up with is the translated opcode (this value remains static in every copy of eqgame.exe I have on hand.)

    0xA6 likely means "invalid opcode" inside this table (and is used for padding as well as an indication of how many real opcodes are present.)

    To make it such that all opcodes are mapped within a few hours of any patch, one must map EVERY opcode now. Then translate them into the native opcodes. Once in native format, when eqgame.exe is updated, reverse the mapping to obtain the "wire opcodes". The native functions do not appear to change (excluding issues like new opcodes added; structures changed; opcodes removed entirely.)

    For the curious I will include a dump of valid opcodes below.
    "wire opcode" (wire opcode - 23) = native opcode:

    opcode 17 (0) = 0
    opcode 1f (8) = 1
    opcode 21 (a) = 2
    opcode 23 (c) = 3
    opcode 27 (10) = 4
    opcode 3b (24) = 5
    opcode 3d (26) = 6
    opcode 42 (2b) = 7
    opcode 43 (2c) = 8
    opcode 54 (3d) = 9
    opcode 60 (49) = a
    opcode 62 (4b) = b
    opcode 65 (4e) = c
    opcode 67 (50) = d
    opcode 70 (59) = e
    opcode 72 (5b) = f
    opcode 74 (5d) = 10
    opcode 75 (5e) = 11
    opcode 76 (5f) = 12
    opcode 7f (68) = 13
    opcode 80 (69) = 14
    opcode 93 (7c) = 15
    opcode 95 (7e) = 16
    opcode 96 (7f) = 17
    opcode 97 (80) = 18
    opcode 9e (87) = 19
    opcode 9f (88) = 1a
    opcode a0 (89) = 1b
    opcode a1 (8a) = 1c
    opcode a2 (8b) = 1d
    opcode a6 (8f) = 1e
    opcode a7 (90) = 1f
    opcode ab (94) = 20
    opcode ad (96) = 21
    opcode b1 (9a) = 22
    opcode b2 (9b) = 23
    opcode b7 (a0) = 24
    opcode bc (a5) = 25
    opcode be (a7) = 26
    opcode bf (a8) = 27
    opcode d1 (ba) = 28
    opcode d2 (bb) = 29
    opcode d5 (be) = 2a
    opcode da (c3) = 2b
    opcode e0 (c9) = 2c
    opcode e4 (cd) = 2d
    opcode e6 (cf) = 2e
    opcode ec (d5) = 2f
    opcode ee (d7) = 30
    opcode fb (e4) = 31
    opcode 102 (eb) = 32
    opcode 103 (ec) = 33
    opcode 104 (ed) = 34
    opcode 10e (f7) = 35
    opcode 10f (f8) = 36
    opcode 110 (f9) = 37
    opcode 11e (107) = 38
    opcode 11f (108) = 39
    opcode 121 (10a) = 3a
    opcode 124 (10d) = 3b
    opcode 126 (10f) = 3c
    opcode 128 (111) = 3d
    opcode 12d (116) = 3e
    opcode 12e (117) = 3f
    opcode 133 (11c) = 40
    opcode 135 (11e) = 41
    opcode 13b (124) = 42
    opcode 142 (12b) = 43
    opcode 146 (12f) = 44
    opcode 148 (131) = 45
    opcode 149 (132) = 46
    opcode 14a (133) = 47
    opcode 14e (137) = 48
    opcode 150 (139) = 49
    opcode 152 (13b) = 4a
    opcode 154 (13d) = 4b
    opcode 155 (13e) = 4c
    opcode 161 (14a) = 4d
    opcode 164 (14d) = 4e
    opcode 165 (14e) = 4f
    opcode 167 (150) = 50
    opcode 169 (152) = 51
    opcode 174 (15d) = 52
    opcode 17c (165) = 53
    opcode 17f (168) = 54
    opcode 180 (169) = 55
    opcode 185 (16e) = 56
    opcode 187 (170) = 57
    opcode 18f (178) = 58
    opcode 190 (179) = 59
    opcode 192 (17b) = 5a
    opcode 19a (183) = 5b
    opcode 19c (185) = 5c
    opcode 19f (188) = 5d
    opcode 1a2 (18b) = 5e
    opcode 1a6 (18f) = 5f
    opcode 1a9 (192) = 60
    opcode 1ac (195) = 61
    opcode 1af (198) = 62
    opcode 1b4 (19d) = 63
    opcode 1b8 (1a1) = 64
    opcode 1b9 (1a2) = 65
    opcode 1be (1a7) = 66
    opcode 1c0 (1a9) = 67
    opcode 1c5 (1ae) = 68
    opcode 1c6 (1af) = 69
    opcode 1c8 (1b1) = 6a
    opcode 1cc (1b5) = 6b
    opcode 1cd (1b6) = 6c
    opcode 1d4 (1bd) = 6d
    opcode 1da (1c3) = 6e
    opcode 1e0 (1c9) = 6f
    opcode 1e8 (1d1) = 70
    opcode 1e9 (1d2) = 71
    opcode 1ea (1d3) = 72
    opcode 1ec (1d5) = 73
    opcode 1ed (1d6) = 73
    opcode 1ee (1d7) = 74
    opcode 1ef (1d8) = 75
    opcode 1f3 (1dc) = 76
    opcode 1f6 (1df) = 77
    opcode 1fa (1e3) = 78
    opcode 1fb (1e4) = 79
    opcode 1fc (1e5) = 7a
    opcode 1fd (1e6) = 7b
    opcode 200 (1e9) = 7c
    opcode 201 (1ea) = 7d
    opcode 203 (1ec) = 7e
    opcode 204 (1ed) = 7f
    opcode 206 (1ef) = 80
    opcode 207 (1f0) = 81
    opcode 209 (1f2) = 82
    opcode 20a (1f3) = 83
    opcode 224 (20d) = 84
    opcode 22b (214) = 85
    opcode 230 (219) = 86
    opcode 231 (21a) = 87
    opcode 232 (21b) = 88
    opcode 233 (21c) = 89
    opcode 24d (236) = 8a
    opcode 24e (237) = 8b
    opcode 252 (23b) = 8c
    opcode 25d (246) = 8d
    opcode 25e (247) = 8e
    opcode 25f (248) = 50
    opcode 262 (24b) = 8f
    opcode 264 (24d) = 90
    opcode 26f (258) = 91
    opcode 272 (25b) = 92
    opcode 275 (25e) = 14
    opcode 279 (262) = 93
    opcode 27b (264) = 94
    opcode 27e (267) = 95
    opcode 27f (268) = 96
    opcode 280 (269) = 97
    opcode 282 (26b) = 98
    opcode 283 (26c) = 99
    opcode 284 (26d) = 9a
    opcode 286 (26f) = 9b
    opcode 289 (272) = 9c
    opcode 28b (274) = 9d
    opcode 296 (27f) = 9e
    opcode 2af (298) = 9f
    opcode 2bb (2a4) = 9a
    opcode 2bf (2a8) = a0
    opcode 2c1 (2aa) = a1
    opcode 2c5 (2ae) = a2
    opcode 2c8 (2b1) = a3
    opcode 2d0 (2b9) = a4
    opcode 2d1 (2ba) = a5

    edit: Why I don't have smilies turned off by default, death to all smilies.
    Last edited by fester; 08-28-2003 at 01:04 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

You may post new threads
You may post replies
You may post attachments
You may edit your posts
HTML code is Off
vB code is On
Smilies are On
[IMG] code is On