Question

I am trying to create a PFS De-compressor using the C Language. For this Project, I need to analyse the Archive's Hex dump from which I will get the Files Offsets, names and Sizes.

Do you think it is good practice to store a Hex dump in a char array, and will I be able to convert Hex to Characters?

Thank you, Andrew Borg

Was it helpful?

Solution

"will I be able to convert Hex to Characters?"

Yes. After your program reads in the literal characters that represent Hex digits -- for example, '5' and 'A', the program can turn that into the hex value 0x5a, which is decimal 90, and then print that value out as a character (which prints as "Z"). Pretty much every other conceivable way of converting characters to hex and vice versa is pretty easy in C.

How to correctly convert a Hex String to Byte Array in C? Printing char buffer in hex array Convert array of bytes to hexadecimal string in plain old C

I am not clear on what you are asking in the rest of your question. Are you asking:

"I have this binary PFS file; can I write a C program that, when the program is run, reads that file into RAM, and if so, is a char array (char[]) a good container?"

Yes. When C programs read raw binary file data into memory, they typically store that data into a char array, and they keep track of the length separately (because, unlike char arrays that represent C strings, your binary data is likely to have the occasional zero byte). You may want to look at the standard memory library functions (memcmp(), memchr(), etc. )

"I have an ASCII text file that is a hex dump of a PFS file; can I write a C program that, when the program is run, reads that ASCII text file into RAM, and if so, is a char array (char[]) a good container?"

Yes. When C programs read text files into memory, they typically store that data in a char array. You don't need to keep track of the length separately, because ASCII text files never include a zero byte, so the normal end-of-string zero byte works normally. You may want to look at the standard string library functions ( strchr(), strstr(), etc.).

"I have this PFS file; can I write a C program that, before the program is ever run, the complete contents of that file are embedded into the executable code of my program?"

In principle, yes, you could convert a raw binary file into a text file full of hex digits that you can include in your source code.

This is rarely done, and is a bigger hassle than simply loading the program in at run time, but occasionally people do it when they want a single self-contained executable:

p.s.: Is your PFS file from an Amiga or a Playstation or something else?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top