I am working on a project where I read data from a file and I need to manipulate some of this data.
The data is binary with some ASCII encoded text in it. The data is also saved Big Endian if that matters.
What I would like to accomplish is to find a pattern with in this data and manipulate parts of that pattern.
Example: (09 49 6E 76 65 6E 74 6F 72 79 0A 00 00 00 02 01 00)
This represents the number 9 for how many letters are in Inventory, followed by ASCII "Inventory" without quotes. "0A" Marks the end of that ASCII text, followed with 00 00 00 02 to mark the size of our inventory "2". "01 00" Marks the end of The entire inventory region.
Example2: (04 53 6C 6F 74 00 02 00)
This represents the number 4 for how many letters are in Slot, followed by ASCII "Slot" without quotes. "00" is a space between ASCII text and Slot number "02", followed by end of region "00".
I need to locate these patterns and several others within the file. I then need to modify parts of the pattern and write to disk.
ExampleModify: (04 53 6C 6F 74 00 02 00) "From above" to (04 53 6C 6F 74 00 07 00) changing "slot number '02' to '07'.
Another caveat is that while I have several patterns that I need to search in the file of varying size, length, and data contained, is that there can be multiple sections of these patterns containing different data that needs to be modified separately as a whole.
To clarify: (Inventory, Slot, id, Count) - is to be treated as information for one person.
There can be multiple copies of (Inventory, Slot, id, Count) for each person that is recorded.
I would like to display this information to the user, and give them the option to modify each of the elements in the group.
I am not a good programmer and want to learn, if you have examples I appreciate that, if you have advice please give it. If you can dumb it down that is even better, thanks. I have a work-in-progress going now, but I am stuck now. If you want to see what I have please let me know.
Summary of what I have: Read file into byte[] then display the whole array to console. That's about it. with a little bit of formatting and some debug info for locating that chunk I read into the array.
Here is a link to my code on pastebin. LINK
I realize that I do not get all occurrences of (Inventory, Slot, id, Count) I need to fix that as well.
EDIT: Example (09 49 6E 76 65 6E 74 6F 72 79 0A 00 00 00 02 01 00) this is a fixed length chunk of binary data within the file I'm reading. As stated 09 represents the length of the string. what follows the string is (0A 00 00 00 02 01 00) the important part of that is (02) this is because that is the only byte(s) that change in that slice of binary data. "02" represents "2" meaning there are 2 instances of (Slot, id, Count) for that particular persons record.
(File)
(09 Inventory 0A 00 00 00 02 01 00) // Start of person 1's record with 2 instances.
(Slot)
(id)
(Count)
(Slot)
(id)
(Count)
(Rotation) // End of person 1's record
(09 Inventory 0A 00 00 00 04 01 00) // Start of person 2's record with 4 instances.
(Slot)
(id)
(Count)
(Slot)
(id)
(Count)
(Slot)
(id)
(Count)
(Slot)
(id)
(Count)
(Rotation) // End of person 2's record
(File End)
The idea is that I want to edit the "id" or increase the number of slots by adding to the inventory and add in more instances of (Slot, id, Count).
"id" - contains item id
"Slot" - contains inventory slot number
"Count" - contains how many of item is in that slot. EDIT Note: Please let me know if I am not being clear, thank you again.