]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - VtoyTool/vtoyvine.c
1 /******************************************************************************
2 * vtoyloader.c ---- ventoy loader (wapper for binary loader)
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 #include <sys/types.h>
29 #include <sys/ioctl.h>
31 #include <sys/types.h>
33 static int verbose
= 0;
34 #define debug(fmt, ...) if(verbose) printf(fmt, ##__VA_ARGS__)
36 static int vine_patch_loader(unsigned char *buf
, int len
, int major
)
44 * http://vinelinux.ime.cmc.osaka-u.ac.jp/Vine-6.5/SRPMS/SRPMS.main/anaconda-vine-11.0.2.1-1vl7.src.rpm
45 * http://vinelinux.ime.cmc.osaka-u.ac.jp/Vine-6.5/SRPMS/SRPMS.main/kudzu-1.2.86-3vl6.src.rpm
46 * anaconda-vine-11.0.2.1
48 * static struct devnum devices[] = {
49 * { "aztcd", 29, 0, 0 },
50 * { "pcd", 46, 0, 0 },
55 ptrlen
= (buf
[4] == 1) ? 4 : 8;
56 debug("ELF %d bit major:%d ptrlen:%d\n", (buf
[4] == 1) ? 32 : 64, major
, ptrlen
);
58 for (i
= 0; i
< len
- 8 - 8 - ptrlen
; i
++)
60 data1
= (unsigned int *)(buf
+ i
);
61 data2
= (unsigned int *)(buf
+ i
+ 8 + ptrlen
);
63 if (data1
[0] == 0x1D && data1
[1] == 0x00 && data2
[0] == 0x2E && data2
[1] == 0x00)
65 debug("Find aztcd patch point at %d\n", i
);
71 for (i
= 0; i
< len
; i
++)
78 data1
= (unsigned int *)(buf
+ i
+ 1);
81 if (data1
[0] == 0x636F7270 && data1
[1] == 0x6564692F)
83 debug("patch string %s\n", (char *)(buf
+ i
));
94 int vtoyvine_main(int argc
, char **argv
)
101 for (i
= 0; i
< argc
; i
++)
103 if (argv
[i
][0] == '-' && argv
[i
][1] == 'v')
110 fp
= fopen(argv
[1], "rb");
113 fprintf(stderr
, "Failed to open file %s err:%d\n", argv
[1], errno
);
117 fseek(fp
, 0, SEEK_END
);
118 len
= (int)ftell(fp
);
119 debug("file length:%d\n", len
);
121 fseek(fp
, 0, SEEK_SET
);
123 buf
= (unsigned char *)malloc(len
);
130 fread(buf
, 1, len
, fp
);
133 vine_patch_loader(buf
, len
, (int)strtoul(argv
[2], NULL
, 10));
135 fp
= fopen(argv
[1], "wb+");
138 fprintf(stderr
, "Failed to open file %s err:%d\n", argv
[1], errno
);
143 debug("write new data length:%d\n", len
);
144 fwrite(buf
, 1, len
, fp
);
153 #ifndef BUILD_VTOY_TOOL
154 int main(int argc
, char **argv
)
156 return vtoyvine_main(argc
, argv
);