"git@developer.sourcefind.cn:lacacy/qwen_lmdeploy.git" did not exist on "3de27ead333b532c7731462f82135a8ea24dca10"
Commit 1f49265f authored by longpanda's avatar longpanda
Browse files

1.0.64 release

parent 25dc3235
...@@ -2022,7 +2022,7 @@ function img_unsupport_menuentry { ...@@ -2022,7 +2022,7 @@ function img_unsupport_menuentry {
############################################################# #############################################################
############################################################# #############################################################
set VENTOY_VERSION="1.0.63" set VENTOY_VERSION="1.0.64"
#ACPI not compatible with Window7/8, so disable by default #ACPI not compatible with Window7/8, so disable by default
set VTOY_PARAM_NO_ACPI=1 set VTOY_PARAM_NO_ACPI=1
......
...@@ -505,6 +505,7 @@ int ventoy_data_cmp_control(data_control *data1, data_control *data2) ...@@ -505,6 +505,7 @@ int ventoy_data_cmp_control(data_control *data1, data_control *data2)
data1->filter_vhd != data2->filter_vhd || data1->filter_vhd != data2->filter_vhd ||
data1->filter_vtoy != data2->filter_vtoy || data1->filter_vtoy != data2->filter_vtoy ||
data1->win11_bypass_check != data2->win11_bypass_check || data1->win11_bypass_check != data2->win11_bypass_check ||
data1->linux_remount != data2->linux_remount ||
data1->menu_timeout != data2->menu_timeout) data1->menu_timeout != data2->menu_timeout)
{ {
return 1; return 1;
...@@ -549,6 +550,7 @@ int ventoy_data_save_control(data_control *data, const char *title, char *buf, i ...@@ -549,6 +550,7 @@ int ventoy_data_save_control(data_control *data, const char *title, char *buf, i
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_FILE_FLT_VHD", filter_vhd); VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_FILE_FLT_VHD", filter_vhd);
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_FILE_FLT_VTOY", filter_vtoy); VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_FILE_FLT_VTOY", filter_vtoy);
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_WIN11_BYPASS_CHECK", win11_bypass_check); VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_WIN11_BYPASS_CHECK", win11_bypass_check);
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_LINUX_REMOUNT", linux_remount);
VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_MENU_TIMEOUT", menu_timeout); VTOY_JSON_FMT_CTRL_INT(L2, "VTOY_MENU_TIMEOUT", menu_timeout);
VTOY_JSON_FMT_CTRL_STRN(L2, "VTOY_DEFAULT_KBD_LAYOUT", default_kbd_layout); VTOY_JSON_FMT_CTRL_STRN(L2, "VTOY_DEFAULT_KBD_LAYOUT", default_kbd_layout);
...@@ -593,6 +595,7 @@ int ventoy_data_json_control(data_control *ctrl, char *buf, int buflen) ...@@ -593,6 +595,7 @@ int ventoy_data_json_control(data_control *ctrl, char *buf, int buflen)
VTOY_JSON_FMT_SINT("filter_vhd", ctrl->filter_vhd); VTOY_JSON_FMT_SINT("filter_vhd", ctrl->filter_vhd);
VTOY_JSON_FMT_SINT("filter_vtoy", ctrl->filter_vtoy); VTOY_JSON_FMT_SINT("filter_vtoy", ctrl->filter_vtoy);
VTOY_JSON_FMT_SINT("win11_bypass_check", ctrl->win11_bypass_check); VTOY_JSON_FMT_SINT("win11_bypass_check", ctrl->win11_bypass_check);
VTOY_JSON_FMT_SINT("linux_remount", ctrl->linux_remount);
VTOY_JSON_FMT_SINT("menu_timeout", ctrl->menu_timeout); VTOY_JSON_FMT_SINT("menu_timeout", ctrl->menu_timeout);
VTOY_JSON_FMT_STRN("default_kbd_layout", ctrl->default_kbd_layout); VTOY_JSON_FMT_STRN("default_kbd_layout", ctrl->default_kbd_layout);
VTOY_JSON_FMT_STRN("help_text_language", ctrl->help_text_language); VTOY_JSON_FMT_STRN("help_text_language", ctrl->help_text_language);
...@@ -658,6 +661,7 @@ static int ventoy_api_save_control(struct mg_connection *conn, VTOY_JSON *json) ...@@ -658,6 +661,7 @@ static int ventoy_api_save_control(struct mg_connection *conn, VTOY_JSON *json)
VTOY_JSON_INT("filter_vhd", ctrl->filter_vhd); VTOY_JSON_INT("filter_vhd", ctrl->filter_vhd);
VTOY_JSON_INT("filter_vtoy", ctrl->filter_vtoy); VTOY_JSON_INT("filter_vtoy", ctrl->filter_vtoy);
VTOY_JSON_INT("win11_bypass_check", ctrl->win11_bypass_check); VTOY_JSON_INT("win11_bypass_check", ctrl->win11_bypass_check);
VTOY_JSON_INT("linux_remount", ctrl->linux_remount);
VTOY_JSON_INT("menu_timeout", ctrl->menu_timeout); VTOY_JSON_INT("menu_timeout", ctrl->menu_timeout);
VTOY_JSON_STR("default_image", ctrl->default_image); VTOY_JSON_STR("default_image", ctrl->default_image);
...@@ -3790,6 +3794,10 @@ static int ventoy_parse_control(VTOY_JSON *json, void *p) ...@@ -3790,6 +3794,10 @@ static int ventoy_parse_control(VTOY_JSON *json, void *p)
{ {
CONTROL_PARSE_INT(child, data->win11_bypass_check); CONTROL_PARSE_INT(child, data->win11_bypass_check);
} }
else if (strcmp(child->pcName, "VTOY_LINUX_REMOUNT") == 0)
{
CONTROL_PARSE_INT(child, data->linux_remount);
}
else if (strcmp(child->pcName, "VTOY_TREE_VIEW_MENU_STYLE") == 0) else if (strcmp(child->pcName, "VTOY_TREE_VIEW_MENU_STYLE") == 0)
{ {
CONTROL_PARSE_INT(child, data->treeview_style); CONTROL_PARSE_INT(child, data->treeview_style);
......
...@@ -58,6 +58,7 @@ typedef struct data_control ...@@ -58,6 +58,7 @@ typedef struct data_control
int filter_vtoy; int filter_vtoy;
int win11_bypass_check; int win11_bypass_check;
int menu_timeout; int menu_timeout;
int linux_remount;
char default_search_root[MAX_PATH]; char default_search_root[MAX_PATH];
char default_image[MAX_PATH]; char default_image[MAX_PATH];
char default_kbd_layout[32]; char default_kbd_layout[32];
......
20211203 17:44:10 20220108 22:41:02
\ No newline at end of file \ No newline at end of file
...@@ -723,7 +723,7 @@ ...@@ -723,7 +723,7 @@
<footer class="main-footer"> <footer class="main-footer">
<div class="pull-right hidden-xs"> <div class="pull-right hidden-xs">
<b id="plugson_build_date">20211203 17:44:10</b> <b id="plugson_build_date">20220108 22:41:02</b>
</div> </div>
<strong><a href="https://www.ventoy.net" target="_blank">https://www.ventoy.net</a></strong> <strong><a href="https://www.ventoy.net" target="_blank">https://www.ventoy.net</a></strong>
</footer> </footer>
......
...@@ -337,6 +337,57 @@ ...@@ -337,6 +337,57 @@
</div><!-- /.box --> </div><!-- /.box -->
<div class="box box-primary box-solid">
<div class="box-header with-border">
<h3 class="box-title" style="font-size: 14px;font-weight: bold;">VTOY_LINUX_REMOUNT
<span id="id_span_desc_cn"> —— Linux 启动后继续访问ISO文件所在分区</span></h3>
<div class="box-tools pull-right">
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div><!-- /.box-tools -->
</div><!-- /.box-header -->
<div class="box-body no-padding">
<table class="table table-bordered no-padding">
<tr style="font-weight:bold;">
<td class="td_ctrl_col" id="td_title_setting">选项设置</td>
<td>
<label class="radio-inline">
<input type="radio" id="id_ctrl_linux_remount_radio0" name="id_ctrl_linux_remount_radio" data-type="0" value="0"/> <span style="font-weight:bold;">0</span>
</label>&nbsp;&nbsp;&nbsp;&nbsp;
<label class="radio-inline">
<input type="radio" id="id_ctrl_linux_remount_radio1" name="id_ctrl_linux_remount_radio" data-type="1" value="1"/> <span style="font-weight:bold;">1</span>
</label>
</td>
</tr>
<tr id="tr_title_desc_cn">
<td class="td_ctrl_col" id="td_title_desc">选项说明</td>
<td>
<code style="font-weight: bold;">0</code> Linux启动后不需要继续访问ISO文件所在的分区。<br/>
<code style="font-weight: bold;">1</code> Linux启动后需要继续访问ISO文件所在的分区。<br/><br/>
该选项只对 Linux 系统镜像有效。<br/>
默认情况下,受Linux内核相关功能的限制,对于Linux系统,在启动后无法继续访问ISO文件所在的分区。在mount的时候会提示 device busy。<br/>
如果这里选择 1,则 Ventoy 会尝试通过一些特殊的手段绕过内核的这个限制,但是这个功能是实验性质的,没有经过大规模和长时间的验证。
</td>
</tr>
<tr id="tr_title_desc_en">
<td class="td_ctrl_col" id="td_title_desc">Option Description</td>
<td>
<code style="font-weight: bold;">0</code> I don't need to access the image partition after boot.<br/>
<code style="font-weight: bold;">1</code> I need to access the image partition after boot. <br/><br/>
This option is only avaliable for Linux distro image files. <br/>
By default, the image partition where the ISO files locate can not be accessed after boot. When you try to mount it you will get device busy error.
This is due to linux kernel restriction (device-mapper module).<br/>
If you select 1 here, Ventoy will try to bypass the restriction with some special mechanism.<br/>
But it should be noted that, this is an experimental feature and is not fully tested.
</td>
</tr>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->
<div class="box box-primary box-solid"> <div class="box box-primary box-solid">
...@@ -881,6 +932,7 @@ ...@@ -881,6 +932,7 @@
var level; var level;
data.win11_bypass_check = parseInt($('input:radio[name=id_ctrl_bypass_win11_radio]:checked').val()); data.win11_bypass_check = parseInt($('input:radio[name=id_ctrl_bypass_win11_radio]:checked').val());
data.linux_remount = parseInt($('input:radio[name=id_ctrl_linux_remount_radio]:checked').val());
data.default_search_root = $('input:text[id=id_ctrl_text_search_root]').val(); data.default_search_root = $('input:text[id=id_ctrl_text_search_root]').val();
data.menu_timeout = parseInt($('input:text[id=id_ctrl_text_timeout]').val()); data.menu_timeout = parseInt($('input:text[id=id_ctrl_text_timeout]').val());
data.default_image = $('input:text[id=id_ctrl_text_default_img]').val(); data.default_image = $('input:text[id=id_ctrl_text_default_img]').val();
...@@ -913,6 +965,7 @@ ...@@ -913,6 +965,7 @@
function VtoyFillCurrentPageItem(data) { function VtoyFillCurrentPageItem(data) {
//VTOY_WIN11_BYPASS_CHECK //VTOY_WIN11_BYPASS_CHECK
$('input:radio[name=id_ctrl_bypass_win11_radio]')[data.win11_bypass_check].checked = true; $('input:radio[name=id_ctrl_bypass_win11_radio]')[data.win11_bypass_check].checked = true;
$('input:radio[name=id_ctrl_linux_remount_radio]')[data.linux_remount].checked = true;
//VTOY_DEFAULT_SEARCH_ROOT //VTOY_DEFAULT_SEARCH_ROOT
$('input:text[id=id_ctrl_text_search_root]').val(data.default_search_root); $('input:text[id=id_ctrl_text_search_root]').val(data.default_search_root);
...@@ -1014,6 +1067,7 @@ ...@@ -1014,6 +1067,7 @@
method : 'save_control', method : 'save_control',
index: current_tab_index, index: current_tab_index,
win11_bypass_check: data.win11_bypass_check, win11_bypass_check: data.win11_bypass_check,
linux_remount:data.linux_remount,
default_search_root: data.default_search_root, default_search_root: data.default_search_root,
menu_timeout: data.menu_timeout, menu_timeout: data.menu_timeout,
default_image: data.default_image, default_image: data.default_image,
......
...@@ -16,7 +16,7 @@ You can copy many image files at a time and ventoy will give you a boot menu to ...@@ -16,7 +16,7 @@ You can copy many image files at a time and ventoy will give you a boot menu to
x86 Legacy BIOS, IA32 UEFI, x86_64 UEFI, ARM64 UEFI and MIPS64EL UEFI are supported in the same way.<br/> x86 Legacy BIOS, IA32 UEFI, x86_64 UEFI, ARM64 UEFI and MIPS64EL UEFI are supported in the same way.<br/>
Both MBR and GPT partition style are supported in the same way.<br/> Both MBR and GPT partition style are supported in the same way.<br/>
Most type of OS supported(Windows/WinPE/Linux/Unix/ChromeOS/Vmware/Xen...) <br/> Most type of OS supported(Windows/WinPE/Linux/Unix/ChromeOS/Vmware/Xen...) <br/>
770+ ISO files are tested (<a href="https://www.ventoy.net/en/isolist.html">List</a>). 90%+ distros in <a href="https://distrowatch.com/">distrowatch.com</a> supported (<a href="https://www.ventoy.net/en/distrowatch.html">Details</a>). <br/> 780+ ISO files are tested (<a href="https://www.ventoy.net/en/isolist.html">List</a>). 90%+ distros in <a href="https://distrowatch.com/">distrowatch.com</a> supported (<a href="https://www.ventoy.net/en/distrowatch.html">Details</a>). <br/>
<br/>Official Website: <a href=https://www.ventoy.net>https://www.ventoy.net</a> <br/>Official Website: <a href=https://www.ventoy.net>https://www.ventoy.net</a>
</h4> </h4>
...@@ -58,7 +58,7 @@ A GUI Ventoy plugin configurator. [VentoyPlugson](https://www.ventoy.net/en/plug ...@@ -58,7 +58,7 @@ A GUI Ventoy plugin configurator. [VentoyPlugson](https://www.ventoy.net/en/plug
* FAT32/exFAT/NTFS/UDF/XFS/Ext2(3)(4) supported for main partition * FAT32/exFAT/NTFS/UDF/XFS/Ext2(3)(4) supported for main partition
* ISO files larger than 4GB supported * ISO files larger than 4GB supported
* Native boot menu style for Legacy & UEFI * Native boot menu style for Legacy & UEFI
* Most type of OS supported, 770+ iso files tested * Most type of OS supported, 780+ iso files tested
* Linux vDisk boot supported * Linux vDisk boot supported
* Not only boot but also complete installation process * Not only boot but also complete installation process
* Menu dynamically switchable between List/TreeView mode * Menu dynamically switchable between List/TreeView mode
......
/******************************************************************************
* vtoykmod.c ---- ventoy kmod
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#define _ull unsigned long long
#define magic_sig 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF
#define EI_NIDENT (16)
#define EI_MAG0 0 /* e_ident[] indexes */
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_OSABI 7
#define EI_PAD 8
#define ELFMAG0 0x7f /* EI_MAG */
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFMAG "\177ELF"
#define SELFMAG 4
#define ELFCLASSNONE 0 /* EI_CLASS */
#define ELFCLASS32 1
#define ELFCLASS64 2
#define ELFCLASSNUM 3
#define ELFDATANONE 0 /* e_ident[EI_DATA] */
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define EV_NONE 0 /* e_version, EI_VERSION */
#define EV_CURRENT 1
#define EV_NUM 2
#define ELFOSABI_NONE 0
#define ELFOSABI_LINUX 3
#define SHT_STRTAB 3
#pragma pack(1)
typedef struct
{
unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
uint16_t e_type; /* Object file type */
uint16_t e_machine; /* Architecture */
uint32_t e_version; /* Object file version */
uint32_t e_entry; /* Entry point virtual address */
uint32_t e_phoff; /* Program header table file offset */
uint32_t e_shoff; /* Section header table file offset */
uint32_t e_flags; /* Processor-specific flags */
uint16_t e_ehsize; /* ELF header size in bytes */
uint16_t e_phentsize; /* Program header table entry size */
uint16_t e_phnum; /* Program header table entry count */
uint16_t e_shentsize; /* Section header table entry size */
uint16_t e_shnum; /* Section header table entry count */
uint16_t e_shstrndx; /* Section header string table index */
} Elf32_Ehdr;
typedef struct
{
unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
uint16_t e_type; /* Object file type */
uint16_t e_machine; /* Architecture */
uint32_t e_version; /* Object file version */
uint64_t e_entry; /* Entry point virtual address */
uint64_t e_phoff; /* Program header table file offset */
uint64_t e_shoff; /* Section header table file offset */
uint32_t e_flags; /* Processor-specific flags */
uint16_t e_ehsize; /* ELF header size in bytes */
uint16_t e_phentsize; /* Program header table entry size */
uint16_t e_phnum; /* Program header table entry count */
uint16_t e_shentsize; /* Section header table entry size */
uint16_t e_shnum; /* Section header table entry count */
uint16_t e_shstrndx; /* Section header string table index */
} Elf64_Ehdr;
typedef struct
{
uint32_t sh_name; /* Section name (string tbl index) */
uint32_t sh_type; /* Section type */
uint32_t sh_flags; /* Section flags */
uint32_t sh_addr; /* Section virtual addr at execution */
uint32_t sh_offset; /* Section file offset */
uint32_t sh_size; /* Section size in bytes */
uint32_t sh_link; /* Link to another section */
uint32_t sh_info; /* Additional section information */
uint32_t sh_addralign; /* Section alignment */
uint32_t sh_entsize; /* Entry size if section holds table */
} Elf32_Shdr;
typedef struct
{
uint32_t sh_name; /* Section name (string tbl index) */
uint32_t sh_type; /* Section type */
uint64_t sh_flags; /* Section flags */
uint64_t sh_addr; /* Section virtual addr at execution */
uint64_t sh_offset; /* Section file offset */
uint64_t sh_size; /* Section size in bytes */
uint32_t sh_link; /* Link to another section */
uint32_t sh_info; /* Additional section information */
uint64_t sh_addralign; /* Section alignment */
uint64_t sh_entsize; /* Entry size if section holds table */
} Elf64_Shdr;
typedef struct elf32_rel {
uint32_t r_offset;
uint32_t r_info;
} Elf32_Rel;
typedef struct elf64_rel {
uint64_t r_offset; /* Location at which to apply the action */
uint64_t r_info; /* index and type of relocation */
} Elf64_Rel;
typedef struct elf32_rela{
uint32_t r_offset;
uint32_t r_info;
int32_t r_addend;
} Elf32_Rela;
typedef struct elf64_rela {
uint64_t r_offset; /* Location at which to apply the action */
uint64_t r_info; /* index and type of relocation */
int64_t r_addend; /* Constant addend used to compute value */
} Elf64_Rela;
struct modversion_info {
unsigned long crc;
char name[64 - sizeof(unsigned long)];
};
typedef struct ko_param
{
unsigned char magic[16];
unsigned long struct_size;
unsigned long pgsize;
unsigned long printk_addr;
unsigned long ro_addr;
unsigned long rw_addr;
unsigned long reg_kprobe_addr;
unsigned long unreg_kprobe_addr;
unsigned long sym_get_addr;
unsigned long sym_get_size;
unsigned long sym_put_addr;
unsigned long sym_put_size;
unsigned long padding[3];
}ko_param;
#pragma pack()
static int verbose = 0;
#define debug(fmt, ...) if(verbose) printf(fmt, ##__VA_ARGS__)
static int vtoykmod_write_file(char *name, void *buf, int size)
{
FILE *fp;
fp = fopen(name, "wb+");
if (!fp)
{
return -1;
}
fwrite(buf, 1, size, fp);
fclose(fp);
return 0;
}
static int vtoykmod_read_file(char *name, char **buf)
{
int size;
FILE *fp;
char *databuf;
fp = fopen(name, "rb");
if (!fp)
{
debug("failed to open %s %d\n", name, errno);
return -1;
}
fseek(fp, 0, SEEK_END);
size = (int)ftell(fp);
fseek(fp, 0, SEEK_SET);
databuf = malloc(size);
if (!databuf)
{
debug("failed to open malloc %d\n", size);
return -1;
}
fread(databuf, 1, size, fp);
fclose(fp);
*buf = databuf;
return size;
}
static int vtoykmod_find_section64(char *buf, char *section, int *offset, int *len)
{
uint16_t i;
int cmplen;
char *name = NULL;
char *strtbl = NULL;
Elf64_Ehdr *elf = NULL;
Elf64_Shdr *sec = NULL;
cmplen = (int)strlen(section);
elf = (Elf64_Ehdr *)buf;
sec = (Elf64_Shdr *)(buf + elf->e_shoff);
strtbl = buf + sec[elf->e_shstrndx].sh_offset;
for (i = 0; i < elf->e_shnum; i++)
{
name = strtbl + sec[i].sh_name;
if (name && strncmp(name, section, cmplen) == 0)
{
*offset = (int)(sec[i].sh_offset);
*len = (int)(sec[i].sh_size);
return 0;
}
}
return 1;
}
static int vtoykmod_find_section32(char *buf, char *section, int *offset, int *len)
{
uint16_t i;
int cmplen;
char *name = NULL;
char *strtbl = NULL;
Elf32_Ehdr *elf = NULL;
Elf32_Shdr *sec = NULL;
cmplen = (int)strlen(section);
elf = (Elf32_Ehdr *)buf;
sec = (Elf32_Shdr *)(buf + elf->e_shoff);
strtbl = buf + sec[elf->e_shstrndx].sh_offset;
for (i = 0; i < elf->e_shnum; i++)
{
name = strtbl + sec[i].sh_name;
if (name && strncmp(name, section, cmplen) == 0)
{
*offset = (int)(sec[i].sh_offset);
*len = (int)(sec[i].sh_size);
return 0;
}
}
return 1;
}
static int vtoykmod_update_modcrc(char *oldmodver, int oldcnt, char *newmodver, int newcnt)
{
int i, j;
struct modversion_info *pold, *pnew;
pold = (struct modversion_info *)oldmodver;
pnew = (struct modversion_info *)newmodver;
for (i = 0; i < oldcnt; i++)
{
for (j = 0; j < newcnt; j++)
{
if (strcmp(pold[i].name, pnew[j].name) == 0)
{
debug("CRC 0x%08lx --> 0x%08lx %s\n", pold[i].crc, pnew[i].crc, pold[i].name);
pold[i].crc = pnew[j].crc;
break;
}
}
}
return 0;
}
static int vtoykmod_update_vermagic(char *oldbuf, int oldsize, char *newbuf, int newsize, int *modver)
{
int i = 0;
char *oldver = NULL;
char *newver = NULL;
*modver = 0;
for (i = 0; i < oldsize - 9; i++)
{
if (strncmp(oldbuf + i, "vermagic=", 9) == 0)
{
oldver = oldbuf + i + 9;
debug("Find old vermagic at %d <%s>\n", i, oldver);
break;
}
}
for (i = 0; i < newsize - 9; i++)
{
if (strncmp(newbuf + i, "vermagic=", 9) == 0)
{
newver = newbuf + i + 9;
debug("Find new vermagic at %d <%s>\n", i, newver);
break;
}
}
if (oldver && newver)
{
memcpy(oldver, newver, strlen(newver) + 1);
if (strstr(newver, "modversions"))
{
*modver = 1;
}
}
return 0;
}
int vtoykmod_update(char *oldko, char *newko)
{
int rc = 0;
int modver = 0;
int oldoff, oldlen;
int newoff, newlen;
int oldsize, newsize;
char *newbuf, *oldbuf;
oldsize = vtoykmod_read_file(oldko, &oldbuf);
newsize = vtoykmod_read_file(newko, &newbuf);
if (oldsize < 0 || newsize < 0)
{
return 1;
}
/* 1: update vermagic */
vtoykmod_update_vermagic(oldbuf, oldsize, newbuf, newsize, &modver);
/* 2: update modversion crc */
if (modver)
{
if (oldbuf[EI_CLASS] == ELFCLASS64)
{
rc = vtoykmod_find_section64(oldbuf, "__versions", &oldoff, &oldlen);
rc += vtoykmod_find_section64(newbuf, "__versions", &newoff, &newlen);
}
else
{
rc = vtoykmod_find_section32(oldbuf, "__versions", &oldoff, &oldlen);
rc += vtoykmod_find_section32(newbuf, "__versions", &newoff, &newlen);
}
if (rc == 0)
{
vtoykmod_update_modcrc(oldbuf + oldoff, oldlen / 64, newbuf + newoff, newlen / 64);
}
}
else
{
debug("no need to proc modversions\n");
}
/* 3: update relocate address */
if (oldbuf[EI_CLASS] == ELFCLASS64)
{
Elf64_Rela *oldRela, *newRela;
rc = vtoykmod_find_section64(oldbuf, ".rela.gnu.linkonce.this_module", &oldoff, &oldlen);
rc += vtoykmod_find_section64(newbuf, ".rela.gnu.linkonce.this_module", &newoff, &newlen);
if (rc == 0)
{
oldRela = (Elf64_Rela *)(oldbuf + oldoff);
newRela = (Elf64_Rela *)(newbuf + newoff);
debug("init_module rela: 0x%llx --> 0x%llx\n", (_ull)(oldRela[0].r_offset), (_ull)(newRela[0].r_offset));
oldRela[0].r_offset = newRela[0].r_offset;
oldRela[0].r_addend = newRela[0].r_addend;
debug("cleanup_module rela: 0x%llx --> 0x%llx\n", (_ull)(oldRela[1].r_offset), (_ull)(newRela[1].r_offset));
oldRela[1].r_offset = newRela[1].r_offset;
oldRela[1].r_addend = newRela[1].r_addend;
}
else
{
debug("section .rela.gnu.linkonce.this_module not found\n");
}
}
else
{
Elf32_Rel *oldRel, *newRel;
rc = vtoykmod_find_section32(oldbuf, ".rel.gnu.linkonce.this_module", &oldoff, &oldlen);
rc += vtoykmod_find_section32(newbuf, ".rel.gnu.linkonce.this_module", &newoff, &newlen);
if (rc == 0)
{
oldRel = (Elf32_Rel *)(oldbuf + oldoff);
newRel = (Elf32_Rel *)(newbuf + newoff);
debug("init_module rel: 0x%x --> 0x%x\n", oldRel[0].r_offset, newRel[0].r_offset);
oldRel[0].r_offset = newRel[0].r_offset;
debug("cleanup_module rel: 0x%x --> 0x%x\n", oldRel[0].r_offset, newRel[0].r_offset);
oldRel[1].r_offset = newRel[1].r_offset;
}
else
{
debug("section .rel.gnu.linkonce.this_module not found\n");
}
}
vtoykmod_write_file(oldko, oldbuf, oldsize);
free(oldbuf);
free(newbuf);
return 0;
}
int vtoykmod_fill_param(char **argv)
{
int i;
int size;
char *buf = NULL;
ko_param *param;
unsigned char magic[16] = { magic_sig };
size = vtoykmod_read_file(argv[0], &buf);
if (size < 0)
{
return 1;
}
for (i = 0; i < size; i++)
{
if (memcmp(buf + i, magic, 16) == 0)
{
debug("Find param magic at %d\n", i);
param = (ko_param *)(buf + i);
param->struct_size = (unsigned long)sizeof(ko_param);
param->pgsize = strtoul(argv[1], NULL, 10);
param->printk_addr = strtoul(argv[2], NULL, 16);
param->ro_addr = strtoul(argv[3], NULL, 16);
param->rw_addr = strtoul(argv[4], NULL, 16);
param->sym_get_addr = strtoul(argv[5], NULL, 16);
param->sym_get_size = strtoul(argv[6], NULL, 10);
param->sym_put_addr = strtoul(argv[7], NULL, 16);
param->sym_put_size = strtoul(argv[8], NULL, 10);
param->reg_kprobe_addr = strtoul(argv[9], NULL, 16);
param->unreg_kprobe_addr = strtoul(argv[10], NULL, 16);
debug("pgsize=%lu (%s)\n", param->pgsize, argv[1]);
debug("printk_addr=0x%lx (%s)\n", param->printk_addr, argv[2]);
debug("ro_addr=0x%lx (%s)\n", param->ro_addr, argv[3]);
debug("rw_addr=0x%lx (%s)\n", param->rw_addr, argv[4]);
debug("sym_get_addr=0x%lx (%s)\n", param->sym_get_addr, argv[5]);
debug("sym_get_size=%lu (%s)\n", param->sym_get_size, argv[6]);
debug("sym_put_addr=0x%lx (%s)\n", param->sym_put_addr, argv[7]);
debug("sym_put_size=%lu (%s)\n", param->sym_put_size, argv[8]);
debug("reg_kprobe_addr=0x%lx (%s)\n", param->reg_kprobe_addr, argv[9]);
debug("unreg_kprobe_addr=0x%lx (%s)\n", param->unreg_kprobe_addr, argv[10]);
break;
}
}
if (i >= size)
{
debug("### param magic not found \n");
}
vtoykmod_write_file(argv[0], buf, size);
free(buf);
return 0;
}
int vtoykmod_main(int argc, char **argv)
{
int i;
for (i = 0; i < argc; i++)
{
if (argv[i][0] == '-' && argv[i][1] == 'v')
{
verbose = 1;
break;
}
}
if (argv[1][0] == '-' && argv[1][1] == 'f')
{
return vtoykmod_fill_param(argv + 2);
}
else if (argv[1][0] == '-' && argv[1][1] == 'u')
{
return vtoykmod_update(argv[2], argv[3]);
}
return 0;
}
// wrapper main
#ifndef BUILD_VTOY_TOOL
int main(int argc, char **argv)
{
return vtoykmod_main(argc, argv);
}
#endif
/******************************************************************************
* vtoyksym.c ---- ventoy ksym
*
* Copyright (c) 2021, longpanda <admin@ventoy.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
static int verbose = 0;
#define debug(fmt, ...) if(verbose) printf(fmt, ##__VA_ARGS__)
int vtoyksym_main(int argc, char **argv)
{
int i;
unsigned long long addr1 = 0;
unsigned long long addr2 = 0;
char sym[256];
char line[1024];
const char *name = NULL;
FILE *fp;
for (i = 0; i < argc; i++)
{
if (argv[i][0] == '-' && argv[i][1] == 'p')
{
printf("%d", getpagesize());
return 0;
}
}
for (i = 0; i < argc; i++)
{
if (argv[i][0] == '-' && argv[i][1] == 'v')
{
verbose = 1;
break;
}
}
name = argv[2] ? argv[2] : "/proc/kallsyms";
fp = fopen(name, "r");
if (!fp)
{
fprintf(stderr, "Failed to open file %s err:%d\n", name, errno);
return 1;
}
debug("open %s success\n", name);
snprintf(sym, sizeof(sym), " %s", argv[1]);
debug("lookup for <%s>\n", sym);
while (fgets(line, sizeof(line), fp))
{
if (strstr(line, sym))
{
addr1 = strtoull(line, NULL, 16);
if (!fgets(line, sizeof(line), fp))
{
addr1 = 0;
fprintf(stderr, "Failed to read next line\n");
}
else
{
addr2 = strtoull(line, NULL, 16);
}
debug("addr1=<0x%llx> addr2=<0x%llx>\n", addr1, addr2);
break;
}
}
if (addr1 > addr2)
{
debug("Invalid addr range\n");
printf("0 0\n");
}
else
{
printf("0x%llx %llu\n", addr1, addr2 - addr1);
}
fclose(fp);
return 0;
}
// wrapper main
#ifndef BUILD_VTOY_TOOL
int main(int argc, char **argv)
{
return vtoyksym_main(argc, argv);
}
#endif
...@@ -36,6 +36,8 @@ int vtoydm_main(int argc, char **argv); ...@@ -36,6 +36,8 @@ int vtoydm_main(int argc, char **argv);
int vtoytool_install(int argc, char **argv); int vtoytool_install(int argc, char **argv);
int vtoyloader_main(int argc, char **argv); int vtoyloader_main(int argc, char **argv);
int vtoyvine_main(int argc, char **argv); int vtoyvine_main(int argc, char **argv);
int vtoyksym_main(int argc, char **argv);
int vtoykmod_main(int argc, char **argv);
static char *g_vtoytool_name = NULL; static char *g_vtoytool_name = NULL;
static cmd_def g_cmd_list[] = static cmd_def g_cmd_list[] =
...@@ -44,6 +46,8 @@ static cmd_def g_cmd_list[] = ...@@ -44,6 +46,8 @@ static cmd_def g_cmd_list[] =
{ "vtoydump", vtoydump_main }, { "vtoydump", vtoydump_main },
{ "vtoydm", vtoydm_main }, { "vtoydm", vtoydm_main },
{ "loader", vtoyloader_main }, { "loader", vtoyloader_main },
{ "vtoyksym", vtoyksym_main },
{ "vtoykmod", vtoykmod_main },
{ "--install", vtoytool_install }, { "--install", vtoytool_install },
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment