mirror of
https://github.com/simtactics/niotso.git
synced 2025-03-15 08:11:22 +00:00
Rewrote hitdump to use a parser and Shutdown_M
This commit is contained in:
parent
6dddbd2efa
commit
5488883991
8 changed files with 311 additions and 323 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -110,6 +110,9 @@ qrc_*.cpp
|
|||
*.tar.*
|
||||
*.zip
|
||||
*.7z
|
||||
*.gz
|
||||
*.bz2
|
||||
*.xz
|
||||
*.rar
|
||||
*.cab
|
||||
*.msi
|
||||
|
|
|
@ -29,10 +29,11 @@ static IFFFile IFFFileInfo;
|
|||
static int iffcreated = 0;
|
||||
|
||||
static void Shutdown_M(const char * Message){
|
||||
fprintf(stderr, "iffexport: error: %s.", Message);
|
||||
fprintf(stderr, "iffexport: error: %s.\n", Message);
|
||||
if(iffcreated)
|
||||
iff_delete(&IFFFileInfo);
|
||||
free(IFFData);
|
||||
if(hFile)
|
||||
fclose(hFile);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -39,9 +39,10 @@ static uint8_t * UTKData = NULL;
|
|||
static uint8_t * WaveData = NULL;
|
||||
|
||||
static void Shutdown_M(const char * Message){
|
||||
fprintf(stderr, "utkdecode: error: %s.", Message);
|
||||
fprintf(stderr, "utkdecode: error: %s.\n", Message);
|
||||
free(WaveData);
|
||||
free(UTKData);
|
||||
if(hFile)
|
||||
fclose(hFile);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -39,9 +39,10 @@ static uint8_t * XAData = NULL;
|
|||
static uint8_t * WaveData = NULL;
|
||||
|
||||
static void Shutdown_M(const char * Message){
|
||||
fprintf(stderr, "xadecode: error: %s.", Message);
|
||||
fprintf(stderr, "xadecode: error: %s.\n", Message);
|
||||
free(WaveData);
|
||||
free(XAData);
|
||||
if(hFile)
|
||||
fclose(hFile);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ static void KillGLWindow()
|
|||
|
||||
static int CreateGLWindow(const char *__restrict title, uint16_t width, uint16_t height)
|
||||
{
|
||||
PIXELFORMATDESCRIPTOR pfd = {
|
||||
const PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof(PIXELFORMATDESCRIPTOR), 1, /* Size and version */
|
||||
PFD_DRAW_TO_WINDOW | /* dwFlags */
|
||||
PFD_SUPPORT_OPENGL |
|
||||
|
|
|
@ -19,50 +19,126 @@
|
|||
#include <basetyps.h>
|
||||
#pragma pack(0)
|
||||
|
||||
DECLARE_INTERFACE(cUnknownObject1)
|
||||
DECLARE_INTERFACE(cRZString)
|
||||
{
|
||||
DWORD Zero1;
|
||||
DWORD Zero2;
|
||||
void * vtable5;
|
||||
char ** Strings1;
|
||||
char ** Strings2;
|
||||
char ** Strings3;
|
||||
DWORD Zero3;
|
||||
DWORD Zero4;
|
||||
DWORD Zero5;
|
||||
void ** Pointer1; //12 bytes
|
||||
void ** Pointer2; //4 bytes
|
||||
void ** Pointer3;
|
||||
DWORD Flags;
|
||||
DWORD * Pointer4; //4 bytes
|
||||
void * Pointer5;
|
||||
void * Pointer6;
|
||||
DWORD Unknown11;
|
||||
DWORD Unknown12;
|
||||
void * vtable1_cRZString;
|
||||
char * mpBegin; //Pointer to beginning of string
|
||||
char * mpEnd; //Pointer to null terminator
|
||||
char * mpCapacity; //mpEnd + 1
|
||||
DWORD mAllocator; //0
|
||||
DWORD Zero1; //0
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE(cTSOEdithEditorDCOMDirector)
|
||||
struct stringstruct
|
||||
{
|
||||
void * vtable2;
|
||||
void * vtable1;
|
||||
cUnknownObject1 Object1;
|
||||
void * vtable4;
|
||||
void * vtable3;
|
||||
cUnknownObject1 Object2;
|
||||
cUnknownObject1 Object3;
|
||||
DWORD StringID;
|
||||
DWORD Unknown;
|
||||
char * PointerToBuffer; //Buffer
|
||||
DWORD SizeOfBuffer; //256
|
||||
char Buffer[256];
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE(cEdithEditorCOMDirector)
|
||||
{
|
||||
void * vtable_1_cEdithEditorCOMDirector;
|
||||
void * vtable_2_cEdithEditorCOMDirector;
|
||||
DWORD Zero1;
|
||||
DWORD Zero2;
|
||||
DWORD Zero3;
|
||||
DWORD Zero4;
|
||||
cRZString string;
|
||||
DWORD Zero5;
|
||||
DWORD Zero6;
|
||||
DWORD Zero7;
|
||||
DWORD Zero8;
|
||||
DWORD Zero9;
|
||||
DWORD Zero10;
|
||||
DWORD Unknown1;
|
||||
DWORD Pointer1;
|
||||
DWORD Pointer2;
|
||||
DWORD Zero11;
|
||||
void * ptr;
|
||||
DWORD Value1; //2
|
||||
DWORD Value2; //1
|
||||
float Value3; //1.0f
|
||||
DWORD Value4; //0x40000000
|
||||
DWORD Value5; //2
|
||||
DWORD Value6; //0
|
||||
DWORD Value7; //1
|
||||
DWORD Value8; //0
|
||||
stringstruct string0; //StringID:0, Unknown:40, value:"index"
|
||||
stringstruct string1; //StringID:1, Unknown:40, value:"value"
|
||||
stringstruct string2; //StringID:2, Unknown:150, value:"Name"
|
||||
stringstruct string3; //StringID:3, Unknown:200, value:"Description"
|
||||
DWORD Value9; //0
|
||||
DWORD Value10; //0
|
||||
stringstruct string4; //StringID:0, Unknown:90, value:"Calling Tree"
|
||||
stringstruct string5; //StringID:1, Unknown:86, value:"Type"
|
||||
stringstruct string6; //StringID:2, Unknown:83, value:"Title"
|
||||
stringstruct string7; //StringID:3, Unknown:65, value:"Yes"
|
||||
stringstruct string8; //StringID:4, Unknown:65, value:"No"
|
||||
stringstruct string9; //StringID:5, Unknown:65, value:"Cancel"
|
||||
stringstruct string10; //StringID:6, Unknown:300, value:"Message"
|
||||
stringstruct string11; //StringID:7, Unknown:45, value:"Tree ID"
|
||||
stringstruct string12; //StringID:8, Unknown:50, value:"Node #"
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE(cTSOEdithEditorDCOMDirector)
|
||||
{
|
||||
void * vtable1_cTSOEdithEditorDCOMDirector;
|
||||
void * vtable2_cTSOEdithEditorDCOMDirector;
|
||||
DWORD Zero1;
|
||||
DWORD Zero2;
|
||||
cRZString String1;
|
||||
DWORD Zero5;
|
||||
DWORD Zero6;
|
||||
cEdithEditorCOMDirector ** memptr_1;
|
||||
void ** memptr_2;
|
||||
void ** memptr_3; //Same as memptr_2
|
||||
DWORD Zero7;
|
||||
DWORD Zero8;
|
||||
void * dllptr_4_100B5834; //CMemoryException TD
|
||||
DWORD Value1; //1
|
||||
DWORD Value2; //0
|
||||
float Value3; //1.0f
|
||||
DWORD Value4; //0x40000000
|
||||
DWORD Value5; //0
|
||||
DWORD Value6; //0
|
||||
DWORD Value7; //1
|
||||
cRZString String2;
|
||||
cRZString String3;
|
||||
cRZString String4;
|
||||
cRZString String5;
|
||||
cRZString String6;
|
||||
cRZString String7;
|
||||
cRZString String8;
|
||||
cRZString String9;
|
||||
DWORD Zero9;
|
||||
DWORD Zero10;
|
||||
DWORD Zero11;
|
||||
DWORD Zero12;
|
||||
DWORD Zero13;
|
||||
DWORD Zero14;
|
||||
DWORD Zero15;
|
||||
cRZString String10;
|
||||
cRZString String11;
|
||||
cRZString String12;
|
||||
cRZString String13;
|
||||
cRZString String14;
|
||||
DWORD Zero16;
|
||||
DWORD Zero17;
|
||||
DWORD Zero18;
|
||||
DWORD Zero19;
|
||||
DWORD Zero20;
|
||||
cRZString String15;
|
||||
cRZString String16;
|
||||
cRZString String17;
|
||||
cRZString String18;
|
||||
cRZString String19;
|
||||
cRZString String20;
|
||||
cRZString String21;
|
||||
cRZString String22;
|
||||
cRZString String23;
|
||||
cRZString String24;
|
||||
cRZString String25;
|
||||
cRZString String26;
|
||||
cRZString String27;
|
||||
cRZString String28;
|
||||
cRZString String29;
|
||||
cRZString String30;
|
||||
};
|
|
@ -16,6 +16,7 @@
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -33,6 +34,8 @@
|
|||
#define read_uint16(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)))
|
||||
#endif
|
||||
|
||||
static void Shutdown_M(const char * Message, ...);
|
||||
|
||||
enum {
|
||||
hsm, hot, evt, hit, out, filecount
|
||||
};
|
||||
|
@ -333,6 +336,55 @@ static __inline const char * find_global(uint32_t x, const global_t * Globals, s
|
|||
return NULL;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8_t * Data;
|
||||
size_t Size;
|
||||
} ByteReaderContext;
|
||||
|
||||
enum TokenizeType {
|
||||
TK_STRING,
|
||||
TK_ID
|
||||
};
|
||||
|
||||
static int parser_find(ByteReaderContext *brc, ...){
|
||||
va_list args;
|
||||
va_start(args, brc);
|
||||
|
||||
while(1){
|
||||
uint8_t * Start = brc->Data;
|
||||
const char * Pattern;
|
||||
size_t Length;
|
||||
void * Destination;
|
||||
enum TokenizeType Type;
|
||||
|
||||
Pattern = va_arg(args, const char *);
|
||||
if(Pattern == NULL){
|
||||
va_end(args);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(Length = strlen(Pattern); ; brc->Data++, brc->Size--){
|
||||
if(brc->Size < Length){
|
||||
va_end(args);
|
||||
return 0;
|
||||
}
|
||||
if(!memcmp(brc->Data, Pattern, Length)) break;
|
||||
}
|
||||
*brc->Data = '\0';
|
||||
brc->Data += Length; brc->Size -= Length;
|
||||
|
||||
Destination = va_arg(args, void *);
|
||||
if(Destination == NULL)
|
||||
continue;
|
||||
|
||||
Type = va_arg(args, enum TokenizeType);
|
||||
if(Type == TK_STRING)
|
||||
*((char**)Destination) = (char*)Start;
|
||||
else
|
||||
*((uint32_t*)Destination) = strtoul((char*)Start, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint32_t LogicalAddress;
|
||||
uint32_t TrackID;
|
||||
|
@ -348,8 +400,11 @@ typedef struct {
|
|||
} addresslist_t;
|
||||
|
||||
static address_t * add_address(addresslist_t * List){
|
||||
if(List->Count == List->Size)
|
||||
if(List->Count == List->Size){
|
||||
List->Entries = realloc(List->Entries, (List->Size <<= 1) * sizeof(address_t));
|
||||
if(!List->Entries)
|
||||
Shutdown_M("%sCould not allocate memory for address list.\n", "hitdump: Error: ");
|
||||
}
|
||||
return memset(List->Entries + List->Count++, 0, sizeof(address_t));
|
||||
}
|
||||
|
||||
|
@ -390,35 +445,21 @@ static __inline address_t * find_address_by_name(addresslist_t * List, const cha
|
|||
}
|
||||
|
||||
static __inline void read_hit_addresses(uint8_t * Data, size_t Size, addresslist_t * AddressList, uint32_t * SymbolTable){
|
||||
uint8_t * Start = Data, * TableData;
|
||||
uint8_t * TableData;
|
||||
unsigned i, count = 0;
|
||||
ByteReaderContext brc;
|
||||
brc.Data = Data; brc.Size = Size;
|
||||
|
||||
if(Size < 32) return;
|
||||
Data += 16;
|
||||
Size -= 16;
|
||||
if(!parser_find(&brc, "ENTP", NULL, NULL) || brc.Size < 4) return;
|
||||
TableData = brc.Data;
|
||||
*SymbolTable = TableData - 4 - Data;
|
||||
|
||||
/* Find the table start */
|
||||
while(memcmp(Data, "ENTP", 4)){
|
||||
if(Size < 17) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
|
||||
TableData = Data;
|
||||
Data += 4;
|
||||
Size -= 4;
|
||||
|
||||
/* Find the table end */
|
||||
while(memcmp(Data, "EENT", 4)){
|
||||
if(Size < 12) return;
|
||||
Data+=8; Size-=8;
|
||||
count++;
|
||||
}
|
||||
|
||||
*SymbolTable = TableData - Start;
|
||||
|
||||
if(count == 0) return;
|
||||
TableData += 4;
|
||||
|
||||
for(i=0; i<count; i++){
|
||||
address_t * Address = add_address(AddressList);
|
||||
Address->Exported = 1;
|
||||
|
@ -428,106 +469,45 @@ static __inline void read_hit_addresses(uint8_t * Data, size_t Size, addresslist
|
|||
}
|
||||
|
||||
static __inline void read_evt_addresses(uint8_t * Data, size_t Size, addresslist_t * AddressList){
|
||||
if(Size < 13) return;
|
||||
ByteReaderContext brc;
|
||||
brc.Data = Data; brc.Size = Size;
|
||||
|
||||
while(1){
|
||||
uint8_t * Name = Data, * TrackIDPos;
|
||||
address_t * Address;
|
||||
char *Name;
|
||||
uint32_t TrackID;
|
||||
if(!parser_find(&brc,
|
||||
",", &Name, TK_STRING,
|
||||
",", NULL,
|
||||
",", &TrackID, TK_ID,
|
||||
NULL)) return;
|
||||
|
||||
Data++; Size--;
|
||||
|
||||
/* End of first field: address name */
|
||||
while(*Data != ','){
|
||||
if(Size < 13) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
*Data = '\0';
|
||||
Data++; Size--;
|
||||
|
||||
/* End of second field: unneeded */
|
||||
while(*Data != ','){
|
||||
if(Size < 11) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
Data++; Size--;
|
||||
TrackIDPos = Data;
|
||||
|
||||
/* End of third field: Track ID */
|
||||
while(*Data != ','){
|
||||
if(Size < 9) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
*Data = '\0';
|
||||
Data++; Size--;
|
||||
|
||||
TrackID = atoi((char*)TrackIDPos);
|
||||
Address = find_address_by_track_id(AddressList, TrackID);
|
||||
if(!Address){
|
||||
Address = add_address(AddressList);
|
||||
Address->Exported = 1;
|
||||
Address->TrackID = TrackID;
|
||||
}
|
||||
Address->Name = (char*)Name;
|
||||
|
||||
while(*Data != '\n'){
|
||||
if(Size < 15) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
Data++; Size--;
|
||||
Address->Name = Name;
|
||||
if(!parser_find(&brc, "\n", NULL, NULL)) return;
|
||||
}
|
||||
}
|
||||
|
||||
static __inline void read_hsm_addresses(uint8_t * Data, size_t Size, addresslist_t * AddressList){
|
||||
if(Size < 24) return;
|
||||
ByteReaderContext brc;
|
||||
brc.Data = Data; brc.Size = Size;
|
||||
|
||||
while(1){
|
||||
uint8_t * Name, * IDPos;
|
||||
address_t * Address;
|
||||
char * Name;
|
||||
uint32_t SoundID, LogicalAddress;
|
||||
|
||||
/* Find the next constant that begins with "tkd_" */
|
||||
while(memcmp(Data, "\ntkd_", 5)){
|
||||
if(Size < 25) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
Name = Data += 5;
|
||||
Size -= 5;
|
||||
|
||||
/* End of tkd constant name */
|
||||
while(*Data != ' '){
|
||||
if(Size < 19) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
*Data = '\0';
|
||||
Data++; Size--;
|
||||
IDPos = Data;
|
||||
|
||||
/* End of tkd constant value */
|
||||
while(*Data != ' '){
|
||||
if(Size < 17) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
*Data = '\0';
|
||||
Data++; Size--;
|
||||
SoundID = atoi((char*)IDPos);
|
||||
|
||||
/* End of address constant name */
|
||||
while(*Data != ' '){
|
||||
if(Size < 9) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
Data++; Size--;
|
||||
IDPos = Data;
|
||||
|
||||
/* End of address constant value */
|
||||
while(*Data != ' '){
|
||||
if(Size < 7) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
*Data = '\0';
|
||||
Data++; Data--;
|
||||
LogicalAddress = atoi((char*)IDPos);
|
||||
if(!parser_find(&brc,
|
||||
"\ntkd_", NULL,
|
||||
" ", &Name, TK_STRING,
|
||||
" ", &SoundID, TK_ID,
|
||||
" ", NULL,
|
||||
" ", &LogicalAddress, TK_ID,
|
||||
NULL)) return;
|
||||
|
||||
Address = find_address_by_logical_address(AddressList, LogicalAddress);
|
||||
if(!Address){
|
||||
|
@ -537,52 +517,25 @@ static __inline void read_hsm_addresses(uint8_t * Data, size_t Size, addresslist
|
|||
Address->Name = (char*)Name;
|
||||
}
|
||||
Address->LogicalAddress = LogicalAddress;
|
||||
} else Address->Name = (char*)Name;
|
||||
} else Address->Name = Name;
|
||||
Address->SoundID = SoundID;
|
||||
|
||||
while(*Data != '\n'){
|
||||
if(Size < 25) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static __inline void read_hot_trackdata(uint8_t * Data, size_t Size, addresslist_t * AddressList){
|
||||
if(Size < 19) return;
|
||||
ByteReaderContext brc;
|
||||
brc.Data = Data; brc.Size = Size;
|
||||
|
||||
while(memcmp(Data, "[TrackData]", 11)){
|
||||
if(Size < 20) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
|
||||
Data += 12;
|
||||
Size -= 12;
|
||||
if(*Data == '\n'){
|
||||
Data++; Size--;
|
||||
}
|
||||
if(!parser_find(&brc, "[TrackData]", NULL, NULL)) return;
|
||||
|
||||
while(1){
|
||||
uint8_t * IDPos = Data;
|
||||
address_t * Address;
|
||||
uint32_t SoundID, LogicalAddress;
|
||||
|
||||
/* End of key: Sound ID */
|
||||
while(*Data != '='){
|
||||
if(Size < 5) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
*Data = '\0';
|
||||
SoundID = strtol((char*)IDPos, NULL, 0);
|
||||
Data++; Size--;
|
||||
IDPos = Data;
|
||||
|
||||
while(*Data != '\n'){
|
||||
if(Size < 2) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
*Data = '\0';
|
||||
LogicalAddress = strtol((char*)IDPos, NULL, 0);
|
||||
Data++; Size--;
|
||||
if(!brc.Size || *brc.Data == '\n' || *brc.Data == '[') return;
|
||||
if(!parser_find(&brc,
|
||||
"=", &SoundID, TK_ID,
|
||||
"\n", &LogicalAddress, TK_ID,
|
||||
NULL)) return;
|
||||
|
||||
Address = find_address_by_logical_address(AddressList, LogicalAddress);
|
||||
if(!Address){
|
||||
|
@ -593,59 +546,25 @@ static __inline void read_hot_trackdata(uint8_t * Data, size_t Size, addresslist
|
|||
}
|
||||
Address->LogicalAddress = LogicalAddress;
|
||||
} else Address->SoundID = SoundID;
|
||||
|
||||
if(Size < 8) return;
|
||||
while(*Data == '\r' || *Data == '\n' || *Data == ' ' || *Data == '\t'){
|
||||
if(Size < 8) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
|
||||
if(*Data == '[') return;
|
||||
}
|
||||
}
|
||||
|
||||
static __inline void read_hot_track(uint8_t * Data, size_t Size, addresslist_t * AddressList){
|
||||
if(Size < 28) return;
|
||||
ByteReaderContext brc;
|
||||
brc.Data = Data; brc.Size = Size;
|
||||
|
||||
while(memcmp(Data, "[Track]", 7)){
|
||||
if(Size < 29) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
|
||||
Data += 8;
|
||||
Size -= 8;
|
||||
if(*Data == '\n'){
|
||||
Data++; Size--;
|
||||
}
|
||||
if(!parser_find(&brc, "[Track]", NULL, NULL)) return;
|
||||
|
||||
while(1){
|
||||
uint8_t * IDPos = Data, * Name;
|
||||
address_t * Address;
|
||||
char * Name;
|
||||
uint32_t TrackID;
|
||||
|
||||
/* End of key: Track ID */
|
||||
while(*Data != '='){
|
||||
if(Size < 20) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
*Data = '\0';
|
||||
TrackID = strtol((char*)IDPos, NULL, 0);
|
||||
Data++; Size--;
|
||||
|
||||
/* End of first field: Unknown */
|
||||
while(*Data != ','){
|
||||
if(Size < 18) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
Data++; Size--;
|
||||
Name = Data;
|
||||
|
||||
/* End of second field: Name */
|
||||
while(*Data != ','){
|
||||
if(Size < 16) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
*Data = '\0';
|
||||
if(!brc.Size || *brc.Data == '\n' || *brc.Data == '[') return;
|
||||
if(!parser_find(&brc,
|
||||
"=", &TrackID, TK_ID,
|
||||
",", NULL,
|
||||
",", &Name, TK_STRING,
|
||||
NULL)) return;
|
||||
|
||||
Address = find_address_by_name(AddressList, (char*)Name);
|
||||
if(!Address){
|
||||
|
@ -654,17 +573,11 @@ static __inline void read_hot_track(uint8_t * Data, size_t Size, addresslist_t *
|
|||
Address = add_address(AddressList);
|
||||
Address->TrackID = TrackID;
|
||||
}
|
||||
Address->Name = (char*)Name;
|
||||
Address->Name = Name;
|
||||
} else Address->TrackID = TrackID;
|
||||
Address->Exported = 1;
|
||||
|
||||
if(Size < 36) return;
|
||||
while(*Data == '\r' || *Data == '\n' || *Data == ' ' || *Data == '\t'){
|
||||
if(Size < 22) return;
|
||||
Data++; Size--;
|
||||
}
|
||||
|
||||
if(*Data == '[') return;
|
||||
if(!parser_find(&brc, "\n", NULL, NULL)) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -673,25 +586,46 @@ static __inline void read_hot_addresses(uint8_t * Data, size_t Size, addresslist
|
|||
read_hot_track(Data, Size, AddressList);
|
||||
}
|
||||
|
||||
static FILE *hFile = NULL;
|
||||
static char *path[filecount] = {NULL};
|
||||
static uint8_t *data[filecount] = {NULL};
|
||||
static char *basename = NULL;
|
||||
static addresslist_t AddressList = {0};
|
||||
|
||||
static void Shutdown(){
|
||||
unsigned i;
|
||||
for(i=0; i<filecount; i++){
|
||||
free(path[i]);
|
||||
free(data[i]);
|
||||
}
|
||||
free(basename);
|
||||
free(AddressList.Entries);
|
||||
if(hFile)
|
||||
fclose(hFile);
|
||||
}
|
||||
|
||||
static void Shutdown_M(const char * Message, ...){
|
||||
va_list args;
|
||||
va_start(args, Message);
|
||||
vfprintf(stderr, Message, args);
|
||||
va_end(args);
|
||||
|
||||
Shutdown();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
unsigned i, addr;
|
||||
unsigned i, j, addr;
|
||||
int SimsVersion = 0;
|
||||
int overwrite = 0;
|
||||
int ShowAddresses = 0;
|
||||
int length;
|
||||
char *basename;
|
||||
char *path[filecount] = {NULL};
|
||||
uint8_t *data[filecount-1] = {NULL};
|
||||
size_t filesize[filecount-1];
|
||||
FILE * hFile;
|
||||
const global_t * Globals;
|
||||
size_t GlobalCount;
|
||||
uint32_t SymbolTable = 0;
|
||||
uint32_t BaseSoundID = 0, BaseSoundIDSet = 0;
|
||||
|
||||
/* collected data */
|
||||
addresslist_t AddressList;
|
||||
|
||||
/****
|
||||
** Parse the command-line arguments
|
||||
*/
|
||||
|
@ -718,7 +652,7 @@ int main(int argc, char *argv[]){
|
|||
else if(!strcmp(argv[i], "-f")) overwrite = 1;
|
||||
else if(!strcmp(argv[i], "-a")) ShowAddresses = 1;
|
||||
else if(i != (unsigned)argc-2){
|
||||
if(!strcmp(argv[i], "-out")) path[out] = argv[++i];
|
||||
if(!strcmp(argv[i], "-o")) path[out] = argv[++i];
|
||||
else if(!strcmp(argv[i], "-hsm")) path[hsm] = argv[++i];
|
||||
else if(!strcmp(argv[i], "-hot")) path[hot] = argv[++i];
|
||||
else if(!strcmp(argv[i], "-evt")) path[evt] = argv[++i];
|
||||
|
@ -726,11 +660,13 @@ int main(int argc, char *argv[]){
|
|||
}
|
||||
else break;
|
||||
}
|
||||
path[hit] = argv[i];
|
||||
for(j=0; j<filecount; j++)
|
||||
if(path[j])
|
||||
path[j] = strdup(path[j]); /* necessary for free(path[i]) in Shutdown_M */
|
||||
|
||||
if(!SimsVersion){
|
||||
fprintf(stderr, "%sSims version not specified. (Use -ts1 or -tso.)\n", "hitdump: Error: ");
|
||||
return -1;
|
||||
}
|
||||
if(!SimsVersion)
|
||||
Shutdown_M("%sSims version not specified. (Use -ts1 or -tso.)\n", "hitdump: Error: ");
|
||||
|
||||
if(SimsVersion == VERSION_TS1){
|
||||
Globals = TS1Globals;
|
||||
|
@ -740,7 +676,6 @@ int main(int argc, char *argv[]){
|
|||
GlobalCount = TSOGlobalCount;
|
||||
}
|
||||
|
||||
path[hit] = argv[i];
|
||||
length = strlen(path[hit]);
|
||||
if(path[out] == NULL){
|
||||
path[out] = malloc(max(length+1, 5));
|
||||
|
@ -757,59 +692,52 @@ int main(int argc, char *argv[]){
|
|||
*/
|
||||
|
||||
for(i=0; i<filecount-1; i++){
|
||||
size_t bytestransferred;
|
||||
if(!path[i]) continue;
|
||||
|
||||
hFile = fopen(path[i], "rb");
|
||||
if(hFile == NULL){
|
||||
if(i != hit){
|
||||
fprintf(stderr, "%sCould not open file: %s\n", "hitdump: Warning: ", path[i]);
|
||||
fprintf(stderr, "%sCould not open file: %s.\n", "hitdump: Warning: ", path[i]);
|
||||
continue;
|
||||
}else{
|
||||
fprintf(stderr, "%sCould not open file: %s\n", "hitdump: Error: ", path[i]);
|
||||
return -1;
|
||||
}
|
||||
}else
|
||||
Shutdown_M("%sCould not open file: %s.\n", "hitdump: Error: ", path[i]);
|
||||
}
|
||||
|
||||
fseek(hFile, 0, SEEK_END);
|
||||
filesize[i] = ftell(hFile);
|
||||
if(filesize[i] == 0){
|
||||
fclose(hFile);
|
||||
fclose(hFile); hFile = NULL;
|
||||
if(i != hit){
|
||||
fprintf(stderr, "%sFile is invalid: %s\n", "hitdump: Warning: ", path[i]);
|
||||
fprintf(stderr, "%sFile is invalid: %s.\n", "hitdump: Warning: ", path[i]);
|
||||
continue;
|
||||
}else{
|
||||
fprintf(stderr, "%sFile is invalid: %s\n", "hitdump: Error: ", path[i]);
|
||||
return -1;
|
||||
}
|
||||
}else
|
||||
Shutdown_M("%sFile is invalid: %s.\n", "hitdump: Error: ", path[i]);
|
||||
}
|
||||
|
||||
data[i] = malloc(filesize[i]);
|
||||
if(data[i] == NULL){
|
||||
fclose(hFile);
|
||||
fclose(hFile); hFile = NULL;
|
||||
if(i != hit){
|
||||
fprintf(stderr, "%sCould not allocate memory for file: %s\n", "hitdump: Warning: ", path[i]);
|
||||
fprintf(stderr, "%sCould not allocate memory for file: %s.\n", "hitdump: Warning: ", path[i]);
|
||||
continue;
|
||||
}else{
|
||||
fprintf(stderr, "%sCould not allocate memory for file: %s\n", "hitdump: Error: ", path[i]);
|
||||
return -1;
|
||||
}
|
||||
}else
|
||||
Shutdown_M("%sCould not allocate memory for file: %s.\n", "hitdump: Error: ", path[i]);
|
||||
}
|
||||
|
||||
fseek(hFile, 0, SEEK_SET);
|
||||
if(fread(data[i], 1, filesize[i], hFile) != filesize[i]){
|
||||
fclose(hFile);
|
||||
bytestransferred = fread(data[i], 1, filesize[i], hFile);
|
||||
fclose(hFile); hFile = NULL;
|
||||
if(bytestransferred != filesize[i]){
|
||||
free(data[i]); data[i] = NULL;
|
||||
if(i != hit){
|
||||
fprintf(stderr, "%sCould not read file: %s\n", "hitdump: Warning: ", path[i]);
|
||||
fprintf(stderr, "%sCould not read file: %s.\n", "hitdump: Warning: ", path[i]);
|
||||
continue;
|
||||
}else{
|
||||
fprintf(stderr, "%sCould not read file: %s\n", "hitdump: Error: ", path[i]);
|
||||
return -1;
|
||||
}else
|
||||
Shutdown_M("%sCould not read file: %s.\n", "hitdump: Error: ", path[i]);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(hFile);
|
||||
}
|
||||
|
||||
/****
|
||||
** Open the output file for writing
|
||||
*/
|
||||
|
@ -819,29 +747,23 @@ int main(int argc, char *argv[]){
|
|||
if(hFile != NULL){
|
||||
/* File exists */
|
||||
char c;
|
||||
fclose(hFile);
|
||||
fprintf(stderr, "hitdump: File \"%s\" exists.\nContinue anyway? (y/n) ", path[out]);
|
||||
fclose(hFile); hFile = NULL;
|
||||
fprintf(stderr, "%sFile \"%s\" exists.\nContinue anyway? (y/n) ", "hitdump: ", path[out]);
|
||||
c = getchar();
|
||||
if(c != 'y' && c != 'Y'){
|
||||
printf("\nAborted.\n");
|
||||
return -1;
|
||||
}
|
||||
if(c != 'y' && c != 'Y')
|
||||
Shutdown_M("\nAborted.\n");
|
||||
}
|
||||
}
|
||||
hFile = fopen(path[out], "wb");
|
||||
if(hFile == NULL){
|
||||
fprintf(stderr, "%sCould not open file: %s\n", "hitdump: Error: ", path[out]);
|
||||
return -1;
|
||||
}
|
||||
if(hFile == NULL)
|
||||
Shutdown_M("%sCould not open file: %s.\n", "hitdump: Error: ", path[out]);
|
||||
|
||||
/****
|
||||
** Verify the header of the HIT file
|
||||
*/
|
||||
|
||||
if(filesize[hit] < 16 || memcmp(data[hit], HITHeader, 16)){
|
||||
fprintf(stderr, "%sFile is invalid: %s\n", "hitdump: Error: ", path[hit]);
|
||||
return -1;
|
||||
}
|
||||
if(filesize[hit] < 16 || memcmp(data[hit], HITHeader, 16))
|
||||
Shutdown_M("%sFile is invalid: %s.\n", "hitdump: Error: ", path[hit]);
|
||||
|
||||
/****
|
||||
** Build up the address list
|
||||
|
@ -868,7 +790,7 @@ int main(int argc, char *argv[]){
|
|||
AddressList.Entries[i].Exported,
|
||||
AddressList.Entries[i].TrackID,
|
||||
AddressList.Entries[i].SoundID,
|
||||
AddressList.Entries[i].Name,
|
||||
AddressList.Entries[i].Name ? AddressList.Entries[i].Name : "",
|
||||
AddressList.Entries[i].LogicalAddress
|
||||
);
|
||||
}
|
||||
|
@ -956,26 +878,19 @@ int main(int argc, char *argv[]){
|
|||
}
|
||||
|
||||
opcode = data[hit][addr];
|
||||
if(opcode == 0 || opcode > 96){
|
||||
fprintf(stderr, "%sIllegal opcode 0x%02X at address 0x%08X.\n", "hitdump: Error: ", opcode, addr);
|
||||
return -1;
|
||||
}
|
||||
if(opcode == 0 || opcode > 96)
|
||||
Shutdown_M("%sIllegal opcode 0x%02X at address 0x%08X.\n", "hitdump: Error: ", opcode, addr);
|
||||
|
||||
instruction = Instructions + opcode - 1;
|
||||
operands = instruction->Operands;
|
||||
if(operands == UNIMPLEMENTED){
|
||||
fprintf(stderr, "%sUnimplemented instruction '%s' at address 0x%08X.\n", "hitdump: Error: ",
|
||||
instruction->Name, addr);
|
||||
return -1;
|
||||
}
|
||||
if(operands == UNIMPLEMENTED)
|
||||
Shutdown_M("%sUnimplemented instruction '%s' at address 0x%08X.\n", "hitdump: Error: ", instruction->Name, addr);
|
||||
|
||||
addr++;
|
||||
|
||||
if(filesize[hit] - addr < (operands & 15)){
|
||||
fprintf(stderr, "%sInsufficient operand bytes for '%s' instruction at address 0x%08X (%u of %u supplied).\n",
|
||||
if(filesize[hit] - addr < (operands & 15))
|
||||
Shutdown_M("%sInsufficient operand bytes for '%s' instruction at address 0x%08X (%u of %u supplied).\n",
|
||||
"hitdump: Error: ", instruction->Name, addr, filesize[hit] - addr, instruction->Operands);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(hFile, "\r\n\t\t%s", instruction->Name);
|
||||
for(i=0; (operands >>= 4) != 0; i++){
|
||||
|
@ -998,11 +913,9 @@ int main(int argc, char *argv[]){
|
|||
int x = data[hit][addr];
|
||||
if(x > 16){
|
||||
const char * Global = find_global(x, Globals, GlobalCount);
|
||||
if(Global == NULL){
|
||||
fprintf(stderr, "%sInvalid %s operand 0x%02X for '%s' instruction at address 0x%08X (expected %s).\n",
|
||||
if(Global == NULL)
|
||||
Shutdown_M("%sInvalid %s operand 0x%02X for '%s' instruction at address 0x%08X (expected %s).\n",
|
||||
"hitdump: Error: ", position[i], x, instruction->Name, addr, "argument, register, or global");
|
||||
return -1;
|
||||
}
|
||||
fprintf(hFile, " %s", Global);
|
||||
} else fprintf(hFile, " %s", Registers[x]);
|
||||
addr += 1;
|
||||
|
@ -1011,12 +924,9 @@ int main(int argc, char *argv[]){
|
|||
|
||||
if(filesize[hit]-addr >= 4)
|
||||
x = read_uint32(data[hit]+addr);
|
||||
else if(data[hit][addr] != 0x05 && data[hit][addr] != 0x06){
|
||||
fprintf(stderr,
|
||||
"%sInsufficient operand bytes for '%s' instruction at address 0x%08X (%u of %u supplied).\n",
|
||||
else if(data[hit][addr] != 0x05 && data[hit][addr] != 0x06)
|
||||
Shutdown_M("%sInsufficient operand bytes for '%s' instruction at address 0x%08X (%u of %u supplied).\n",
|
||||
"hitdump: Error: ", instruction->Name, addr, filesize[hit] - addr, 4);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(x >= 16 && x < filesize[hit]){
|
||||
Address = find_address_by_logical_address(&AddressList, x);
|
||||
|
@ -1027,12 +937,9 @@ int main(int argc, char *argv[]){
|
|||
x = data[hit][addr];
|
||||
if(x > 16){
|
||||
const char * Global = find_global(x, Globals, GlobalCount);
|
||||
if(Global == NULL){
|
||||
fprintf(stderr,
|
||||
"%sInvalid %s operand 0x%02X for '%s' instruction at address 0x%08X (expected %s).\n",
|
||||
if(Global == NULL)
|
||||
Shutdown_M("%sInvalid %s operand 0x%02X for '%s' instruction at address 0x%08X (expected %s).\n",
|
||||
"hitdump: Error: ", position[i], x, instruction->Name, addr, "argument, register, or global");
|
||||
return -1;
|
||||
}
|
||||
fprintf(hFile, " %s", Global);
|
||||
} else fprintf(hFile, " %s", Registers[x]);
|
||||
addr += (data[hit][addr] != 0x05 && data[hit][addr] != 0x06) ? 4 : 1;
|
||||
|
@ -1043,7 +950,7 @@ int main(int argc, char *argv[]){
|
|||
|
||||
fprintf(hFile, "\r\n]\r\n\r\n");
|
||||
|
||||
fclose(hFile);
|
||||
Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -193,7 +193,6 @@ struct PEFile {
|
|||
~PEFile(){
|
||||
if(hFile)
|
||||
fclose(hFile);
|
||||
if(Data)
|
||||
free(Data);
|
||||
}
|
||||
|
||||
|
@ -305,7 +304,7 @@ struct PEFile {
|
|||
PEFile * PEFile::ptr;
|
||||
|
||||
static void Shutdown_M(const char * Message){
|
||||
fprintf(stderr, "rtti-reader: error: %s.", Message);
|
||||
fprintf(stderr, "rtti-reader: error: %s.\n", Message);
|
||||
if(PEFile::ptr)
|
||||
PEFile::ptr->~PEFile();
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -344,13 +343,13 @@ int main(int argc, char *argv[]){
|
|||
|
||||
for(i=0; i<SegmentCount; i++){
|
||||
if(!DLL.strcmp(".rdata")){
|
||||
DLL.skip(8); DLL.rdata.size = DLL.read32();
|
||||
DLL.skip(16); DLL.rdata.size = DLL.read32();
|
||||
DLL.rdata.offset = DLL.read32();
|
||||
DLL.skip(24);
|
||||
DLL.skip(16);
|
||||
} else if(!DLL.strcmp(".data")){
|
||||
DLL.skip(8); DLL.data.size = DLL.read32();
|
||||
DLL.skip(16); DLL.data.size = DLL.read32();
|
||||
DLL.data.offset = DLL.read32();
|
||||
DLL.skip(24);
|
||||
DLL.skip(16);
|
||||
} else DLL.skip(40);
|
||||
}
|
||||
if(DLL.rdata.size == 0)
|
||||
|
@ -409,7 +408,7 @@ int main(int argc, char *argv[]){
|
|||
Shutdown_M("Unexpectedly reached end of binary");
|
||||
|
||||
DLL.lookat(DLL.rdata);
|
||||
COL.VTableAddress = (DLL.find32(COLAddress)) ? DLL.brc.position + ImageBase : (uint32_t)-1;
|
||||
COL.VTableAddress = (DLL.find32(COLAddress)) ? DLL.brc.position + ImageBase + 4: (uint32_t)-1;
|
||||
|
||||
if(newclass){
|
||||
if(!DLL.seek(COL.Fields.ClassDescriptorAddress - ImageBase))
|
||||
|
|
Loading…
Add table
Reference in a new issue