]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - VtoyTool/vtoyksym.c
1 /******************************************************************************
2 * vtoyksym.c ---- ventoy ksym
4 * Copyright (c) 2021, 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/>.
28 static int verbose
= 0;
29 #define debug(fmt, ...) if(verbose) printf(fmt, ##__VA_ARGS__)
31 int vtoyksym_main(int argc
, char **argv
)
35 unsigned long long addr1
= 0;
36 unsigned long long addr2
= 0;
40 const char *name
= NULL
;
43 for (i
= 0; i
< argc
; i
++)
45 if (argv
[i
][0] == '-' && argv
[i
][1] == 'p')
47 printf("%d", getpagesize());
52 for (i
= 0; i
< argc
; i
++)
54 if (argv
[i
][0] == '-' && argv
[i
][1] == 'v')
61 name
= argv
[2] ? argv
[2] : "/proc/kallsyms";
62 fp
= fopen(name
, "r");
65 fprintf(stderr
, "Failed to open file %s err:%d\n", name
, errno
);
69 debug("open %s success\n", name
);
71 snprintf(sym
, sizeof(sym
), " %s", argv
[1]);
72 debug("lookup for <%s>\n", sym
);
74 len
= (int)strlen(sym
);
75 while (fgets(line
, sizeof(line
), fp
))
77 start
= strstr(line
, sym
);
78 if (start
&& (start
> line
) && isspace(*(start
+ len
)))
80 addr1
= strtoull(line
, NULL
, 16);
81 if (!fgets(line
, sizeof(line
), fp
))
84 fprintf(stderr
, "Failed to read next line\n");
88 addr2
= strtoull(line
, NULL
, 16);
91 debug("addr1=<0x%llx> addr2=<0x%llx>\n", addr1
, addr2
);
98 debug("Invalid addr range\n");
103 printf("0x%llx %llu\n", addr1
, addr2
- addr1
);
112 #ifndef BUILD_VTOY_TOOL
113 int main(int argc
, char **argv
)
115 return vtoyksym_main(argc
, argv
);