Compare commits
10 Commits
9dfd2ea57f
...
1c28a9520f
Author | SHA1 | Date | |
---|---|---|---|
1c28a9520f | |||
7922bb06a3 | |||
![]() |
b88c83d4d5 | ||
![]() |
a11c95787a | ||
![]() |
6556774140 | ||
c98551ce1c | |||
8d8f390e98 | |||
67068807a7 | |||
4e4dbc7d10 | |||
7a3a986ea6 |
4
.github/workflows/build.yaml
vendored
4
.github/workflows/build.yaml
vendored
@ -2,9 +2,9 @@ name: build all
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "2.0" ]
|
||||
branches: [ "v2.0" ]
|
||||
pull_request:
|
||||
branches: [ "2.0" ]
|
||||
branches: [ "v2.0" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
||||
build/
|
||||
target/
|
||||
Cargo.lock
|
||||
*.bin*
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
8
Makefile
8
Makefile
@ -5,7 +5,6 @@ SHELL ?= /bin/sh
|
||||
KVSFLIST := \
|
||||
src/KVS/main.c \
|
||||
src/KVS/tpm.c \
|
||||
src/KVS/rmasmoke.c \
|
||||
src/KVS/ui.c \
|
||||
src/KVS/hex_utils.c
|
||||
|
||||
@ -21,7 +20,6 @@ TOOL_BINS := $(patsubst %,build/$(ARCH)/tools/%,$(TOOLS))
|
||||
CFLAGS := \
|
||||
-Iinclude \
|
||||
-g \
|
||||
-O3 \
|
||||
-Llib \
|
||||
-static
|
||||
|
||||
@ -41,6 +39,8 @@ all: clean build kvs kvg tools
|
||||
kvs: build build/$(ARCH)/bin/kvs
|
||||
kvg: build build/$(ARCH)/bin/kvg
|
||||
|
||||
.PHONY: build
|
||||
|
||||
tools: build $(TOOL_BINS)
|
||||
|
||||
build/$(ARCH)/tools/%: build/$(ARCH)/tools/%.o
|
||||
@ -68,5 +68,9 @@ install:
|
||||
cp -r build/* /usr/local/
|
||||
|
||||
clean:
|
||||
rm -rf build/$(ARCH)
|
||||
rm -rf target/$(TARGET)
|
||||
|
||||
deepclean:
|
||||
rm -rf build
|
||||
rm -rf target
|
||||
|
@ -1,11 +1,13 @@
|
||||
# kvs
|
||||
KVS: Kernel Version Switcher (anti-rollback rollbacker)
|
||||
<br>
|
||||
[](https://github.com/kxtzownsu/KVS-private/actions/workflows/kvs.yaml)
|
||||
[](https://github.com/kxtzownsu/KVS-private/actions/workflows/kvg.yaml)
|
||||
[](https://github.com/kxtzownsu/KVS/actions/workflows/build.yaml)
|
||||
|
||||
<sub> my first real C project, the code may look like shit, dont get mad at me because of it! :3 </sub>
|
||||
<sub> my first real C project, the code may look like shit, dont get mad at me because of it! </sub>
|
||||
<sub> github is a mirror, source is at https://git.kxtz.dev/kxtzownsu/KVS </sub>
|
||||
|
||||
> [!IMPORTANT]
|
||||
> This requires an unenrolled device. Any errors relating to being enrolled will be ignored and closed.
|
||||
|
||||
## Build Instructions
|
||||
1) Clone the repo: <br />
|
||||
@ -44,3 +46,4 @@ Any legal trouble you recieve due to possessing a raw shim for KVS is not my res
|
||||
## Credits
|
||||
kxtzownsu - writing KVS & KVG, porting to C <br />
|
||||
hannah - writing the `is_ti50` tool, moral support, testing <br />
|
||||
Darkn - testing
|
||||
|
@ -12,7 +12,7 @@ USAGE: ./kvg <kernver> <optional flags>
|
||||
e.g.: ./kvg 0x00010001 --raw --ver=0
|
||||
--raw - prints the output as raw hex bytes
|
||||
--ver=<0/1> - specifies the kernver struct version to use
|
||||
--help - shows this message :3
|
||||
--help - shows this message
|
||||
KVG was created by kxtzownsu
|
||||
(now written in Rust)
|
||||
$
|
||||
@ -31,13 +31,7 @@ NOT like this:
|
||||
Passing `--raw` will give you the raw hex output, instead of it printing like this `02 4c` it would print `\x2\x4c`.
|
||||
|
||||
# Using KVS (Kernel Version Switcher)
|
||||
One thing to note, if you aren't using cr50-hammer or RMASmoke, then you must be **UNENROLLED**!
|
||||
|
||||
If you *are* using RMASmoke, make sure you're on Cr50 RW Version 0.5.229 or lower.
|
||||
|
||||
If you *are* using cr50-hammer, make sure <fill in later when cr50-hammer patch>.
|
||||
|
||||
If you *aren't* using RMASmoke or cr50-hammer, make sure to use the `tpm0 flash` method!
|
||||
you MUST be unenrolled!!
|
||||
|
||||
## Examples:
|
||||
***Flashing via tpm0 flash***
|
||||
@ -50,18 +44,14 @@ FWMP: 0x1
|
||||
GSC RW Version: 0.5.229
|
||||
GSC Type: Cr50
|
||||
-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
1) Flash new kernver via /dev/tpm0 (REQ. UNENROLLED)
|
||||
2) Flash new kernver via RMASmoke (REQ. CR50 VER 0.5.229 OR LOWER)
|
||||
3) Make kernver index unwritable
|
||||
4) Shell
|
||||
5) Reboot
|
||||
1) Flash new kernver
|
||||
2) Run KAUB
|
||||
3) Kernver FAQ
|
||||
4) Credits
|
||||
5) Shell
|
||||
6) Reboot
|
||||
> 1
|
||||
What kernver would you like to flash?
|
||||
> 0x00010001
|
||||
Does your device have lightmode (v0) or darkmode (v1) recovery? Please type either v0 or v1.
|
||||
> v0
|
||||
writing 13 bytes...
|
||||
Finished! Press ENTER to return to main menu
|
||||
Press ENTER to return to main menu
|
||||
```
|
||||
|
||||
<finish docs when RMASmoke & cr50-hammer release>
|
||||
|
@ -10,24 +10,17 @@
|
||||
int gargc;
|
||||
char **gargv;
|
||||
|
||||
char *fval(const char *arg, int param)
|
||||
// fval("--parameter", 1) = "burger" (assuming --parameter burger was passed)
|
||||
char *fval(const char *arg, const char *shorthand, int param)
|
||||
{
|
||||
for (int i = 0; i < gargc; i++) {
|
||||
if (!strcmp(gargv[i], arg)) return gargv[i + param];
|
||||
if (!strcmp(gargv[i], arg) || !strcmp(gargv[i], shorthand)) return gargv[i + param];
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
bool fbool(const char *arg)
|
||||
{
|
||||
for (int i = 0; i < gargc; i++) {
|
||||
if (!strcmp(gargv[i], arg)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// fequals("--parameter"); = "burger" (assuming --parameter=burger was passed)
|
||||
char *fequals(const char *arg)
|
||||
{
|
||||
for (int i = 0; i < gargc; i++) {
|
||||
@ -38,4 +31,14 @@ char *fequals(const char *arg)
|
||||
return "";
|
||||
}
|
||||
|
||||
// fbool("--parameter") == true (assuming --parameter was passed)
|
||||
bool fbool(const char *arg, const char *shorthand)
|
||||
{
|
||||
for (int i = 0; i < gargc; i++) {
|
||||
if (!strcmp(gargv[i], arg) || !strcmp(gargv[i], shorthand)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
@ -15,20 +15,28 @@ const char *KERNVER_TYPE = "N/A. This is an error, please report at https://gith
|
||||
const char* getFirmwareVersion(){
|
||||
// note, may not work on all chromebooks
|
||||
// I also don't wanna have to rely on the crossystem binary for it
|
||||
FILE *fptr;
|
||||
char stupidfile[] = "/sys/class/dmi/id/bios_version";
|
||||
fptr = fopen(stupidfile, "r");
|
||||
|
||||
// i hate ChromeOS
|
||||
FILE *fp;
|
||||
#ifdef __x86_64__
|
||||
char stupidfile[] = "/sys/class/platform/chromeos_acpi/FWID";
|
||||
#elif defined(__aarch64__)
|
||||
char stupidfile[] = "/proc/device-tree/firmware/chromeos/firmware-version";
|
||||
#elif defined(__arm__)
|
||||
char stupidfile[] = "/proc/device-tree/firmware/chromeos/firmware-version";
|
||||
#endif
|
||||
fp = fopen(stupidfile, "r");
|
||||
static char firmwareVersion[1024];
|
||||
|
||||
if (fptr == NULL) {
|
||||
if (fp == NULL) {
|
||||
printf("Error reading Firmware Version\n");
|
||||
printf("Please report as a bug at https://github.com/kxtzownsu/KVS\n");
|
||||
|
||||
sleep(86400);
|
||||
return "Error!";
|
||||
}
|
||||
fgets(firmwareVersion, 100, fptr);
|
||||
fclose(fptr);
|
||||
fgets(firmwareVersion, 100, fp);
|
||||
fclose(fp);
|
||||
trim_newline(firmwareVersion);
|
||||
|
||||
return firmwareVersion;
|
||||
@ -49,7 +57,13 @@ char* getKernver() {
|
||||
char cmd[] = "tpmc read 0x1008 9 2>/dev/null";
|
||||
static char output[26];
|
||||
FILE* fp = popen(cmd, "r");
|
||||
fgets(output, sizeof(output), fp);
|
||||
if (fgets(output, sizeof(output), fp) == NULL) {
|
||||
printf("Error reading kernver\n");
|
||||
printf("Please report as a bug at https://github.com/kxtzownsu/KVS\n");
|
||||
|
||||
sleep(86400);
|
||||
return "Error!";
|
||||
}
|
||||
fclose(fp);
|
||||
trim_newline(output);
|
||||
|
||||
@ -57,6 +71,7 @@ char* getKernver() {
|
||||
static char kernver_str[18] = "0x00000000";
|
||||
|
||||
// ewwww yucky i hate this
|
||||
// bitshift stuff sucks so bad when looking at it
|
||||
|
||||
if (strncmp(output, "10", 2) == 0) {
|
||||
printf("using v1.0\n");
|
||||
@ -73,6 +88,7 @@ char* getKernver() {
|
||||
KERNVER_TYPE = "v0";
|
||||
}
|
||||
|
||||
KERNVER_TYPE = "v0";
|
||||
return kernver_str;
|
||||
}
|
||||
|
||||
@ -93,12 +109,10 @@ const char* getFWMPFlags(){
|
||||
static char fwmp_str[5];
|
||||
|
||||
if (num_parsed != 1) {
|
||||
printf("Failed to parse FWMP value from output.\n");
|
||||
return 0;
|
||||
return "Failed to parse FWMP value from output.";
|
||||
}
|
||||
|
||||
snprintf(fwmp_str, sizeof(fwmp_str), "0x%02x", fwmp);
|
||||
|
||||
return fwmp_str;
|
||||
}
|
||||
|
||||
@ -106,18 +120,33 @@ const char* getGSCRWVersion(){
|
||||
char cmd[] = "gsctool -a -f | tail -n 1 | awk '{printf $2}'";
|
||||
static char output[8];
|
||||
FILE* fp = popen(cmd, "r");
|
||||
fgets(output, sizeof(output), fp);
|
||||
if (fgets(output, sizeof(output), fp) == NULL) {
|
||||
printf("Error reading GSC(cr50/ti50) version\n");
|
||||
printf("Please report as a bug at https://github.com/kxtzownsu/KVS\n");
|
||||
|
||||
sleep(86400);
|
||||
return "Error!";
|
||||
}
|
||||
fclose(fp);
|
||||
trim_newline(output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
// this being at a pre-made directory instead of
|
||||
// being in PATH or /bin is probably bad, but
|
||||
// I don't really care that much
|
||||
const char* getGSCType(){
|
||||
char cmd[] = "/opt/kvs/bin/is_ti50 2>/dev/null";
|
||||
static char output[7];
|
||||
FILE* fp = popen(cmd, "r");
|
||||
fgets(output, sizeof(output), fp);
|
||||
if (fgets(output, sizeof(output), fp) == NULL) {
|
||||
printf("Error getting GSC(cr50/ti50) type!\n");
|
||||
printf("Please report as a bug at https://github.com/kxtzownsu/KVS\n");
|
||||
|
||||
sleep(86400);
|
||||
return "Error!";
|
||||
}
|
||||
fclose(fp);
|
||||
trim_newline(output);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define UI_H
|
||||
|
||||
void ui_flash(char* flashtype);
|
||||
void ui_header(const char* fwver, const char* kernver, const char* tpmver, const char* fwmp, const char* gscver, const char* gsctype);
|
||||
void ui_header(const char* kernver, const char* tpmver, const char* fwmp, const char* gscver, const char* gsctype);
|
||||
void show_credits();
|
||||
void troll();
|
||||
void enterToContinue();
|
||||
|
@ -3,7 +3,7 @@
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
VERSION=2.0.0
|
||||
|
||||
HOST_ARCH=$(lscpu | grep Architecture | awk '{print $2}')
|
||||
HOST_ARCH=$(arch)
|
||||
if [ $HOST_ARCH == "x86_64" ]; then
|
||||
CGPT="$SCRIPT_DIR/bins/cgpt.x86-64"
|
||||
SFDISK="$SCRIPT_DIR/bins/sfdisk.x86-64"
|
||||
|
@ -100,7 +100,7 @@ fn main() {
|
||||
e.g.: {} 0x00010001 --raw\n\
|
||||
--raw - prints the output as raw hex bytes\n\
|
||||
--ver=<0/1> - specifies the kernver struct version to use\n\
|
||||
--help - shows this message :3\n\
|
||||
--help - shows this message\n\
|
||||
KVG was created by kxtzownsu\n\
|
||||
(now written in Rust)",
|
||||
args[0], args[0]
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <unistd.h>
|
||||
#include "ui.h"
|
||||
#include "sysinfo.h"
|
||||
#include "arg_checks.h"
|
||||
|
||||
void kernver_faq(){
|
||||
printf(
|
||||
@ -18,14 +19,22 @@ void kernver_faq(){
|
||||
);
|
||||
};
|
||||
|
||||
void dbgprintf(char* text){
|
||||
if (fbool("--debug","-d")){
|
||||
printf("DEBUG: %s\n", text);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
gargc = argc;
|
||||
gargv = argv;
|
||||
if (geteuid() != 0){
|
||||
printf("Please run KVS as root!\n");
|
||||
exit(1);
|
||||
printf("This is a bug, please report it at https://github.com/kxtzownsu/KVS");
|
||||
sleep(86400);
|
||||
}
|
||||
|
||||
// example values for testing
|
||||
const char* fwver = getFirmwareVersion();
|
||||
// const char* fwver = getFirmwareVersion();
|
||||
const char* tpmver = getTpmVersion();
|
||||
const char* fwmp = getFWMPFlags();
|
||||
const char* gscver = getGSCRWVersion();
|
||||
@ -34,12 +43,13 @@ int main(int argc, char **argv) {
|
||||
|
||||
// only allow 2 characters (option & newline)
|
||||
char choice[3];
|
||||
dbgprintf("ui loop \n");
|
||||
while (true) {
|
||||
char* kernver = getKernver();
|
||||
|
||||
printf("\033[H\033[J"); // clears the screen
|
||||
|
||||
ui_header(fwver, kernver, tpmver, fwmp, gscver, gsctype);
|
||||
ui_header(kernver, tpmver, fwmp, gscver, gsctype);
|
||||
printf("1) Flash new kernver \n");
|
||||
printf("2) Run KAUB (Kernver Automatic Update Blocker) \n");
|
||||
printf("3) Kernver FAQ \n");
|
||||
@ -71,6 +81,10 @@ int main(int argc, char **argv) {
|
||||
exit(1);
|
||||
} else if (!strcmp(choice, "7")) {
|
||||
troll();
|
||||
} else {
|
||||
printf("You have entered an invalid option... how?? Next time, only input the number.\n");
|
||||
printf("Example: > 1\n");
|
||||
enterToContinue();
|
||||
}
|
||||
}
|
||||
|
||||
|
57
src/KVS/ui.c
57
src/KVS/ui.c
@ -24,55 +24,49 @@ void ui_flash(char* flashtype) {
|
||||
printf("What kernver would you like to flash? \n");
|
||||
printf("> ");
|
||||
fgets(kerninput, sizeof(kerninput), stdin);
|
||||
// nya
|
||||
if (kerninput[strlen(kerninput) - 1] == '\n') {
|
||||
kerninput[strlen(kerninput) - 1] = '\0';
|
||||
}
|
||||
if (!is_valid_hex(kerninput)){
|
||||
fprintf(stderr, "Your kernver, %s, was an invalid input. Not hex.", kerninput);
|
||||
fprintf(stderr, "Your kernver, %s, was an invalid input, not hex. A valid input would be: 0x00010001", kerninput);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
// the output of strcmp if it fails is True
|
||||
if (strcmp(KERNVER_TYPE, "v0") && strcmp(KERNVER_TYPE, "v1")){
|
||||
// the reason we're not redirecting the user to the issues page is because if KERNVER_TYPE
|
||||
// isn't detected as v0 or v1 in sysinfo.h, it'll do that already
|
||||
fprintf(stderr, "%s", KERNVER_TYPE);
|
||||
sleep(86400);
|
||||
}
|
||||
|
||||
// the output of strcmp if it fails is True
|
||||
if (strcmp(KERNVER_TYPE, "v0") && strcmp(KERNVER_TYPE, "v1")){
|
||||
fprintf(stderr, KERNVER_TYPE);
|
||||
exit(1);
|
||||
}
|
||||
// we check if its *false* since strcmp returns true if failing
|
||||
if (!strcmp(KERNVER_TYPE, "v0")){
|
||||
char cmd[128];
|
||||
|
||||
// we check if its *false* since strcmp returns true if failing
|
||||
if (!strcmp(KERNVER_TYPE, "v0")){
|
||||
char cmd[128];
|
||||
snprintf(cmd, sizeof(cmd), "kvg %s --ver=0", kerninput);
|
||||
FILE* fp = popen(cmd, "r");
|
||||
fgets(kvgout_v0, sizeof(kvgout_v0), fp);
|
||||
fclose(fp);
|
||||
} else if (!strcmp(KERNVER_TYPE, "v1")) {
|
||||
char cmd[128];
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "kvg %s --ver=0", kerninput);
|
||||
FILE* fp = popen(cmd, "r");
|
||||
fgets(kvgout_v0, sizeof(kvgout_v0), fp);
|
||||
fclose(fp);
|
||||
} else if (!strcmp(KERNVER_TYPE, "v1")) {
|
||||
char cmd[128];
|
||||
snprintf(cmd, sizeof(cmd), "kvg %s --ver=1", kerninput);
|
||||
FILE* fp = popen(cmd, "r");
|
||||
fgets(kvgout_v1, sizeof(kvgout_v1), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "kvg %s --ver=1", kerninput);
|
||||
FILE* fp = popen(cmd, "r");
|
||||
fgets(kvgout_v1, sizeof(kvgout_v1), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
if (flashtype == "tpm0"){
|
||||
if (!strcmp(KERNVER_TYPE, "v0")) {
|
||||
tpm_nvwrite("0x1008", kvgout_v0);
|
||||
|
||||
} else if (!strcmp(KERNVER_TYPE, "v1")) {
|
||||
tpm_nvwrite("0x1008", kvgout_v1);
|
||||
}
|
||||
} else if (flashtype == "rmasmoke"){
|
||||
printf("using rmasmoke\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ui_header(const char* fwver, char* kernver, const char* tpmver, const char* fwmp, const char* gscver, const char* gsctype){
|
||||
void ui_header(char* kernver, const char* tpmver, const char* fwmp, const char* gscver, const char* gsctype){
|
||||
printf("KVS: Kernel Version Switcher (codename Maglev, bid: 2.0.0)\n");
|
||||
printf("FW Version: %s\n", fwver);
|
||||
printf("Kernel Version: %s\n", kernver);
|
||||
printf("Kernver: %s\n", kernver);
|
||||
printf("TPM: %s\n", tpmver);
|
||||
printf("FWMP: %s\n", fwmp);
|
||||
printf("GSC RW Version: %s\n", gscver);
|
||||
@ -83,6 +77,7 @@ void ui_header(const char* fwver, char* kernver, const char* tpmver, const char*
|
||||
void show_credits(){
|
||||
printf("kxtzownsu - Writing KVS 1 and 2\n");
|
||||
printf("Hannah/ZegLol - writing is_ti50, mental support, testing\n");
|
||||
printf("Darkn - testing\n");
|
||||
}
|
||||
|
||||
void troll(){
|
||||
|
@ -31,8 +31,9 @@
|
||||
<p>This works using the hexdumps of 0x1008 (kernver TPM index) and <code>tpmc</code> to write the hexdumps of your selected kernver to the 0x1008 TPM index.</p>
|
||||
</div>
|
||||
<div class="installation">
|
||||
<p><b>YOU MUST BE UNENROLLED TO USE KVS! ANY ISSUES REPORTED RELATING TO BEING ENROLLED WHILE TRYING TO USE THIS WILL GET CLOSED IMMEDIATELY</b></p>
|
||||
<h3>How do I use this?</h3>
|
||||
<p>To use KVS, you must download your shim from <a href="https://dl.kxtz.dev/shims/KVS/">kxtz' shim mirror</a></p>
|
||||
<p>To use KVS, you must download your shim from <a href="https://dl.kxtz.dev/ChromeOS/shims/KVS/">kxtz' shim mirror</a></p>
|
||||
<p>After downloading, flash your USB/SD with the file, I recommend Chrome Recovery Utility.</p>
|
||||
</div>
|
||||
<div class="faq">
|
||||
@ -46,7 +47,6 @@
|
||||
<p>kernver 0: any</p>
|
||||
<p>kernver 1: any</p>
|
||||
<p>kernver 2: 112 - 119</p>
|
||||
<p>kernver 3: 120 - 124</p>
|
||||
<p>kernver 4: 125 - latest</p>
|
||||
<h4><b>Q: </b>What is the difference between kernver 0 and kernver 1?</h4>
|
||||
<p><b>A: </b>literally none, its just cool to see</p>
|
||||
@ -55,7 +55,7 @@
|
||||
<h3>Credits</h3>
|
||||
<p><b>kxtzownsu</b> - Writing KVS</p>
|
||||
<p><b>OlyB</b> - Helping me with the shim builder, most of the shim builder wouldn't exist without him.</p>
|
||||
<p><b>Google</b> - Writing the <code>tpmc</code> command :3</p>
|
||||
<p><b>Google</b> - Writing the <code>tpmc</code> command</p>
|
||||
</div>
|
||||
<div style="padding-bottom: 3%;"></div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user