Jump to content

Convert byte[] to string


Recommended Posts

I am using a DllCall that returns a byte[] array. Now I need to decode that to a string. The byte[] array seems to contain arrays of strings.

Here is an example of what it is returning:

8;24;67;1;188;23;67;1;32;0;0;0;1;0;0;0;0;0;0;0;53;4;0;0;0;0;0;0;0;0;0;0;0;0;0;0;82;0;101;0;109;0;111

;0;116;0;101;0;32;0;65;0;99;0;99;0;101;0;115;0;115;0;32;0;65;0;117;0;116;0;111;0;32;0;67;0;111;0;110

;0;110;0;101;0;99;0;116;0;105;0;111;0;110;0;32;0;77;0;97;0;110;0;97;0;103;0;101;0;114;0;0;0;82;0;97;

0;115;0;65;0;117;0;116;0;111;0;0;0

The ";" are separating the elements of the byte array.

Thanks in advance.

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

I am using a DllCall that returns a byte[] array. Now I need to decode that to a string. The byte[] array seems to contain arrays of strings.

Here is an example of what it is returning:

The ";" are separating the elements of the byte array.

Thanks in advance.

If it's really a byte array, then here's my Bug Trac on it: Ticket #50 (assigned Feature Request)

But that has to do with returned arrays from COM interfaces. Are you sure it's a byte array? Can you post a link to the interface description?

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for you reply PsaltyDS.

Yes I am sure it is a byte array.

I am defining a structure like this:

DllStructCreate["ubyte[" & $Size & "]")

Where $Size was determined by a previous DllCall.

I need to call the same function in the dll again to fill the structure with the data.

I need to translate this data to a form, us humans can understand. :P

Edited by engine

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

Thanks.

Already tried char, but the data reported also contains non printing characters. It's really ugly! Also there are lots of null characters. They are working as separators for the elements in the ubyte array.

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

Is there a way to get data from a pointer? I am pretty sure two of the elements in the structure are pointers to the data I need.

Let me explain better.

Those pointers aren't defined by me. So I can't access the data by calling DllStructGetData(). I have a pointer not a structure.

They are inside the ubyte[] array. I know those elements are pointers because I have decoded much of that data myself.

Thanks.

Edited by engine

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

Never mind.

I already found how to get data from a pointer. By creating a new structure and supply that pointer.

Like this:

$tData = DllStructCreate( "ubyte[256]", DllStructGetData($tC, 1, 1) )oÝ÷ Ù8^¦§µêⱫ­¢+Ù±±MÑÉÕÑÑÑ ÀÌØíѰİĤoÝ÷ Ù8^u«Z"wv+"«­¢+Ù±±MÑÉÕÑÑÑ ÀÌØíÑѰĤ
Edited by engine

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

Does this work: ?

$tData = DllStructCreate( "char[256]", DllStructGetData($tC, 1, 1) )

If Not, you could try to use BinaryToString :P Then you can specify if it is ANSI, UTF-8, UTF-16 Little Endian or UTF-16 Big Endian :P

Btw: Often, Windows Strings are encoded with UTF-16 Little Endian

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Thanks ProgAndy

Yes that works.

This problem is solved. I found the way to get all the data!

That's cool, glad you got it working.

But that's not a byte array, at least in the context I was talking about in my post. I'm not a C++ guy, but Valik and the Devs are, and they tried patiently to explain the difference.

I'm thinking because you are looking at returned elements from a DLL call, not a COM object reference, that I was off track bringing it up. The byte array object is not just an array (of bytes), or an array set in a DLL struct, and it presents problems for the Devs in determining how to handle them consistently. When they get the time to figure it out, we'll have our cake, and eat it too!

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...