Erusso87
Erusso87

Reputation: 677

How to get raw bytes from ZXing - IPhone

i have a big problem. I have read some post and can´t solve this problem. I have a Iphone App, this app read a QR code with zxing, but the QR have a personal encryptation. When ZXing parse this bytes and convert to NSString, the bytes change and i can´t get the originals bytes.

I was reading Decoder.mm and many others classes of ZXing library and i can´t get this.

Any idea?

Thanks

Upvotes: 1

Views: 1788

Answers (3)

Silas007
Silas007

Reputation: 11

For anyone wanting to know, how to do that:

I had the same problem (getting raw bytes from the qr-code):

I "fixed" DecodedBitStreamParser.cpp and function

void DecodedBitStreamParser::decodeByteSegment(..) to get a hex-string e.g. ab0cd42...

I replaced the line at the end of the function:

append(result, readBytes, nBytes, encoding);

with:

try {
    char buffer [nBytes * 2];
    for (int i = 0; i < nBytes; i++) {
        std::sprintf(buffer, "%s%02x", buffer, readBytes[i]);
    }
    append(result, (unsigned char*)buffer, nBytes * 2, encoding.c_str());
} catch (ReaderException const& re) {
    throw FormatException();
}
byteSegments->values().push_back(bytes_);

Upvotes: 1

Erusso87
Erusso87

Reputation: 677

Ok... i will answer my own question. That what you said is true, ZXingWidgetController think that the returned pointer of char is in UTF8 and make a string with this bytes. What i did? I need the Hexadecimal value of each byte in the string, so if the hexa value of the char 68 is 0x57, i made a string concatenating 57|45|25|a7|7e ...... i convert the hexa value into string format... then i parse that string... is not a good solution but is only what i can do at this moments.

Upvotes: 1

smparkes
smparkes

Reputation: 14063

Unfortunately, the ZXWidgetController and Decoder classes aren't set up to make this easy and refactoring them to make it easier is itself not the easiest thing because of the way they were originally designed.

If you wanted to try to patch something in, you just need to go into the Decoder class and modify it to grab the byte results instead of the text results in the - decode method.

There are some classes in the objc directory that might make this particular part easier but they're at a lower level (they are at the CALayer level rather than the UIKit controller level). And they don't have much documentation.

Upvotes: 1

Related Questions