1 /* getcto.h -- calltrick util 2 3 This file is part of the UPX executable compressor. 4 5 Copyright (C) 1996-2020 Markus Franz Xaver Johannes Oberhumer 6 Copyright (C) 1996-2020 Laszlo Molnar 7 All Rights Reserved. 8 9 UPX and the UCL library are free software; you can redistribute them 10 and/or modify them under the terms of the GNU General Public License as 11 published by the Free Software Foundation; either version 2 of 12 the License, or (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; see the file COPYING. 21 If not, write to the Free Software Foundation, Inc., 22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 23 24 Markus F.X.J. Oberhumer Laszlo Molnar 25 <markus@oberhumer.com> <ezerotven+github@gmail.com> 26 */ 27 28 29 30 /************************************************************************* 31 // 32 **************************************************************************/ 33 34 static int getcto(Filter *f, const unsigned char *buf, const int n=256) 35 { 36 int ic = n; 37 38 if (f->preferred_ctos) 39 { 40 for (const int *pc = f->preferred_ctos; *pc >= 0; pc++) 41 { 42 if (*pc < n && buf[*pc] == 0) 43 { 44 ic = *pc; 45 break; 46 } 47 } 48 } 49 50 #if 0 51 // just a test to see if certain ctos would improve compression 52 if (ic >= n) 53 for (ic = 0; ic < n; ic += 16) 54 if (buf[ic] == 0) 55 break; 56 #endif 57 if (ic >= n) 58 for (ic = 0; ic < n; ic++) 59 if (buf[ic] == 0) 60 break; 61 62 if (ic >= n) 63 //throwCantPack("call trick problem"); 64 return -1; 65 66 f->cto = (unsigned char) ic; 67 return ic; 68 } 69 70 /* vim:set ts=4 sw=4 et: */ 71