Sign in to follow this  
Followers 0
DPyro

[C#] Getting values from byte array?

6 posts in this topic

I have the following hex string:


010101030300000000000000000000000D00000001000000010000009050AA35B23BDA4B3532F2ABDF4A382E80100000014324686468645602538589053568950000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
[/CODE]

In hex editor it would look like this:

0ZTghjR.png

I need to get the data at offset 0x1C - 0x2B (9050AA35B23BDA4B3532F2ABDF4A382E)

I have the following code:

[CODE]
byte[] data = ConvertHexStringToByteArray(Encoding.Default.GetString(hexstring));
MemoryStream input = new MemoryStream(data);
BinaryReader reader = new BinaryReader(input);
reader.ReadBytes(0x1C);
byte[] buffer = reader.ReadBytes(16);
[/CODE]

Share this post


Link to post
Share on other sites

doesn't that code already does what you need? or did I read the question wrong?

Share this post


Link to post
Share on other sites

doesn't that code already do what you need?

Yes and no. I get the data but need it as hex (9050AA35B23BDA4B3532F2ABDF4A382E) instead of ANSI (.P?5²;?K52???J8.).

Share this post


Link to post
Share on other sites

Yes and no. I get the data but need it as hex (9050AA35B23BDA4B3532F2ABDF4A382E) instead of ANSI (.P?5²;?K52???J8.).

But what is the output type you need? A string or another byte array? Anyway if the input string is hex you just need to copy twice the bytes/characters from the original hex string to obtain the hex substring. Example: hexstring.SubString(0x1C * 2, 16 * 2);

Share this post


Link to post
Share on other sites

But what is the output type you need? A string or another byte array? Anyway if the input string is hex you just need to copy twice the bytes/characters from the original hex string to obtain the hex substring. Example: hexstring.SubString(0x1C * 2, 16 * 2);

This makes it way simpler, thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.