Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Build

on:
push:
branches:
- main
paths-ignore:
- '.github/**'
- '!.github/workflows/**'
- 'README.md'
pull_request:
paths-ignore:
- '.github/**'
- '!.github/workflows/**'
- 'README.md'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
BuildLinux:
name: Build Linux
runs-on: ubuntu-latest
steps:
- name: Clone tree
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
cmake \
libboost-all-dev \
llvm
- name: Compile
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -- -j$(grep -c processor /proc/cpuinfo)
- name: Test
run: |
ctest --test-dir build --output-on-failure
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: xbox_bios_tool_linux
path: build/xbox_bios_tool

BuildMacOS:
name: Build macOS
runs-on: macOS-latest
steps:
- name: Clone tree
uses: actions/checkout@v4
- name: Install dependencies
run: |
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
brew install \
cmake \
coreutils \
boost \
llvm
- name: Compile
run: |
export PATH="$(brew --prefix llvm@18)/bin:$PATH"
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -- -j
- name: Test
run: |
ctest --test-dir build --output-on-failure
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: xbox_bios_tool_macos
path: build/xbox_bios_tool

BuildWindows:
runs-on: windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v2.0.0
- name: Build solution
run: msbuild vc/XboxBiosTools.sln /p:Configuration=Release
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: xbox_bios_tool_win64
path: |
bin
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ obj/
XbBiosTool.vcxproj.filters
XbBiosTool.vcxproj.user
/tests/xcodes_no_branching.txt
.idea/

cmake-build-debug/
cmake-build-release/
77 changes: 77 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 3.30)

project(XboxBiosTool)

set(CMAKE_VERBOSE_MAKEFILE TRUE)

set(CMAKE_CXX_STANDARD 17)
include(CMakePushCheckState)
set(_CMAKE_PROCESSING_LANGUAGE "C")
include(CheckSymbolExists)
include (ExternalProject)
include(FindPkgConfig)

add_library(
compressor_lib
src/lzx_decoder.c
src/lzx_encoder.c
)

target_include_directories(
compressor_lib
PUBLIC
inc
)

target_compile_options(
compressor_lib
PRIVATE
-Wstrict-aliasing
)

add_executable(
xbox_bios_tool
src/Bios.cpp
src/Mcpx.c
src/XbTool.cpp
src/XcodeDecoder.cpp
src/XcodeInterp.cpp
src/cli_tbl.cpp
src/file.c
src/loadini.c
src/mem_tracking.cpp
src/nt_headers.c
src/rc4.c
src/rsa.c
src/sha1.c
src/str_util.c
src/tea.c
src/util.c
inc/posix_shims.h
)

target_include_directories(
xbox_bios_tool
PRIVATE
inc
)

target_compile_definitions(
xbox_bios_tool
PUBLIC
-D __STDC_WANT_LIB_EXT1__=1
)

target_link_libraries(
xbox_bios_tool
PRIVATE
compressor_lib
)

target_compile_options(
xbox_bios_tool
PRIVATE
-Wstrict-aliasing
)

add_subdirectory(tests)
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ xbios.exe /replicate <bios_file> /binsize 512

## Building

### Windows
The project is built in Visual Studio 2022

1. Clone the repo
Expand All @@ -407,6 +408,22 @@ The project is built in Visual Studio 2022

2. Open vc\XboxBiosTools.sln in visual studio and build and run

### Linux/macOS
This project is built using CMake and Clang or GCC.

1. Clone the repo

```
git clone https://github.com/tommojphillips/XboxBiosTool.git
```

2. Inside the cloned workspace:

```
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
```

## Credits / Resources

- [Xbox Dev Wiki](https://xboxdevwiki.net/Main_Page)
Expand Down
2 changes: 1 addition & 1 deletion inc/XcodeDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class XcodeDecoder

private:
int loadSettings(const char* ini, DECODE_SETTINGS* settings) const;
int getCommentStr(char* str);
int getCommentStr(char* str, size_t buf_size);
};

#endif // !XCODE_DECODER_H
34 changes: 17 additions & 17 deletions inc/lzx.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#ifndef LZX_H
#define LZX_H

#ifdef __cplusplus
extern "C" {
#endif

// std incl
#include <stdint.h>
#include <stdbool.h>
Expand Down Expand Up @@ -66,16 +70,16 @@ typedef struct {
uint32_t window_size;
uint32_t window_mask;
uint32_t last_matchpos_offset[LZX_NUM_REPEATED_OFFSETS];
short main_tree_table[1 << MAIN_TREE_TABLE_BITS];
short secondary_len_tree_table[1 << SECONDARY_LEN_TREE_TABLE_BITS];
int16_t main_tree_table[1 << MAIN_TREE_TABLE_BITS];
int16_t secondary_len_tree_table[1 << SECONDARY_LEN_TREE_TABLE_BITS];
uint8_t main_tree_len[LZX_MAX_MAIN_TREE_ELEMENTS];
uint8_t secondary_len_tree_len[LZX_NUM_SECONDARY_LEN];
uint8_t pad1[2];
uint8_t num_position_slots;
char aligned_table[1 << LZX_ALIGNED_TABLE_BITS];
uint8_t aligned_len[LZX_ALIGNED_NUM_ELEMENTS];
short main_tree_left_right[LZX_MAX_MAIN_TREE_ELEMENTS * 4];
short secondary_len_tree_left_right[LZX_NUM_SECONDARY_LEN * 4];
int16_t main_tree_left_right[LZX_MAX_MAIN_TREE_ELEMENTS * 4];
int16_t secondary_len_tree_left_right[LZX_NUM_SECONDARY_LEN * 4];
const uint8_t* input_curpos;
const uint8_t* end_input_pos;
uint8_t* output_buffer;
Expand Down Expand Up @@ -111,11 +115,11 @@ typedef struct {
uint32_t* left;
uint32_t* right;
uint32_t bitbuf;
char bitcount;
char depth;
uint8_t bitcount;
uint8_t depth;
bool output_overflow;
uint32_t literals;
uint32_t distances;
int32_t distances;
uint32_t* dist_data;
uint8_t* lit_data;
uint8_t* item_type;
Expand All @@ -140,15 +144,15 @@ typedef struct {
uint32_t earliest_window_data_remaining;
uint32_t bufpos_at_last_block;
uint8_t* input_ptr;
long input_left;
uint32_t input_left;
uint32_t instr_pos;
uint16_t* tree_freq;
uint16_t* tree_sortptr;
uint8_t* len;
short tree_heap[LZX_MAX_MAIN_TREE_ELEMENTS + 2];
uint16_t tree_heap[LZX_MAX_MAIN_TREE_ELEMENTS + 2];
uint16_t tree_leftright[2 * (2 * LZX_MAX_MAIN_TREE_ELEMENTS - 1)];
uint16_t tree_len_cnt[17];
short tree_heapsize;
int16_t tree_len_cnt[17];
uint16_t tree_heapsize;
int tree_n;
uint32_t next_tree_create;
uint32_t last_literals;
Expand Down Expand Up @@ -176,10 +180,6 @@ typedef struct {
uint32_t output_buffer_block_count;
} ENCODER_CONTEXT;

#ifdef __cplusplus
extern "C" {
#endif

/* Create lzx decoder */
LZX_DECODER_CONTEXT* lzx_create_decompression();

Expand All @@ -199,7 +199,7 @@ int lzx_decompress_next_block(LZX_DECODER_CONTEXT* context, const uint8_t** src,
dest_size: Output buffer size; returns the output buffer size. if output buffer is pre-allocated, this should be the size of the pre-allocated buffer.
decompressed_size: Returns the decompressed size.
returns 0 on SUCCESS, otherwise LZX_ERROR */
int lzx_decompress(const uint8_t* src, const uint32_t src_size, uint8_t** dest, uint32_t* dest_size, uint32_t* decompressed_size);
int lzx_decompress(const uint8_t* src, uint32_t src_size, uint8_t** dest, uint32_t* dest_size, uint32_t* decompressed_size);

/* Create lzx encoder */
ENCODER_CONTEXT* lzx_create_compression(uint8_t* dest);
Expand All @@ -222,7 +222,7 @@ void lzx_flush_compression(ENCODER_CONTEXT* context);
dest: Address of the output buffer. pre-allocate or null buffer
compressed_size: Returns the compressed size
returns 0 on SUCCESS, otherwise LZX_ERROR */
int lzx_compress(const uint8_t* src, const uint32_t src_size, uint8_t** dest, uint32_t* compressed_size);
int lzx_compress(const uint8_t* src, uint32_t src_size, uint8_t** dest, uint32_t* compressed_size);

#ifdef __cplusplus
};
Expand Down
31 changes: 31 additions & 0 deletions inc/posix_shims.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef POSIX_SHIMS_H
#define POSIX_SHIMS_H

#if !defined(_WIN32) && !defined(_WIN64)

#include <errno.h>

#ifdef __cplusplus
extern "C" {
#endif

static void fopen_s(
FILE** pFile,
const char *filename,
const char *mode
) {
*pFile = fopen(filename, mode);
}

#define strncpy_s strncpy
#define strcat_s strcat
#define strcpy_s strcpy
#define _chdir chdir

#ifdef __cplusplus
} // extern "C"
#endif

#endif // !defined(_WIN32) && !defined(_WIN64)

#endif //POSIX_SHIMS_H
1 change: 1 addition & 0 deletions inc/rc4.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#ifndef RC4_H
#define RC4_H

#include <stddef.h>
#include <stdint.h>

typedef struct _RC4_CONTEXT {
Expand Down
Loading