-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,075 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ mtlGen | |
*.exe | ||
*.ow | ||
*.txt | ||
!license.txt | ||
*Check* | ||
tests/benchmark | ||
mtlFiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "cNBT"] | ||
path = cNBT | ||
url = git@github.com:chmod222/cNBT.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.o | ||
*.a | ||
*.plist | ||
tags | ||
check | ||
nbtreader | ||
regioninfo | ||
testdata/dump.bin | ||
testdata/dump2.bin | ||
build/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# ----------------------------------------------------------------------------- | ||
# "THE BEER-WARE LICENSE" (Revision 42): | ||
# Lukas Niederbremer <webmaster@flippeh.de> and Clark Gaebel <cg.wowus.cg@gmail.com> | ||
# wrote this file. As long as you retain this notice you can do whatever you | ||
# want with this stuff. If we meet some day, and you think this stuff is worth | ||
# it, you can buy us a beer in return. | ||
# ----------------------------------------------------------------------------- | ||
|
||
CFLAGS=-g -Wall -Wextra -std=c99 -pedantic -fPIC | ||
|
||
all: nbtreader check | ||
|
||
nbtreader: main.o libnbt.a | ||
$(CC) $(CFLAGS) main.o -L. -lnbt -lz -o nbtreader | ||
|
||
check: check.c libnbt.a | ||
$(CC) $(CFLAGS) check.c -L. -lnbt -lz -o check | ||
|
||
regioninfo: regioninfo.c libnbt.a | ||
$(CC) $(CFLAGS) regioninfo.c -L. -lnbt -lz -o regioninfo | ||
|
||
test: check | ||
cd testdata && ls -1 *.nbt | xargs -n1 valgrind ../check && cd .. | ||
|
||
main.o: main.c | ||
|
||
libnbt.a: buffer.o nbt_loading.o nbt_parsing.o nbt_treeops.o nbt_util.o | ||
ar -rcs libnbt.a buffer.o nbt_loading.o nbt_parsing.o nbt_treeops.o nbt_util.o | ||
|
||
buffer.o: buffer.c | ||
nbt_loading.o: nbt_loading.c | ||
nbt_parsing.o: nbt_parsing.c | ||
nbt_treeops.o: nbt_treeops.c | ||
nbt_util.o: nbt_util.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cNBT is an NBT File (see NBT.txt) parser that doesn't | ||
depend on the horrible slowdown that is the JRE and sticks to the C principle of | ||
being as simple (and, consequently, as fast) as possible. | ||
|
||
Currently implemented features: | ||
|
||
* Complete parsing of NBT files | ||
* Basic tree-manipulation | ||
* Pretty printing with indentation | ||
* Writing modified NBT structures back to a compressed file | ||
* Full error reporting and graceful recovery from corrupt files and trees | ||
|
||
This project depends on zlib for gzip decompressing and compressing, and a compiler | ||
with C99 support. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "nbt.h" | ||
|
||
int main(int argc, const char *argv[]) { | ||
FILE *in = stdin; | ||
if (argc > 1) { | ||
in = fopen(argv[1], "rb"); | ||
if (!in) { | ||
perror("fopen"); | ||
return -1; | ||
} | ||
} | ||
|
||
#ifdef __AFL_HAVE_MANUAL_CONTROL | ||
__AFL_INIT(); | ||
#endif | ||
|
||
|
||
#ifdef __AFL_HAVE_MANUAL_CONTROL | ||
while (__AFL_LOOP(10000)) { | ||
#endif | ||
char buf[65536]; | ||
size_t len = fread(buf, 1, sizeof(buf), in); | ||
nbt_free(nbt_parse(buf, len)); | ||
#ifdef __AFL_HAVE_MANUAL_CONTROL | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
afl_check="$1" | ||
|
||
echo -ne '\x09\x00\x00' | $afl_check | ||
echo -ne '\x64' | $afl_check | ||
echo -ne '\xff\xfe\xff\xfe\x00\x03\xe8\xff\xfe\xff\xfe\x00\x03\xe8\xfe\x96\xf3\xf8' | $afl_check | ||
echo -ne '\x40' | $afl_check | ||
echo -ne '\x00\x64\x2e' | $afl_check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include "nbt.h" | ||
|
||
#include <errno.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
static void die(const char* message) | ||
{ | ||
fprintf(stderr, "%s\n", message); | ||
exit(1); | ||
} | ||
|
||
static void die_with_err(int err) | ||
{ | ||
fprintf(stderr, "Error %i: %s\n", err, nbt_error_to_string(err)); | ||
exit(1); | ||
} | ||
|
||
static nbt_node* get_tree(const char* filename) | ||
{ | ||
FILE* fp = fopen(filename, "rb"); | ||
if(fp == NULL) die("Could not open the file for reading."); | ||
|
||
nbt_node* ret = nbt_parse_file(fp); | ||
if(ret == NULL) die_with_err(errno); | ||
fclose(fp); | ||
|
||
return ret; | ||
} | ||
|
||
static bool check_size(nbt_node* n, void* aux) | ||
{ | ||
(void)n; | ||
int* size = aux; | ||
*size += 1; | ||
|
||
return true; | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if(argc == 1 || strcmp(argv[1], "--help") == 0) | ||
{ | ||
printf("Usage: %s [nbt file]\n", argv[0]); | ||
return 0; | ||
} | ||
|
||
printf("Getting tree from %s... ", argv[1]); | ||
nbt_node* tree = get_tree(argv[1]); | ||
printf("OK.\n"); | ||
|
||
/* Use this to refer to the tree in gdb. */ | ||
char* the_tree = nbt_dump_ascii(tree); | ||
|
||
if(the_tree == NULL) | ||
die_with_err(errno); | ||
|
||
{ | ||
printf("Checking nbt_map and nbt_size..."); | ||
size_t mapped_size = 0; | ||
bool ret = nbt_map(tree, check_size, &mapped_size); | ||
size_t actual_size = nbt_size(tree); | ||
if(!ret) | ||
die("FAILED. nbt_map was terminated by a visitor, even though the visitor wants to do no such thing."); | ||
if(mapped_size != actual_size) | ||
die("FAILED. nbt_map and nbt_size are not playing nice."); | ||
printf("OK.\n"); | ||
} | ||
|
||
{ | ||
printf("Checking nbt_clone... "); | ||
nbt_node* clone = nbt_clone(tree); | ||
if(!nbt_eq(tree, clone)) | ||
die("FAILED. Clones not equal."); | ||
nbt_free(tree); /* swap the tree out for its clone */ | ||
tree = clone; | ||
printf("OK.\n"); | ||
} | ||
|
||
FILE* temp = fopen("delete_me.nbt", "wb"); | ||
if(temp == NULL) die("Could not open a temporary file."); | ||
|
||
nbt_status err; | ||
|
||
printf("Dumping binary... "); | ||
if((err = nbt_dump_file(tree, temp, STRAT_GZIP)) != NBT_OK) | ||
die_with_err(err); | ||
printf("OK.\n"); | ||
|
||
fclose(temp); | ||
temp = fopen("delete_me.nbt", "rb"); | ||
if(temp == NULL) die("Could not re-open a temporary file."); | ||
|
||
printf("Reparsing... "); | ||
nbt_node* tree_copy = nbt_parse_file(temp); | ||
if(tree_copy == NULL) die_with_err(errno); | ||
printf("OK.\n"); | ||
|
||
printf("Checking trees... "); | ||
if(!nbt_eq(tree, tree_copy)) | ||
{ | ||
printf("Original tree:\n%s\n", the_tree); | ||
|
||
char* copy = nbt_dump_ascii(tree_copy); | ||
if(copy == NULL) die_with_err(err); | ||
|
||
printf("Reparsed tree:\n%s\n", copy); | ||
die("Trees not equal."); | ||
} | ||
printf("OK.\n"); | ||
|
||
printf("Freeing resources... "); | ||
|
||
fclose(temp); | ||
|
||
if(remove("delete_me.nbt") == -1) | ||
die("Could not delete delete_me.nbt. Race condition?"); | ||
|
||
nbt_free(tree); | ||
nbt_free(tree_copy); | ||
|
||
printf("OK.\n"); | ||
|
||
free(the_tree); | ||
return 0; | ||
} |
Oops, something went wrong.