Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ok on inspection of a file i am trying to get names out of it keeps failing because it dont get to the name part but the debug spits this out

C#
"r\0\0\0�\0\0\0\0+\u0001\u0001\0\0\0\0\0\u0002 \b\u0004\0\0\0\0\u0001\0\u0001\0\0\0\0\0@\0\0\u0004\0\0(e�\u0012\b\f\0\0\0\u0002\0\u0001\0l\0\0\0@\0\0\0X\0\0\0�\0\0\0\v\u0002\0\0�\0\0\0�\0\0\0\u0001\u0005\0\0�\0\0\0�\0\0\0\0\0�?\0\0�?\0\0�?\0\0�?tools\0lightgrid_volume\0lightgrid_volume\0colorMap\0normalMap\0$identitynormalmap\0colorTint\0"


and i am not sure how i read this file im trying my best to get the code that says lightgrid_volume and other stuff in that part i made a regex part

C#
public void findmaterialname()
{
    Regex regex = new Regex(@"(.+)(tools)(\\[0-9a-z_]+\\)([0-9A-Z_a-z]+)", RegexOptions.Singleline);
    // (.+)(tools)(\\[0-9a-z_]+\\)([0-9A-Z_a-z]+) selects all stuff to tools then is meant to get the other lines but refues
    // ([a-z_0-9]+_c\s)(colorMap) ment to select the path and then link with colour map
    // output should be 0lightgrid_volume\0colorMap  use grop 3 for this colour map refence
    using (StreamReader reader = new StreamReader(@"F:\world_at_war_with_nuketown\Call of Duty - World at War\raw\materials\" + mattofind))
    {
        string line;
        while ((line = reader.ReadToEnd())!= "")
        {
            // Try to match each line against the Regex.
            Match match = regex.Match(line);
            if (match.Success)
            {
                // Write original line and the value.
                string v = match.Groups[4].Value;
                MessageBox.Show(v);
            }
        }
    }
}


but currenly having issues


https://i.imgur.com/CAx4fhs.png[^]

What I have tried:

regex and tryied using binaryreader but regex and binaryreader dont want to play ball with me.
Posted
Updated 26-May-19 2:26am
v3
Comments
Dave Kreskowiak 25-May-19 15:04pm    
RegEx isn't going to help you in this case. RegEx works on strings and text, not binary data.

Quote:
How can I read a file that format is like this C#

With pain, this file is "binary", it mean that this file is meant to be read by computer, not by humans.
First of all you need to understand that the debugger have changed the file to make it more human readable, so trying to match what the debugger display will never work.

Knowing what is in the file may also help to decipher.

The first step is to use a programmer's editor with hexadecimal mode, it will display the exact contain of the file, printable chars or not.
Notepad++ Home[^]
ultraedit[^]

[Update]
As the filename from picture look to come from a game, you need to know that such file are usually intentionally encoded to make them difficult to decipher in order to avoid unauthorized tempering.
 
Share this answer
 
v2
Comments
elfenliedtopfan5 25-May-19 15:48pm    
https://i.imgur.com/CAx4fhs.png that is the file in ultra edit
Patrice T 25-May-19 15:52pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
elfenliedtopfan5 25-May-19 17:26pm    
have now updated sorry dont usally ask on forms did not know how you could do that
Patrice T 25-May-19 17:34pm    
No problem.
It was my guess that you are new to this forum.
You need to start by finding out what the content is, and how it is formatted. Where does the file come from, or which application creates it? Once you have that information you can figure out how to read it. Often a binary file will be formatted into records, either fixed or variable length. If fixed length then it is easy just to read each block of data. If variable then each record is usually preceded by a value that gives the record length. This could be a byte, short, int or long, but only the creator of the file will know which.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900