You've already forked ultrasm64-2
mirror of
https://github.com/HackerN64/ultrasm64-2.git
synced 2026-01-21 10:38:08 -08:00
refresh 6
This commit is contained in:
@@ -169,32 +169,7 @@ int main(int argc, char **argv)
|
||||
fclose(ifile);
|
||||
|
||||
if (coefTable == NULL) {
|
||||
// Missing codebook, execute tabledesign instead
|
||||
const char *procDirs[] = {
|
||||
"/proc/self/exe", // Linux
|
||||
"/proc/curproc/exe", // FreeBSD
|
||||
"/proc/self/path/a.out", // Solaris
|
||||
};
|
||||
char buf[0x1000 + 0x100];
|
||||
s32 bufSize = 0x1000, found = 0;
|
||||
for (s32 i = 0; i < 3; i++) {
|
||||
ssize_t ret = readlink(procDirs[i], buf, bufSize);
|
||||
if (ret > 0 && ret < bufSize) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
// Not able to determine filename, let's guess
|
||||
strcpy(buf, "./tools/");
|
||||
}
|
||||
char *sep = strrchr(buf, '/');
|
||||
if (sep == NULL) {
|
||||
sep = buf + strlen(buf);
|
||||
}
|
||||
*sep++ = '/';
|
||||
strcpy(sep, "tabledesign");
|
||||
execl(buf, "tabledesign", "-s", "1", infilename, NULL);
|
||||
execl("./tools/tabledesign", "tabledesign", "-s", "1", infilename, NULL);
|
||||
} else {
|
||||
printf("%d\n%d\n", order, npredictors);
|
||||
for (s32 i = 0; i < npredictors; i++) {
|
||||
|
||||
27
tools/apply_patch.sh
Normal file
27
tools/apply_patch.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# apply_patch.sh - Applies an enhancement patch
|
||||
#
|
||||
|
||||
if [ "$#" -ne 1 ]
|
||||
then
|
||||
echo "Usage: $0 patch_file"
|
||||
echo ' Applies a patch file to the current directory'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -p "Do you wish to apply the patch '$1'? [Y/N] " response
|
||||
case "$response" in
|
||||
Y|y)
|
||||
patch -p1 < "$1"
|
||||
;;
|
||||
N|n)
|
||||
echo 'Quit'
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "Invalid response '$response'."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
25
tools/create_patch.sh
Normal file
25
tools/create_patch.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# create_patch.sh - Creates an enhancement patch based on the current Git changes
|
||||
#
|
||||
|
||||
if [ "$#" -ne 1 ]
|
||||
then
|
||||
echo "Usage: $0 patch_file"
|
||||
echo ' Creates a patch file based on the changes made to the current directory'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure this is a git repository
|
||||
if [ ! -d .git ]
|
||||
then
|
||||
echo 'Error: The current directory is not a Git repository.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 'git diff' is stupid and doesn't show new untracked files, so we must add them first.
|
||||
git add .
|
||||
# Generate the patch.
|
||||
git diff -p --staged > "$1"
|
||||
# Undo the 'git add'.
|
||||
git reset
|
||||
@@ -1,6 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#include "libmio0.h"
|
||||
#include "utils.h"
|
||||
@@ -291,6 +295,17 @@ int mio0_encode(const unsigned char *in, unsigned int length, unsigned char *out
|
||||
return bytes_written;
|
||||
}
|
||||
|
||||
static FILE *mio0_open_out_file(const char *out_file) {
|
||||
if (strcmp(out_file, "-") == 0) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
_setmode(_fileno(stdout), _O_BINARY);
|
||||
#endif
|
||||
return stdout;
|
||||
} else {
|
||||
return fopen(out_file, "wb");
|
||||
}
|
||||
}
|
||||
|
||||
int mio0_decode_file(const char *in_file, unsigned long offset, const char *out_file)
|
||||
{
|
||||
mio0_header_t head;
|
||||
@@ -339,7 +354,7 @@ int mio0_decode_file(const char *in_file, unsigned long offset, const char *out_
|
||||
}
|
||||
|
||||
// open output file
|
||||
out = fopen(out_file, "wb");
|
||||
out = mio0_open_out_file(out_file);
|
||||
if (out == NULL) {
|
||||
ret_val = 4;
|
||||
goto free_all;
|
||||
@@ -352,7 +367,9 @@ int mio0_decode_file(const char *in_file, unsigned long offset, const char *out_
|
||||
}
|
||||
|
||||
// clean up
|
||||
fclose(out);
|
||||
if (out != stdout) {
|
||||
fclose(out);
|
||||
}
|
||||
free_all:
|
||||
if (out_buf) {
|
||||
free(out_buf);
|
||||
@@ -402,7 +419,7 @@ int mio0_encode_file(const char *in_file, const char *out_file)
|
||||
bytes_encoded = mio0_encode(in_buf, file_size, out_buf);
|
||||
|
||||
// open output file
|
||||
out = fopen(out_file, "wb");
|
||||
out = mio0_open_out_file(out_file);
|
||||
if (out == NULL) {
|
||||
ret_val = 4;
|
||||
goto free_all;
|
||||
@@ -415,7 +432,9 @@ int mio0_encode_file(const char *in_file, const char *out_file)
|
||||
}
|
||||
|
||||
// clean up
|
||||
fclose(out);
|
||||
if (out != stdout) {
|
||||
fclose(out);
|
||||
}
|
||||
free_all:
|
||||
if (out_buf) {
|
||||
free(out_buf);
|
||||
@@ -459,7 +478,7 @@ static void print_usage(void)
|
||||
"\n"
|
||||
"File arguments:\n"
|
||||
" FILE input file\n"
|
||||
" [OUTPUT] output file (default: FILE.out)\n");
|
||||
" [OUTPUT] output file (default: FILE.out), \"-\" for stdout\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -473,7 +492,7 @@ static void parse_arguments(int argc, char *argv[], arg_config *config)
|
||||
exit(1);
|
||||
}
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
if (argv[i][0] == '-' && argv[i][1] != '\0') {
|
||||
switch (argv[i][1]) {
|
||||
case 'c':
|
||||
config->compress = 1;
|
||||
|
||||
58
tools/patch_libmalloc.py
Normal file
58
tools/patch_libmalloc.py
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Patches the malloc() function in libmalloc.so to allocate more than the
|
||||
# specified number of bytes. This is needed to work around issues with the
|
||||
# compiler occasionally crashing.
|
||||
#
|
||||
# This script replaces the "move a1, a0" (00 80 28 25) instruction with
|
||||
# "addiu a1, a0, n" (24 85 nn nn), which causes the malloc function to add n to
|
||||
# the size parameter that was passed in.
|
||||
|
||||
import hashlib
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
# file to patch
|
||||
filename = 'tools/ido5.3_compiler/lib/libmalloc.so'
|
||||
# Expected (unpatched) hash of file
|
||||
filehash = 'adde672b5d79b52ca3cce9a47c7cb648'
|
||||
# location in file to patch
|
||||
address = 0xAB4
|
||||
|
||||
# Get parameter
|
||||
if len(sys.argv) != 2:
|
||||
print('Usage: ' + sys.argv[0] + ' n\n where n is the number of extra bytes to allocate in malloc()')
|
||||
exit(1)
|
||||
n = int(sys.argv[1])
|
||||
|
||||
# Original instruction "move a1, a0"
|
||||
oldinsn = bytearray([0x00, 0x80, 0x28, 0x25])
|
||||
|
||||
# New instruction "addiu a1, a0, n"
|
||||
newinsn = bytearray([0x24, 0x85, (n >> 8) & 0xFF, (n & 0xFF)])
|
||||
|
||||
# Patch the file
|
||||
try:
|
||||
with open(filename, 'rb+') as f:
|
||||
# Read file contents
|
||||
contents = bytearray(f.read())
|
||||
|
||||
# Unpatch the file by restoring original instruction
|
||||
contents[address:address+4] = oldinsn
|
||||
|
||||
# Verify the (unpatched) hash of the file
|
||||
md5 = hashlib.md5()
|
||||
md5.update(contents)
|
||||
if md5.hexdigest() != filehash:
|
||||
print('Error: ' + filename + ' does not appear to be the correct version.')
|
||||
exit(1)
|
||||
|
||||
# Patch the file
|
||||
if n != 0:
|
||||
contents[address:address+4] = newinsn
|
||||
|
||||
# Write file
|
||||
f.seek(0, os.SEEK_SET)
|
||||
f.write(contents)
|
||||
except IOError as e:
|
||||
print('Error: Could not open library file for writing: ' + str(e))
|
||||
28
tools/revert_patch.sh
Normal file
28
tools/revert_patch.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# revert_patch.sh - Reverts an enhancement patch
|
||||
#
|
||||
|
||||
if [ "$#" -ne 1 ]
|
||||
then
|
||||
echo "Usage: $0 patch_file"
|
||||
echo ' Reverts the changes made by an enhancement patch'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -p "Do you wish to revert the patch '$1'? [Y/N] " response
|
||||
case "$response" in
|
||||
Y|y)
|
||||
patch -p1 -R < "$1"
|
||||
;;
|
||||
N|n)
|
||||
echo 'Quit'
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "Invalid response '$response'."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user