1/* 2; macros.S -- 3; 4; This file is part of the UPX executable compressor. 5; 6; Copyright (C) 1996-2020 Markus Franz Xaver Johannes Oberhumer 7; Copyright (C) 1996-2020 Laszlo Molnar 8; All Rights Reserved. 9; 10; UPX and the UCL library are free software; you can redistribute them 11; and/or modify them under the terms of the GNU General Public License as 12; published by the Free Software Foundation; either version 2 of 13; the License, or (at your option) any later version. 14; 15; This program is distributed in the hope that it will be useful, 16; but WITHOUT ANY WARRANTY; without even the implied warranty of 17; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18; GNU General Public License for more details. 19; 20; You should have received a copy of the GNU General Public License 21; along with this program; see the file COPYING. 22; If not, write to the Free Software Foundation, Inc., 23; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 24; 25; Markus F.X.J. Oberhumer Laszlo Molnar 26; <markus@oberhumer.com> <ezerotven+github@gmail.com> 27; 28*/ 29 30#undef amd64 31#undef i386 32#undef i486 33#undef i586 34#undef x86_64 35 36 .altmacro 37 .intel_syntax noprefix 38 .arch i8086, jumps 39 .code16 40 41.macro section name 42 .section \name 43 .code16 44 .set current_section,\name 45.endm 46 47.macro ignore_reloc_overflow sym 48 .pushsection ignore_reloc_overflow 49 .byte \sym 50 .byte current_section 51 .popsection 52.endm 53 54.macro CPU id 55 .ifc \id, 8086 56 .arch i8086, jumps 57 .endif 58 .ifc \id, 286 59 .arch i286, jumps 60 .endif 61.endm 62 63.macro jmps target 64 .byte 0xeb, \target - . - 1 65.endm 66 67.macro jos target 68 .byte 0x70, \target - . - 1 69.endm 70 71.macro jnos target 72 .byte 0x71, \target - . - 1 73.endm 74 75.macro jcs target 76 .byte 0x72, \target - . - 1 77.endm 78 79.macro jncs target 80 .byte 0x73, \target - . - 1 81.endm 82 83.macro jzs target 84 .byte 0x74, \target - . - 1 85.endm 86 87.macro jnzs target 88 .byte 0x75, \target - . - 1 89.endm 90 91.macro jnas target 92 .byte 0x76, \target - . - 1 93.endm 94 95.macro jas target 96 .byte 0x77, \target - . - 1 97.endm 98 99.macro jss target 100 .byte 0x78, \target - . - 1 101.endm 102 103.macro jnss target 104 .byte 0x79, \target - . - 1 105.endm 106 107.macro jps target 108 .byte 0x7a, \target - . - 1 109.endm 110 111.macro jnps target 112 .byte 0x7b, \target - . - 1 113.endm 114 115.macro jls target 116 .byte 0x7c, \target - . - 1 117.endm 118 119.macro jnls target 120 .byte 0x7d, \target - . - 1 121.endm 122 123.macro jngs target 124 .byte 0x7e, \target - . - 1 125.endm 126 127.macro jgs target 128 .byte 0x7f, \target - . - 1 129.endm 130 131#define jaes jncs 132#define jbes jnas 133#define jbs jcs 134#define jes jzs 135#define jnbs jncs 136#define jnes jnzs 137 138 139/* 140; ============= 141; ============= 16-BIT CALLTRICK & JUMPTRICK 142; ============= 143*/ 144 145.macro cjt16 ct_end 146section CALLTR16 147 pop si 148 mov cx, offset calltrick_calls 149cjt16_L1: 150 lodsb 151 sub al, 0xe8 152 cmp al, 1 153 jas cjt16_L1 154 155section CT16I286 156 CPU 286 157 rolw [si], 8 158 CPU 8086 159section CT16SUB0 160 sub [si], si 161section CT16I086 162 mov bx, [si] 163 xchg bh, bl 164 sub bx, si 165 mov [si], bx 166section CALLTRI2 167 lodsw 168 loop cjt16_L1 169 170 171/* 172; ============= 173*/ 174 175section CT16E800 176 mov al, 0xe8 177section CT16E900 178 mov al, 0xe9 179section CALLTRI5 180 pop di 181 mov cx, offset calltrick_calls 182cjt16_L11: 183 repne 184 scasb 185section CT16JEND 186 jnzs \ct_end 187section CT16JUL2 188 jnzs cjt16_L2 189section CT16I287 190 CPU 286 191 rolw [di], 8 192 CPU 8086 193section CT16SUB1 194 sub [di], di 195section CT16I087 196 mov bx, [di] 197 xchg bh, bl 198 sub bx, di 199 mov [di], bx 200section CALLTRI6 201 scasw 202 jmps cjt16_L11 203cjt16_L2: 204.endm 205 206 207/* 208; vi:ts=8:et:nowrap 209*/ 210