Compare commits

..

No commits in common. "1c28a9520f144923e9c86208fb454b2d1bb07146" and "9dfd2ea57f005e53362014ad3ef6e059c21521ad" have entirely different histories.

15 changed files with 91 additions and 130 deletions

View File

@ -2,9 +2,9 @@ name: build all
on:
push:
branches: [ "v2.0" ]
branches: [ "2.0" ]
pull_request:
branches: [ "v2.0" ]
branches: [ "2.0" ]
jobs:
build:

1
.gitignore vendored
View File

@ -2,7 +2,6 @@
build/
target/
Cargo.lock
*.bin*
# Prerequisites
*.d

View File

@ -5,6 +5,7 @@ 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
@ -20,6 +21,7 @@ TOOL_BINS := $(patsubst %,build/$(ARCH)/tools/%,$(TOOLS))
CFLAGS := \
-Iinclude \
-g \
-O3 \
-Llib \
-static
@ -39,8 +41,6 @@ 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,9 +68,5 @@ install:
cp -r build/* /usr/local/
clean:
rm -rf build/$(ARCH)
rm -rf target/$(TARGET)
deepclean:
rm -rf build
rm -rf target

View File

@ -1,13 +1,11 @@
# kvs
KVS: Kernel Version Switcher (anti-rollback rollbacker)
<br>
[![build all](https://github.com/kxtzownsu/KVS/actions/workflows/build.yaml/badge.svg)](https://github.com/kxtzownsu/KVS/actions/workflows/build.yaml)
[![build kvs](https://github.com/kxtzownsu/KVS-private/actions/workflows/kvs.yaml/badge.svg)](https://github.com/kxtzownsu/KVS-private/actions/workflows/kvs.yaml)
[![build kvg](https://github.com/kxtzownsu/KVS-private/actions/workflows/kvg.yaml/badge.svg)](https://github.com/kxtzownsu/KVS-private/actions/workflows/kvg.yaml)
<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>
<sub> my first real C project, the code may look like shit, dont get mad at me because of it! :3 </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 />
@ -46,4 +44,3 @@ 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

View File

@ -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
--help - shows this message :3
KVG was created by kxtzownsu
(now written in Rust)
$
@ -31,7 +31,13 @@ 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)
you MUST be unenrolled!!
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!
## Examples:
***Flashing via tpm0 flash***
@ -44,14 +50,18 @@ FWMP: 0x1
GSC RW Version: 0.5.229
GSC Type: Cr50
-=-=-=-=-=-=-=-=-=-=-=-=-
1) Flash new kernver
2) Run KAUB
3) Kernver FAQ
4) Credits
5) Shell
6) Reboot
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
What kernver would you like to flash?
> 0x00010001
Press ENTER to return to main menu
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
```
<finish docs when RMASmoke & cr50-hammer release>

View File

@ -10,17 +10,24 @@
int gargc;
char **gargv;
// fval("--parameter", 1) = "burger" (assuming --parameter burger was passed)
char *fval(const char *arg, const char *shorthand, int param)
char *fval(const char *arg, int param)
{
for (int i = 0; i < gargc; i++) {
if (!strcmp(gargv[i], arg) || !strcmp(gargv[i], shorthand)) return gargv[i + param];
if (!strcmp(gargv[i], arg)) return gargv[i + param];
}
return "";
}
// fequals("--parameter"); = "burger" (assuming --parameter=burger was passed)
bool fbool(const char *arg)
{
for (int i = 0; i < gargc; i++) {
if (!strcmp(gargv[i], arg)) return true;
}
return false;
}
char *fequals(const char *arg)
{
for (int i = 0; i < gargc; i++) {
@ -31,14 +38,4 @@ 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

0
include/rmasmoke.h Normal file
View File

View File

@ -15,28 +15,20 @@ 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
// 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");
FILE *fptr;
char stupidfile[] = "/sys/class/dmi/id/bios_version";
fptr = fopen(stupidfile, "r");
static char firmwareVersion[1024];
if (fp == NULL) {
if (fptr == 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, fp);
fclose(fp);
fgets(firmwareVersion, 100, fptr);
fclose(fptr);
trim_newline(firmwareVersion);
return firmwareVersion;
@ -57,13 +49,7 @@ char* getKernver() {
char cmd[] = "tpmc read 0x1008 9 2>/dev/null";
static char output[26];
FILE* fp = popen(cmd, "r");
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!";
}
fgets(output, sizeof(output), fp);
fclose(fp);
trim_newline(output);
@ -71,7 +57,6 @@ 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");
@ -88,7 +73,6 @@ char* getKernver() {
KERNVER_TYPE = "v0";
}
KERNVER_TYPE = "v0";
return kernver_str;
}
@ -109,10 +93,12 @@ const char* getFWMPFlags(){
static char fwmp_str[5];
if (num_parsed != 1) {
return "Failed to parse FWMP value from output.";
printf("Failed to parse FWMP value from output.\n");
return 0;
}
snprintf(fwmp_str, sizeof(fwmp_str), "0x%02x", fwmp);
return fwmp_str;
}
@ -120,33 +106,18 @@ const char* getGSCRWVersion(){
char cmd[] = "gsctool -a -f | tail -n 1 | awk '{printf $2}'";
static char output[8];
FILE* fp = popen(cmd, "r");
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!";
}
fgets(output, sizeof(output), fp);
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");
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!";
}
fgets(output, sizeof(output), fp);
fclose(fp);
trim_newline(output);

View File

@ -2,7 +2,7 @@
#define UI_H
void ui_flash(char* flashtype);
void ui_header(const char* kernver, const char* tpmver, const char* fwmp, const char* gscver, const char* gsctype);
void ui_header(const char* fwver, const char* kernver, const char* tpmver, const char* fwmp, const char* gscver, const char* gsctype);
void show_credits();
void troll();
void enterToContinue();

View File

@ -3,7 +3,7 @@
SCRIPT_DIR=$(dirname "$0")
VERSION=2.0.0
HOST_ARCH=$(arch)
HOST_ARCH=$(lscpu | grep Architecture | awk '{print $2}')
if [ $HOST_ARCH == "x86_64" ]; then
CGPT="$SCRIPT_DIR/bins/cgpt.x86-64"
SFDISK="$SCRIPT_DIR/bins/sfdisk.x86-64"

View File

@ -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\n\
--help - shows this message :3\n\
KVG was created by kxtzownsu\n\
(now written in Rust)",
args[0], args[0]

View File

@ -4,7 +4,6 @@
#include <unistd.h>
#include "ui.h"
#include "sysinfo.h"
#include "arg_checks.h"
void kernver_faq(){
printf(
@ -19,22 +18,14 @@ 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");
printf("This is a bug, please report it at https://github.com/kxtzownsu/KVS");
sleep(86400);
exit(1);
}
// const char* fwver = getFirmwareVersion();
// example values for testing
const char* fwver = getFirmwareVersion();
const char* tpmver = getTpmVersion();
const char* fwmp = getFWMPFlags();
const char* gscver = getGSCRWVersion();
@ -43,13 +34,12 @@ 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(kernver, tpmver, fwmp, gscver, gsctype);
ui_header(fwver, 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");
@ -81,10 +71,6 @@ 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();
}
}

0
src/KVS/rmasmoke.c Normal file
View File

View File

@ -24,19 +24,19 @@ 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. A valid input would be: 0x00010001", kerninput);
fprintf(stderr, "Your kernver, %s, was an invalid input. Not hex.", 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);
fprintf(stderr, KERNVER_TYPE);
exit(1);
}
// we check if its *false* since strcmp returns true if failing
@ -56,17 +56,23 @@ void ui_flash(char* flashtype) {
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(char* kernver, const char* tpmver, const char* fwmp, const char* gscver, const char* gsctype){
void ui_header(const char* fwver, 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("Kernver: %s\n", kernver);
printf("FW Version: %s\n", fwver);
printf("Kernel Version: %s\n", kernver);
printf("TPM: %s\n", tpmver);
printf("FWMP: %s\n", fwmp);
printf("GSC RW Version: %s\n", gscver);
@ -77,7 +83,6 @@ void ui_header(char* kernver, const char* tpmver, const char* fwmp, 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(){

View File

@ -31,9 +31,8 @@
<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/ChromeOS/shims/KVS/">kxtz' shim mirror</a></p>
<p>To use KVS, you must download your shim from <a href="https://dl.kxtz.dev/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">
@ -47,6 +46,7 @@
<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</p>
<p><b>Google</b> - Writing the <code>tpmc</code> command :3</p>
</div>
<div style="padding-bottom: 3%;"></div>
</div>