开发者

Blindly converting a bytearray to a structure?

开发者 https://www.devze.com 2023-02-18 22:33 出处:网络
Is it possible to, say, convert a byte array passed from an older C++ application to C# without exactly knowing what the structure is?

Is it possible to, say, convert a byte array passed from an older C++ application to C# without exactly knowing what the structure is?

I'm trying to re-make an old application that our company uses, but the source code is no longer available. Any help would be greatly appre开发者_运维技巧ciated. Thanks!


You would need to know something about the structure of the byte array if you want to actually use the data embedded in the array. Without that information, the array is nothing but bytes - you could easily pull it in as bytes, but that will be of little use.

If this information is unavailable, you could use a hex editor to try to reverse engineer the byte data.


You could always cast the address of the first byte as a Type * and hope that it works. There maybe be some sizing issues with 32 and 64 bits OS though it really depends on how the c++ code was compiled. The thing is you have to know the type you want to cast to. you could use the size of the byte array as an indicator maybe or use pointer arithmetic to read the fields. In this case you would have to know information about the structure if not it all just looks like bytes to you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号