mirror of
https://github.com/zeldaret/af.git
synced 2026-09-26 13:33:16 -04:00
d66a21685f
* git subrepo clone git@github.com:ethteck/splat.git tools/splat subrepo: subdir: "tools/splat" merged: "4fec014" upstream: origin: "git@github.com:ethteck/splat.git" branch: "master" commit: "4fec014" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * gitignore * decompress_baserom.py * Initial yaml * run flib * more yaml stuff * Builds an uncompressed ROM * setup ido download * git subrepo clone git@github.com:simonlindholm/asm-differ.git tools/asm-differ subrepo: subdir: "tools/asm-differ" merged: "ae40866" upstream: origin: "git@github.com:simonlindholm/asm-differ.git" branch: "main" commit: "ae40866" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo clone git@github.com:simonlindholm/asm-processor.git tools/asm-processor subrepo: subdir: "tools/asm-processor" merged: "bbd86ea" upstream: origin: "git@github.com:simonlindholm/asm-processor.git" branch: "main" commit: "bbd86ea" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo clone (merge) git@github.com:EllipticEllipsis/fado.git tools/fado subrepo: subdir: "tools/fado" merged: "8d896ee" upstream: origin: "git@github.com:EllipticEllipsis/fado.git" branch: "master" commit: "8d896ee" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * setup ido in makefile * data and rodata * add automatic file splits * bootstrap most symbol_addrs * git subrepo clone --branch=irix git@github.com:hensldm/ultralib.git lib/ultralib subrepo: subdir: "lib/ultralib" merged: "0d1e095" upstream: origin: "git@github.com:hensldm/ultralib.git" branch: "irix" commit: "0d1e095" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * setup ido building * various tooling * git subrepo pull tools/asm-differ subrepo: subdir: "tools/asm-differ" merged: "857b398" upstream: origin: "git@github.com:simonlindholm/asm-differ.git" branch: "main" commit: "857b398" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Change defines to match IDO * review * newlin * update gitignore * Windows error * D_01000000 * yeet settings.json * yeet * git subrepo clone git@github.com:decompals/ultralib.git lib/ultralib subrepo: subdir: "lib/ultralib" merged: "d03b2a3" upstream: origin: "git@github.com:decompals/ultralib.git" branch: "main" commit: "d03b2a3" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * clangformat and clangtidy * Setup a bunch of headers * bootstrap boot and code functions and variables headers * global.h * update format.py includes * -D_MIPS_SZLONG=32 * format.py: --verbose * Update tools/decompress_baserom.py Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> * Add libc to global.h * review * yeet saved_regs * yeet headers * yeet _MSC_VER * more header cleanup * add readme licensing note --------- Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>
69 lines
2.3 KiB
Python
Executable File
69 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# Fixes garbage data between sections and optionally rodata section flags
|
|
#
|
|
|
|
import argparse
|
|
from libelf import *
|
|
|
|
def fix_section_flags(elf):
|
|
for section in elf.sections:
|
|
# Unset Alloc flag in .rodata section
|
|
if section.name == ".rodata":
|
|
section.sh_flags &= ~SHF_ALLOC
|
|
|
|
def fix_garbage(elf, original):
|
|
# Begin with the original data, and paste header and section data over it
|
|
result = original
|
|
if len(original) < len(elf.data):
|
|
result.extend([0]*(len(elf.data) - len(original)))
|
|
else:
|
|
result = result[:len(elf.data)]
|
|
|
|
# NOTE: This only supports the elf header, program headers, section headers and section data at this time
|
|
|
|
# emplace elf header
|
|
hdr = elf.elf_header.to_bin()
|
|
result[0:len(hdr)] = hdr
|
|
|
|
# emplace program headers
|
|
for i,proghdr in enumerate(elf.progheaders):
|
|
offset = elf.elf_header.e_phoff + i * elf.elf_header.e_phentsize
|
|
result[offset:offset+elf.elf_header.e_phentsize] = proghdr.to_bin()
|
|
|
|
# emplace section headers and section data
|
|
for i,section in enumerate(elf.sections):
|
|
offset = elf.elf_header.e_shoff + i * elf.elf_header.e_shentsize
|
|
section_header, section_data = section.to_bin()
|
|
result[offset:offset+elf.elf_header.e_shentsize] = section_header
|
|
if section_data is not None:
|
|
result[section.sh_offset:section.sh_offset+section.sh_size] = section_data
|
|
|
|
return result
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Disassemble relocatable ELF object.")
|
|
parser.add_argument("compiled", help="path to the compiled ELF file")
|
|
parser.add_argument("original", help="path to the original ELF file")
|
|
parser.add_argument("--fix-section-flags", help="", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
elf = None
|
|
with open(args.compiled, "rb") as elf_file:
|
|
elf = ElfFile(bytearray(elf_file.read()))
|
|
|
|
original = None
|
|
with open(args.original, "rb") as original_file:
|
|
original = bytearray(original_file.read())
|
|
|
|
if args.fix_section_flags:
|
|
fix_section_flags(elf)
|
|
|
|
result_data = fix_garbage(elf, original)
|
|
|
|
with open(args.compiled, "wb") as elf_file:
|
|
elf_file.write(result_data)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|