Convert so it works on Linux

This commit is contained in:
twinaphex 2016-05-02 22:51:36 +02:00
parent 72618c6bc2
commit 4dfc6eb676
11 changed files with 116 additions and 280 deletions

42
Windows/Makefile Normal file
View File

@ -0,0 +1,42 @@
TARGET := psxtract
LIBRETRO_COMM_DIR := ../../..
SOURCES := \
lz.c \
libkirk/aes.c \
libkirk/amctrl.c \
libkirk/bn.c \
libkirk/des.c \
libkirk/ec.c \
libkirk/kirk_engine.c \
libkirk/sha1.c
SOURCES_CXX := \
cdrom.cpp \
crypto.cpp \
psxtract.cpp \
utils.cpp
OBJS := $(SOURCES:.c=.o) $(SOURCES_CXX:.cpp=.o)
CFLAGS += -Wall -pedantic -std=gnu99 -g
CXXFLAGS += -Wall -pedantic -g
all: $(TARGET)
%.o: %.cpp
$(CXX) -c -o $@ $< $(CXXFLAGS)
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)
$(TARGET): $(OBJS)
$(CXX) -o $@ $^ $(LDFLAGS)
clean:
rm -f $(TARGET) $(OBJS)
.PHONY: clean

39
Windows/boolean.h Normal file
View File

@ -0,0 +1,39 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (boolean.h).
* ---------------------------------------------------------------------------------------
*
* 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 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.
*/
#ifndef __LIBRETRO_SDK_BOOLEAN_H
#define __LIBRETRO_SDK_BOOLEAN_H
#ifndef __cplusplus
#if defined(_MSC_VER) && !defined(SN_TARGET_PS3)
/* Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. */
#define bool unsigned char
#define true 1
#define false 0
#else
#include <stdbool.h>
#endif
#endif
#endif

View File

@ -11,6 +11,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "boolean.h"
// Position and size of individual elements in a CD sector.
#define SECTOR_SIZE 2352
@ -140,4 +142,4 @@ struct fixImageStatus
int form2bootsectorswithoutedc;
};
int make_cdrom(char* inputfile, char* outputfile, bool verbose);
int make_cdrom(char* inputfile, char* outputfile, bool verbose);

View File

@ -6,8 +6,16 @@
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
int decode_range(unsigned int *range, unsigned int *code, unsigned char **src);
int decode_bit(unsigned int *range, unsigned int *code, int *index, unsigned char **src, unsigned char *c);
int decode_number(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src);
int decode_word(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src);
int decompress(unsigned char *out, unsigned char *in, unsigned int size);
int decompress(unsigned char *out, unsigned char *in, unsigned int size);
#ifdef __cplusplus
}
#endif

View File

@ -1,6 +1,7 @@
// Copyright (C) 2014 Hykem <hykem@hotmail.com>
// Licensed under the terms of the GNU GPL, version 3
// http://www.gnu.org/licenses/gpl-3.0.txt
#include <sys/stat.h>
#include "psxtract.h"
@ -932,30 +933,30 @@ int main(int argc, char **argv)
printf("Unpacking PBP %s...\n", input_filename);
// Setup a new directory to output the unpacked contents.
_mkdir("PBP");
_chdir("PBP");
mkdir("PBP", 0755);
chdir("PBP");
// Unpack the EBOOT.PBP file.
if (unpack_pbp(input))
{
printf("ERROR: Failed to unpack %s!", input_filename);
_chdir("..");
_rmdir("PBP");
chdir("..");
rmdir("PBP");
return -1;
}
else
printf("Successfully unpacked %s!\n\n", input_filename);
// Change the directory back.
_chdir("..");
chdir("..");
// Make a directory for CD-ROM images if required.
if (conv)
_mkdir("CDROM");
mkdir("CDROM", 0755);
// Make a new directory for the ISO data.
_mkdir("ISO");
_chdir("ISO");
mkdir("ISO", 0755);
chdir("ISO");
// Locate DATA.PSAR.
FILE* psar = fopen("../PBP/DATA.PSAR", "rb");
@ -1009,7 +1010,7 @@ int main(int argc, char **argv)
decrypt_single_disc(psar, psar_size, startdat_offset, pgd_key, conv);
// Change the directory back.
_chdir("..");
chdir("..");
// Clean up.
fclose(psar);

View File

@ -2,9 +2,12 @@
// Licensed under the terms of the GNU GPL, version 3
// http://www.gnu.org/licenses/gpl-3.0.txt
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#include <direct.h>
#else
#include <unistd.h>
#endif
#include "cdrom.h"
#include "lz.h"
@ -93,4 +96,4 @@ typedef struct {
unsigned int data_size;
unsigned int unk3; // 0 or chcksm
unsigned int unk4; // 0 or chcksm
} SIMPLE_HEADER;
} SIMPLE_HEADER;

View File

@ -1,162 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B86E1508-26B6-465B-ABEC-A35E07E2A187}</ProjectGuid>
<RootNamespace>psxtract</RootNamespace>
<ProjectName>psxtract</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>..\bin</OutDir>
<TargetName>psxtract.debug</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TargetName>psxtract.debug</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>..\bin</OutDir>
<TargetName>psxtract</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetName>psxtract</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="cdrom.cpp" />
<ClCompile Include="crypto.cpp" />
<ClCompile Include="libkirk\aes.c" />
<ClCompile Include="libkirk\amctrl.c" />
<ClCompile Include="libkirk\bn.c" />
<ClCompile Include="libkirk\des.c" />
<ClCompile Include="libkirk\ec.c" />
<ClCompile Include="libkirk\kirk_engine.c" />
<ClCompile Include="libkirk\sha1.c" />
<ClCompile Include="lz.cpp" />
<ClCompile Include="psxtract.cpp" />
<ClCompile Include="utils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="cdrom.h" />
<ClInclude Include="crypto.h" />
<ClInclude Include="libkirk\aes.h" />
<ClInclude Include="libkirk\amctrl.h" />
<ClInclude Include="libkirk\des.h" />
<ClInclude Include="libkirk\kirk_engine.h" />
<ClInclude Include="libkirk\sha1.h" />
<ClInclude Include="libkirk\key_vault.h" />
<ClInclude Include="libkirk\psp_headers.h" />
<ClInclude Include="lz.h" />
<ClInclude Include="psxtract.h" />
<ClInclude Include="utils.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,96 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Source Files\libkirk">
<UniqueIdentifier>{587a9468-22a3-4044-b7f3-87bb43cf8eb8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="psxtract.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="libkirk\aes.c">
<Filter>Source Files\libkirk</Filter>
</ClCompile>
<ClCompile Include="libkirk\amctrl.c">
<Filter>Source Files\libkirk</Filter>
</ClCompile>
<ClCompile Include="libkirk\bn.c">
<Filter>Source Files\libkirk</Filter>
</ClCompile>
<ClCompile Include="libkirk\ec.c">
<Filter>Source Files\libkirk</Filter>
</ClCompile>
<ClCompile Include="libkirk\kirk_engine.c">
<Filter>Source Files\libkirk</Filter>
</ClCompile>
<ClCompile Include="libkirk\sha1.c">
<Filter>Source Files\libkirk</Filter>
</ClCompile>
<ClCompile Include="libkirk\des.c">
<Filter>Source Files\libkirk</Filter>
</ClCompile>
<ClCompile Include="crypto.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="lz.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cdrom.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="psxtract.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="libkirk\aes.h">
<Filter>Source Files\libkirk</Filter>
</ClInclude>
<ClInclude Include="libkirk\amctrl.h">
<Filter>Source Files\libkirk</Filter>
</ClInclude>
<ClInclude Include="libkirk\kirk_engine.h">
<Filter>Source Files\libkirk</Filter>
</ClInclude>
<ClInclude Include="libkirk\sha1.h">
<Filter>Source Files\libkirk</Filter>
</ClInclude>
<ClInclude Include="libkirk\des.h">
<Filter>Source Files\libkirk</Filter>
</ClInclude>
<ClInclude Include="libkirk\key_vault.h">
<Filter>Source Files\libkirk</Filter>
</ClInclude>
<ClInclude Include="libkirk\psp_headers.h">
<Filter>Source Files\libkirk</Filter>
</ClInclude>
<ClInclude Include="crypto.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="lz.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="utils.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="cdrom.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -2,16 +2,19 @@
// Licensed under the terms of the GNU GPL, version 3
// http://www.gnu.org/licenses/gpl-3.0.txt
#include <stdint.h>
#include <string.h>
typedef unsigned long long u64;
typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;
#include "boolean.h"
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
u16 se16(u16 i);
u32 se32(u32 i);
u64 se64(u64 i);
unsigned char* strip_utf8(unsigned char *src, int size);
bool isEmpty(unsigned char* buf, int buf_size);
bool isEmpty(unsigned char* buf, int buf_size);