mirror of
https://github.com/SabreTools/psxt001z.git
synced 2026-02-09 21:32:36 +00:00
Compare commits
25 Commits
0.21-beta2
...
rolling
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efe4bad4c8 | ||
|
|
3e88270d14 | ||
|
|
905b622c27 | ||
|
|
d1e3c82e23 | ||
|
|
45e3ad8e48 | ||
|
|
0197d4f794 | ||
|
|
577052a5b2 | ||
|
|
0d79e88377 | ||
|
|
2508b71cc8 | ||
|
|
bc85c4a73b | ||
|
|
1a4fa8db4e | ||
|
|
3bfabc26a4 | ||
|
|
911649a91a | ||
|
|
ee8eb7cb57 | ||
|
|
8d17292db6 | ||
|
|
1871d1f02a | ||
|
|
596b1028ab | ||
|
|
32c24e395a | ||
|
|
03c713e82b | ||
|
|
77e49c3174 | ||
|
|
335107da38 | ||
|
|
68075a7186 | ||
|
|
a87602b015 | ||
|
|
a120fdc880 | ||
|
|
0301dab094 |
167
.editorconfig
Normal file
167
.editorconfig
Normal file
@@ -0,0 +1,167 @@
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# C# files
|
||||
[*.cs]
|
||||
|
||||
# Indentation and spacing
|
||||
charset = utf-8
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
tab_width = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# New line preferences
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
max_line_length = unset
|
||||
|
||||
# using directive preferences
|
||||
csharp_using_directive_placement = outside_namespace
|
||||
dotnet_diagnostic.IDE0005.severity = error
|
||||
|
||||
# Code-block preferences
|
||||
csharp_style_namespace_declarations = block_scoped
|
||||
csharp_style_prefer_method_group_conversion = true
|
||||
csharp_style_prefer_top_level_statements = false
|
||||
|
||||
# Expression-level preferences
|
||||
csharp_prefer_simple_default_expression = true
|
||||
csharp_style_inlined_variable_declaration = true
|
||||
csharp_style_unused_value_assignment_preference = discard_variable
|
||||
csharp_style_unused_value_expression_statement_preference = discard_variable
|
||||
dotnet_diagnostic.IDE0001.severity = warning
|
||||
dotnet_diagnostic.IDE0002.severity = warning
|
||||
dotnet_diagnostic.IDE0004.severity = warning
|
||||
dotnet_diagnostic.IDE0010.severity = error
|
||||
dotnet_diagnostic.IDE0051.severity = warning
|
||||
dotnet_diagnostic.IDE0052.severity = warning
|
||||
dotnet_diagnostic.IDE0072.severity = warning
|
||||
dotnet_diagnostic.IDE0080.severity = warning
|
||||
dotnet_diagnostic.IDE0100.severity = error
|
||||
dotnet_diagnostic.IDE0110.severity = error
|
||||
dotnet_diagnostic.IDE0120.severity = warning
|
||||
dotnet_diagnostic.IDE0121.severity = warning
|
||||
dotnet_diagnostic.IDE0240.severity = error
|
||||
dotnet_diagnostic.IDE0241.severity = error
|
||||
dotnet_style_coalesce_expression = true
|
||||
dotnet_style_namespace_match_folder = false
|
||||
dotnet_style_null_propagation = true
|
||||
dotnet_style_prefer_auto_properties = true
|
||||
dotnet_style_prefer_collection_expression = when_types_loosely_match
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
|
||||
dotnet_style_prefer_compound_assignment = true
|
||||
csharp_style_prefer_simple_property_accessors = true
|
||||
dotnet_style_prefer_simplified_interpolation = true
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true
|
||||
csharp_style_prefer_unbound_generic_type_in_nameof = true
|
||||
|
||||
# Field preferences
|
||||
dotnet_diagnostic.IDE0044.severity = warning
|
||||
dotnet_style_readonly_field = true
|
||||
|
||||
# Language keyword vs. framework types preferences
|
||||
dotnet_diagnostic.IDE0049.severity = error
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true
|
||||
dotnet_style_predefined_type_for_member_access = true
|
||||
|
||||
# Modifier preferences
|
||||
csharp_prefer_static_local_function = true
|
||||
csharp_style_prefer_readonly_struct = true
|
||||
dotnet_diagnostic.IDE0036.severity = warning
|
||||
dotnet_diagnostic.IDE0040.severity = error
|
||||
dotnet_diagnostic.IDE0380.severity = error
|
||||
dotnet_style_require_accessibility_modifiers = always
|
||||
|
||||
# New-line preferences
|
||||
dotnet_diagnostic.IDE2000.severity = warning
|
||||
dotnet_diagnostic.IDE2002.severity = warning
|
||||
dotnet_diagnostic.IDE2003.severity = warning
|
||||
dotnet_diagnostic.IDE2004.severity = warning
|
||||
dotnet_diagnostic.IDE2005.severity = warning
|
||||
dotnet_diagnostic.IDE2006.severity = warning
|
||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
|
||||
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false
|
||||
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
|
||||
dotnet_style_allow_multiple_blank_lines_experimental = false
|
||||
dotnet_style_allow_statement_immediately_after_block_experimental = false
|
||||
|
||||
# Null-checking preferences
|
||||
csharp_style_conditional_delegate_call = true
|
||||
|
||||
# Parameter preferences
|
||||
dotnet_code_quality_unused_parameters = all
|
||||
dotnet_diagnostic.IDE0280.severity = error
|
||||
|
||||
# Parentheses preferences
|
||||
dotnet_diagnostic.IDE0047.severity = warning
|
||||
dotnet_diagnostic.IDE0048.severity = warning
|
||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
|
||||
|
||||
# Pattern-matching preferences
|
||||
dotnet_diagnostic.IDE0019.severity = warning
|
||||
dotnet_diagnostic.IDE0020.severity = warning
|
||||
dotnet_diagnostic.IDE0038.severity = warning
|
||||
dotnet_diagnostic.IDE0066.severity = none
|
||||
dotnet_diagnostic.IDE0083.severity = warning
|
||||
dotnet_diagnostic.IDE0260.severity = warning
|
||||
csharp_style_pattern_matching_over_as_with_null_check = true
|
||||
csharp_style_pattern_matching_over_is_with_cast_check = true
|
||||
csharp_style_prefer_not_pattern = true
|
||||
csharp_style_prefer_pattern_matching = true
|
||||
|
||||
# this. and Me. preferences
|
||||
dotnet_style_qualification_for_event = false
|
||||
dotnet_style_qualification_for_field = false
|
||||
dotnet_style_qualification_for_method = false
|
||||
dotnet_style_qualification_for_property = false
|
||||
|
||||
# var preferences
|
||||
csharp_style_var_for_built_in_types = false
|
||||
csharp_style_var_when_type_is_apparent = true
|
||||
|
||||
# .NET formatting options
|
||||
dotnet_separate_import_directive_groups = false
|
||||
dotnet_sort_system_directives_first = true
|
||||
|
||||
# C# formatting options
|
||||
csharp_indent_block_contents = true
|
||||
csharp_indent_braces = false
|
||||
csharp_indent_case_contents = true
|
||||
csharp_indent_case_contents_when_block = false
|
||||
csharp_indent_labels = one_less_than_current
|
||||
csharp_indent_switch_labels = true
|
||||
csharp_new_line_before_catch = true
|
||||
csharp_new_line_before_else = true
|
||||
csharp_new_line_before_finally = true
|
||||
csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = all
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
csharp_preserve_single_line_blocks = true
|
||||
csharp_preserve_single_line_statements = true
|
||||
csharp_space_after_cast = false
|
||||
csharp_space_after_colon_in_inheritance_clause = true
|
||||
csharp_space_after_comma = true
|
||||
csharp_space_after_dot = false
|
||||
csharp_space_after_keywords_in_control_flow_statements = true
|
||||
csharp_space_after_semicolon_in_for_statement = true
|
||||
csharp_space_around_binary_operators = before_and_after
|
||||
csharp_space_around_declaration_statements = false
|
||||
csharp_space_before_colon_in_inheritance_clause = true
|
||||
csharp_space_before_comma = false
|
||||
csharp_space_before_dot = false
|
||||
csharp_space_before_open_square_brackets = false
|
||||
csharp_space_before_semicolon_in_for_statement = false
|
||||
csharp_space_between_empty_square_brackets = false
|
||||
csharp_space_between_method_call_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_call_name_and_opening_parenthesis = false
|
||||
csharp_space_between_method_call_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_parameter_list_parentheses = false
|
||||
csharp_space_between_parentheses = false
|
||||
csharp_space_between_square_brackets = false
|
||||
45
.github/workflows/build_and_test.yml
vendored
Normal file
45
.github/workflows/build_and_test.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: Build and Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
dotnet-version: |
|
||||
8.0.x
|
||||
9.0.x
|
||||
10.0.x
|
||||
|
||||
- name: Run publish script
|
||||
run: ./publish-nix.sh -d
|
||||
|
||||
- name: Update rolling tag
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -f rolling
|
||||
git push origin :refs/tags/rolling || true
|
||||
git push origin rolling --force
|
||||
|
||||
- name: Upload to rolling
|
||||
uses: ncipollo/release-action@v1.20.0
|
||||
with:
|
||||
allowUpdates: True
|
||||
artifacts: "*.nupkg,*.snupkg,*.zip"
|
||||
body: "Last built commit: ${{ github.sha }}"
|
||||
name: "Rolling Release"
|
||||
prerelease: True
|
||||
replacesArtifacts: True
|
||||
tag: "rolling"
|
||||
updateOnlyUnreleased: True
|
||||
20
.github/workflows/check_pr.yml
vendored
Normal file
20
.github/workflows/check_pr.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: Build PR
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
dotnet-version: |
|
||||
8.0.x
|
||||
9.0.x
|
||||
10.0.x
|
||||
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
296
.gitignore
vendored
296
.gitignore
vendored
@@ -1,15 +1,7 @@
|
||||
*.swp
|
||||
*.*~
|
||||
project.lock.json
|
||||
.DS_Store
|
||||
*.pyc
|
||||
nupkg/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
|
||||
# Rider
|
||||
.idea
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
@@ -17,6 +9,9 @@ nupkg/
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
@@ -24,15 +19,280 @@ nupkg/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
build/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Oo]ut/
|
||||
msbuild.log
|
||||
msbuild.err
|
||||
msbuild.wrn
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
**/Properties/launchSettings.json
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
15
.vscode/tasks.json
vendored
Normal file
15
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/psxt001z.sln",
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
]
|
||||
}
|
||||
60
CRC32.cs
60
CRC32.cs
@@ -1,60 +0,0 @@
|
||||
namespace psxt001z
|
||||
{
|
||||
internal class CRC32
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const uint CRC_POLY = 0xEDB88320;
|
||||
|
||||
private const uint CRC_MASK = 0xD202EF8D;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
protected uint[] Table { get; private set; } = new uint[256];
|
||||
|
||||
public uint m_crc32 { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public CRC32()
|
||||
{
|
||||
for (uint i = 0; i < 256; i++)
|
||||
{
|
||||
uint r, j;
|
||||
for (r = i, j = 8; j != 0; j--)
|
||||
{
|
||||
r = ((r & 1) != 0) ? (r >> 1) ^ CRC_POLY : r >> 1;
|
||||
}
|
||||
|
||||
Table[i] = r;
|
||||
}
|
||||
|
||||
m_crc32 = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Functions
|
||||
|
||||
public void ProcessCRC(byte[]? pData, int pDataPtr, int nLen)
|
||||
{
|
||||
if (pData == null)
|
||||
return;
|
||||
|
||||
uint crc = m_crc32;
|
||||
while (nLen-- != 0)
|
||||
{
|
||||
crc = Table[(byte)(crc ^ pData[pDataPtr++])] ^ crc >> 8;
|
||||
crc ^= CRC_MASK;
|
||||
}
|
||||
|
||||
m_crc32 = crc;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
19
Common.cs
19
Common.cs
@@ -1,19 +0,0 @@
|
||||
namespace psxt001z
|
||||
{
|
||||
public static class Common
|
||||
{
|
||||
public const int ZERO = 0;
|
||||
|
||||
public const string VERSION = "v0.21 beta 1";
|
||||
|
||||
/// <summary>
|
||||
/// BCD to u_char
|
||||
/// </summary>
|
||||
public static byte btoi(byte b) => (byte)(((b) / 16 * 10 + (b) % 16));
|
||||
|
||||
/// <summary>
|
||||
/// u_char to BCD
|
||||
/// </summary>
|
||||
public static byte itob(byte i) => (byte)(((i) / 10 * 16 + (i) % 10));
|
||||
}
|
||||
}
|
||||
178
FileTools.cs
178
FileTools.cs
@@ -1,178 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
internal class FileTools
|
||||
{
|
||||
#region Properties
|
||||
|
||||
private Stream InputStream { get; set; }
|
||||
|
||||
private byte[] ExeName { get; set; } = new byte[20];
|
||||
|
||||
private byte[] DateValue { get; set; } = new byte[11];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public FileTools(Stream file)
|
||||
{
|
||||
InputStream = file;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Functions
|
||||
|
||||
/// <summary>
|
||||
/// Get file size
|
||||
/// </summary>
|
||||
public long size() => InputStream.Length;
|
||||
|
||||
/// <summary>
|
||||
/// Get executable name
|
||||
/// </summary>
|
||||
public string exe()
|
||||
{
|
||||
InputStream.Seek(51744, SeekOrigin.Begin);
|
||||
|
||||
string filename = string.Empty;
|
||||
while (filename != "SYSTEM.CNF")
|
||||
{
|
||||
byte[] buf = new byte[10];
|
||||
InputStream.Read(buf, 0, 10);
|
||||
filename = Encoding.ASCII.GetString(buf);
|
||||
InputStream.Seek(-9, SeekOrigin.Current);
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[20];
|
||||
|
||||
InputStream.Seek(-32, SeekOrigin.Current);
|
||||
InputStream.Read(buffer, 0, 4);
|
||||
uint lba = BitConverter.ToUInt32(buffer, 0);
|
||||
|
||||
InputStream.Seek((2352 * lba) + 29, SeekOrigin.Begin);
|
||||
InputStream.Read(buffer, 0, 6);
|
||||
|
||||
string iniLine = Encoding.ASCII.GetString(buffer);
|
||||
while (iniLine != "cdrom:")
|
||||
{
|
||||
InputStream.Seek(-5, SeekOrigin.Current);
|
||||
InputStream.Read(buffer, 0, 6);
|
||||
iniLine = Encoding.ASCII.GetString(buffer);
|
||||
}
|
||||
|
||||
InputStream.Read(buffer, 0, 1);
|
||||
if (buffer[0] != '\\')
|
||||
InputStream.Seek(-1, SeekOrigin.Current);
|
||||
|
||||
int i = -1;
|
||||
do
|
||||
{
|
||||
InputStream.Read(buffer, ++i, 1);
|
||||
} while (buffer[i] != ';');
|
||||
|
||||
for (long a = 0; a < i; a++)
|
||||
{
|
||||
ExeName[a] = (byte)char.ToUpper((char)buffer[a]);
|
||||
}
|
||||
|
||||
return Encoding.ASCII.GetString(ExeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get human-readable date
|
||||
/// </summary>
|
||||
public string date()
|
||||
{
|
||||
byte[] buffer = new byte[12], datenofrmt = new byte[3];
|
||||
|
||||
InputStream.Seek(51744, SeekOrigin.Begin);
|
||||
|
||||
do
|
||||
{
|
||||
InputStream.Read(buffer, 0, 11);
|
||||
buffer[11] = 0;
|
||||
InputStream.Seek(-10, SeekOrigin.Current);
|
||||
} while (Encoding.ASCII.GetString(ExeName) != Encoding.ASCII.GetString(buffer));
|
||||
|
||||
InputStream.Seek(-16, SeekOrigin.Current);
|
||||
InputStream.Read(datenofrmt, 0, 3);
|
||||
|
||||
if (datenofrmt[0] < 50)
|
||||
{
|
||||
byte[] year = Encoding.ASCII.GetBytes($"{2000 + datenofrmt[0]}");
|
||||
Array.Copy(year, 0, buffer, 0, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] year = Encoding.ASCII.GetBytes($"{1900 + datenofrmt[0]}");
|
||||
Array.Copy(year, 0, buffer, 0, 4);
|
||||
}
|
||||
|
||||
DateValue[4] = (byte)'-';
|
||||
if (datenofrmt[1] < 10)
|
||||
{
|
||||
byte[] month = Encoding.ASCII.GetBytes($"0{datenofrmt[1]}");
|
||||
Array.Copy(month, 0, buffer, 5, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] month = Encoding.ASCII.GetBytes($"{datenofrmt[1]}");
|
||||
Array.Copy(month, 0, buffer, 5, 2);
|
||||
}
|
||||
|
||||
DateValue[7] = (byte)'-';
|
||||
if (datenofrmt[2] < 10)
|
||||
{
|
||||
byte[] day = Encoding.ASCII.GetBytes($"0{datenofrmt[2]}");
|
||||
Array.Copy(day, 0, buffer, 8, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] day = Encoding.ASCII.GetBytes($"{datenofrmt[2]}");
|
||||
Array.Copy(day, 0, buffer, 8, 2);
|
||||
}
|
||||
|
||||
return Encoding.ASCII.GetString(DateValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resize the image
|
||||
/// </summary>
|
||||
public int resize(long newsize)
|
||||
{
|
||||
long oldsize = size();
|
||||
if (oldsize < newsize)
|
||||
{
|
||||
InputStream.SetLength(newsize);
|
||||
return 1;
|
||||
}
|
||||
else if (oldsize > newsize)
|
||||
{
|
||||
InputStream.SetLength(newsize);
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the reported sector count from the image
|
||||
/// </summary>
|
||||
public int imagesize()
|
||||
{
|
||||
InputStream.Seek(0x9368, SeekOrigin.Begin);
|
||||
byte[] sizebuf = new byte[4];
|
||||
InputStream.Read(sizebuf, 0, 4);
|
||||
return BitConverter.ToInt32(sizebuf, 0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
7
LICENSE
Normal file
7
LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2018-2025 Matt Nadareski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
825
LibCrypt.cs
825
LibCrypt.cs
@@ -1,825 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using static psxt001z.Common;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
internal class ScsiPassThroughDirect
|
||||
{
|
||||
public ushort Length { get; set; }
|
||||
|
||||
public byte ScsiStatus { get; set; }
|
||||
|
||||
public byte PathId { get; set; }
|
||||
|
||||
public byte TargetId { get; set; }
|
||||
|
||||
public byte Lun { get; set; }
|
||||
|
||||
public byte CDBLength { get; set; }
|
||||
|
||||
public byte SenseInfoLength { get; set; }
|
||||
|
||||
public byte DataIn { get; set; }
|
||||
|
||||
public uint DataTransferLength { get; set; }
|
||||
|
||||
public uint TimeOutValue { get; set; }
|
||||
|
||||
public byte[]? DataBuffer { get; set; }
|
||||
|
||||
public uint SenseInfoOffset { get; set; }
|
||||
|
||||
public byte[] CDB { get; set; } = new byte[16];
|
||||
}
|
||||
|
||||
public class LibCrypt
|
||||
{
|
||||
#region OLD
|
||||
|
||||
public static bool CheckSubfile(string subFilePath)
|
||||
{
|
||||
// Check the file exists first
|
||||
if (!File.Exists(subFilePath))
|
||||
return false;
|
||||
|
||||
// Check the extension is a subfile
|
||||
string ext = Path.GetExtension(subFilePath).TrimStart('.').ToLowerInvariant();
|
||||
if (ext != "sub")
|
||||
return false;
|
||||
|
||||
// Open and check the subfile for LibCrypt
|
||||
try
|
||||
{
|
||||
using (FileStream subfile = File.OpenRead(subFilePath))
|
||||
{
|
||||
return CheckSubfile(subfile);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckSubfile(Stream subfile)
|
||||
{
|
||||
// Check the length is valid for subfiles
|
||||
long size = subfile.Length;
|
||||
if (size % 96 != 0)
|
||||
return false;
|
||||
|
||||
// Persistent values
|
||||
byte[] buffer = new byte[16];
|
||||
byte[] sub = new byte[16];
|
||||
int tpos = 0;
|
||||
int modifiedSectors = 0;
|
||||
|
||||
// Check each sector for modifications
|
||||
for (uint sector = 150; sector < ((size / 96) + 150); sector++)
|
||||
{
|
||||
subfile.Seek(12, SeekOrigin.Current);
|
||||
if (subfile.Read(buffer, 0, 12) == 0)
|
||||
return modifiedSectors != 0;
|
||||
|
||||
subfile.Seek(72, SeekOrigin.Current);
|
||||
|
||||
// New track
|
||||
if ((btoi(buffer[1]) == (btoi(sub[1]) + 1)) && (buffer[2] == 0 || buffer[2] == 1))
|
||||
{
|
||||
Array.Copy(buffer, sub, 6);
|
||||
tpos = ((btoi((byte)(buffer[3] * 60)) + btoi(buffer[4])) * 75) + btoi(buffer[5]);
|
||||
}
|
||||
|
||||
// New index
|
||||
else if (btoi(buffer[2]) == (btoi(sub[2]) + 1) && buffer[1] == sub[1])
|
||||
{
|
||||
Array.Copy(buffer, 2, sub, 2, 4);
|
||||
tpos = ((btoi((byte)(buffer[3] * 60)) + btoi(buffer[4])) * 75) + btoi(buffer[5]);
|
||||
}
|
||||
|
||||
// MSF1 [3-5]
|
||||
else
|
||||
{
|
||||
if (sub[2] == 0)
|
||||
tpos--;
|
||||
else
|
||||
tpos++;
|
||||
|
||||
sub[3] = itob((byte)(tpos / 60 / 75));
|
||||
sub[4] = itob((byte)((tpos / 75) % 60));
|
||||
sub[5] = itob((byte)(tpos % 75));
|
||||
}
|
||||
|
||||
// MSF2 [7-9]
|
||||
sub[7] = itob((byte)(sector / 60 / 75));
|
||||
sub[8] = itob((byte)((sector / 75) % 60));
|
||||
sub[9] = itob((byte)(sector % 75));
|
||||
|
||||
// CRC-16 [10-11]
|
||||
ushort crc = CRC16.Calculate(sub, 0, 10);
|
||||
byte[] crcBytes = BitConverter.GetBytes(crc);
|
||||
sub[10] = crcBytes[0];
|
||||
sub[11] = crcBytes[1];
|
||||
|
||||
// If any byte (except position 6) is different, it's a modified sector
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
if (i == 6)
|
||||
continue;
|
||||
|
||||
if (buffer[i] != sub[i])
|
||||
{
|
||||
modifiedSectors++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return modifiedSectors != 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constants
|
||||
|
||||
private const uint IOCTL_SCSI_PASS_THROUGH_DIRECT = 0x4D014;
|
||||
private const byte SCSI_IOCTL_DATA_IN = 0x1;
|
||||
private const byte RAW_READ_CMD = 0xBE;
|
||||
private const int BUFFER_LEN = 96;
|
||||
private const int SENSE_SIZE = 0; //14
|
||||
private const string F_NAME = "sectors.log";
|
||||
private const int CYCLES = 5;
|
||||
private const int LIBCRYPT_NUM_SECTORS = 64;
|
||||
private const int READ_TIMES = 5;
|
||||
|
||||
private static readonly uint[] lc_addresses = new uint[LIBCRYPT_NUM_SECTORS]
|
||||
{
|
||||
13955, 13960, 14081, 14086, 14335, 14340, 14429, 14434,
|
||||
14499, 14504, 14749, 14754, 14906, 14911, 14980, 14985,
|
||||
15092, 15097, 15162, 15167, 15228, 15233, 15478, 15483,
|
||||
15769, 15774, 15881, 15886, 15951, 15956, 16017, 16022,
|
||||
41895, 41900, 42016, 42021, 42282, 42287, 42430, 42435,
|
||||
42521, 42526, 42663, 42668, 42862, 42867, 43027, 43032,
|
||||
43139, 43144, 43204, 43209, 43258, 43263, 43484, 43489,
|
||||
43813, 43818, 43904, 43909, 44009, 44014, 44162, 44167
|
||||
};
|
||||
|
||||
private static readonly byte[] lc1_sectors_contents = new byte[768]
|
||||
{
|
||||
0x41, 0x01, 0x01, 0x07, 0x06, 0x05, 0x00, 0x23, 0x08, 0x05, 0x38, 0x39,
|
||||
0x41, 0x01, 0x01, 0x03, 0x06, 0x11, 0x00, 0x03, 0x08, 0x90, 0x5d, 0xa0,
|
||||
0x41, 0x01, 0x01, 0x07, 0x07, 0x56, 0x00, 0x23, 0x09, 0x56, 0xdf, 0xde,
|
||||
0x41, 0x01, 0x01, 0x03, 0x07, 0x60, 0x00, 0x03, 0x09, 0xe1, 0xf2, 0x50,
|
||||
0x41, 0x01, 0x01, 0x03, 0x13, 0x10, 0x00, 0x03, 0x53, 0x10, 0x50, 0xec,
|
||||
0x41, 0x01, 0x01, 0x43, 0x11, 0x15, 0x00, 0x01, 0x13, 0x15, 0x23, 0x1e,
|
||||
0x41, 0x01, 0x01, 0x03, 0x12, 0x09, 0x00, 0x03, 0x14, 0x2d, 0x04, 0x73,
|
||||
0x41, 0x01, 0x01, 0x03, 0x1a, 0x34, 0x00, 0x03, 0x04, 0x34, 0xe2, 0xcf,
|
||||
0x41, 0x01, 0x01, 0x03, 0x13, 0x20, 0x00, 0x03, 0x15, 0x04, 0x82, 0x35,
|
||||
0x41, 0x01, 0x01, 0x01, 0x13, 0x29, 0x00, 0x43, 0x15, 0x29, 0x72, 0xe2,
|
||||
0x41, 0x01, 0x01, 0x03, 0x1e, 0x49, 0x00, 0x03, 0x08, 0x49, 0x32, 0xc5,
|
||||
0x41, 0x01, 0x01, 0x01, 0x16, 0x54, 0x00, 0x43, 0x18, 0x54, 0xd4, 0x79,
|
||||
0x41, 0x01, 0x01, 0x03, 0x18, 0x57, 0x00, 0x03, 0x20, 0xd6, 0xbc, 0x27,
|
||||
0x41, 0x01, 0x01, 0x03, 0x38, 0x61, 0x00, 0x03, 0x24, 0x61, 0x91, 0xa9,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x19, 0x55, 0x00, 0x13, 0x21, 0x55, 0x14, 0x07,
|
||||
0x41, 0x01, 0x01, 0x03, 0x19, 0x62, 0x00, 0x03, 0x21, 0x20, 0x5d, 0x48,
|
||||
0x41, 0x01, 0x01, 0x03, 0x23, 0x17, 0x00, 0x03, 0x63, 0x17, 0x6d, 0xc6,
|
||||
0x41, 0x01, 0x01, 0x43, 0x21, 0x22, 0x00, 0x01, 0x23, 0x22, 0x24, 0x89,
|
||||
0x41, 0x01, 0x01, 0x03, 0x02, 0x12, 0x00, 0x03, 0x20, 0x12, 0x49, 0x43,
|
||||
0x41, 0x01, 0x01, 0x03, 0x22, 0x07, 0x00, 0x03, 0x24, 0x1f, 0x3a, 0xb1,
|
||||
0x41, 0x01, 0x01, 0x03, 0x23, 0x13, 0x00, 0x03, 0x25, 0x0b, 0x93, 0xc9,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x23, 0x08, 0x00, 0x13, 0x25, 0x08, 0xce, 0x5d,
|
||||
0x41, 0x01, 0x01, 0x03, 0x06, 0x28, 0x00, 0x03, 0x2c, 0x28, 0xd7, 0xd6,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x26, 0x33, 0x00, 0x13, 0x28, 0x33, 0x9c, 0x29,
|
||||
0x41, 0x01, 0x01, 0x03, 0x30, 0x59, 0x00, 0x03, 0x32, 0x1b, 0x2c, 0xc6,
|
||||
0x41, 0x01, 0x01, 0x03, 0x20, 0x24, 0x00, 0x03, 0x3a, 0x24, 0xe6, 0xac,
|
||||
0x41, 0x01, 0x01, 0x13, 0x31, 0x56, 0x00, 0x0b, 0x33, 0x56, 0x97, 0xed,
|
||||
0x41, 0x01, 0x01, 0x03, 0x31, 0x65, 0x00, 0x03, 0x33, 0x41, 0xba, 0x63,
|
||||
0x41, 0x01, 0x01, 0x01, 0x32, 0x51, 0x00, 0x43, 0x34, 0x51, 0xd7, 0xa9,
|
||||
0x41, 0x01, 0x01, 0x03, 0x33, 0x56, 0x00, 0x03, 0xb4, 0x56, 0xc0, 0x9a,
|
||||
0x41, 0x01, 0x01, 0x03, 0x32, 0x42, 0x00, 0x03, 0xb5, 0x42, 0x69, 0xe2,
|
||||
0x41, 0x01, 0x01, 0x03, 0x33, 0x07, 0x00, 0x03, 0x35, 0x45, 0x1a, 0x10,
|
||||
0x41, 0x01, 0x01, 0x09, 0x18, 0x65, 0x00, 0x09, 0x20, 0x41, 0x40, 0x72,
|
||||
0x41, 0x01, 0x01, 0x19, 0x18, 0x50, 0x00, 0x01, 0x20, 0x50, 0x25, 0xeb,
|
||||
0x41, 0x01, 0x01, 0x08, 0x20, 0x16, 0x00, 0x89, 0x22, 0x16, 0x95, 0xa8,
|
||||
0x41, 0x01, 0x01, 0x09, 0x20, 0x01, 0x00, 0x09, 0x22, 0x25, 0xb8, 0x26,
|
||||
0x41, 0x01, 0x01, 0x09, 0x23, 0x53, 0x00, 0x09, 0x25, 0x77, 0x21, 0x03,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x23, 0x62, 0x00, 0x49, 0x25, 0x62, 0x68, 0x4c,
|
||||
0x41, 0x01, 0x01, 0x0d, 0x25, 0x55, 0x00, 0x29, 0x27, 0x55, 0xae, 0x41,
|
||||
0x41, 0x01, 0x01, 0x09, 0x25, 0x61, 0x00, 0x09, 0x27, 0xe0, 0xe7, 0x0e,
|
||||
0x41, 0x01, 0x01, 0x08, 0x26, 0x71, 0x00, 0x89, 0x28, 0x71, 0x95, 0xcb,
|
||||
0x41, 0x01, 0x01, 0x09, 0x27, 0x21, 0x00, 0x09, 0x29, 0x05, 0x80, 0x4b,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x28, 0x63, 0x00, 0x49, 0x30, 0x63, 0xed, 0x18,
|
||||
0x41, 0x01, 0x01, 0x09, 0x29, 0x68, 0x00, 0x09, 0xb0, 0x68, 0xb0, 0x8c,
|
||||
0x41, 0x01, 0x01, 0x29, 0x31, 0x37, 0x00, 0x0d, 0x33, 0x37, 0x6c, 0x68,
|
||||
0x41, 0x01, 0x01, 0x09, 0x31, 0x4a, 0x00, 0x09, 0x33, 0x52, 0x7c, 0x8b,
|
||||
0x41, 0x01, 0x01, 0x09, 0x73, 0x52, 0x00, 0x09, 0x37, 0x52, 0x4b, 0x06,
|
||||
0x41, 0x01, 0x01, 0x19, 0x33, 0x57, 0x00, 0x01, 0x35, 0x57, 0x38, 0xf4,
|
||||
0x41, 0x01, 0x01, 0x09, 0x35, 0x04, 0x00, 0x09, 0x37, 0x1c, 0x54, 0x6a,
|
||||
0x41, 0x01, 0x01, 0x09, 0x31, 0x19, 0x00, 0x09, 0x17, 0x19, 0xa4, 0xbd,
|
||||
0x41, 0x01, 0x01, 0x01, 0x36, 0x04, 0x00, 0x19, 0x38, 0x04, 0x9c, 0xdf,
|
||||
0x41, 0x01, 0x01, 0x09, 0x36, 0x0b, 0x00, 0x09, 0x38, 0x49, 0x6c, 0x08,
|
||||
0x41, 0x01, 0x01, 0x49, 0x36, 0x58, 0x00, 0x0b, 0x38, 0x58, 0x99, 0xbf,
|
||||
0x41, 0x01, 0x01, 0x09, 0x36, 0x73, 0x00, 0x09, 0x38, 0x6b, 0xfe, 0x96,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x39, 0x59, 0x00, 0x49, 0x41, 0x59, 0x54, 0x0d,
|
||||
0x41, 0x01, 0x01, 0x09, 0x39, 0x24, 0x00, 0x09, 0x41, 0x66, 0x9e, 0x67,
|
||||
0x41, 0x01, 0x01, 0x09, 0x44, 0x1b, 0x00, 0x09, 0x46, 0x03, 0x78, 0x0d,
|
||||
0x41, 0x01, 0x01, 0x09, 0x46, 0x18, 0x00, 0x09, 0x06, 0x18, 0x25, 0x99,
|
||||
0x41, 0x01, 0x01, 0x09, 0x45, 0x2b, 0x00, 0x09, 0x47, 0x69, 0xd3, 0xc5,
|
||||
0x41, 0x01, 0x01, 0x09, 0x05, 0x34, 0x00, 0x09, 0x45, 0x34, 0x35, 0x79,
|
||||
0x41, 0x01, 0x01, 0x09, 0x44, 0x59, 0x00, 0x09, 0x08, 0x59, 0x6e, 0x0a,
|
||||
0x41, 0x01, 0x01, 0x49, 0x46, 0x64, 0x00, 0x0b, 0x48, 0x64, 0xa4, 0x60,
|
||||
0x41, 0x01, 0x01, 0x09, 0x08, 0x62, 0x00, 0x09, 0x52, 0x62, 0x03, 0x5a,
|
||||
0x41, 0x01, 0x01, 0x19, 0x48, 0x67, 0x00, 0x01, 0x50, 0x67, 0x70, 0xa8
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
// TODO: Enable the following only if reading from a drive directly
|
||||
|
||||
/*
|
||||
internal static byte LibCryptDrive(string[] args)
|
||||
{
|
||||
byte offset = 0;
|
||||
string path = $"\\\\.\\{args[0][0]}:";
|
||||
byte i;
|
||||
byte[] sub = new byte[12], buffer = new byte[BUFFER_LEN], buffer2352 = new byte[23520], buffer2 = new byte[BUFFER_LEN], buffer3 = new byte[BUFFER_LEN], buffer4 = new byte[BUFFER_LEN];
|
||||
byte[] status;
|
||||
ushort crc;
|
||||
uint sector, sector_start, sector_end, a, lcsectors = 0, todo = 9300, done = 0;
|
||||
|
||||
if (args.Length != 1 || (args.Length == 1 && (args[0][1] != 0 && (args[0][1] != ':' || args[0][2] != 0))))
|
||||
{
|
||||
Console.WriteLine("LibCrypt drive detector");
|
||||
Console.WriteLine("nUsage: psxt001z.exe --libcryptdrv <drive letter>");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Stream hDevice;
|
||||
try
|
||||
{
|
||||
hDevice = File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Can't open device!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Stream f;
|
||||
try
|
||||
{
|
||||
f = File.Open(F_NAME, FileMode.Open, FileAccess.Write);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Can't open file {F_NAME}!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
byte[] status1 = new byte[4650];
|
||||
byte[] status2 = new byte[4650];
|
||||
|
||||
// Offset detection
|
||||
Console.WriteLine("Determining offset...\r");
|
||||
ScsiPassThroughDirect SRB = new ScsiPassThroughDirect();
|
||||
ReadSub(buffer, 0, f, offset, hDevice, SRB);
|
||||
|
||||
switch (buffer[8])
|
||||
{
|
||||
case 0x01:
|
||||
offset = (byte)(75 - btoi(buffer[9]));
|
||||
break;
|
||||
case 0x02:
|
||||
offset = (byte)(-btoi(buffer[9]));
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Can't determine offset!");
|
||||
Console.WriteLine(BitConverter.ToString(buffer).Replace('-', ' '));
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub[0] = buffer[0];
|
||||
sub[1] = 0x01;
|
||||
sub[2] = 0x01;
|
||||
sub[6] = 0x00;
|
||||
|
||||
Console.WriteLine($"Subchannels offset correction: {offset}");
|
||||
|
||||
// Section 1) 02:58:00 - 03:69:74 -- status1
|
||||
// Section 2) 08:58:00 - 09:69:74 -- status2
|
||||
|
||||
// Step 1
|
||||
|
||||
for (i = 0; i < CYCLES * 3; i++)
|
||||
{
|
||||
|
||||
if (todo == 0)
|
||||
goto end;
|
||||
|
||||
if (i % 3 == 0)
|
||||
{
|
||||
sector_start = 13350;
|
||||
sector_end = 18000;
|
||||
status = status1;
|
||||
}
|
||||
else if (i % 3 == 1)
|
||||
{
|
||||
sector_start = 40350;
|
||||
sector_end = 45000;
|
||||
status = status2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Left: {todo:4} / Flushing cache... \r");
|
||||
ClearCache(buffer2352, f, offset, hDevice, SRB);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (sector = sector_start; sector < sector_end; sector++)
|
||||
{
|
||||
if (status[sector - sector_start] != 0)
|
||||
continue;
|
||||
|
||||
ReadSub(buffer, sector, f, offset, hDevice, SRB);
|
||||
Console.WriteLine("Left: %4u / Sector %u... \r", todo, sector);
|
||||
// generating q-channel
|
||||
sub[3] = itob((byte)(sector / 60 / 75));
|
||||
sub[4] = itob((byte)((sector / 75) % 60));
|
||||
sub[5] = itob((byte)(sector % 75));
|
||||
sub[7] = itob((byte)((sector + 150) / 60 / 75));
|
||||
sub[8] = itob((byte)(((sector + 150) / 75) % 60));
|
||||
sub[9] = itob((byte)((sector + 150) % 75));
|
||||
crc = CRC16.Calculate(sub, 0, 10);
|
||||
sub[10] = (byte)(crc >> 8);
|
||||
sub[11] = (byte)(crc & 0xFF);
|
||||
if (sub.SequenceEqual(buffer.Take(12)))
|
||||
{
|
||||
status[sector - sector_start] = 1;
|
||||
todo--;
|
||||
done++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
sector_start = 13350;
|
||||
sector_end = 18000;
|
||||
status = status1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sector_start = 40350;
|
||||
sector_end = 45000;
|
||||
status = status2;
|
||||
}
|
||||
|
||||
for (sector = sector_start; sector < sector_end; sector++)
|
||||
{
|
||||
if (status[sector - sector_start] != 0)
|
||||
continue;
|
||||
ReadSub(buffer, sector, f, offset, hDevice, SRB);
|
||||
Console.WriteLine($"Left: {todo:4} / Sector {sector}... \r");
|
||||
|
||||
// generating q-channel
|
||||
sub[3] = itob((byte)(sector / 60 / 75));
|
||||
sub[4] = itob((byte)((sector / 75) % 60));
|
||||
sub[5] = itob((byte)(sector % 75));
|
||||
sub[7] = itob((byte)((sector + 150) / 60 / 75));
|
||||
sub[8] = itob((byte)(((sector + 150) / 75) % 60));
|
||||
sub[9] = itob((byte)((sector + 150) % 75));
|
||||
crc = CRC16.Calculate(sub, 0, 10);
|
||||
sub[10] = (byte)(crc >> 8);
|
||||
sub[11] = (byte)(crc ^ 0xFF);
|
||||
if (sub.SequenceEqual(buffer.Take(12)))
|
||||
{
|
||||
Console.WriteLine($"Left: {todo:4} / Sector {sector}: flushing cache... \r");
|
||||
do
|
||||
{
|
||||
ReadSub(buffer, sector, f, offset, hDevice, SRB);
|
||||
ClearCache(buffer2352, f, offset, hDevice, SRB);
|
||||
ReadSub(buffer2, sector, f, offset, hDevice, SRB);
|
||||
ClearCache(buffer2352, f, offset, hDevice, SRB);
|
||||
ReadSub(buffer3, sector, f, offset, hDevice, SRB);
|
||||
ClearCache(buffer2352, f, offset, hDevice, SRB);
|
||||
} while (!buffer.SequenceEqual(buffer2) || !buffer.SequenceEqual(buffer3));
|
||||
//} while (!matrix(buffer, buffer2, buffer3, buffer4, BUFFER_LEN));
|
||||
|
||||
if (buffer.SequenceEqual(sub))
|
||||
{
|
||||
byte[] buf = Encoding.ASCII.GetBytes($"MSF: {sub[7]:2x}:{sub[8]:2x}:{sub[9]:2x} Q-Data: {BitConverter.ToString(buffer.Take(12).ToArray()).Replace('-', ' ')}");
|
||||
f.Write(buf, 0, buf.Length);
|
||||
lcsectors++;
|
||||
//fwrite(SRB.SRB_BufPointer, 1, SRB.SRB_BufLen - 4, f);
|
||||
f.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
todo--;
|
||||
done++;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
Console.WriteLine($"Done! \nProtected sectors: {(lcsectors == 0 ? "None" : lcsectors.ToString())}");
|
||||
|
||||
f.Close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
internal static int LibCryptDriveFast(string[] args)
|
||||
{
|
||||
Stream f;
|
||||
Stream hDevice;
|
||||
ScsiPassThroughDirect SRB;
|
||||
s8 offset = 0, path[] = "\\\\.\\X:";
|
||||
u8 buffer[BUFFER_LEN], buffer2352[23520], sub[12], lc1sectors = 0, lc2sectors = 0, othersectors = 0;
|
||||
u16 crc;
|
||||
|
||||
if (argc != 1 || (argc == 1 && (args[0][1] != 0 && (args[0][1] != ':' || args[0][2] != 0))))
|
||||
{
|
||||
Console.WriteLine("LibCrypt drive detector (fast)\nUsage: psxt001z.exe --libcryptdrvfast <drive letter>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
path[4] = args[0][0];
|
||||
|
||||
if ((hDevice = CreateFile(path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
Console.WriteLine("Can't open device!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fopen_s(&f, F_NAME, "wb") != 0)
|
||||
{
|
||||
Console.WriteLine("Can\'t open file %s!\n", F_NAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Offset detection
|
||||
ReadSub(buffer, 0, f, offset, hDevice, SRB);
|
||||
//if (buffer[5] != buffer[9]) {
|
||||
// Console.WriteLine("Error determining offset!\nSector 0: %02x%02x%02x %02x:%02x:%02x %02x %02x:%02x:%02x %02x%02x\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9], buffer[10], buffer[11]);
|
||||
//}
|
||||
switch (buffer[8])
|
||||
{
|
||||
case 0x01:
|
||||
offset = 75 - btoi(buffer[9]);
|
||||
break;
|
||||
case 0x02:
|
||||
offset = -btoi(buffer[9]);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Can't determine offset!\nSector 0: %02x%02x%02x %02x:%02x:%02x %02x %02x:%02x:%02x %02x%02x\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9], buffer[10], buffer[11]);
|
||||
return 0;
|
||||
}
|
||||
Console.WriteLine("Subchannels offset correction: %d\n", offset);
|
||||
sub[0] = buffer[0];
|
||||
sub[1] = 0x01;
|
||||
sub[2] = 0x01;
|
||||
sub[6] = 0x00;
|
||||
|
||||
for (int i = 0; i < LIBCRYPT_NUM_SECTORS; i++)
|
||||
{
|
||||
Console.WriteLine("\nReading sector %u... ", lc_addresses[i]);
|
||||
ReadSub(buffer, lc_addresses[i], f, offset, hDevice, SRB);
|
||||
// generating q-channel
|
||||
sub[3] = itob(lc_addresses[i] / 60 / 75);
|
||||
sub[4] = itob((lc_addresses[i] / 75) % 60);
|
||||
sub[5] = itob(lc_addresses[i] % 75);
|
||||
sub[7] = itob((lc_addresses[i] + 150) / 60 / 75);
|
||||
sub[8] = itob(((lc_addresses[i] + 150) / 75) % 60);
|
||||
sub[9] = itob((lc_addresses[i] + 150) % 75);
|
||||
crc = crc16(sub, 10);
|
||||
sub[10] = HIbyte(crc);
|
||||
sub[11] = LObyte(crc);
|
||||
for (int a = 1; a <= READ_TIMES; a++)
|
||||
{
|
||||
if (!memcmp(sub, buffer, 12))
|
||||
{
|
||||
Console.WriteLine("original sector");
|
||||
break;
|
||||
}
|
||||
else if (!memcmp(lc1_sectors_contents + (12 * i), buffer, 12))
|
||||
{
|
||||
Console.WriteLine("LibCrypt, LC1 sector");
|
||||
fConsole.WriteLine(f, "MSF: %02x:%02x:%02x Q-Data: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", sub[7], sub[8], sub[9], buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9], buffer[10], buffer[11]);
|
||||
lc1sectors++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (a < READ_TIMES)
|
||||
{
|
||||
ClearCache(buffer2352, 0, offset, hDevice, SRB);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("unknown");
|
||||
fConsole.WriteLine(f, "MSF: %02x:%02x:%02x Q-Data: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", sub[7], sub[8], sub[9], buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9], buffer[10], buffer[11]);
|
||||
othersectors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Console.WriteLine("\n\nOriginal sectors: %u", LIBCRYPT_NUM_SECTORS - lc1sectors - lc2sectors - othersectors);
|
||||
Console.WriteLine("\nLC1 sectors: %u", lc1sectors);
|
||||
Console.WriteLine("\nLC2 sectors: %u", lc2sectors);
|
||||
Console.WriteLine("\nOther sectors: %u", othersectors);
|
||||
|
||||
fConsole.WriteLine(f, "\nOriginal sectors: %u", LIBCRYPT_NUM_SECTORS - lc1sectors - lc2sectors - othersectors);
|
||||
fConsole.WriteLine(f, "\nLC1 sectors: %u", lc1sectors);
|
||||
fConsole.WriteLine(f, "\nLC2 sectors: %u", lc2sectors);
|
||||
fConsole.WriteLine(f, "\nOther sectors: %u", othersectors);
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
internal static void ReadSub(byte[] buffer, uint sector, Stream f, byte offset, Stream hDevice, ScsiPassThroughDirect SRB)
|
||||
{
|
||||
uint returned;
|
||||
ZeroMemory(&SRB, sizeof(ScsiPassThroughDirect));
|
||||
SRB.Length = sizeof(ScsiPassThroughDirect);
|
||||
SRB.CDBLength = 12;
|
||||
SRB.DataIn = SCSI_IOCTL_DATA_IN;
|
||||
SRB.DataTransferLength = BUFFER_LEN;
|
||||
SRB.TimeOutValue = 30;
|
||||
SRB.DataBuffer = buffer;
|
||||
SRB.CDB[0] = RAW_READ_CMD;
|
||||
SRB.CDB[2] = HIbyte(HIWORD(sector + offset));
|
||||
SRB.CDB[3] = LObyte(HIWORD(sector + offset));
|
||||
SRB.CDB[4] = HIbyte(LOWORD(sector + offset));
|
||||
SRB.CDB[5] = LObyte(LOWORD(sector + offset));
|
||||
SRB.CDB[8] = 1;
|
||||
SRB.CDB[10] = 1;
|
||||
|
||||
if (!DeviceIoControl(hDevice, IOCTL_SCSI_PASS_THROUGH_DIRECT, &SRB, sizeof(ScsiPassThroughDirect), &SRB, SENSE_SIZE, &returned, 0))
|
||||
{
|
||||
Console.WriteLine("\nError reading subchannel data!\n");
|
||||
if (f != 0)
|
||||
fConsole.WriteLine(f, "Error reading subchannel data!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Deinterleave(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
internal static void ClearCache(byte[] buffer, Stream f, byte offset, Stream hDevice, ScsiPassThroughDirect SRB)
|
||||
{
|
||||
static uint returned;
|
||||
for (uint sector = 0; sector < 1000; sector += 10)
|
||||
{
|
||||
ZeroMemory(&SRB, sizeof(ScsiPassThroughDirect));
|
||||
SRB.Length = sizeof(ScsiPassThroughDirect);
|
||||
SRB.CDBLength = 12;
|
||||
SRB.DataIn = SCSI_IOCTL_DATA_IN;
|
||||
SRB.DataTransferLength = 23520;
|
||||
SRB.TimeOutValue = 30;
|
||||
SRB.DataBuffer = buffer;
|
||||
SRB.CDB[0] = RAW_READ_CMD;
|
||||
SRB.CDB[2] = HIbyte(HIWORD(sector + offset));
|
||||
SRB.CDB[3] = LObyte(HIWORD(sector + offset));
|
||||
SRB.CDB[4] = HIbyte(LOWORD(sector + offset));
|
||||
SRB.CDB[5] = LObyte(LOWORD(sector + offset));
|
||||
SRB.CDB[8] = 10;
|
||||
SRB.CDB[9] = 0xF8;
|
||||
|
||||
DeviceIoControl(hDevice, IOCTL_SCSI_PASS_THROUGH_DIRECT, &SRB, sizeof(ScsiPassThroughDirect), &SRB, SENSE_SIZE, &returned, 0);
|
||||
|
||||
if (!DeviceIoControl(hDevice, IOCTL_SCSI_PASS_THROUGH_DIRECT, &SRB, sizeof(ScsiPassThroughDirect), &SRB, SENSE_SIZE, &returned, 0))
|
||||
{
|
||||
Console.WriteLine("\nError clearing cache!\n");
|
||||
if (f != 0)
|
||||
fConsole.WriteLine(f, "Error clearing cache!");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
internal static bool Matrix(byte[] buffer, byte[] buffer2, byte[] buffer3, byte[] buffer4, uint length)
|
||||
{
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
if (buffer[i] == buffer2[i])
|
||||
{
|
||||
if (buffer[i] == buffer3[i])
|
||||
continue;
|
||||
if (buffer[i] == buffer4[i])
|
||||
continue;
|
||||
}
|
||||
else if (buffer[i] == buffer3[i] && buffer[i] == buffer4[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (buffer2[i] == buffer3[i] && buffer2[i] == buffer4[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static void Deinterleave(byte[] buffer)
|
||||
{
|
||||
byte[] buffertmp = new byte[12];
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
buffertmp[i] |= (byte)((buffer[i * 8] & 0x40) << 1);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 1] & 0x40));
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 2] & 0x40) >> 1);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 3] & 0x40) >> 2);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 4] & 0x40) >> 3);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 5] & 0x40) >> 4);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 6] & 0x40) >> 5);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 7] & 0x40) >> 6);
|
||||
}
|
||||
|
||||
Array.Copy(buffertmp, buffer, 12);
|
||||
return;
|
||||
}
|
||||
|
||||
internal static bool LibCryptDetect(string subPath, string? sbiPath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(subPath) || !File.Exists(subPath))
|
||||
return false;
|
||||
|
||||
// Variables
|
||||
byte[] buffer = new byte[16], sub = new byte[16];//, pregap = 0;
|
||||
uint sector, psectors = 0, tpos = 0;
|
||||
|
||||
// Opening .sub
|
||||
Stream subfile = File.OpenRead(subPath);
|
||||
|
||||
// checking extension
|
||||
if (Path.GetExtension(subPath).TrimStart('.').ToLowerInvariant() != "sub")
|
||||
{
|
||||
Console.WriteLine($"{subPath}: unknown file extension");
|
||||
return false;
|
||||
}
|
||||
|
||||
// filesize
|
||||
long size = subfile.Length;
|
||||
if (size % 96 != 0)
|
||||
{
|
||||
Console.WriteLine($"{subfile}: wrong size");
|
||||
return false;
|
||||
}
|
||||
|
||||
// sbi
|
||||
Stream? sbi = null;
|
||||
if (sbiPath != null)
|
||||
{
|
||||
sbi = File.OpenWrite(sbiPath);
|
||||
sbi.Write(Encoding.ASCII.GetBytes("SBI\0"), 0, 4);
|
||||
}
|
||||
|
||||
for (sector = 150; sector < ((size / 96) + 150); sector++)
|
||||
{
|
||||
subfile.Seek(12, SeekOrigin.Current);
|
||||
if (subfile.Read(buffer, 0, 12) != 12)
|
||||
return true;
|
||||
|
||||
subfile.Seek(72, SeekOrigin.Current);
|
||||
|
||||
// New track
|
||||
if ((btoi(buffer[1]) == (btoi(sub[1]) + 1)) && (buffer[2] == 0 || buffer[2] == 1))
|
||||
{
|
||||
Array.Copy(buffer, sub, 6);
|
||||
tpos = (uint)((btoi((byte)(buffer[3] * 60)) + btoi(buffer[4])) * 75) + btoi(buffer[5]);
|
||||
}
|
||||
|
||||
// New index
|
||||
else if (btoi(buffer[2]) == (btoi(sub[2]) + 1) && buffer[1] == sub[1])
|
||||
{
|
||||
Array.Copy(buffer, 2, sub, 2, 4);
|
||||
tpos = (uint)((btoi((byte)(buffer[3] * 60)) + btoi(buffer[4])) * 75) + btoi(buffer[5]);
|
||||
}
|
||||
|
||||
// MSF1 [3-5]
|
||||
else
|
||||
{
|
||||
if (sub[2] == 0)
|
||||
tpos--;
|
||||
else
|
||||
tpos++;
|
||||
|
||||
sub[3] = itob((byte)(tpos / 60 / 75));
|
||||
sub[4] = itob((byte)((tpos / 75) % 60));
|
||||
sub[5] = itob((byte)(tpos % 75));
|
||||
}
|
||||
|
||||
//MSF2 [7-9]
|
||||
sub[7] = itob((byte)(sector / 60 / 75));
|
||||
sub[8] = itob((byte)((sector / 75) % 60));
|
||||
sub[9] = itob((byte)(sector % 75));
|
||||
|
||||
// CRC-16 [10-11]
|
||||
ushort crc = CRC16.Calculate(sub, 0, 10);
|
||||
sub[10] = (byte)(crc >> 8);
|
||||
sub[11] = (byte)(crc & 0xFF);
|
||||
|
||||
//if (buffer[10] != sub[10] && buffer[11] != sub[11] && (buffer[3] != sub[3] || buffer[7] != sub[7] || buffer[4] != sub[4] || buffer[8] != sub[8] || buffer[5] != sub[5] || buffer[9] != sub[9])) {
|
||||
//if (buffer[10] != sub[10] || buffer[11] != sub[11] || buffer[3] != sub[3] || buffer[7] != sub[7] || buffer[4] != sub[4] || buffer[8] != sub[8] || buffer[5] != sub[5] || buffer[9] != sub[9]) {
|
||||
if (!buffer.Take(6).SequenceEqual(sub.Take(6)) || !buffer.Skip(7).Take(5).SequenceEqual(sub.Skip(7).Take(5)))
|
||||
{
|
||||
Console.WriteLine($"MSF: {sub[7]:2x}:{sub[8]:2x}:{sub[9]:2x} Q-Data: {buffer[0]:2x}{buffer[1]:2x}{buffer[2]:2x} {buffer[3]:2x}:{buffer[4]:2x}:{buffer[5]:2x} {buffer[6]:2x} {buffer[7]:2x}:{buffer[8]:2x}:{buffer[9]:2x} {buffer[10]:2x}{buffer[11]:2x} xor {crc ^ ((buffer[10] << 8) + buffer[11]):4x} {CRC16.Calculate(buffer, 0, 10) ^ ((buffer[10] << 8) + buffer[11]):4x}");
|
||||
//Console.WriteLine("\nMSF: %02x:%02x:%02x Q-Data: %02x%02x%02x %02x:%02x:%02x %02x %02x:%02x:%02x %02x%02x", sub[7], sub[8], sub[9], sub[0], sub[1], sub[2], sub[3], sub[4], sub[5], sub[6], sub[7], sub[8], sub[9], sub[10], sub[11]);
|
||||
|
||||
if (buffer[3] != sub[3] && buffer[7] != sub[7] && buffer[4] == sub[4] && buffer[8] == sub[8] && buffer[5] == sub[5] && buffer[9] == sub[9])
|
||||
Console.WriteLine($" P1 xor {buffer[3] ^ sub[3]:2x} {buffer[7] ^ sub[7]:2x}");
|
||||
else if (buffer[3] == sub[3] && buffer[7] == sub[7] && buffer[4] != sub[4] && buffer[8] != sub[8] && buffer[5] == sub[5] && buffer[9] == sub[9])
|
||||
Console.WriteLine($" P2 xor {buffer[4] ^ sub[4]:2x} {buffer[8] ^ sub[8]:2x}");
|
||||
else if (buffer[3] == sub[3] && buffer[7] == sub[7] && buffer[4] == sub[4] && buffer[8] == sub[8] && buffer[5] != sub[5] && buffer[9] != sub[9])
|
||||
Console.WriteLine($" P3 xor {buffer[5] ^ sub[5]:2x} {buffer[9] ^ sub[9]:2x}");
|
||||
else
|
||||
Console.WriteLine(" ?");
|
||||
|
||||
Console.WriteLine("\n");
|
||||
psectors++;
|
||||
if (sbi != null)
|
||||
{
|
||||
sbi.Write(sub, 7, 3);
|
||||
sbi.Write(new byte[] { 0x01 }, 0, 1);
|
||||
sbi.Write(buffer, 0, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
Console.WriteLine($"Number of modified sectors: {psectors}");
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static int XorLibCrypt()
|
||||
{
|
||||
sbyte b;
|
||||
byte d;
|
||||
byte i, a, x;
|
||||
byte[] sub = new byte[12]
|
||||
{
|
||||
0x41, 0x01, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
ushort crc;
|
||||
for (i = 0; i < LIBCRYPT_NUM_SECTORS; i++)
|
||||
{
|
||||
sub[3] = itob((byte)(lc_addresses[i] / 60 / 75));
|
||||
sub[4] = itob((byte)((lc_addresses[i] / 75) % 60));
|
||||
sub[5] = itob((byte)(lc_addresses[i] % 75));
|
||||
sub[7] = itob((byte)((lc_addresses[i] + 150) / 60 / 75));
|
||||
sub[8] = itob((byte)(((lc_addresses[i] + 150) / 75) % 60));
|
||||
sub[9] = itob((byte)((lc_addresses[i] + 150) % 75));
|
||||
crc = CRC16.Calculate(sub, 0, 10);
|
||||
sub[10] = (byte)(crc >> 8);
|
||||
sub[11] = (byte)(crc & 0xFF);
|
||||
|
||||
Console.WriteLine($"%u %02x:%02x:%02x", lc_addresses[i], sub[7], sub[8], sub[9]);
|
||||
Console.WriteLine($" %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x", sub[0], sub[1], sub[2], sub[3], sub[4], sub[5], sub[6], sub[7], sub[8], sub[9], sub[10], sub[11]);
|
||||
Console.WriteLine($" %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %02x%02x", lc1_sectors_contents[i * 12], lc1_sectors_contents[(i * 12) + 1], lc1_sectors_contents[(i * 12) + 2], lc1_sectors_contents[(i * 12) + 3], lc1_sectors_contents[(i * 12) + 4], lc1_sectors_contents[(i * 12) + 5], lc1_sectors_contents[(i * 12) + 6], lc1_sectors_contents[(i * 12) + 7], lc1_sectors_contents[(i * 12) + 8], lc1_sectors_contents[(i * 12) + 9], lc1_sectors_contents[(i * 12) + 10], lc1_sectors_contents[(i * 12) + 11]);
|
||||
|
||||
d = 0;
|
||||
|
||||
for (a = 3; a < 12; a++)
|
||||
{
|
||||
x = (byte)(lc1_sectors_contents[(i * 12) + a] ^ sub[a]);
|
||||
Console.WriteLine($" %x%x%x%x%x%x%x%x", (x >> 7) & 0x1, (x >> 6) & 0x1, (x >> 5) & 0x1, (x >> 4) & 0x1, (x >> 3) & 0x1, (x >> 2) & 0x1, (x >> 1) & 0x1, x & 0x1);
|
||||
if (x == 0)
|
||||
continue;
|
||||
for (b = 7; b >= 0; b--)
|
||||
{
|
||||
if (((x >> b) & 0x1) != 0)
|
||||
{
|
||||
d = (byte)(d << 1);
|
||||
d |= (byte)((sub[a] >> b) & 0x1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($" {(d >> 3) & 0x1:x}{(d >> 2) & 0x1:x}{(d >> 1) & 0x1:x}{d & 0x1}");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
README.MD
10
README.MD
@@ -1,5 +1,13 @@
|
||||
# psxt001z
|
||||
|
||||
[](https://github.com/SabreTools/psxt001z/actions/workflows/build_and_test.yml)
|
||||
|
||||
This library is a mostly-complete port of the [tool of the same name](https://github.com/Dremora/psxt001z) by [Dremora](https://github.com/Dremora/). This currently compiles as a library and does not feature any of the direct disc reading that the original tool did. There are aspirations to changes this in the future.
|
||||
|
||||
Find the link to the Nuget package [here](https://www.nuget.org/packages/psxt001z).
|
||||
Find the link to the Nuget package [here](https://www.nuget.org/packages/psxt001z.Library/).
|
||||
|
||||
## Releases
|
||||
|
||||
For the most recent stable build, download the latest release here: [Releases Page](https://github.com/SabreTools/psxt001z/releases)
|
||||
|
||||
For the latest WIP build here: [Rolling Release](https://github.com/SabreTools/psxt001z/releases/tag/rolling)
|
||||
|
||||
310
Track.cs
310
Track.cs
@@ -1,310 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
internal class Track
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Original input path for the track
|
||||
/// </summary>
|
||||
private string InputPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Stream representing the track data
|
||||
/// </summary>
|
||||
private Stream InputStream { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Output for saving the track data
|
||||
/// </summary>
|
||||
private string? OutputPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Starting offset within the file
|
||||
/// </summary>
|
||||
private int Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of the input file
|
||||
/// </summary>
|
||||
private int Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CRC-32 of the track data to compare against
|
||||
/// </summary>
|
||||
private uint CRC32 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Audio data header
|
||||
/// </summary>
|
||||
private byte[] RiffData { get; set; } = new byte[44];
|
||||
|
||||
/// <summary>
|
||||
/// True if the track is audio data
|
||||
/// </summary>
|
||||
private bool IsRiff { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if the file is under ~100MB
|
||||
/// </summary>
|
||||
private bool SmallFile { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// True to write out the track data
|
||||
/// </summary>
|
||||
private bool SaveTrack { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True means '+' or 'p'
|
||||
/// False means '-' or 'n'
|
||||
/// Null means neither
|
||||
/// </summary>
|
||||
private bool? Mode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cache for small file data
|
||||
/// </summary>
|
||||
private byte[]? FileContents { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cached file offset
|
||||
/// </summary>
|
||||
private int Offset { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Current file offset
|
||||
/// </summary>
|
||||
private int Current { get; set; } = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public Track(string filename, int start, int size, uint crc, bool isRiff = false, bool? mode = null, string? output = null)
|
||||
{
|
||||
InputPath = filename;
|
||||
InputStream = File.OpenRead(filename);
|
||||
OutputPath = output;
|
||||
|
||||
Start = start;
|
||||
Size = size;
|
||||
CRC32 = crc;
|
||||
Mode = mode;
|
||||
|
||||
IsRiff = isRiff;
|
||||
SmallFile = Size <= 100_000_000;
|
||||
SaveTrack = output != null;
|
||||
|
||||
Console.WriteLine($"File: {InputPath}\nStart: {Start}\nSize: {Size}\nCRC-32: {CRC32:8x}");
|
||||
Console.WriteLine();
|
||||
|
||||
if (IsRiff)
|
||||
PopulateRiffData();
|
||||
|
||||
if (SmallFile)
|
||||
CacheFileData();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Functions
|
||||
|
||||
public bool FindTrack()
|
||||
{
|
||||
// Positive mode
|
||||
if (Mode == true)
|
||||
{
|
||||
if (Current > 20000)
|
||||
{
|
||||
Mode = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
Offset = Current;
|
||||
Current += 4;
|
||||
return MatchesCRC();
|
||||
}
|
||||
|
||||
// Negative mode
|
||||
else if (Mode == false)
|
||||
{
|
||||
if (Current > 20000)
|
||||
{
|
||||
Mode = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
Offset = -Current;
|
||||
Current += 4;
|
||||
return MatchesCRC();
|
||||
}
|
||||
|
||||
// Neutral mode
|
||||
else
|
||||
{
|
||||
if (Current > 20000)
|
||||
{
|
||||
Mode = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
Offset = Current;
|
||||
if (MatchesCRC())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Offset = -Current;
|
||||
Current += 4;
|
||||
return MatchesCRC();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MatchesCRC()
|
||||
{
|
||||
CRC32 calc = new CRC32();
|
||||
if (SmallFile)
|
||||
{
|
||||
if (IsRiff)
|
||||
calc.ProcessCRC(RiffData, 0, 44);
|
||||
|
||||
calc.ProcessCRC(FileContents, (int)(20000 + Offset), (int)Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
InputStream.Seek(Start + Offset, SeekOrigin.Begin);
|
||||
if (IsRiff)
|
||||
calc.ProcessCRC(RiffData, 0, 44);
|
||||
|
||||
for (long i = 0; i < Size; i++)
|
||||
{
|
||||
byte[] buffer = new byte[1];
|
||||
if (InputStream.Read(buffer, 0, 1) != 1)
|
||||
{
|
||||
buffer[0] = 0x00;
|
||||
InputStream.Seek(Start + Offset + i + 1, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
calc.ProcessCRC(buffer, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Console.Write($"Offset correction {Offset} bytes, {Offset / 4} samples, CRC-32 {calc.m_crc32:8x}");
|
||||
return (calc.m_crc32 == CRC32);
|
||||
}
|
||||
|
||||
public void Done()
|
||||
{
|
||||
if (SmallFile)
|
||||
FileContents = null;
|
||||
|
||||
if (Mode == null)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Can't find offset!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (SaveTrack)
|
||||
{
|
||||
byte[] buffer = new byte[1];
|
||||
Stream f2 = File.Open(OutputPath ?? "default", FileMode.Create, FileAccess.ReadWrite);
|
||||
if (IsRiff)
|
||||
f2.Write(RiffData, 0, 44);
|
||||
|
||||
InputStream.Seek(Start + Offset, SeekOrigin.Begin);
|
||||
for (long i = 0; i < Size; i++)
|
||||
{
|
||||
if (InputStream.Read(buffer, 0, 1) != 1)
|
||||
{
|
||||
buffer[0] = 0x00;
|
||||
InputStream.Seek(Start + Offset + i + 1, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
f2.Write(buffer, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.Write("DONE!");
|
||||
Console.WriteLine();
|
||||
Console.Write($"Offset correction: {Offset} bytes / {Offset / 4} samples");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utilities
|
||||
|
||||
// TODO: Figure out what this actually does
|
||||
private void CacheFileData()
|
||||
{
|
||||
FileContents = new byte[Size + 40000];
|
||||
InputStream.Seek(Start - 20000, SeekOrigin.Begin);
|
||||
|
||||
for (int i = 0; i < Size + 40000; i++)
|
||||
{
|
||||
if (Start + i <= 20000)
|
||||
InputStream.Seek(Start + i - 20000, SeekOrigin.Begin);
|
||||
|
||||
if (InputStream.Read(new byte[1], 0, 1) != 1)
|
||||
FileContents[i] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateRiffData()
|
||||
{
|
||||
RiffData[0] = 0x52;
|
||||
RiffData[1] = 0x49;
|
||||
RiffData[2] = 0x46;
|
||||
RiffData[3] = 0x46;
|
||||
|
||||
byte[] temp = BitConverter.GetBytes(Size - 8);
|
||||
Array.Copy(temp, 0, RiffData, 4, 4);
|
||||
|
||||
RiffData[8] = 0x57;
|
||||
RiffData[9] = 0x41;
|
||||
RiffData[10] = 0x56;
|
||||
RiffData[11] = 0x45;
|
||||
RiffData[12] = 0x66;
|
||||
RiffData[13] = 0x6D;
|
||||
RiffData[14] = 0x74;
|
||||
RiffData[15] = 0x20;
|
||||
RiffData[16] = 0x10;
|
||||
RiffData[17] = 0x00;
|
||||
RiffData[18] = 0x00;
|
||||
RiffData[19] = 0x00;
|
||||
RiffData[20] = 0x01;
|
||||
RiffData[21] = 0x00;
|
||||
RiffData[22] = 0x02;
|
||||
RiffData[23] = 0x00;
|
||||
RiffData[24] = 0x44;
|
||||
RiffData[25] = 0xAC;
|
||||
RiffData[26] = 0x00;
|
||||
RiffData[27] = 0x00;
|
||||
RiffData[28] = 0x10;
|
||||
RiffData[29] = 0xB1;
|
||||
RiffData[30] = 0x02;
|
||||
RiffData[31] = 0x00;
|
||||
RiffData[32] = 0x04;
|
||||
RiffData[33] = 0x00;
|
||||
RiffData[34] = 0x10;
|
||||
RiffData[35] = 0x00;
|
||||
RiffData[36] = 0x64;
|
||||
RiffData[37] = 0x61;
|
||||
RiffData[38] = 0x74;
|
||||
RiffData[39] = 0x61;
|
||||
|
||||
temp = BitConverter.GetBytes(Size - 44);
|
||||
Array.Copy(temp, 0, RiffData, 40, 4);
|
||||
|
||||
Size -= 44;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
namespace psxt001z
|
||||
{
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/functions.cpp"/>
|
||||
public class CRC16
|
||||
{
|
||||
// Table of CRC constants - implements x^16+x^12+x^5+1
|
||||
private static ushort[] CRC16Table = new ushort[]
|
||||
{
|
||||
/// <summary>
|
||||
/// Table of CRC constants - implements x^16+x^12+x^5+1
|
||||
/// </summary>
|
||||
private static readonly ushort[] table =
|
||||
[
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
||||
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
|
||||
@@ -37,14 +40,14 @@
|
||||
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
||||
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
||||
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
|
||||
};
|
||||
];
|
||||
|
||||
public static ushort Calculate(byte[] buf, int bufPtr, int len)
|
||||
{
|
||||
ushort cksum = 0;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
cksum = (ushort)(CRC16Table[((cksum >> 8) ^ buf[bufPtr++]) & 0xFF] ^ (cksum << 8));
|
||||
cksum = (ushort)(table[((cksum >> 8) ^ buf[bufPtr++]) & 0xFF] ^ (cksum << 8));
|
||||
}
|
||||
|
||||
return (ushort)(~cksum);
|
||||
42
psxt001z.Library/CRC32.cs
Normal file
42
psxt001z.Library/CRC32.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace psxt001z
|
||||
{
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/main.cpp"/>
|
||||
public class CRC32
|
||||
{
|
||||
private const uint CRC_POLY = 0xEDB88320;
|
||||
|
||||
private const uint CRC_MASK = 0xD202EF8D;
|
||||
|
||||
private readonly uint[] table = new uint[256];
|
||||
|
||||
public uint Hash { get; private set; }
|
||||
|
||||
public CRC32()
|
||||
{
|
||||
for (uint i = 0; i < 256; i++)
|
||||
{
|
||||
uint r, j;
|
||||
for (r = i, j = 8; j != 0; j--)
|
||||
{
|
||||
r = ((r & 1) != 0) ? (r >> 1) ^ CRC_POLY : r >> 1;
|
||||
}
|
||||
|
||||
table[i] = r;
|
||||
}
|
||||
|
||||
Hash = 0;
|
||||
}
|
||||
|
||||
public void Calculate(byte[] pData, int pDataPtr, int nLen)
|
||||
{
|
||||
uint crc = Hash;
|
||||
while (nLen-- > 0)
|
||||
{
|
||||
crc = table[(byte)(crc ^ pData[pDataPtr++])] ^ crc >> 8;
|
||||
crc ^= CRC_MASK;
|
||||
}
|
||||
|
||||
Hash = crc;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
psxt001z.Library/Common.cs
Normal file
28
psxt001z.Library/Common.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/common.h"/>
|
||||
public partial class LibCrypt
|
||||
{
|
||||
internal const int ZERO = 0;
|
||||
|
||||
public const string VERSION = "v0.21 beta 1";
|
||||
|
||||
/// <summary>
|
||||
/// BCD to Byte
|
||||
/// </summary>
|
||||
public static byte BinaryToInteger(byte b) => (byte)(b / 16 * 10 + b % 16);
|
||||
|
||||
/// <summary>
|
||||
/// Byte to BCD
|
||||
/// </summary>
|
||||
public static byte IntegerToBinary(byte i) => (byte)(i / 10 * 16 + i % 10);
|
||||
|
||||
/// <summary>
|
||||
/// Get a santized hex string from an input byte array
|
||||
/// </summary>
|
||||
public static string GetHexString(byte[] bytes, int startIndex, int length) =>
|
||||
BitConverter.ToString(bytes, startIndex, length).Replace("-", string.Empty);
|
||||
}
|
||||
}
|
||||
113
psxt001z.Library/Constants.cs
Normal file
113
psxt001z.Library/Constants.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
namespace psxt001z
|
||||
{
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/libcrypt.h"/>
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/libcrypt.cpp"/>
|
||||
internal static class Constants
|
||||
{
|
||||
#region libcrypt.h
|
||||
|
||||
public const uint IOCTL_SCSI_PASS_THROUGH_DIRECT = 0x4D014;
|
||||
|
||||
public const byte SCSI_IOCTL_DATA_IN = 0x1;
|
||||
|
||||
public const byte RAW_READ_CMD = 0xBE;
|
||||
|
||||
public const int BUFFER_LEN = 96;
|
||||
|
||||
public const int SENSE_SIZE = 0; //14
|
||||
|
||||
public const string F_NAME = "sectors.log";
|
||||
|
||||
public const int CYCLES = 5;
|
||||
|
||||
public const int LIBCRYPT_NUM_SECTORS = 64;
|
||||
|
||||
public const int READ_TIMES = 5;
|
||||
|
||||
#endregion
|
||||
|
||||
#region libcrypt.cpp
|
||||
|
||||
public static readonly uint[] lc_addresses =
|
||||
[
|
||||
13955, 13960, 14081, 14086, 14335, 14340, 14429, 14434,
|
||||
14499, 14504, 14749, 14754, 14906, 14911, 14980, 14985,
|
||||
15092, 15097, 15162, 15167, 15228, 15233, 15478, 15483,
|
||||
15769, 15774, 15881, 15886, 15951, 15956, 16017, 16022,
|
||||
41895, 41900, 42016, 42021, 42282, 42287, 42430, 42435,
|
||||
42521, 42526, 42663, 42668, 42862, 42867, 43027, 43032,
|
||||
43139, 43144, 43204, 43209, 43258, 43263, 43484, 43489,
|
||||
43813, 43818, 43904, 43909, 44009, 44014, 44162, 44167
|
||||
];
|
||||
|
||||
public static readonly byte[] lc1_sectors_contents =
|
||||
[
|
||||
0x41, 0x01, 0x01, 0x07, 0x06, 0x05, 0x00, 0x23, 0x08, 0x05, 0x38, 0x39,
|
||||
0x41, 0x01, 0x01, 0x03, 0x06, 0x11, 0x00, 0x03, 0x08, 0x90, 0x5d, 0xa0,
|
||||
0x41, 0x01, 0x01, 0x07, 0x07, 0x56, 0x00, 0x23, 0x09, 0x56, 0xdf, 0xde,
|
||||
0x41, 0x01, 0x01, 0x03, 0x07, 0x60, 0x00, 0x03, 0x09, 0xe1, 0xf2, 0x50,
|
||||
0x41, 0x01, 0x01, 0x03, 0x13, 0x10, 0x00, 0x03, 0x53, 0x10, 0x50, 0xec,
|
||||
0x41, 0x01, 0x01, 0x43, 0x11, 0x15, 0x00, 0x01, 0x13, 0x15, 0x23, 0x1e,
|
||||
0x41, 0x01, 0x01, 0x03, 0x12, 0x09, 0x00, 0x03, 0x14, 0x2d, 0x04, 0x73,
|
||||
0x41, 0x01, 0x01, 0x03, 0x1a, 0x34, 0x00, 0x03, 0x04, 0x34, 0xe2, 0xcf,
|
||||
0x41, 0x01, 0x01, 0x03, 0x13, 0x20, 0x00, 0x03, 0x15, 0x04, 0x82, 0x35,
|
||||
0x41, 0x01, 0x01, 0x01, 0x13, 0x29, 0x00, 0x43, 0x15, 0x29, 0x72, 0xe2,
|
||||
0x41, 0x01, 0x01, 0x03, 0x1e, 0x49, 0x00, 0x03, 0x08, 0x49, 0x32, 0xc5,
|
||||
0x41, 0x01, 0x01, 0x01, 0x16, 0x54, 0x00, 0x43, 0x18, 0x54, 0xd4, 0x79,
|
||||
0x41, 0x01, 0x01, 0x03, 0x18, 0x57, 0x00, 0x03, 0x20, 0xd6, 0xbc, 0x27,
|
||||
0x41, 0x01, 0x01, 0x03, 0x38, 0x61, 0x00, 0x03, 0x24, 0x61, 0x91, 0xa9,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x19, 0x55, 0x00, 0x13, 0x21, 0x55, 0x14, 0x07,
|
||||
0x41, 0x01, 0x01, 0x03, 0x19, 0x62, 0x00, 0x03, 0x21, 0x20, 0x5d, 0x48,
|
||||
0x41, 0x01, 0x01, 0x03, 0x23, 0x17, 0x00, 0x03, 0x63, 0x17, 0x6d, 0xc6,
|
||||
0x41, 0x01, 0x01, 0x43, 0x21, 0x22, 0x00, 0x01, 0x23, 0x22, 0x24, 0x89,
|
||||
0x41, 0x01, 0x01, 0x03, 0x02, 0x12, 0x00, 0x03, 0x20, 0x12, 0x49, 0x43,
|
||||
0x41, 0x01, 0x01, 0x03, 0x22, 0x07, 0x00, 0x03, 0x24, 0x1f, 0x3a, 0xb1,
|
||||
0x41, 0x01, 0x01, 0x03, 0x23, 0x13, 0x00, 0x03, 0x25, 0x0b, 0x93, 0xc9,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x23, 0x08, 0x00, 0x13, 0x25, 0x08, 0xce, 0x5d,
|
||||
0x41, 0x01, 0x01, 0x03, 0x06, 0x28, 0x00, 0x03, 0x2c, 0x28, 0xd7, 0xd6,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x26, 0x33, 0x00, 0x13, 0x28, 0x33, 0x9c, 0x29,
|
||||
0x41, 0x01, 0x01, 0x03, 0x30, 0x59, 0x00, 0x03, 0x32, 0x1b, 0x2c, 0xc6,
|
||||
0x41, 0x01, 0x01, 0x03, 0x20, 0x24, 0x00, 0x03, 0x3a, 0x24, 0xe6, 0xac,
|
||||
0x41, 0x01, 0x01, 0x13, 0x31, 0x56, 0x00, 0x0b, 0x33, 0x56, 0x97, 0xed,
|
||||
0x41, 0x01, 0x01, 0x03, 0x31, 0x65, 0x00, 0x03, 0x33, 0x41, 0xba, 0x63,
|
||||
0x41, 0x01, 0x01, 0x01, 0x32, 0x51, 0x00, 0x43, 0x34, 0x51, 0xd7, 0xa9,
|
||||
0x41, 0x01, 0x01, 0x03, 0x33, 0x56, 0x00, 0x03, 0xb4, 0x56, 0xc0, 0x9a,
|
||||
0x41, 0x01, 0x01, 0x03, 0x32, 0x42, 0x00, 0x03, 0xb5, 0x42, 0x69, 0xe2,
|
||||
0x41, 0x01, 0x01, 0x03, 0x33, 0x07, 0x00, 0x03, 0x35, 0x45, 0x1a, 0x10,
|
||||
0x41, 0x01, 0x01, 0x09, 0x18, 0x65, 0x00, 0x09, 0x20, 0x41, 0x40, 0x72,
|
||||
0x41, 0x01, 0x01, 0x19, 0x18, 0x50, 0x00, 0x01, 0x20, 0x50, 0x25, 0xeb,
|
||||
0x41, 0x01, 0x01, 0x08, 0x20, 0x16, 0x00, 0x89, 0x22, 0x16, 0x95, 0xa8,
|
||||
0x41, 0x01, 0x01, 0x09, 0x20, 0x01, 0x00, 0x09, 0x22, 0x25, 0xb8, 0x26,
|
||||
0x41, 0x01, 0x01, 0x09, 0x23, 0x53, 0x00, 0x09, 0x25, 0x77, 0x21, 0x03,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x23, 0x62, 0x00, 0x49, 0x25, 0x62, 0x68, 0x4c,
|
||||
0x41, 0x01, 0x01, 0x0d, 0x25, 0x55, 0x00, 0x29, 0x27, 0x55, 0xae, 0x41,
|
||||
0x41, 0x01, 0x01, 0x09, 0x25, 0x61, 0x00, 0x09, 0x27, 0xe0, 0xe7, 0x0e,
|
||||
0x41, 0x01, 0x01, 0x08, 0x26, 0x71, 0x00, 0x89, 0x28, 0x71, 0x95, 0xcb,
|
||||
0x41, 0x01, 0x01, 0x09, 0x27, 0x21, 0x00, 0x09, 0x29, 0x05, 0x80, 0x4b,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x28, 0x63, 0x00, 0x49, 0x30, 0x63, 0xed, 0x18,
|
||||
0x41, 0x01, 0x01, 0x09, 0x29, 0x68, 0x00, 0x09, 0xb0, 0x68, 0xb0, 0x8c,
|
||||
0x41, 0x01, 0x01, 0x29, 0x31, 0x37, 0x00, 0x0d, 0x33, 0x37, 0x6c, 0x68,
|
||||
0x41, 0x01, 0x01, 0x09, 0x31, 0x4a, 0x00, 0x09, 0x33, 0x52, 0x7c, 0x8b,
|
||||
0x41, 0x01, 0x01, 0x09, 0x73, 0x52, 0x00, 0x09, 0x37, 0x52, 0x4b, 0x06,
|
||||
0x41, 0x01, 0x01, 0x19, 0x33, 0x57, 0x00, 0x01, 0x35, 0x57, 0x38, 0xf4,
|
||||
0x41, 0x01, 0x01, 0x09, 0x35, 0x04, 0x00, 0x09, 0x37, 0x1c, 0x54, 0x6a,
|
||||
0x41, 0x01, 0x01, 0x09, 0x31, 0x19, 0x00, 0x09, 0x17, 0x19, 0xa4, 0xbd,
|
||||
0x41, 0x01, 0x01, 0x01, 0x36, 0x04, 0x00, 0x19, 0x38, 0x04, 0x9c, 0xdf,
|
||||
0x41, 0x01, 0x01, 0x09, 0x36, 0x0b, 0x00, 0x09, 0x38, 0x49, 0x6c, 0x08,
|
||||
0x41, 0x01, 0x01, 0x49, 0x36, 0x58, 0x00, 0x0b, 0x38, 0x58, 0x99, 0xbf,
|
||||
0x41, 0x01, 0x01, 0x09, 0x36, 0x73, 0x00, 0x09, 0x38, 0x6b, 0xfe, 0x96,
|
||||
0x41, 0x01, 0x01, 0x0b, 0x39, 0x59, 0x00, 0x49, 0x41, 0x59, 0x54, 0x0d,
|
||||
0x41, 0x01, 0x01, 0x09, 0x39, 0x24, 0x00, 0x09, 0x41, 0x66, 0x9e, 0x67,
|
||||
0x41, 0x01, 0x01, 0x09, 0x44, 0x1b, 0x00, 0x09, 0x46, 0x03, 0x78, 0x0d,
|
||||
0x41, 0x01, 0x01, 0x09, 0x46, 0x18, 0x00, 0x09, 0x06, 0x18, 0x25, 0x99,
|
||||
0x41, 0x01, 0x01, 0x09, 0x45, 0x2b, 0x00, 0x09, 0x47, 0x69, 0xd3, 0xc5,
|
||||
0x41, 0x01, 0x01, 0x09, 0x05, 0x34, 0x00, 0x09, 0x45, 0x34, 0x35, 0x79,
|
||||
0x41, 0x01, 0x01, 0x09, 0x44, 0x59, 0x00, 0x09, 0x08, 0x59, 0x6e, 0x0a,
|
||||
0x41, 0x01, 0x01, 0x49, 0x46, 0x64, 0x00, 0x0b, 0x48, 0x64, 0xa4, 0x60,
|
||||
0x41, 0x01, 0x01, 0x09, 0x08, 0x62, 0x00, 0x09, 0x52, 0x62, 0x03, 0x5a,
|
||||
0x41, 0x01, 0x01, 0x19, 0x48, 0x67, 0x00, 0x01, 0x50, 0x67, 0x70, 0xa8
|
||||
];
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
143
psxt001z.Library/FileTools.cs
Normal file
143
psxt001z.Library/FileTools.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/main.cpp"/>
|
||||
public class FileTools(Stream file)
|
||||
{
|
||||
private readonly Stream _file = file;
|
||||
|
||||
private readonly byte[] _executableName = new byte[20];
|
||||
|
||||
private readonly byte[] _dateValue = new byte[11];
|
||||
|
||||
public long Size() => _file.Length;
|
||||
|
||||
public string GetExecutableName()
|
||||
{
|
||||
_file.Seek(51744, SeekOrigin.Begin);
|
||||
|
||||
string filename = string.Empty;
|
||||
while (filename != "SYSTEM.CNF")
|
||||
{
|
||||
byte[] buf = _file.ReadBytes(10);
|
||||
filename = Encoding.ASCII.GetString(buf);
|
||||
_file.Seek(-9, SeekOrigin.Current);
|
||||
}
|
||||
|
||||
_file.Seek(-32, SeekOrigin.Current);
|
||||
uint lba = _file.ReadUInt32();
|
||||
|
||||
_file.Seek((2352 * lba) + 29, SeekOrigin.Begin);
|
||||
byte[] buffer = _file.ReadBytes(6);
|
||||
|
||||
string iniLine = Encoding.ASCII.GetString(buffer);
|
||||
while (iniLine != "cdrom:")
|
||||
{
|
||||
_file.Seek(-5, SeekOrigin.Current);
|
||||
buffer = _file.ReadBytes(6);
|
||||
iniLine = Encoding.ASCII.GetString(buffer);
|
||||
}
|
||||
|
||||
buffer = _file.ReadBytes(1);
|
||||
if (buffer[0] != '\\')
|
||||
_file.Seek(-1, SeekOrigin.Current);
|
||||
|
||||
int i = -1;
|
||||
do
|
||||
{
|
||||
_ = _file.Read(buffer, ++i, 1);
|
||||
} while (buffer[i] != ';');
|
||||
|
||||
for (long a = 0; a < i; a++)
|
||||
{
|
||||
_executableName[a] = (byte)char.ToUpper((char)buffer[a]);
|
||||
}
|
||||
|
||||
return Encoding.ASCII.GetString(_executableName);
|
||||
}
|
||||
|
||||
public string GetDate()
|
||||
{
|
||||
_file.Seek(51744, SeekOrigin.Begin);
|
||||
|
||||
byte[] buffer = new byte[12];
|
||||
do
|
||||
{
|
||||
_ = _file.Read(buffer, 0, 11);
|
||||
buffer[11] = 0;
|
||||
_file.Seek(-10, SeekOrigin.Current);
|
||||
} while (Encoding.ASCII.GetString(_executableName) != Encoding.ASCII.GetString(buffer));
|
||||
|
||||
_file.Seek(-16, SeekOrigin.Current);
|
||||
|
||||
byte[] datenofrmt = _file.ReadBytes(3);
|
||||
if (datenofrmt[0] < 50)
|
||||
{
|
||||
byte[] year = Encoding.ASCII.GetBytes($"{2000 + datenofrmt[0]}");
|
||||
Array.Copy(year, 0, buffer, 0, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] year = Encoding.ASCII.GetBytes($"{1900 + datenofrmt[0]}");
|
||||
Array.Copy(year, 0, buffer, 0, 4);
|
||||
}
|
||||
|
||||
_dateValue[4] = (byte)'-';
|
||||
if (datenofrmt[1] < 10)
|
||||
{
|
||||
byte[] month = Encoding.ASCII.GetBytes($"0{datenofrmt[1]}");
|
||||
Array.Copy(month, 0, buffer, 5, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] month = Encoding.ASCII.GetBytes($"{datenofrmt[1]}");
|
||||
Array.Copy(month, 0, buffer, 5, 2);
|
||||
}
|
||||
|
||||
_dateValue[7] = (byte)'-';
|
||||
if (datenofrmt[2] < 10)
|
||||
{
|
||||
byte[] day = Encoding.ASCII.GetBytes($"0{datenofrmt[2]}");
|
||||
Array.Copy(day, 0, buffer, 8, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] day = Encoding.ASCII.GetBytes($"{datenofrmt[2]}");
|
||||
Array.Copy(day, 0, buffer, 8, 2);
|
||||
}
|
||||
|
||||
return Encoding.ASCII.GetString(_dateValue);
|
||||
}
|
||||
|
||||
public int Resize(long newsize)
|
||||
{
|
||||
long oldsize = Size();
|
||||
if (oldsize < newsize)
|
||||
{
|
||||
_file.SetLength(newsize);
|
||||
return 1;
|
||||
}
|
||||
else if (oldsize > newsize)
|
||||
{
|
||||
_file.SetLength(newsize);
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetImageSize()
|
||||
{
|
||||
_file.Seek(0x9368, SeekOrigin.Begin);
|
||||
byte[] sizebuf = new byte[4];
|
||||
_ = _file.Read(sizebuf, 0, 4);
|
||||
return BitConverter.ToInt32(sizebuf, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using static psxt001z.Common;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
internal static class Functions
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/functions.cpp"/>
|
||||
public partial class LibCrypt
|
||||
{
|
||||
public static int CalculateEDC(in byte[] src, int srcPtr, int size, int[] edc_lut)
|
||||
{
|
||||
int edc = 0;
|
||||
while (size-- != 0)
|
||||
while (size-- > 0)
|
||||
{
|
||||
edc = (edc >> 8) ^ edc_lut[(edc ^ src[srcPtr++]) & 0xFF];
|
||||
}
|
||||
@@ -18,7 +19,7 @@ namespace psxt001z
|
||||
return edc;
|
||||
}
|
||||
|
||||
public static bool ZeroCompare(byte[] buffer, int bufferPtr, int bsize)
|
||||
internal static bool ZeroCompare(byte[] buffer, int bufferPtr, int bsize)
|
||||
{
|
||||
for (int i = 0; i < bsize; i++)
|
||||
{
|
||||
@@ -29,7 +30,7 @@ namespace psxt001z
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void MSF(long lba, byte[] buffer, int bufferOffset)
|
||||
internal static void MSF(long lba, byte[] buffer, int bufferOffset)
|
||||
{
|
||||
lba += 150;
|
||||
|
||||
@@ -39,28 +40,21 @@ namespace psxt001z
|
||||
byte sec = (byte)Math.Floor(secdbl);
|
||||
byte frame = (byte)(lba - (min * 60 * 75) - (sec * 75));
|
||||
|
||||
buffer[bufferOffset] = itob(min);
|
||||
buffer[bufferOffset + 1] = itob(sec);
|
||||
buffer[bufferOffset + 2] = itob(frame);
|
||||
|
||||
return;
|
||||
buffer[bufferOffset] = IntegerToBinary(min);
|
||||
buffer[bufferOffset + 1] = IntegerToBinary(sec);
|
||||
buffer[bufferOffset + 2] = IntegerToBinary(frame);
|
||||
}
|
||||
|
||||
public static bool GetEDCStatus(Stream file)
|
||||
public static bool GetEDC(Stream file)
|
||||
{
|
||||
long currentposition = file.Position;
|
||||
|
||||
file.Seek(30572, SeekOrigin.Begin);
|
||||
|
||||
byte[] buffer = new byte[4];
|
||||
file.Read(buffer, 0, 4);
|
||||
|
||||
uint buffer = file.ReadUInt32();
|
||||
file.Seek(currentposition, SeekOrigin.Begin);
|
||||
|
||||
return BitConverter.ToInt32(buffer, 0) == 0;
|
||||
return buffer == 0;
|
||||
}
|
||||
|
||||
public static byte[] ExecutableName(Stream file)
|
||||
internal static byte[] GetExecutableName(Stream file)
|
||||
{
|
||||
byte[] buffer = new byte[20];
|
||||
byte[] exename = new byte[20];
|
||||
@@ -69,31 +63,30 @@ namespace psxt001z
|
||||
file.Seek(51744, SeekOrigin.Begin);
|
||||
while (Encoding.ASCII.GetString(buffer) != "SYSTEM.CNF")
|
||||
{
|
||||
file.Read(buffer, 0, 10);
|
||||
_ = file.Read(buffer, 0, 10);
|
||||
buffer[10] = 0;
|
||||
file.Seek(-9, SeekOrigin.Current);
|
||||
}
|
||||
|
||||
file.Seek(-32, SeekOrigin.Current);
|
||||
byte[] lba = new byte[4];
|
||||
file.Read(lba, 0, 4);
|
||||
file.Seek((2352 * BitConverter.ToInt32(lba, 0)) + 29, SeekOrigin.Begin);
|
||||
file.Read(buffer, 0, 6);
|
||||
uint lba = file.ReadUInt32();
|
||||
file.Seek((2352 * lba) + 29, SeekOrigin.Begin);
|
||||
_ = file.Read(buffer, 0, 6);
|
||||
buffer[6] = 0;
|
||||
while (Encoding.ASCII.GetString(buffer) != "cdrom:")
|
||||
{
|
||||
file.Seek(-5, SeekOrigin.Current);
|
||||
file.Read(buffer, 0, 6);
|
||||
_ = file.Read(buffer, 0, 6);
|
||||
}
|
||||
|
||||
file.Read(buffer, 0, 1);
|
||||
_ = file.Read(buffer, 0, 1);
|
||||
if (buffer[0] != '\\')
|
||||
file.Seek(-1, SeekOrigin.Current);
|
||||
|
||||
int i = -1;
|
||||
do
|
||||
{
|
||||
file.Read(buffer, ++i, 1);
|
||||
_ = file.Read(buffer, ++i, 1);
|
||||
} while (buffer[i] != ';');
|
||||
|
||||
for (int a = 0; a < i; a++)
|
||||
@@ -1,30 +1,27 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using static psxt001z.Functions;
|
||||
using SabreTools.IO.Extensions;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
public class Info
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/info.cpp"/>
|
||||
public partial class LibCrypt
|
||||
{
|
||||
#region Constants
|
||||
private static readonly byte[] edc_form_2 = [0x3F, 0x13, 0xB0, 0xBE];
|
||||
|
||||
private static readonly byte[] edc_form_2 = { 0x3F, 0x13, 0xB0, 0xBE };
|
||||
private static readonly byte[] syncheader = [0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
|
||||
private static readonly byte[] syncheader = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
private static readonly byte[] subheader = [0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00];
|
||||
|
||||
private static readonly byte[] subheader = { 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00 };
|
||||
|
||||
#endregion
|
||||
|
||||
#region Functions
|
||||
|
||||
public static int GetInfo(string filename, bool fix)
|
||||
public static bool Info(string filename, bool fix)
|
||||
{
|
||||
// Variables
|
||||
#region Variables
|
||||
|
||||
bool errors = false;
|
||||
byte[] buffer = new byte[2352], buffer2 = new byte[2352];
|
||||
int mode = 15; // synñheader[15];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Opening image
|
||||
|
||||
@@ -37,7 +34,7 @@ namespace psxt001z
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex);
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
long size = image.Length;
|
||||
@@ -47,7 +44,7 @@ namespace psxt001z
|
||||
|
||||
#region Type
|
||||
|
||||
image.Read(buffer, 0, 12);
|
||||
_ = image.Read(buffer, 0, 12);
|
||||
|
||||
int sectorsize;
|
||||
if (buffer.Take(12).SequenceEqual(syncheader.Take(12)))
|
||||
@@ -61,7 +58,7 @@ namespace psxt001z
|
||||
if (size % sectorsize != 0)
|
||||
{
|
||||
Console.WriteLine($"{filename}: not ModeX/{sectorsize} image!");
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
long sectors = size / sectorsize;
|
||||
@@ -72,32 +69,30 @@ namespace psxt001z
|
||||
|
||||
if (sectorsize == 2352)
|
||||
{
|
||||
image.Seek(0xF, SeekOrigin.Begin);
|
||||
mode = image.ReadByte();
|
||||
if (mode != 1 && mode != 2)
|
||||
image.Seek(0x0F, SeekOrigin.Begin);
|
||||
syncheader[15] = (byte)image.ReadByte();
|
||||
if (syncheader[15] != 1 && syncheader[15] != 2)
|
||||
{
|
||||
Console.WriteLine($"{filename}: unknown mode!");
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mode = -1;
|
||||
syncheader[15] = 0xFF;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Size
|
||||
|
||||
image.Seek(sectorsize * 16 + ((mode == 2) ? 24 : ((mode == 1) ? 16 : 0)) + 0x50, SeekOrigin.Begin);
|
||||
image.Seek(sectorsize * 16 + ((syncheader[15] == 2) ? 24 : ((syncheader[15] == 1) ? 16 : 0)) + 0x50, SeekOrigin.Begin);
|
||||
|
||||
// ISO size
|
||||
byte[] buf = new byte[4];
|
||||
image.Read(buf, 0, 4);
|
||||
int realsectors = BitConverter.ToInt32(buf, 0);
|
||||
|
||||
int realsectors = image.ReadInt32();
|
||||
image.Seek(0, SeekOrigin.Begin);
|
||||
int realsize = realsectors * sectorsize;
|
||||
|
||||
if (sectors == realsectors)
|
||||
{
|
||||
Console.WriteLine($"Size (bytes): {size} (OK)");
|
||||
@@ -115,14 +110,14 @@ namespace psxt001z
|
||||
|
||||
#region Mode
|
||||
|
||||
if (mode > 0)
|
||||
Console.WriteLine($"Mode: {mode}");
|
||||
if (syncheader[15] > 0)
|
||||
Console.WriteLine($"Mode: {syncheader[15]}");
|
||||
|
||||
if (mode == 2)
|
||||
if (syncheader[15] == 2)
|
||||
{
|
||||
#region EDC in Form 2
|
||||
|
||||
bool imageedc = GetEDCStatus(image);
|
||||
bool imageedc = GetEDC(image);
|
||||
Console.WriteLine($"EDC in Form 2 sectors: {(imageedc ? "YES" : "NO")}");
|
||||
|
||||
#endregion
|
||||
@@ -132,16 +127,27 @@ namespace psxt001z
|
||||
string systemArea = "System area: ";
|
||||
image.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
CRC32 crc = new CRC32();
|
||||
var crc = new CRC32();
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
image.Read(buffer, 0, 2352);
|
||||
crc.ProcessCRC(buffer, 0, 2352);
|
||||
_ = image.Read(buffer, 0, 2352);
|
||||
crc.Calculate(buffer, 0, 2352);
|
||||
}
|
||||
|
||||
uint imagecrc = crc.m_crc32;
|
||||
systemArea += GetEdcType(imagecrc);
|
||||
|
||||
uint imagecrc = crc.Hash;
|
||||
systemArea += imagecrc switch
|
||||
{
|
||||
0x11e3052d => "Eu EDC",
|
||||
0x808c19f6 => "Eu NoEDC",
|
||||
0x70ffa73e => "Eu Alt NoEDC",
|
||||
0x7f9a25b1 => "Eu Alt 2 EDC",
|
||||
0x783aca30 => "Jap EDC",
|
||||
0xe955d6eb => "Jap NoEDC",
|
||||
0x9b519a2e => "US EDC",
|
||||
0x0a3e86f5 => "US NoEDC",
|
||||
0x6773d4db => "US Alt NoEDC",
|
||||
_ => $"Unknown, crc {imagecrc:8x}",
|
||||
};
|
||||
Console.WriteLine(systemArea);
|
||||
|
||||
#endregion
|
||||
@@ -149,10 +155,10 @@ namespace psxt001z
|
||||
#region Postgap
|
||||
|
||||
image.Seek((sectors - 150) * sectorsize + 16, SeekOrigin.Begin);
|
||||
image.Read(buffer, 0, 2336);
|
||||
_ = image.Read(buffer, 0, 2336);
|
||||
|
||||
string postgap = "Postgap type: Form ";
|
||||
if ((buffer[2] >> 5 & 0x1) != 0)
|
||||
if ((buffer[2] >> 5 & 0x01) != 0)
|
||||
{
|
||||
postgap += "2";
|
||||
if (buffer.Take(8).SequenceEqual(subheader))
|
||||
@@ -190,18 +196,19 @@ namespace psxt001z
|
||||
#endregion
|
||||
}
|
||||
|
||||
if (mode < 0)
|
||||
return 0;
|
||||
if (syncheader[15] < 0)
|
||||
return true;
|
||||
|
||||
for (long sector = sectors - 150; sector < sectors; sector++)
|
||||
{
|
||||
bool bad = false;
|
||||
image.Seek(sector * sectorsize, SeekOrigin.Begin);
|
||||
image.Read(buffer, 0, sectorsize);
|
||||
_ = image.Read(buffer, 0, sectorsize);
|
||||
|
||||
// Sync
|
||||
string sectorInfo = string.Empty;
|
||||
|
||||
#region Sync
|
||||
|
||||
MSF(sector, syncheader, 12);
|
||||
if (!syncheader.SequenceEqual(buffer.Take(16)))
|
||||
{
|
||||
@@ -215,8 +222,11 @@ namespace psxt001z
|
||||
}
|
||||
}
|
||||
|
||||
// Mode 2
|
||||
if (mode == 2 && buffer.Skip(16).Take(2336).SequenceEqual(buffer2))
|
||||
#endregion
|
||||
|
||||
#region Mode 2
|
||||
|
||||
if (syncheader[15] == 2 && buffer.Skip(16).Take(2336).SequenceEqual(buffer2))
|
||||
{
|
||||
if (bad)
|
||||
{
|
||||
@@ -224,7 +234,7 @@ namespace psxt001z
|
||||
}
|
||||
else
|
||||
{
|
||||
sectorInfo = $"Sector {sector}: Subheader/Data/EDC/ECC";
|
||||
sectorInfo += $"\nSector {sector}: Subheader/Data/EDC/ECC";
|
||||
bad = true;
|
||||
}
|
||||
|
||||
@@ -236,6 +246,8 @@ namespace psxt001z
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Console.WriteLine(sectorInfo);
|
||||
|
||||
if (bad && (sector + 1 != sectors))
|
||||
@@ -254,40 +266,7 @@ namespace psxt001z
|
||||
|
||||
#endregion
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utilities
|
||||
|
||||
internal static string GetEdcType(uint imageCrc)
|
||||
{
|
||||
switch (imageCrc)
|
||||
{
|
||||
case 0x11e3052d:
|
||||
return "Eu EDC";
|
||||
case 0x808c19f6:
|
||||
return "Eu NoEDC";
|
||||
case 0x70ffa73e:
|
||||
return "Eu Alt NoEDC";
|
||||
case 0x7f9a25b1:
|
||||
return "Eu Alt 2 EDC";
|
||||
case 0x783aca30:
|
||||
return "Jap EDC";
|
||||
case 0xe955d6eb:
|
||||
return "Jap NoEDC";
|
||||
case 0x9b519a2e:
|
||||
return "US EDC";
|
||||
case 0x0a3e86f5:
|
||||
return "US NoEDC";
|
||||
case 0x6773d4db:
|
||||
return "US Alt NoEDC";
|
||||
default:
|
||||
return $"Unknown, crc {imageCrc:8x}";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
254
psxt001z.Library/LibCrypt.cs
Normal file
254
psxt001z.Library/LibCrypt.cs
Normal file
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using static psxt001z.Constants;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/libcrypt.cpp"/>
|
||||
public partial class LibCrypt
|
||||
{
|
||||
// TODO: Implement
|
||||
public static byte DetectLibCryptDrive(string[] args)
|
||||
{
|
||||
Console.WriteLine("Not implemented, requires direct drive access");
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
public static byte DetectLibCryptDriveFast(string[] args)
|
||||
{
|
||||
Console.WriteLine("Not implemented, requires direct drive access");
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
public static void ReadSub(byte[] buffer, uint sector, Stream f, byte offset, IntPtr hDevice, ScsiPassThroughDirect SRB)
|
||||
{
|
||||
Console.WriteLine("Not implemented, requires direct drive access");
|
||||
}
|
||||
|
||||
// TODO: Implement
|
||||
public static void ClearCache(byte[] buffer, Stream f, byte offset, IntPtr hDevice, ScsiPassThroughDirect SRB)
|
||||
{
|
||||
Console.WriteLine("Not implemented, requires direct drive access");
|
||||
}
|
||||
|
||||
public static bool Matrix(byte[] buffer, byte[] buffer2, byte[] buffer3, byte[] buffer4, uint length)
|
||||
{
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
if (buffer[i] == buffer2[i])
|
||||
{
|
||||
if (buffer[i] == buffer3[i])
|
||||
continue;
|
||||
if (buffer[i] == buffer4[i])
|
||||
continue;
|
||||
}
|
||||
else if (buffer[i] == buffer3[i] && buffer[i] == buffer4[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (buffer2[i] == buffer3[i] && buffer2[i] == buffer4[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Deinterleave(byte[] buffer)
|
||||
{
|
||||
byte[] buffertmp = new byte[12];
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
buffertmp[i] |= (byte)((buffer[i * 8] & 0x40) << 1);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 1] & 0x40));
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 2] & 0x40) >> 1);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 3] & 0x40) >> 2);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 4] & 0x40) >> 3);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 5] & 0x40) >> 4);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 6] & 0x40) >> 5);
|
||||
buffertmp[i] |= (byte)((buffer[i * 8 + 7] & 0x40) >> 6);
|
||||
}
|
||||
|
||||
Array.Copy(buffertmp, buffer, 12);
|
||||
return;
|
||||
}
|
||||
|
||||
public static bool DetectLibCrypt(string[] args)
|
||||
{
|
||||
if (args.Length != 1 && args.Length != 2)
|
||||
{
|
||||
Console.WriteLine("LibCrypt detector\nUsage: psxt001z.exe --libcrypt <sub> [<sbi>]");
|
||||
Console.WriteLine(" Check subchannel for LibCrypt protection.");
|
||||
Console.WriteLine(" [in] <sub> Specifies the subchannel file to be scanned.");
|
||||
Console.WriteLine(" [out] <sbi> Specifies the subchannel file in SBI format where protected\n sectors will be written.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Variables
|
||||
byte[] buffer = new byte[16], sub = new byte[16];//, pregap = 0;
|
||||
uint sector, psectors = 0, tpos = 0;
|
||||
|
||||
// Opening .sub
|
||||
Stream subfile = File.OpenRead(args[0]);
|
||||
|
||||
// Checking extension
|
||||
if (!string.Equals(Path.GetExtension(args[0]).TrimStart('.'), "sub", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Console.WriteLine($"{args[0]}: unknown file extension");
|
||||
return false;
|
||||
}
|
||||
|
||||
// filesize
|
||||
long size = subfile.Length;
|
||||
if (size % 96 != 0)
|
||||
{
|
||||
Console.WriteLine($"{subfile}: wrong size");
|
||||
return false;
|
||||
}
|
||||
|
||||
// sbi
|
||||
Stream? sbi = null;
|
||||
if (args.Length > 1 && args[1] is not null)
|
||||
{
|
||||
sbi = File.OpenWrite(args[1]);
|
||||
sbi.Write(Encoding.ASCII.GetBytes("SBI\0"), 0, 4);
|
||||
}
|
||||
|
||||
for (sector = 150; sector < ((size / 96) + 150); sector++)
|
||||
{
|
||||
subfile.Seek(12, SeekOrigin.Current);
|
||||
if (subfile.Read(buffer, 0, 12) != 12)
|
||||
return true;
|
||||
|
||||
subfile.Seek(72, SeekOrigin.Current);
|
||||
|
||||
// New track
|
||||
if ((BinaryToInteger(buffer[1]) == (BinaryToInteger(sub[1]) + 1)) && (buffer[2] == 0 || buffer[2] == 1))
|
||||
{
|
||||
Array.Copy(buffer, sub, 6);
|
||||
tpos = (uint)((BinaryToInteger((byte)(buffer[3] * 60)) + BinaryToInteger(buffer[4])) * 75) + BinaryToInteger(buffer[5]);
|
||||
}
|
||||
|
||||
// New index
|
||||
else if (BinaryToInteger(buffer[2]) == (BinaryToInteger(sub[2]) + 1) && buffer[1] == sub[1])
|
||||
{
|
||||
Array.Copy(buffer, 2, sub, 2, 4);
|
||||
tpos = (uint)((BinaryToInteger((byte)(buffer[3] * 60)) + BinaryToInteger(buffer[4])) * 75) + BinaryToInteger(buffer[5]);
|
||||
}
|
||||
|
||||
// MSF1 [3-5]
|
||||
else
|
||||
{
|
||||
if (sub[2] == 0)
|
||||
tpos--;
|
||||
else
|
||||
tpos++;
|
||||
|
||||
sub[3] = IntegerToBinary((byte)(tpos / 60 / 75));
|
||||
sub[4] = IntegerToBinary((byte)((tpos / 75) % 60));
|
||||
sub[5] = IntegerToBinary((byte)(tpos % 75));
|
||||
}
|
||||
|
||||
//MSF2 [7-9]
|
||||
sub[7] = IntegerToBinary((byte)(sector / 60 / 75));
|
||||
sub[8] = IntegerToBinary((byte)((sector / 75) % 60));
|
||||
sub[9] = IntegerToBinary((byte)(sector % 75));
|
||||
|
||||
// CRC-16 [10-11]
|
||||
ushort crc = CRC16.Calculate(sub, 0, 10);
|
||||
sub[10] = (byte)(crc >> 8);
|
||||
sub[11] = (byte)(crc & 0xFF);
|
||||
|
||||
//if (buffer[10] != sub[10] && buffer[11] != sub[11] && (buffer[3] != sub[3] || buffer[7] != sub[7] || buffer[4] != sub[4] || buffer[8] != sub[8] || buffer[5] != sub[5] || buffer[9] != sub[9])) {
|
||||
//if (buffer[10] != sub[10] || buffer[11] != sub[11] || buffer[3] != sub[3] || buffer[7] != sub[7] || buffer[4] != sub[4] || buffer[8] != sub[8] || buffer[5] != sub[5] || buffer[9] != sub[9]) {
|
||||
if (!buffer.Take(6).SequenceEqual(sub.Take(6)) || !buffer.Skip(7).Take(5).SequenceEqual(sub.Skip(7).Take(5)))
|
||||
{
|
||||
Console.WriteLine($"MSF: {GetHexString(sub, 7, 3)} Q-Data: {GetHexString(buffer, 0, 3)} {GetHexString(buffer, 3, 3)} {GetHexString(buffer, 6, 1)} {GetHexString(buffer, 7, 1)}:{GetHexString(buffer, 8, 1)}:{GetHexString(buffer, 9, 1)} {GetHexString(buffer, 10, 2)} xor {crc ^ ((buffer[10] << 8) + buffer[11]):4x} {CRC16.Calculate(buffer, 0, 10) ^ ((buffer[10] << 8) + buffer[11]):4x}");
|
||||
//Console.WriteLine("\nMSF: %02x:%02x:%02x Q-Data: %02x%02x%02x %02x:%02x:%02x %02x %02x:%02x:%02x %02x%02x", sub[7], sub[8], sub[9], sub[0], sub[1], sub[2], sub[3], sub[4], sub[5], sub[6], sub[7], sub[8], sub[9], sub[10], sub[11]);
|
||||
|
||||
if (buffer[3] != sub[3] && buffer[7] != sub[7] && buffer[4] == sub[4] && buffer[8] == sub[8] && buffer[5] == sub[5] && buffer[9] == sub[9])
|
||||
Console.WriteLine($" P1 xor {buffer[3] ^ sub[3]:2x} {buffer[7] ^ sub[7]:2x}");
|
||||
else if (buffer[3] == sub[3] && buffer[7] == sub[7] && buffer[4] != sub[4] && buffer[8] != sub[8] && buffer[5] == sub[5] && buffer[9] == sub[9])
|
||||
Console.WriteLine($" P2 xor {buffer[4] ^ sub[4]:2x} {buffer[8] ^ sub[8]:2x}");
|
||||
else if (buffer[3] == sub[3] && buffer[7] == sub[7] && buffer[4] == sub[4] && buffer[8] == sub[8] && buffer[5] != sub[5] && buffer[9] != sub[9])
|
||||
Console.WriteLine($" P3 xor {buffer[5] ^ sub[5]:2x} {buffer[9] ^ sub[9]:2x}");
|
||||
else
|
||||
Console.WriteLine(" ?");
|
||||
|
||||
Console.WriteLine("");
|
||||
psectors++;
|
||||
if (sbi is not null)
|
||||
{
|
||||
sbi.Write(sub, 7, 3);
|
||||
sbi.Write([0x01], 0, 1);
|
||||
sbi.Write(buffer, 0, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
Console.WriteLine($"Number of modified sectors: {psectors}");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int XorLibCrypt()
|
||||
{
|
||||
sbyte b;
|
||||
byte d;
|
||||
byte i, a, x;
|
||||
byte[] sub =
|
||||
[
|
||||
0x41, 0x01, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
];
|
||||
|
||||
ushort crc;
|
||||
for (i = 0; i < LIBCRYPT_NUM_SECTORS; i++)
|
||||
{
|
||||
sub[3] = IntegerToBinary((byte)(lc_addresses[i] / 60 / 75));
|
||||
sub[4] = IntegerToBinary((byte)((lc_addresses[i] / 75) % 60));
|
||||
sub[5] = IntegerToBinary((byte)(lc_addresses[i] % 75));
|
||||
sub[7] = IntegerToBinary((byte)((lc_addresses[i] + 150) / 60 / 75));
|
||||
sub[8] = IntegerToBinary((byte)(((lc_addresses[i] + 150) / 75) % 60));
|
||||
sub[9] = IntegerToBinary((byte)((lc_addresses[i] + 150) % 75));
|
||||
crc = CRC16.Calculate(sub, 0, 10);
|
||||
sub[10] = (byte)(crc >> 8);
|
||||
sub[11] = (byte)(crc & 0xFF);
|
||||
|
||||
Console.WriteLine($"{lc_addresses[i]} {GetHexString(sub, 7, 3)}");
|
||||
Console.WriteLine($" {GetHexString(sub, 0, 10)} {GetHexString(sub, 10, 2)}");
|
||||
Console.WriteLine($" {GetHexString(lc1_sectors_contents, i * 12, 10)} {GetHexString(lc1_sectors_contents, i * 12 + 10, 2)}");
|
||||
|
||||
d = 0;
|
||||
|
||||
for (a = 3; a < 12; a++)
|
||||
{
|
||||
x = (byte)(lc1_sectors_contents[(i * 12) + a] ^ sub[a]);
|
||||
Console.WriteLine($" {(x >> 7) & 0x01:x}{(x >> 6) & 0x01:x}{(x >> 5) & 0x01:x}{(x >> 4) & 0x01:x}{(x >> 3) & 0x01:x}{(x >> 2) & 0x01:x}{(x >> 1) & 0x01:x}{x & 0x01:x}");
|
||||
if (x == 0)
|
||||
continue;
|
||||
for (b = 7; b >= 0; b--)
|
||||
{
|
||||
if (((x >> b) & 0x01) != 0)
|
||||
{
|
||||
d = (byte)(d << 1);
|
||||
d |= (byte)((sub[a] >> b) & 0x01);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($" {(d >> 3) & 0x01:x}{(d >> 2) & 0x01:x}{(d >> 1) & 0x01:x}{d & 0x01}");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using static psxt001z.Common;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
public class Scramble
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/scramble.cpp"/>
|
||||
public partial class LibCrypt
|
||||
{
|
||||
private static readonly byte[] sync = new byte[12] { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };
|
||||
private static readonly byte[] sync = [0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00];
|
||||
|
||||
public int __main(string[] args)
|
||||
internal static int __main(string[] args)
|
||||
{
|
||||
if (args.Length < 2 || args.Length > 3)
|
||||
{
|
||||
@@ -44,17 +41,14 @@ namespace psxt001z
|
||||
byte[] sector = new byte[sectors];
|
||||
if (args.Length == 2)
|
||||
{
|
||||
uint hex;
|
||||
for (int i = 0; sector_file.Position < sector_file.Length && i < 3252; i++)
|
||||
{
|
||||
byte[] buf = new byte[2];
|
||||
hex = uint.Parse(Encoding.ASCII.GetString(buf), NumberStyles.HexNumber);
|
||||
sector[i] = (byte)hex;
|
||||
sector[i] = (byte)sector_file.ReadByte();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sector_file.Read(sector, 0, sectors);
|
||||
_ = sector_file.Read(sector, 0, sectors);
|
||||
}
|
||||
|
||||
int offset = MemSearch(sector, sync, sectors, 12);
|
||||
@@ -66,7 +60,7 @@ namespace psxt001z
|
||||
|
||||
Console.WriteLine($"MSF: {sector[offset + 12]:2x}:{sector[offset + 12 + 1]:2x}:{sector[offset + 12 + 2]:2x}");
|
||||
|
||||
int shiftRegister = 0x1;
|
||||
int shiftRegister = 0x01;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
sector[offset + 12 + i] ^= (byte)(shiftRegister & 0xFF);
|
||||
@@ -77,7 +71,7 @@ namespace psxt001z
|
||||
}
|
||||
}
|
||||
|
||||
int start_sector = (btoi(sector[offset + 12]) * 60 + btoi(sector[offset + 13])) * 75 + btoi(sector[offset + 14]) - 150;
|
||||
int start_sector = (BinaryToInteger(sector[offset + 12]) * 60 + BinaryToInteger(sector[offset + 13])) * 75 + BinaryToInteger(sector[offset + 14]) - 150;
|
||||
|
||||
Console.WriteLine($"MSF: {sector[offset + 12]:2x}:{sector[offset + 12 + 1]:2x}:{sector[offset + 12 + 2]:2x}");
|
||||
|
||||
@@ -87,10 +81,7 @@ namespace psxt001z
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search for a byte array in another
|
||||
/// </summary>
|
||||
private int MemSearch(in byte[] buf_where, in byte[] buf_search, int buf_where_len, int buf_search_len)
|
||||
private static int MemSearch(in byte[] buf_where, in byte[] buf_search, int buf_where_len, int buf_search_len)
|
||||
{
|
||||
for (int i = 0; i <= buf_where_len - buf_search_len; i++)
|
||||
{
|
||||
32
psxt001z.Library/ScsiPassThroughDirect.cs
Normal file
32
psxt001z.Library/ScsiPassThroughDirect.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace psxt001z
|
||||
{
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/libcrypt.h"/>
|
||||
public class ScsiPassThroughDirect
|
||||
{
|
||||
public ushort Length { get; set; }
|
||||
|
||||
public byte ScsiStatus { get; set; }
|
||||
|
||||
public byte PathId { get; set; }
|
||||
|
||||
public byte TargetId { get; set; }
|
||||
|
||||
public byte Lun { get; set; }
|
||||
|
||||
public byte CDBLength { get; set; }
|
||||
|
||||
public byte SenseInfoLength { get; set; }
|
||||
|
||||
public byte DataIn { get; set; }
|
||||
|
||||
public uint DataTransferLength { get; set; }
|
||||
|
||||
public uint TimeOutValue { get; set; }
|
||||
|
||||
public byte[]? DataBuffer { get; set; }
|
||||
|
||||
public uint SenseInfoOffset { get; set; }
|
||||
|
||||
public byte[] CDB { get; set; } = new byte[16];
|
||||
}
|
||||
}
|
||||
252
psxt001z.Library/Track.cs
Normal file
252
psxt001z.Library/Track.cs
Normal file
@@ -0,0 +1,252 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
/// <see href="https://github.com/Dremora/psxt001z/blob/master/main.cpp"/>
|
||||
public class Track
|
||||
{
|
||||
private readonly Stream _file;
|
||||
|
||||
private readonly string? _path;
|
||||
|
||||
private readonly uint _start;
|
||||
|
||||
private readonly uint _crc;
|
||||
|
||||
private readonly uint _size;
|
||||
|
||||
private readonly byte[] _riff = new byte[44];
|
||||
|
||||
private readonly bool _isRiff;
|
||||
|
||||
private byte _mode;
|
||||
|
||||
private readonly bool _smallFile;
|
||||
|
||||
private readonly byte[]? _fileContents;
|
||||
|
||||
private readonly bool _saveTrack;
|
||||
|
||||
//private readonly long[] _fastOffset = new long[77];
|
||||
|
||||
private long _offset;
|
||||
|
||||
private long _current;
|
||||
|
||||
public Track(string[] args)
|
||||
{
|
||||
_file = File.OpenRead(args[1]);
|
||||
_start = uint.Parse(args[2]);
|
||||
_size = uint.Parse(args[3]);
|
||||
_crc = uint.Parse(args[4], NumberStyles.HexNumber);
|
||||
_offset = 0;
|
||||
_isRiff = false;
|
||||
_current = 0;
|
||||
_smallFile = false;
|
||||
_mode = 1;
|
||||
_saveTrack = false;
|
||||
|
||||
Console.WriteLine($"File: {args[1]}");
|
||||
Console.WriteLine($"Start: {_start}");
|
||||
Console.WriteLine($"Size: {_size}");
|
||||
Console.WriteLine($"CRC-32: {_crc}");
|
||||
|
||||
for (byte i = 6; i < args.Length; i++)
|
||||
{
|
||||
if (args.Length >= 7)
|
||||
{
|
||||
if (args[i] == "r")
|
||||
{
|
||||
_riff[0] = 0x52;
|
||||
_riff[1] = 0x49;
|
||||
_riff[2] = 0x46;
|
||||
_riff[3] = 0x46;
|
||||
_riff[8] = 0x57;
|
||||
_riff[9] = 0x41;
|
||||
_riff[10] = 0x56;
|
||||
_riff[11] = 0x45;
|
||||
_riff[12] = 0x66;
|
||||
_riff[13] = 0x6D;
|
||||
_riff[14] = 0x74;
|
||||
_riff[15] = 0x20;
|
||||
_riff[16] = 0x10;
|
||||
_riff[17] = 0x00;
|
||||
_riff[18] = 0x00;
|
||||
_riff[19] = 0x00;
|
||||
_riff[20] = 0x01;
|
||||
_riff[21] = 0x00;
|
||||
_riff[22] = 0x02;
|
||||
_riff[23] = 0x00;
|
||||
_riff[24] = 0x44;
|
||||
_riff[25] = 0xAC;
|
||||
_riff[26] = 0x00;
|
||||
_riff[27] = 0x00;
|
||||
_riff[28] = 0x10;
|
||||
_riff[29] = 0xB1;
|
||||
_riff[30] = 0x02;
|
||||
_riff[31] = 0x00;
|
||||
_riff[32] = 0x04;
|
||||
_riff[33] = 0x00;
|
||||
_riff[34] = 0x10;
|
||||
_riff[35] = 0x00;
|
||||
_riff[36] = 0x64;
|
||||
_riff[37] = 0x61;
|
||||
_riff[38] = 0x74;
|
||||
_riff[39] = 0x61;
|
||||
_isRiff = true;
|
||||
Array.Copy(BitConverter.GetBytes(_size - 8), 0, _riff, 4, 4);
|
||||
Array.Copy(BitConverter.GetBytes(_size - 44), 0, _riff, 40, 4);
|
||||
_size -= 44;
|
||||
}
|
||||
else if (args[i][0] == '+')
|
||||
{
|
||||
_mode = (byte)'p';
|
||||
}
|
||||
else if (args[i][0] == '-')
|
||||
{
|
||||
_mode = (byte)'n';
|
||||
}
|
||||
else if (args[i] == "s")
|
||||
{
|
||||
_saveTrack = true;
|
||||
i++;
|
||||
_path = args[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_size <= 100000000)
|
||||
{
|
||||
_fileContents = new byte[_size + 40000];
|
||||
_file.Seek(_start - 20000, SeekOrigin.Begin);
|
||||
//f.Read(fcontents, 0, (int)size);
|
||||
for (uint i = 0; i < _size + 40000; i++)
|
||||
{
|
||||
if (_start + i <= 20000)
|
||||
_file.Seek(_start + i - 20000, SeekOrigin.Begin);
|
||||
if (_file.Read(_fileContents, (int)i, 1) == 0)
|
||||
_fileContents[i] = 0x00;
|
||||
}
|
||||
_smallFile = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool GuessOffsetCorrection()
|
||||
{
|
||||
if (_mode == 'p')
|
||||
{
|
||||
if (_current > 20000)
|
||||
{
|
||||
_mode = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
_offset = _current;
|
||||
_current += 4;
|
||||
return Calculate();
|
||||
}
|
||||
else if (_mode == 'n')
|
||||
{
|
||||
if (_current > 20000)
|
||||
{
|
||||
_mode = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
_offset = -_current;
|
||||
_current += 4;
|
||||
return Calculate();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_current > 20000)
|
||||
{
|
||||
_mode = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
_offset = _current;
|
||||
if (Calculate())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_offset = -_current;
|
||||
_current += 4;
|
||||
return Calculate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool Calculate()
|
||||
{
|
||||
var calc = new CRC32();
|
||||
if (_smallFile && _fileContents is not null)
|
||||
{
|
||||
if (_isRiff)
|
||||
calc.Calculate(_riff, 0, 44);
|
||||
|
||||
calc.Calculate(_fileContents, (int)(20000 + _offset), (int)_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
var buffer = new byte[1];
|
||||
uint i;
|
||||
_file.Seek(_start + _offset, SeekOrigin.Begin);
|
||||
if (_isRiff)
|
||||
calc.Calculate(_riff, 0, 44);
|
||||
|
||||
for (i = 0; i < _size; i++)
|
||||
{
|
||||
if (_file.Read(buffer, 0, 1) == 0)
|
||||
{
|
||||
buffer[0] = 0x00;
|
||||
_file.Seek(_start + _offset + i + 1, SeekOrigin.Begin);
|
||||
}
|
||||
calc.Calculate(buffer, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Offset correction {_offset} bytes, {_offset / 4} samples, CRC-32 {calc.Hash:08x}");
|
||||
return (calc.Hash == _crc);
|
||||
}
|
||||
|
||||
public void Done()
|
||||
{
|
||||
//if (smallfile)
|
||||
// fcontents = null;
|
||||
|
||||
if (_mode == 0x00)
|
||||
{
|
||||
Console.WriteLine("\nCan't find offset!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_saveTrack && !string.IsNullOrEmpty(_path))
|
||||
{
|
||||
byte[] buffer = new byte[1];
|
||||
Stream f2 = File.OpenWrite(_path);
|
||||
if (_isRiff)
|
||||
f2.Write(_riff, 0, 44);
|
||||
|
||||
_file.Seek(_start + _offset, SeekOrigin.Begin);
|
||||
for (uint i = 0; i < _size; i++)
|
||||
{
|
||||
if (_file.Read(buffer, 0, 1) == 0)
|
||||
{
|
||||
buffer[0] = 0x00;
|
||||
_file.Seek(_start + _offset + i + 1, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
f2.Write(buffer, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"\nDONE!\n\nOffset correction: {_offset} bytes / {_offset / 4} samples");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
psxt001z.Library/psxt001z.Library.csproj
Normal file
37
psxt001z.Library/psxt001z.Library.csproj
Normal file
@@ -0,0 +1,37 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Assembly Properties -->
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0;netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>0.21-rc3</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Kirill Korolyov, Matt Nadareski</Authors>
|
||||
<Description>C# port of psxt001z as a library</Description>
|
||||
<Copyright>Copyright (c)2013 Dremora, Copyright (c)2018-2025 Matt Nadareski</Copyright>
|
||||
<PackageProjectUrl>https://github.com/SabreTools/</PackageProjectUrl>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<RepositoryUrl>https://github.com/SabreTools/psxt001z</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>libcrypt psx ps1 psone</PackageTags>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../README.md" Pack="true" PackagePath="" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Net30.LinqBridge" Version="1.6.0" Condition="$(TargetFramework.StartsWith(`net2`))" />
|
||||
<PackageReference Include="SabreTools.IO" Version="[1.9.0]" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,28 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Assembly Properties -->
|
||||
<TargetFrameworks>net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>0.21-beta2</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Kirill Korolyov , Matt Nadareski</Authors>
|
||||
<Description>C# port of psxt001z as a library</Description>
|
||||
<Copyright>Copyright (c)2013 Dremora, Copyright (c)2018-2023 Matt Nadareski</Copyright>
|
||||
<PackageProjectUrl>https://github.com/SabreTools/</PackageProjectUrl>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<RepositoryUrl>https://github.com/SabreTools/psxt001z</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>libcrypt psx ps1 psone</PackageTags>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="README.md" Pack="true" PackagePath=""/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
19
psxt001z.sln
19
psxt001z.sln
@@ -3,20 +3,31 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "psxt001z", "psxt001z.csproj", "{1F3CFA21-FE9A-41C0-9919-712C612DC160}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "psxt001z.Library", "psxt001z.Library\psxt001z.Library.csproj", "{1F3CFA21-FE9A-41C0-9919-712C612DC160}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "psxt001z", "psxt001z\psxt001z.csproj", "{4A7C6E6E-4447-4198-9C97-9F5C4952DB47}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5D42A768-A040-4E6E-BEC9-61CBC81D3582}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
README.MD = README.MD
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1F3CFA21-FE9A-41C0-9919-712C612DC160}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1F3CFA21-FE9A-41C0-9919-712C612DC160}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1F3CFA21-FE9A-41C0-9919-712C612DC160}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1F3CFA21-FE9A-41C0-9919-712C612DC160}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4A7C6E6E-4447-4198-9C97-9F5C4952DB47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4A7C6E6E-4447-4198-9C97-9F5C4952DB47}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4A7C6E6E-4447-4198-9C97-9F5C4952DB47}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4A7C6E6E-4447-4198-9C97-9F5C4952DB47}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -1,166 +1,113 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using static psxt001z.Common;
|
||||
using static psxt001z.Functions;
|
||||
using SabreTools.IO.Extensions;
|
||||
using static psxt001z.LibCrypt;
|
||||
|
||||
namespace psxt001z
|
||||
{
|
||||
public class Main
|
||||
public class Program
|
||||
{
|
||||
public static int main(string[] args)
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine($"psxt001z by Dremora, {VERSION}");
|
||||
Console.WriteLine($"psxt001z by Dremora (ported by Matt Nadareski), {VERSION}");
|
||||
Console.WriteLine();
|
||||
|
||||
if (args == null || args.Length == 0)
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Help();
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.Length == 1)
|
||||
GetInfo(args[0]);
|
||||
|
||||
string feature = args[0];
|
||||
switch (feature)
|
||||
switch (args[0])
|
||||
{
|
||||
case "--checksums":
|
||||
case "-c":
|
||||
case "--checksums" or "-c":
|
||||
Checksums(args);
|
||||
break;
|
||||
|
||||
case "--libcrypt":
|
||||
case "-l":
|
||||
{
|
||||
if (args.Length != 1 && args.Length != 2)
|
||||
{
|
||||
LibCryptHelp();
|
||||
return 0;
|
||||
}
|
||||
case "--libcrypt" or "-l":
|
||||
DetectLibCrypt([.. args.Skip(2)]);
|
||||
break;
|
||||
|
||||
string subPath = args[0];
|
||||
string? sbiPath = null;
|
||||
if (args.Length == 2)
|
||||
sbiPath = args[1];
|
||||
case "--libcryptdrv":
|
||||
DetectLibCryptDrive([.. args.Skip(2)]);
|
||||
break;
|
||||
|
||||
if (!LibCrypt.LibCryptDetect(subPath, sbiPath))
|
||||
LibCryptHelp();
|
||||
|
||||
break;
|
||||
}
|
||||
case "--libcryptdrvfast":
|
||||
DetectLibCryptDriveFast([.. args.Skip(2)]);
|
||||
break;
|
||||
|
||||
case "--xorlibcrypt":
|
||||
LibCrypt.XorLibCrypt();
|
||||
XorLibCrypt();
|
||||
break;
|
||||
|
||||
case "--zektor":
|
||||
ClearEDCData(args[1]);
|
||||
case "--zektor" when args.Length == 2:
|
||||
Zektor(args[1]);
|
||||
break;
|
||||
|
||||
case "--antizektor":
|
||||
SetEDCData(args[1]);
|
||||
case "--antizektor" when args.Length == 2:
|
||||
AntiZektor(args[1]);
|
||||
break;
|
||||
|
||||
case "--patch":
|
||||
{
|
||||
string output = args[1];
|
||||
string input = args[2];
|
||||
int skip = 0;
|
||||
if (args.Length == 4)
|
||||
skip = int.Parse(args[3]);
|
||||
|
||||
Patch(output, input, skip);
|
||||
break;
|
||||
}
|
||||
|
||||
case "--resize":
|
||||
{
|
||||
string input = args[1];
|
||||
long newsize = long.Parse(args[2]);
|
||||
Resize(input, newsize);
|
||||
break;
|
||||
}
|
||||
|
||||
case "--track":
|
||||
{
|
||||
string filename = args[1];
|
||||
int start = int.Parse(args[2]);
|
||||
int size = int.Parse(args[3]);
|
||||
uint crc = uint.Parse(args[4]);
|
||||
|
||||
bool isRiff = false;
|
||||
bool? mode = null;
|
||||
string? output = null;
|
||||
for (int i = 5; i < args.Length; i++)
|
||||
{
|
||||
if (args[i] == "r")
|
||||
isRiff = true;
|
||||
else if (args[i][0] == '+')
|
||||
mode = true;
|
||||
else if (args[i][1] == '-')
|
||||
mode = false;
|
||||
else if (args[i] == "s")
|
||||
output = args[++i];
|
||||
}
|
||||
|
||||
Track trackfix = new Track(filename, start, size, crc, isRiff, mode, output);
|
||||
while (!trackfix.FindTrack()) ;
|
||||
trackfix.Done();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "--str":
|
||||
SplitStr(args);
|
||||
case "--patch" when args.Length == 4:
|
||||
Patch(args);
|
||||
break;
|
||||
|
||||
case "--str2bs":
|
||||
StrToBs(args);
|
||||
case "--resize" when args.Length == 3:
|
||||
Resize(args);
|
||||
break;
|
||||
|
||||
case "--gen":
|
||||
case "--track" when args.Length >= 5 && args.Length <= 9:
|
||||
var trackfix = new Track(args);
|
||||
while (!trackfix.GuessOffsetCorrection()) { }
|
||||
trackfix.Done();
|
||||
break;
|
||||
|
||||
case "--str" when args.Length == 4:
|
||||
Str(args);
|
||||
break;
|
||||
|
||||
case "--str2bs" when args.Length == 2:
|
||||
Str2Bs(args);
|
||||
break;
|
||||
|
||||
case "--gen" when args.Length == 3 || args.Length == 4:
|
||||
Generate(args);
|
||||
break;
|
||||
|
||||
case "--scan":
|
||||
Info.GetInfo(args[2], false);
|
||||
case "--scan" when args.Length == 2:
|
||||
LibCrypt.Info(args[1], false);
|
||||
break;
|
||||
|
||||
case "--fix":
|
||||
Info.GetInfo(args[2], true);
|
||||
case "--fix" when args.Length == 2:
|
||||
LibCrypt.Info(args[1], true);
|
||||
break;
|
||||
|
||||
case "--sub":
|
||||
CreateSubchannel(args[2], args[3]);
|
||||
case "--sub" when args.Length == 3:
|
||||
Sub(args[1], args[2]);
|
||||
break;
|
||||
|
||||
case "--m3s":
|
||||
M3S(args[2]);
|
||||
case "--m3s" when args.Length == 2:
|
||||
M3S(args[1]);
|
||||
break;
|
||||
|
||||
case "--matrix":
|
||||
{
|
||||
Matrix(args);
|
||||
break;
|
||||
}
|
||||
|
||||
//case "--libcryptdrv":
|
||||
// LibCrypt.LibCryptDrive(argv + 2);
|
||||
// break;
|
||||
//case "--libcryptdrvfast":
|
||||
// LibCrypt.LibCryptDriveFast(argv + 2);
|
||||
// break;
|
||||
case "--matrix" when args.Length == 5:
|
||||
Matrix(args);
|
||||
break;
|
||||
|
||||
default:
|
||||
Help();
|
||||
if (args.Length == 1)
|
||||
Info(args[1]);
|
||||
else
|
||||
Help();
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static void GetInfo(string filename)
|
||||
private static void Info(string filename)
|
||||
{
|
||||
Stream image;
|
||||
try
|
||||
@@ -173,7 +120,7 @@ namespace psxt001z
|
||||
return;
|
||||
}
|
||||
|
||||
FileTools file = new FileTools(image);
|
||||
var file = new FileTools(image);
|
||||
long imagesize = image.Length;
|
||||
|
||||
Console.WriteLine($"File: {filename}");
|
||||
@@ -184,7 +131,7 @@ namespace psxt001z
|
||||
return;
|
||||
}
|
||||
|
||||
long realsectors = file.imagesize();
|
||||
long realsectors = file.GetImageSize();
|
||||
long imagesectors = imagesize / 2352;
|
||||
long realsize = realsectors * 2352;
|
||||
if (imagesize == realsize)
|
||||
@@ -200,115 +147,125 @@ namespace psxt001z
|
||||
Console.WriteLine($"From image: {realsectors}");
|
||||
}
|
||||
|
||||
Console.WriteLine($"EDC in Form 2 sectors: {(GetEDCStatus(image) ? "YES" : "NO")}");
|
||||
Console.WriteLine($"EDC in Form 2 sectors: {(GetEDC(image) ? "YES" : "NO")}");
|
||||
|
||||
string exe = file.exe();
|
||||
string exe = file.GetExecutableName();
|
||||
Console.WriteLine($"ID: {exe.Substring(0, 4)}-{exe.Substring(5)}");
|
||||
Console.WriteLine($"Date: {file.date()}");
|
||||
Console.WriteLine($"Date: {file.GetDate()}");
|
||||
|
||||
Console.Write("System area: ");
|
||||
image.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
byte[] buffer = new byte[2352];
|
||||
CRC32 crc = new CRC32();
|
||||
var crc = new CRC32();
|
||||
for (uint i = 0; i < 16; i++)
|
||||
{
|
||||
image.Read(buffer, 0, 2352);
|
||||
crc.ProcessCRC(buffer, 0, 2352);
|
||||
_ = image.Read(buffer, 0, 2352);
|
||||
crc.Calculate(buffer, 0, 2352);
|
||||
}
|
||||
|
||||
uint imagecrc = crc.m_crc32;
|
||||
Console.WriteLine($"{Info.GetEdcType(imagecrc)}");
|
||||
uint imagecrc = crc.Hash;
|
||||
switch (imagecrc)
|
||||
{
|
||||
case 0x11e3052d: Console.WriteLine("Eu EDC"); break;
|
||||
case 0x808c19f6: Console.WriteLine("Eu NoEDC"); break;
|
||||
case 0x70ffa73e: Console.WriteLine("Eu Alt NoEDC"); break;
|
||||
case 0x7f9a25b1: Console.WriteLine("Eu Alt 2 EDC"); break;
|
||||
case 0x783aca30: Console.WriteLine("Jap EDC"); break;
|
||||
case 0xe955d6eb: Console.WriteLine("Jap NoEDC"); break;
|
||||
case 0x9b519a2e: Console.WriteLine("US EDC"); break;
|
||||
case 0x0a3e86f5: Console.WriteLine("US NoEDC"); break;
|
||||
case 0x6773d4db: Console.WriteLine("US Alt NoEDC"); break;
|
||||
default: Console.WriteLine($"Unknown, crc {imagecrc:x}"); break;
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
image.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
public static void Help()
|
||||
private static void Help()
|
||||
{
|
||||
Console.Write("Usage:\n");
|
||||
|
||||
Console.Write("======\n");
|
||||
|
||||
Console.Write("psxt001z.exe image.bin\n");
|
||||
Console.Write(" Display image's info.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --scan image.bin\n");
|
||||
Console.Write(" Scan image.bin postgap for errors.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --fix image.bin\n");
|
||||
Console.Write(" Scan image.bin postgap for errors and fix them.\n\n");
|
||||
|
||||
//Console.Write("psxt001z.exe --libcryptdrvfast <drive letter>\n");
|
||||
//Console.Write(" Check subchannels for LibCrypt protection using new detection\n method (disc).\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --checksums file [start [end]]\n");
|
||||
Console.Write(" Calculate file's checksums (CRC-32, MD5, SHA-1).\n");
|
||||
Console.Write(" [in] file Specifies the file, which checksums will be calculated.\n");
|
||||
Console.Write(" start Specifies start position for checksums calculation.\n");
|
||||
Console.Write(" size Specifies size of block for checksums calculation.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --zektor image.bin\n");
|
||||
Console.Write(" Zektor. Replace EDC in Form 2 Mode 2 sectors with zeroes.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --antizektor image.bin\n");
|
||||
Console.Write(" Antizektor. Restore EDC in Form 2 Mode 2 sectors.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --resize image.bin size\n");
|
||||
Console.Write(" Resize file to requested size.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --patch image.bin patch.bin offset\n");
|
||||
Console.Write(" Insert patch.bin into image.bin, skipping given number of bytes from the\n offset.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --track image.bin bytes_to_skip size crc-32 [r] [+/-/f] [s filename]\n");
|
||||
Console.Write(" Try to guess an offset correction of the image dump by searching a track with\n given size and CRC-32.\n r - Calculate crc with RIFF header.\n +/- - Search only for positive or negative offset correction.\n s - Save track with given filename.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --gen file.bin filesize [-r]\n");
|
||||
Console.Write(" Generate a file of the requested size.\n -r - add RIFF header.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --str file.str video.str audio.xa\n");
|
||||
Console.Write(" Deinterleave file.str to video.str and audio.xa.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --str2bs file.str\n");
|
||||
Console.Write(" Convert file.str to .bs-files.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --sub subchannel.sub size\n");
|
||||
Console.Write(" Generate RAW subchannel with given size (in sectors).\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --m3s subchannel.m3s\n");
|
||||
Console.Write(" Generate M3S subchannel.\n\n");
|
||||
|
||||
Console.Write("psxt001z.exe --libcrypt <sub> [<sbi>]\n");
|
||||
Console.Write("Usage: psxt001z.exe --libcrypt <sub> [<sbi>]\n");
|
||||
Console.Write(" Check subchannels for LibCrypt protection. (file)\n");
|
||||
Console.Write(" [in] <sub> Specifies the subchannel file to be scanned.\n");
|
||||
Console.Write(" [out] <sbi> Specifies the subchannel file in SBI format where protected\n sectors will be written.\n\n");
|
||||
|
||||
//Console.Write("psxt001z.exe --libcryptdrv <drive letter>\n");
|
||||
//Console.Write(" Check subchannels for LibCrypt protection (disc).\n\n");
|
||||
|
||||
Console.WriteLine("Usage:");
|
||||
Console.WriteLine("======");
|
||||
Console.WriteLine("psxt001z.exe image.bin");
|
||||
Console.WriteLine(" Display image's info.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --scan image.bin");
|
||||
Console.WriteLine(" Scan image.bin postgap for errors.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --fix image.bin");
|
||||
Console.WriteLine(" Scan image.bin postgap for errors and fix them.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --libcryptdrvfast <drive letter>");
|
||||
Console.WriteLine(" Check subchannels for LibCrypt protection using new detection\n method (disc).");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --checksums file [start [end]]");
|
||||
Console.WriteLine(" Calculate file's checksums (CRC-32, MD5, SHA-1).");
|
||||
Console.WriteLine(" [in] file Specifies the file, which checksums will be calculated.");
|
||||
Console.WriteLine(" start Specifies start position for checksums calculation.");
|
||||
Console.WriteLine(" size Specifies size of block for checksums calculation.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --zektor image.bin");
|
||||
Console.WriteLine(" Zektor. Replace EDC in Form 2 Mode 2 sectors with zeroes.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --antizektor image.bin");
|
||||
Console.WriteLine(" Antizektor. Restore EDC in Form 2 Mode 2 sectors.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --resize image.bin size");
|
||||
Console.WriteLine(" Resize file to requested size.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --patch image.bin patch.bin offset");
|
||||
Console.WriteLine(" Insert patch.bin into image.bin, skipping given number of bytes from the\n offset.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --track image.bin bytes_to_skip size crc-32 [r] [+/-/f] [s filename]");
|
||||
Console.WriteLine(" Try to guess an offset correction of the image dump by searching a track with\n given size and CRC-32.\n r - Calculate crc with RIFF header.\n +/- - Search only for positive or negative offset correction.\n s - Save track with given filename.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --gen file.bin filesize [-r]");
|
||||
Console.WriteLine(" Generate a file of the requested size.\n -r - add RIFF header.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --str file.str video.str audio.xa");
|
||||
Console.WriteLine(" Deinterleave file.str to video.str and audio.xa.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --str2bs file.str");
|
||||
Console.WriteLine(" Convert file.str to .bs-files.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --sub subchannel.sub size");
|
||||
Console.WriteLine(" Generate RAW subchannel with given size (in sectors).");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --m3s subchannel.m3s");
|
||||
Console.WriteLine(" Generate M3S subchannel.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --libcrypt <sub> [<sbi>]");
|
||||
Console.WriteLine("Usage: psxt001z.exe --libcrypt <sub> [<sbi>]");
|
||||
Console.WriteLine(" Check subchannels for LibCrypt protection. (file)");
|
||||
Console.WriteLine(" [in] <sub> Specifies the subchannel file to be scanned.");
|
||||
Console.WriteLine(" [out] <sbi> Specifies the subchannel file in SBI format where protected\n sectors will be written.");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("psxt001z.exe --libcryptdrv <drive letter>");
|
||||
Console.WriteLine(" Check subchannels for LibCrypt protection (disc).");
|
||||
Console.WriteLine();
|
||||
Console.Write("Press any key to continue...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
public static bool Patch(string output, string input, int skip = 0)
|
||||
private static bool Patch(string[] args)
|
||||
{
|
||||
Stream f1, f2;
|
||||
try
|
||||
{
|
||||
f1 = File.Open(output, FileMode.Open, FileAccess.ReadWrite);
|
||||
f2 = File.Open(input, FileMode.Open, FileAccess.Read);
|
||||
f1 = File.Open(args[1], FileMode.Open, FileAccess.ReadWrite);
|
||||
f2 = File.Open(args[2], FileMode.Open, FileAccess.Read);
|
||||
|
||||
f1.Seek(skip, SeekOrigin.Begin);
|
||||
f1.Seek(long.Parse(args[3]), SeekOrigin.Begin);
|
||||
|
||||
Console.WriteLine($"Patching \"{output}\" with \"{input}\", skipping {skip} bytes...");
|
||||
Console.WriteLine($"Patching \"{args[1]}\" with \"{args[2]}\", skipping {args[3]} bytes...");
|
||||
|
||||
int i = 0;
|
||||
while (f1.Position < f1.Length && f2.Position < f2.Length)
|
||||
{
|
||||
byte[] buffer = new byte[1];
|
||||
f2.Read(buffer, 0, 1);
|
||||
_ = f2.Read(buffer, 0, 1);
|
||||
f1.Write(buffer, 0, 1);
|
||||
i++;
|
||||
}
|
||||
@@ -327,12 +284,12 @@ namespace psxt001z
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Resize(string input, long newsize)
|
||||
private static bool Resize(string[] args)
|
||||
{
|
||||
Stream f;
|
||||
try
|
||||
{
|
||||
f = File.Open(input, FileMode.Open, FileAccess.ReadWrite);
|
||||
f = File.Open(args[1], FileMode.Open, FileAccess.ReadWrite);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -340,46 +297,49 @@ namespace psxt001z
|
||||
return false;
|
||||
}
|
||||
|
||||
FileTools image = new FileTools(f);
|
||||
switch (image.resize(newsize))
|
||||
var image = new FileTools(f);
|
||||
uint newsize = uint.Parse(args[2]);
|
||||
switch (image.Resize(newsize))
|
||||
{
|
||||
case 0:
|
||||
Console.Write($"File's \"{input}\" size is already {newsize} bytes!");
|
||||
Console.Write($"File's \"{args[1]}\" size is already {newsize} bytes!");
|
||||
break;
|
||||
case 1:
|
||||
Console.Write($"File \"{input}\" was successfully resized to {newsize} bytes!");
|
||||
Console.Write($"File \"{args[1]}\" was successfully resized to {newsize} bytes!");
|
||||
break;
|
||||
case 2:
|
||||
Console.Write($"File \"{input}\" was successfully truncated to {newsize} bytes!");
|
||||
Console.Write($"File \"{args[1]}\" was successfully truncated to {newsize} bytes!");
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Copy(string input, string output, long startbyte, long length)
|
||||
private static bool Copy(string[] args)
|
||||
{
|
||||
//args[1] - infile
|
||||
//args[2] - outfile
|
||||
//args[3] - startbyte
|
||||
//args[4] - length
|
||||
|
||||
Stream infile;
|
||||
try
|
||||
{
|
||||
infile = File.Open(input, FileMode.Open, FileAccess.Read);
|
||||
infile = File.Open(args[1], FileMode.Open, FileAccess.Read);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"File {input} can't be found.");
|
||||
Console.WriteLine($"File {args[1]} can't be found.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
//HANDLE hfile = CreateFileW(argv[1], GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0);
|
||||
//HANDLE hfile = CreateFileW(args[1], GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0);
|
||||
//SetFilePointer(hfile, newsize, 0, FILE_BEGIN);
|
||||
//SetEndOfFile(hfile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate EDC data for a Mode2/2352 image
|
||||
/// </summary>
|
||||
public static void SetEDCData(string filename)
|
||||
private static void AntiZektor(string filename)
|
||||
{
|
||||
Stream image = File.Open(filename, FileMode.Open, FileAccess.ReadWrite);
|
||||
|
||||
@@ -418,13 +378,13 @@ namespace psxt001z
|
||||
image.Seek(sector * 2352 + 18, SeekOrigin.Begin);
|
||||
|
||||
byte[] z = new byte[1];
|
||||
image.Read(z, 0, 1);
|
||||
_ = image.Read(z, 0, 1);
|
||||
if ((z[0] >> 5 & 0x1) != 0)
|
||||
{
|
||||
image.Seek(-3, SeekOrigin.Current);
|
||||
|
||||
byte[] buffer = new byte[2332];
|
||||
image.Read(buffer, 0, 2332);
|
||||
_ = image.Read(buffer, 0, 2332);
|
||||
image.Seek(0, SeekOrigin.Current);
|
||||
|
||||
buffer = BitConverter.GetBytes(CalculateEDC(buffer, 0, 2332, edc_lut));
|
||||
@@ -437,14 +397,16 @@ namespace psxt001z
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate CRC-32, MD5, and SHA-1 checksums
|
||||
/// </summary>
|
||||
public static byte Checksums(string[] args)
|
||||
private static byte Checksums(string[] args)
|
||||
{
|
||||
if (args.Length < 3 || args.Length > 5)
|
||||
{
|
||||
ChecksumsHelp();
|
||||
Console.WriteLine("psxt001z.exe --checksums file [start [end]]");
|
||||
Console.WriteLine(" Calculate file's checksums (CRC-32, MD5, SHA-1).");
|
||||
Console.WriteLine(" [in] file Specifies the file, which checksums will be calculated.");
|
||||
Console.WriteLine(" start Specifies start position for checksums calculation.");
|
||||
Console.WriteLine(" size Specifies size of block for checksums calculation.");
|
||||
Console.WriteLine();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -508,7 +470,7 @@ namespace psxt001z
|
||||
byte[] buffer = new byte[1024], digest = new byte[16];
|
||||
int len;
|
||||
|
||||
CRC32 crc = new CRC32();
|
||||
var crc = new CRC32();
|
||||
MD5 md5 = MD5.Create();
|
||||
md5.Initialize();
|
||||
SHA1 sha1 = SHA1.Create();
|
||||
@@ -537,24 +499,20 @@ namespace psxt001z
|
||||
|
||||
md5.TransformBlock(buffer, 0, len, null, 0);
|
||||
sha1.TransformBlock(buffer, 0, len, null, 0);
|
||||
crc.ProcessCRC(buffer, 0, len);
|
||||
crc.Calculate(buffer, 0, len);
|
||||
}
|
||||
|
||||
md5.TransformFinalBlock(digest, 0, digest.Length);
|
||||
sha1.TransformFinalBlock(Message_Digest, 0, Message_Digest.Length);
|
||||
|
||||
Console.Write($"\rCRC-32: {crc.m_crc32:8x} \n");
|
||||
Console.Write($"MD5: {BitConverter.ToString(md5.Hash!).Replace("-", string.Empty)}");
|
||||
Console.WriteLine($"MD5: {BitConverter.ToString(md5.Hash!).Replace("-", string.Empty)}");
|
||||
Console.WriteLine($"SHA-1: {BitConverter.ToString(sha1.Hash!).Replace("-", string.Empty)}");
|
||||
Console.WriteLine($"\rCRC-32: {crc.Hash:8x} \n");
|
||||
Console.WriteLine($"MD5: {md5.Hash.ToHexString()}");
|
||||
Console.WriteLine($"SHA-1: {sha1.Hash.ToHexString()}");
|
||||
Console.WriteLine();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate missing RIFF headers
|
||||
/// </summary>
|
||||
public static void Generate(string[] args)
|
||||
private static void Generate(string[] args)
|
||||
{
|
||||
Stream f = File.OpenWrite(args[2]);
|
||||
byte[] riff = new byte[44];
|
||||
@@ -568,10 +526,6 @@ namespace psxt001z
|
||||
riff[1] = 0x49;
|
||||
riff[2] = 0x46;
|
||||
riff[3] = 0x46;
|
||||
riff[4] = (byte)((size - 8) & 0xFF);
|
||||
riff[5] = (byte)((size - 8) >> 8);
|
||||
riff[6] = (byte)((size - 8) >> 16);
|
||||
riff[7] = (byte)((size - 8) >> 24);
|
||||
riff[8] = 0x57;
|
||||
riff[9] = 0x41;
|
||||
riff[10] = 0x56;
|
||||
@@ -604,11 +558,8 @@ namespace psxt001z
|
||||
riff[37] = 0x61;
|
||||
riff[38] = 0x74;
|
||||
riff[39] = 0x61;
|
||||
riff[40] = (byte)((size - 44) & 0xFF);
|
||||
riff[41] = (byte)((size - 44) >> 8);
|
||||
riff[42] = (byte)((size - 44) >> 16);
|
||||
riff[43] = (byte)((size - 44) >> 24);
|
||||
|
||||
Array.Copy(BitConverter.GetBytes(size - 8), 0, riff, 4, 4);
|
||||
Array.Copy(BitConverter.GetBytes(size - 44), 0, riff, 40, 4);
|
||||
f.Write(riff, 0, 44);
|
||||
}
|
||||
}
|
||||
@@ -621,13 +572,9 @@ namespace psxt001z
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a generic M3S subchannel file for a sector count
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
public static void M3S(string filename)
|
||||
private static void M3S(string filename)
|
||||
{
|
||||
byte[] buffer = { 0x41, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
byte[] buffer = [0x41, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
|
||||
Stream subchannel = File.Open(filename, FileMode.Create, FileAccess.Write);
|
||||
Console.Write($"File: {filename}");
|
||||
@@ -642,9 +589,9 @@ namespace psxt001z
|
||||
|
||||
byte frame = (byte)(sector - (min * 60 * 75) - (sec * 75));
|
||||
|
||||
buffer[3] = itob(min);
|
||||
buffer[4] = itob(sec);
|
||||
buffer[5] = itob(frame);
|
||||
buffer[3] = IntegerToBinary(min);
|
||||
buffer[4] = IntegerToBinary(sec);
|
||||
buffer[5] = IntegerToBinary(frame);
|
||||
|
||||
mindbl = sector2 / 60 / 75;
|
||||
min = (byte)Math.Floor(mindbl);
|
||||
@@ -654,9 +601,9 @@ namespace psxt001z
|
||||
|
||||
frame = (byte)(sector2 - (min * 60 * 75) - (sec * 75));
|
||||
|
||||
buffer[7] = itob(min);
|
||||
buffer[8] = itob(sec);
|
||||
buffer[9] = itob(frame);
|
||||
buffer[7] = IntegerToBinary(min);
|
||||
buffer[8] = IntegerToBinary(sec);
|
||||
buffer[9] = IntegerToBinary(frame);
|
||||
|
||||
ushort crc = CRC16.Calculate(buffer, 0, 10);
|
||||
subchannel.Write(buffer, 0, 10);
|
||||
@@ -672,17 +619,12 @@ namespace psxt001z
|
||||
}
|
||||
|
||||
Console.WriteLine("Creating M3S: 100%");
|
||||
|
||||
subchannel.Close();
|
||||
|
||||
Console.WriteLine("Done!");
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matrix 3 input files into a single output
|
||||
/// </summary>
|
||||
public static void Matrix(string[] args)
|
||||
private static void Matrix(string[] args)
|
||||
{
|
||||
Stream f1 = File.Open(args[2], FileMode.Open, FileAccess.ReadWrite);
|
||||
Stream f2 = File.Open(args[3], FileMode.Open, FileAccess.ReadWrite);
|
||||
@@ -693,13 +635,13 @@ namespace psxt001z
|
||||
for (long i = 0; i < subsize; i++)
|
||||
{
|
||||
byte[] r1 = new byte[1];
|
||||
f1.Read(r1, 0, 1);
|
||||
_ = f1.Read(r1, 0, 1);
|
||||
|
||||
byte[] r2 = new byte[1];
|
||||
f2.Read(r2, 0, 1);
|
||||
_ = f2.Read(r2, 0, 1);
|
||||
|
||||
byte[] r3 = new byte[1];
|
||||
f3.Read(r3, 0, 1);
|
||||
_ = f3.Read(r3, 0, 1);
|
||||
|
||||
if (r1 == r2)
|
||||
{
|
||||
@@ -728,44 +670,41 @@ namespace psxt001z
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Split a STR-formatted image into audio and video
|
||||
/// </summary>
|
||||
public static void SplitStr(string[] argv)
|
||||
private static void Str(string[] args)
|
||||
{
|
||||
Stream str = File.OpenRead(argv[2]);
|
||||
Stream str = File.OpenRead(args[2]);
|
||||
long filesize = str.Length;
|
||||
if (filesize % 2336 != 0)
|
||||
{
|
||||
Console.Write($"File '{argv[2]}' is not in STR format!");
|
||||
Console.Write($"File '{args[2]}' is not in STR format!");
|
||||
str.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
long sectors = filesize / 2336;
|
||||
Stream video = File.OpenWrite(argv[3]);
|
||||
Stream video = File.OpenWrite(args[3]);
|
||||
|
||||
sectors = filesize / 2336;
|
||||
Stream audio = File.OpenWrite(argv[4]);
|
||||
Stream audio = File.OpenWrite(args[4]);
|
||||
|
||||
for (long i = 0; i < sectors; i++)
|
||||
{
|
||||
str.Seek(2, SeekOrigin.Current);
|
||||
|
||||
byte[] ctrlbyte = new byte[1];
|
||||
str.Read(ctrlbyte, 0, 1);
|
||||
_ = str.Read(ctrlbyte, 0, 1);
|
||||
|
||||
byte[] buffer = new byte[2336];
|
||||
if ((ctrlbyte[0] >> 5 & 0x1) != 0)
|
||||
{
|
||||
str.Seek(-3, SeekOrigin.Current);
|
||||
str.Read(buffer, 0, 2336);
|
||||
_ = str.Read(buffer, 0, 2336);
|
||||
audio.Write(buffer, 0, 2336);
|
||||
}
|
||||
else
|
||||
{
|
||||
str.Seek(5, SeekOrigin.Current);
|
||||
str.Read(buffer, 0, 2048);
|
||||
_ = str.Read(buffer, 0, 2048);
|
||||
video.Write(buffer, 0, 2048);
|
||||
str.Seek(280, SeekOrigin.Current);
|
||||
}
|
||||
@@ -780,46 +719,27 @@ namespace psxt001z
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Split a STR-formatted file into BS-formatted blocks
|
||||
/// </summary>
|
||||
public static void StrToBs(string[] argv)
|
||||
private static void Str2Bs(string[] args)
|
||||
{
|
||||
byte[] buffer = new byte[2016];
|
||||
int filenamesize = argv[2].Length;
|
||||
string directory = $"{argv[2]}-bs";
|
||||
string directory = $"{args[2]}-bs";
|
||||
|
||||
Stream str = File.OpenRead(argv[2]);
|
||||
Stream str = File.OpenRead(args[2]);
|
||||
long filesize = str.Length;
|
||||
if (filesize % 2048 != 0)
|
||||
{
|
||||
Console.Write($"File '{argv[2]}; is not in STR format!");
|
||||
Console.Write($"File '{args[2]}; is not in STR format!");
|
||||
str.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
/*wchar_t newfilename[2048];
|
||||
for (u8 f = 0; f < strlen(filename); f++) {
|
||||
newfilename[f] = filename[f];
|
||||
*((char *)newfilename +f*2 +1) = 0;
|
||||
}*/
|
||||
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
long numblocks = filesize / 2048;
|
||||
Stream bs = File.OpenWrite(directory + "\\000001.bs");
|
||||
|
||||
// TODO: Figure out what these values were for
|
||||
// ushort a = 1;
|
||||
// ushort b = 0;
|
||||
// ushort c = 0;
|
||||
|
||||
byte[] ax = { 0, 0 };
|
||||
byte[] bx = { 0, 0 };
|
||||
byte[] cx = { 0, 0 };
|
||||
|
||||
str.Seek(32, SeekOrigin.Current);
|
||||
str.Read(buffer, 0, 2016);
|
||||
_ = str.Read(buffer, 0, 2016);
|
||||
Console.WriteLine(directory);
|
||||
|
||||
bs.Write(buffer, 0, 2016);
|
||||
@@ -831,7 +751,7 @@ namespace psxt001z
|
||||
str.Seek(1, SeekOrigin.Current);
|
||||
|
||||
byte[] byt = new byte[1];
|
||||
str.Read(byt, 0, 1);
|
||||
_ = str.Read(byt, 0, 1);
|
||||
|
||||
if (byt[0] == 0)
|
||||
{
|
||||
@@ -841,7 +761,7 @@ namespace psxt001z
|
||||
}
|
||||
|
||||
str.Seek(30, SeekOrigin.Current);
|
||||
str.Read(buffer, 0, 2016);
|
||||
_ = str.Read(buffer, 0, 2016);
|
||||
bs.Write(buffer, 0, 2016);
|
||||
}
|
||||
|
||||
@@ -854,10 +774,7 @@ namespace psxt001z
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a generic SUB subchannel file for a sector count
|
||||
/// </summary>
|
||||
public static void CreateSubchannel(string filename, string strsectors)
|
||||
private static void Sub(string filename, string strsectors)
|
||||
{
|
||||
long sectors = long.Parse(strsectors);
|
||||
if (sectors == 0 || sectors == -1)
|
||||
@@ -893,9 +810,9 @@ namespace psxt001z
|
||||
|
||||
byte frame = (byte)(sector - (min * 60 * 75) - (sec * 75));
|
||||
|
||||
buffer[3] = itob(min);
|
||||
buffer[4] = itob(sec);
|
||||
buffer[5] = itob(frame);
|
||||
buffer[3] = IntegerToBinary(min);
|
||||
buffer[4] = IntegerToBinary(sec);
|
||||
buffer[5] = IntegerToBinary(frame);
|
||||
|
||||
mindbl = sector2 / 60 / 75;
|
||||
min = (byte)Math.Floor(mindbl);
|
||||
@@ -905,9 +822,9 @@ namespace psxt001z
|
||||
|
||||
frame = (byte)(sector2 - (min * 60 * 75) - (sec * 75));
|
||||
|
||||
buffer[7] = itob(min);
|
||||
buffer[8] = itob(sec);
|
||||
buffer[9] = itob(frame);
|
||||
buffer[7] = IntegerToBinary(min);
|
||||
buffer[8] = IntegerToBinary(sec);
|
||||
buffer[9] = IntegerToBinary(frame);
|
||||
|
||||
ushort crc = CRC16.Calculate(buffer, 0, 10);
|
||||
|
||||
@@ -925,7 +842,7 @@ namespace psxt001z
|
||||
subchannel.WriteByte(0x00);
|
||||
}
|
||||
|
||||
Console.Write("Creating: %02u%%\r", (100 * sector) / sectors);
|
||||
Console.Write($"Creating: {(100 * sector) / sectors}%\r");
|
||||
}
|
||||
|
||||
subchannel.Seek(0, SeekOrigin.Begin);
|
||||
@@ -935,19 +852,14 @@ namespace psxt001z
|
||||
}
|
||||
|
||||
Console.WriteLine("Creating: 100%");
|
||||
|
||||
subchannel.Close();
|
||||
|
||||
Console.WriteLine("Done!");
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear EDC data from a Mode2/2352 image
|
||||
/// </summary>
|
||||
public static void ClearEDCData(string filename)
|
||||
private static void Zektor(string filename)
|
||||
{
|
||||
byte[] zero = { 0x00, 0x00, 0x00, 0x00 };
|
||||
byte[] zero = [0x00, 0x00, 0x00, 0x00];
|
||||
|
||||
Stream image = File.Open(filename, FileMode.Open, FileAccess.ReadWrite);
|
||||
long filesize = image.Length;
|
||||
@@ -966,7 +878,7 @@ namespace psxt001z
|
||||
image.Seek(sector * 2352 + 18, SeekOrigin.Begin);
|
||||
|
||||
byte[] z = new byte[1];
|
||||
image.Read(z, 0, 1);
|
||||
_ = image.Read(z, 0, 1);
|
||||
if ((z[0] >> 5 & 0x1) != 0)
|
||||
{
|
||||
image.Seek(2329, SeekOrigin.Current);
|
||||
@@ -978,28 +890,5 @@ namespace psxt001z
|
||||
Console.WriteLine("Done!");
|
||||
return;
|
||||
}
|
||||
|
||||
#region Help
|
||||
|
||||
private static void ChecksumsHelp()
|
||||
{
|
||||
Console.WriteLine("psxt001z.exe --checksums file [start [end]]");
|
||||
Console.WriteLine(" Calculate file's checksums (CRC-32, MD5, SHA-1).");
|
||||
Console.WriteLine(" [in] file Specifies the file, which checksums will be calculated.");
|
||||
Console.WriteLine(" start Specifies start position for checksums calculation.");
|
||||
Console.WriteLine(" size Specifies size of block for checksums calculation.");
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
private static void LibCryptHelp()
|
||||
{
|
||||
Console.WriteLine("LibCrypt detector\nUsage: psxt001z.exe --libcrypt <sub> [<sbi>]");
|
||||
Console.WriteLine(" Check subchannel for LibCrypt protection.");
|
||||
Console.WriteLine(" [in] <sub> Specifies the subchannel file to be scanned.");
|
||||
Console.WriteLine(" [out] <sbi> Specifies the subchannel file in SBI format where protected\n sectors will be written.");
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
46
psxt001z/psxt001z.csproj
Normal file
46
psxt001z/psxt001z.csproj
Normal file
@@ -0,0 +1,46 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Assembly Properties -->
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
|
||||
<OutputType>Exe</OutputType>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>0.21-rc3</Version>
|
||||
|
||||
<!-- Package Properties -->
|
||||
<Authors>Kirill Korolyov, Matt Nadareski</Authors>
|
||||
<Description>C# port of psxt001z</Description>
|
||||
<Copyright>Copyright (c)2013 Dremora, Copyright (c)2018-2024 Matt Nadareski</Copyright>
|
||||
<RepositoryUrl>https://github.com/SabreTools/psxt001z</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Support All Frameworks -->
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`)) OR $(TargetFramework.StartsWith(`net4`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`)) OR $(TargetFramework.StartsWith(`net10`))">
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\psxt001z.Library\psxt001z.Library.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Net30.LinqBridge" Version="1.6.0" Condition="$(TargetFramework.StartsWith(`net2`))" />
|
||||
<PackageReference Include="SabreTools.IO" Version="[1.9.0]" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
151
publish-nix.sh
Executable file
151
publish-nix.sh
Executable file
@@ -0,0 +1,151 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This batch file assumes the following:
|
||||
# - .NET 10.0 (or newer) SDK is installed and in PATH
|
||||
# - zip is installed and in PATH
|
||||
# - Git is installed and in PATH
|
||||
#
|
||||
# If any of these are not satisfied, the operation may fail
|
||||
# in an unpredictable way and result in an incomplete output.
|
||||
|
||||
# Optional parameters
|
||||
USE_ALL=false
|
||||
INCLUDE_DEBUG=false
|
||||
NO_BUILD=false
|
||||
NO_ARCHIVE=false
|
||||
while getopts "udba" OPTION; do
|
||||
case $OPTION in
|
||||
u)
|
||||
USE_ALL=true
|
||||
;;
|
||||
d)
|
||||
INCLUDE_DEBUG=true
|
||||
;;
|
||||
b)
|
||||
NO_BUILD=true
|
||||
;;
|
||||
a)
|
||||
NO_ARCHIVE=true
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option provided"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Set the current directory as a variable
|
||||
BUILD_FOLDER=$PWD
|
||||
|
||||
# Set the current commit hash
|
||||
COMMIT=$(git log --pretty=%H -1)
|
||||
|
||||
# Output the selected options
|
||||
echo "Selected Options:"
|
||||
echo " Use all frameworks (-u) $USE_ALL"
|
||||
echo " Include debug builds (-d) $INCLUDE_DEBUG"
|
||||
echo " No build (-b) $NO_BUILD"
|
||||
echo " No archive (-a) $NO_ARCHIVE"
|
||||
echo " "
|
||||
|
||||
# Create the build matrix arrays
|
||||
FRAMEWORKS=("net10.0")
|
||||
RUNTIMES=("win-x86" "win-x64" "win-arm64" "linux-x64" "linux-arm64" "osx-x64" "osx-arm64")
|
||||
|
||||
# Use expanded lists, if requested
|
||||
if [ $USE_ALL = true ]; then
|
||||
FRAMEWORKS=("net20" "net35" "net40" "net452" "net462" "net472" "net48" "netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0" "net9.0" "net10.0")
|
||||
fi
|
||||
|
||||
# Create the filter arrays
|
||||
SINGLE_FILE_CAPABLE=("net5.0" "net6.0" "net7.0" "net8.0" "net9.0" "net10.0")
|
||||
VALID_APPLE_FRAMEWORKS=("net6.0" "net7.0" "net8.0" "net9.0" "net10.0")
|
||||
VALID_CROSS_PLATFORM_FRAMEWORKS=("netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0" "net9.0" "net10.0")
|
||||
VALID_CROSS_PLATFORM_RUNTIMES=("win-arm64" "linux-x64" "linux-arm64" "osx-x64" "osx-arm64")
|
||||
|
||||
# Only build if requested
|
||||
if [ $NO_BUILD = false ]; then
|
||||
# Restore Nuget packages for all builds
|
||||
echo "Restoring Nuget packages"
|
||||
dotnet restore
|
||||
|
||||
# Create Nuget Package
|
||||
dotnet pack psxt001z.Library/psxt001z.Library.csproj --output $BUILD_FOLDER
|
||||
|
||||
# Build psxt001z
|
||||
for FRAMEWORK in "${FRAMEWORKS[@]}"; do
|
||||
for RUNTIME in "${RUNTIMES[@]}"; do
|
||||
# Output the current build
|
||||
echo "===== Build psxt001z - $FRAMEWORK, $RUNTIME ====="
|
||||
|
||||
# If we have an invalid combination of framework and runtime
|
||||
if [[ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then
|
||||
if [[ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then
|
||||
echo "Skipped due to invalid combination"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# If we have Apple silicon but an unsupported framework
|
||||
if [[ ! $(echo ${VALID_APPLE_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then
|
||||
if [ $RUNTIME = "osx-arm64" ]; then
|
||||
echo "Skipped due to no Apple Silicon support"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Only .NET 5 and above can publish to a single file
|
||||
if [[ $(echo ${SINGLE_FILE_CAPABLE[@]} | fgrep -w $FRAMEWORK) ]]; then
|
||||
# Only include Debug if set
|
||||
if [ $INCLUDE_DEBUG = true ]; then
|
||||
dotnet publish psxt001z/psxt001z.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true
|
||||
fi
|
||||
dotnet publish psxt001z/psxt001z.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false
|
||||
else
|
||||
# Only include Debug if set
|
||||
if [ $INCLUDE_DEBUG = true ]; then
|
||||
dotnet publish psxt001z/psxt001z.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT
|
||||
fi
|
||||
dotnet publish psxt001z/psxt001z.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:DebugType=None -p:DebugSymbols=false
|
||||
fi
|
||||
done
|
||||
done
|
||||
fi
|
||||
|
||||
# Only create archives if requested
|
||||
if [ $NO_ARCHIVE = false ]; then
|
||||
# Create psxt001z archives
|
||||
for FRAMEWORK in "${FRAMEWORKS[@]}"; do
|
||||
for RUNTIME in "${RUNTIMES[@]}"; do
|
||||
# Output the current build
|
||||
echo "===== Archive psxt001z - $FRAMEWORK, $RUNTIME ====="
|
||||
|
||||
# If we have an invalid combination of framework and runtime
|
||||
if [[ ! $(echo ${VALID_CROSS_PLATFORM_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then
|
||||
if [[ $(echo ${VALID_CROSS_PLATFORM_RUNTIMES[@]} | fgrep -w $RUNTIME) ]]; then
|
||||
echo "Skipped due to invalid combination"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# If we have Apple silicon but an unsupported framework
|
||||
if [[ ! $(echo ${VALID_APPLE_FRAMEWORKS[@]} | fgrep -w $FRAMEWORK) ]]; then
|
||||
if [ $RUNTIME = "osx-arm64" ]; then
|
||||
echo "Skipped due to no Apple Silicon support"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Only include Debug if set
|
||||
if [ $INCLUDE_DEBUG = true ]; then
|
||||
cd $BUILD_FOLDER/psxt001z/bin/Debug/${FRAMEWORK}/${RUNTIME}/publish/
|
||||
zip -r $BUILD_FOLDER/psxt001z_${FRAMEWORK}_${RUNTIME}_debug.zip .
|
||||
fi
|
||||
cd $BUILD_FOLDER/psxt001z/bin/Release/${FRAMEWORK}/${RUNTIME}/publish/
|
||||
zip -r $BUILD_FOLDER/psxt001z_${FRAMEWORK}_${RUNTIME}_release.zip .
|
||||
done
|
||||
done
|
||||
|
||||
# Reset the directory
|
||||
cd $BUILD_FOLDER
|
||||
fi
|
||||
136
publish-win.ps1
Normal file
136
publish-win.ps1
Normal file
@@ -0,0 +1,136 @@
|
||||
# This batch file assumes the following:
|
||||
# - .NET 10.0 (or newer) SDK is installed and in PATH
|
||||
# - 7-zip commandline (7z.exe) is installed and in PATH
|
||||
# - Git for Windows is installed and in PATH
|
||||
#
|
||||
# If any of these are not satisfied, the operation may fail
|
||||
# in an unpredictable way and result in an incomplete output.
|
||||
|
||||
# Optional parameters
|
||||
param(
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias("UseAll")]
|
||||
[switch]$USE_ALL,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias("IncludeDebug")]
|
||||
[switch]$INCLUDE_DEBUG,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias("NoBuild")]
|
||||
[switch]$NO_BUILD,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[Alias("NoArchive")]
|
||||
[switch]$NO_ARCHIVE
|
||||
)
|
||||
|
||||
# Set the current directory as a variable
|
||||
$BUILD_FOLDER = $PSScriptRoot
|
||||
|
||||
# Set the current commit hash
|
||||
$COMMIT = git log --pretty=format:"%H" -1
|
||||
|
||||
# Output the selected options
|
||||
Write-Host "Selected Options:"
|
||||
Write-Host " Use all frameworks (-UseAll) $USE_ALL"
|
||||
Write-Host " Include debug builds (-IncludeDebug) $INCLUDE_DEBUG"
|
||||
Write-Host " No build (-NoBuild) $NO_BUILD"
|
||||
Write-Host " No archive (-NoArchive) $NO_ARCHIVE"
|
||||
Write-Host " "
|
||||
|
||||
# Create the build matrix arrays
|
||||
$FRAMEWORKS = @('net10.0')
|
||||
$RUNTIMES = @('win-x86', 'win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64')
|
||||
|
||||
# Use expanded lists, if requested
|
||||
if ($USE_ALL.IsPresent) {
|
||||
$FRAMEWORKS = @('net20', 'net35', 'net40', 'net452', 'net462', 'net472', 'net48', 'netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0', 'net9.0', 'net10.0')
|
||||
}
|
||||
|
||||
# Create the filter arrays
|
||||
$SINGLE_FILE_CAPABLE = @('net5.0', 'net6.0', 'net7.0', 'net8.0', 'net9.0', 'net10.0')
|
||||
$VALID_APPLE_FRAMEWORKS = @('net6.0', 'net7.0', 'net8.0', 'net9.0', 'net10.0')
|
||||
$VALID_CROSS_PLATFORM_FRAMEWORKS = @('netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0', 'net9.0', 'net10.0')
|
||||
$VALID_CROSS_PLATFORM_RUNTIMES = @('win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64')
|
||||
|
||||
# Only build if requested
|
||||
if (!$NO_BUILD.IsPresent) {
|
||||
# Restore Nuget packages for all builds
|
||||
Write-Host "Restoring Nuget packages"
|
||||
dotnet restore
|
||||
|
||||
# Create Nuget Package
|
||||
dotnet pack psxt001z.Library\psxt001z.Library.csproj --output $BUILD_FOLDER
|
||||
|
||||
# Build psxt001z
|
||||
foreach ($FRAMEWORK in $FRAMEWORKS) {
|
||||
foreach ($RUNTIME in $RUNTIMES) {
|
||||
# Output the current build
|
||||
Write-Host "===== Build psxt001z - $FRAMEWORK, $RUNTIME ====="
|
||||
|
||||
# If we have an invalid combination of framework and runtime
|
||||
if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) {
|
||||
Write-Host "Skipped due to invalid combination"
|
||||
continue
|
||||
}
|
||||
|
||||
# If we have Apple silicon but an unsupported framework
|
||||
if ($VALID_APPLE_FRAMEWORKS -notcontains $FRAMEWORK -and $RUNTIME -eq 'osx-arm64') {
|
||||
Write-Host "Skipped due to no Apple Silicon support"
|
||||
continue
|
||||
}
|
||||
|
||||
# Only .NET 5 and above can publish to a single file
|
||||
if ($SINGLE_FILE_CAPABLE -contains $FRAMEWORK) {
|
||||
# Only include Debug if set
|
||||
if ($INCLUDE_DEBUG.IsPresent) {
|
||||
dotnet publish psxt001z\psxt001z.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true
|
||||
}
|
||||
dotnet publish psxt001z\psxt001z.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false
|
||||
}
|
||||
else {
|
||||
# Only include Debug if set
|
||||
if ($INCLUDE_DEBUG.IsPresent) {
|
||||
dotnet publish psxt001z\psxt001z.csproj -f $FRAMEWORK -r $RUNTIME -c Debug --self-contained true --version-suffix $COMMIT
|
||||
}
|
||||
dotnet publish psxt001z\psxt001z.csproj -f $FRAMEWORK -r $RUNTIME -c Release --self-contained true --version-suffix $COMMIT -p:DebugType=None -p:DebugSymbols=false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Only create archives if requested
|
||||
if (!$NO_ARCHIVE.IsPresent) {
|
||||
# Create psxt001z archives
|
||||
foreach ($FRAMEWORK in $FRAMEWORKS) {
|
||||
foreach ($RUNTIME in $RUNTIMES) {
|
||||
# Output the current build
|
||||
Write-Host "===== Archive Program - $FRAMEWORK, $RUNTIME ====="
|
||||
|
||||
# If we have an invalid combination of framework and runtime
|
||||
if ($VALID_CROSS_PLATFORM_FRAMEWORKS -notcontains $FRAMEWORK -and $VALID_CROSS_PLATFORM_RUNTIMES -contains $RUNTIME) {
|
||||
Write-Host "Skipped due to invalid combination"
|
||||
continue
|
||||
}
|
||||
|
||||
# If we have Apple silicon but an unsupported framework
|
||||
if ($VALID_APPLE_FRAMEWORKS -notcontains $FRAMEWORK -and $RUNTIME -eq 'osx-arm64') {
|
||||
Write-Host "Skipped due to no Apple Silicon support"
|
||||
continue
|
||||
}
|
||||
|
||||
# Only include Debug if set
|
||||
if ($INCLUDE_DEBUG.IsPresent) {
|
||||
Set-Location -Path $BUILD_FOLDER\psxt001z\bin\Debug\${FRAMEWORK}\${RUNTIME}\publish\
|
||||
7z a -tzip $BUILD_FOLDER\psxt001z_${FRAMEWORK}_${RUNTIME}_debug.zip *
|
||||
}
|
||||
|
||||
Set-Location -Path $BUILD_FOLDER\psxt001z\bin\Release\${FRAMEWORK}\${RUNTIME}\publish\
|
||||
7z a -tzip $BUILD_FOLDER\psxt001z_${FRAMEWORK}_${RUNTIME}_release.zip *
|
||||
}
|
||||
}
|
||||
|
||||
# Reset the directory
|
||||
Set-Location -Path $PSScriptRoot
|
||||
}
|
||||
Reference in New Issue
Block a user