Getting wxImage in a panel - c++

I've a problem to get a wxImage into a wxPanel.
I want to create a .exe with some pics in the exe, but I want to avoid to give the PNG-Pics with the exe.
So far, I get the PNGs into the exe with this:
wxStaticBitmap *image = new wxStaticBitmap(p_img, wxID_ANY,
wxBitmap("Bild.png", wxBITMAP_TYPE_PNG),
wxPoint(0,0),
wxSize(width, height);
where p_img ist the panel and Bild.png the picture.
Now, I have followed http://wiki.wxwidgets.org/WxImage And have now a wxImage... But I don't know how I can get the wxImage in the panel.
wxMemoryInputStream istream1(Bild_png, sizeof Bild_png);
wxImage Bild_png(istream1, wxBITMAP_TYPE_PNG);
I hope somebody has a idea.
-Casisto
My System:
OS: Win 8.1; wxW 2.9.4; IDE: CodeLite5.1

You can pass wxImage into wxBitmap constructor (wxBitmap Class Reference):
wxBitmap(const wxImage &img, int depth=wxBITMAP_SCREEN_DEPTH)
And then you can create wxStaticBitmap. So the code would be something like that:
wxImage Bild_png(istream1, wxBITMAP_TYPE_PNG);
wxStaticBitmap *staticBitmap = new wxStaticBitmap(p_img, wxID_ANY, wxBitmap(Bild_png));

As I understand you want to use the images and do not want to ship with exe as a physical files on the file system.
For Windows platform resource only Dll can be used. If you want cross platform you can use following technique:
Convert your PNG file to C++ style array.
And use this C++ array to create wxImage object.
You can download the application to get C++ array from:
http://sourceforge.net/projects/png2cscc/
you will get C++ array like below and put this array in some source file of your project.
static const unsigned int the_sizeof_swdXW_bytes = 2304 ;
static const unsigned char the_swdXW_bytes[ the_sizeof_swdXW_bytes ] =
{
0xED, 0xF8, 0xFC, 0xFF, 0xEB, 0xF4, 0xF9, 0xFF, 0xEF, 0xF3, 0xFC, 0xFF, 0xF4, 0xF7, 0xFF, 0xFF,
0xF7, 0xF7, 0xFF, 0xFF, 0xEE, 0xF1, 0xFA, 0xFF, 0xEB, 0xF0, 0xF6, 0xFF, 0xF1, 0xF9, 0xFC, 0xFF,
0xEE, 0xF8, 0xFA, 0xFF, 0xED, 0xF6, 0xF5, 0xFF, 0xEC, 0x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x14, 0x19, 0xFF, 0x0B, 0x0B, 0x0D, 0xFF, 0x3F, 0x37, 0x35, 0xFF,
0xA4, 0x91, 0x8B, 0xFF, 0x91, 0x7E, 0x78, 0xFF, 0x69, 0x5F, 0x60, 0xFF, 0x5E, 0x59, 0x5D, 0xFF,
0xBA, 0xBB, 0xB5, 0xFF, 0xB9, 0xBA, 0xB4, 0xFF, 0xBA, 0xB9, 0xB4, 0xFF, 0xB2, 0xB1, 0xAC, 0xFF,
0xAB, 0xA7, 0xA4, 0xFF, 0x8D, 0x89, 0x88, 0xFF, 0x3E, 0x3C, 0x3D, 0xFF, 0x6E, 0x6D, 0x72, 0xFF,
0x41, 0x40, 0x46, 0xFF, 0x14, 0x14, 0x1C, 0xFF, 0x13, 0x15, 0x21, 0xFF, 0x16, 0x18, 0x24, 0xFF,
0x11, 0x13, 0x1F, 0xFF, 0x16, 0x18, 0x24, 0xFF, 0x11, 0x14, 0x1D, 0xFF, 0x16, 0x19, 0x22, 0xFF,
0x15, 0x1A, 0x20, 0xFF, 0x11, 0x14, 0x19, 0xFF, 0x10, 0x10, 0x12, 0xFF, 0x2B, 0x23, 0x20, 0xFF,
0x7E, 0x67, 0x61, 0xFF, 0x85, 0x6E, 0x68, 0xFF, 0x6B, 0x5F, 0x5F, 0xFF, 0xCB, 0xC5, 0xC9, 0xFF
};

Related

CryptDecrypt fails with ERROR_INVALID_PARAMETER when called for openssl encrypted data

I'm trying to use encryption/decryption functions available in Windows.
I generated RSA key pair in PuTTYgen, extracted private and public keys to separate pem files. Then I use OpenSSL to test those keys by encrypting and then decrypting some message.
openssl.exe rsautl -in input.txt -out encrypted.bin -inkey public_key_4096_puttygen.pem -encrypt -oaep -pubin
openssl.exe rsautl -in encrypted.bin -out decrypted.txt -inkey private_key_4096_puttygen.pem -decrypt -oaep
At this step everything is fine.
Then I take the private key data into sample C++ program written in Visual Studio C++. I call the following functions: CryptAcquireContext, CryptImportKey, CryptEncrypt and CryptDecrypt to test encryption/decryption chain. And also there is everything allright.
Finally I wand to encrypt some data by openssl command and try to decrypt it in C++ program with above functions. And CryptDecrypt returns FALSE (GetLastError returns ERROR_INVALID_PARAMETER).
Here is the program code:
#include "windows.h"
#include "stdio.h"
#define KEY_BUFFER_LENGTH (8 * 1024)
void main()
{
LPCSTR encryptedBase64 = "EyKgay5XppNIX0vVEUuOJ11TYTn5vMHBu1gQJObjWzc7kVCi6dgvmI/r10NeRwQWDDp8m2NluC77ndbZT2CeCMnc9GXG7OwXVLasz8AC1pwC6ZVSsKshp1927mpOn0ZyJK3Ry4hV/jWvBOspDAT1f0ovRqB0Zl2dvN1jwrPjJK4xgREWq9JR8ElEptVd3kRZWkUOrpw0QpCVFmK8mJOlP7ayR2gRhDbQNdbgo12QN0Hsurqjyu8zEb4rEPrw8Ywj3apKytNOFSiQSlXmtCQC+T7vVSQVaVddgLWvXCQFA8tFGyWq+8f4dEl6qfn0/E4RKbJlSs7G2pqTgSnlZVf7NcctJrQP5AUz0bihxEb0+H4TYojYenb98fdu6/QEjHiQH2VzD07VwIyOIGZiL9NhtDc1EOyvtXuGF5t4Zw6wLgeuYvT9HWLYO6dh8zIu2032vKJ+EIkKd4wTotdZlqIWfDRjyKJUIYVwOl4dHXPO2cdCburmzsVooat0LttJjBjJmhxk1D25RjdOgJl6dhq3N/zmcSO0eoCnXZGbGUOAcsVJATo6u7Oo0KCHPsbEkk2iw/WjAT1H1fFJ2XZcLGxfKHYNEtRg25dtbnKPzscxY02AhwEv4v0o/9dEoasxrdJEIh5mpKRJK4xY7E4iAyLIKJ17c6wJ3zu3wfSeJlM1auY=";
HCRYPTPROV provider;
BYTE privKey[] = {0x30, 0x82, 0x09, 0x26, 0x02, 0x01, 0x00, 0x02, 0x82, 0x02, 0x01, 0x00, 0xAE, 0xFF, 0x2C, 0x1E, 0xBD, 0x7A, 0xF3, 0xC0, 0x71, 0x56, 0x6D, 0x4C, 0x54, 0x59, 0x77, 0xCE, 0x88, 0xFB, 0x59, 0xB9, 0xB7, 0xDA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, 0x84, 0xC0, 0x6E, 0x86, 0x03, 0x5E, 0xBE, 0xF8, 0x79, 0x7E, 0x1C, 0x2C, 0x93, 0x07, 0x35, 0xEB, 0xBA, 0x84, 0xF7, 0xAE, 0xC5, 0x9C, 0xB7, 0xAD, 0x31, 0x7D, 0xBB, 0x9C, 0x20, 0xAC, 0x8F, 0xD6, 0xB9, 0x63, 0xAE, 0xDC, 0xE3, 0x75, 0xF1, 0x41, 0x18, 0x5F, 0xCA, 0x35, 0x52, 0xFD, 0xD0, 0x8C, 0x75, 0xA6, 0x6C, 0xE1, 0x31, 0x2D, 0x11, 0x9A, 0x0D, 0x7B, 0x83, 0x04, 0xB3, 0xA1, 0x88, 0x3C, 0x2E, 0xF9, 0xD8, 0x5E, 0x10, 0x29, 0xE0, 0x3C, 0xBF, 0x4E, 0xFD, 0x7A, 0xC3, 0xF5, 0x19, 0x37, 0x41, 0x42, 0x88, 0x67, 0x4D, 0xB2, 0x99, 0x25, 0xAA, 0xC5, 0x5F, 0xE6, 0x9D, 0x47, 0x95, 0xE7, 0x86, 0x04, 0xF4, 0xA5, 0xE2, 0xC1, 0x61, 0x6F, 0x81, 0x0E, 0x4B, 0x21, 0x69, 0x45, 0x73, 0xA7, 0x0D, 0x6B};
DWORD keyBufferLength = sizeof(privKey);
CHAR encrypted[KEY_BUFFER_LENGTH];
DWORD encryptedLength = KEY_BUFFER_LENGTH;
CryptStringToBinaryA(encryptedBase64, strlen(encryptedBase64), CRYPT_STRING_BASE64, (LPBYTE)encrypted, &encryptedLength, NULL, NULL);
if (CryptAcquireContextA(&provider, NULL, MS_ENHANCED_PROV_A, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT) == TRUE)
{
DWORD derSize = 0;
BYTE *privateKeyInfo;
if (CryptDecodeObjectEx(X509_ASN_ENCODING, PKCS_RSA_PRIVATE_KEY, privKey, keyBufferLength, CRYPT_DECODE_ALLOC_FLAG, NULL, &privateKeyInfo, &derSize) != FALSE)
{
HCRYPTKEY key = 0;
if (CryptImportKey(provider, privateKeyInfo, derSize, 0, CRYPT_EXPORTABLE | CRYPT_OAEP, &key) != FALSE)
{
if (CryptDecrypt(key, NULL, TRUE, CRYPT_OAEP, (LPBYTE) encrypted, &encryptedLength) != FALSE)
{
encrypted[encryptedLength] = '\0';
printf("%s\n", encrypted);
}
else
{
DWORD error = GetLastError();
printf("%d\n", error);
}
CryptDestroyKey(key);
}
LocalFree(privateKeyInfo);
}
CryptReleaseContext(provider, 0);
}
}
Could you please tell, what is wrong with this code?

Reading raw SSL/TLS Certificate from memory using OpenSSL

I'm having trouble using OpenSSL to parse certificates from bytes acquired from a pcap file. The data is coming directly from ssl.handshake.certificate field in Wireshark (when observing the pcap).
The raw data is from a pcap file i found from Wireshark. This is just the 10th packet and is a certificate with a commonName 'Ubuntu'. I believe my problem is that i'm giving the OpenSSL function data that is incorrectly formatted but i wouldve thought that it could handle network order bytes (as i have directly from a pcap).
const unsigned int raw[] = {
0x30, 0x82, 0x02, 0xb2, 0x30, 0x82, 0x01, 0x9a,
0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
0xcd, 0xdb, 0x2b, 0xb3, 0xe2, 0xa7, 0x1b, 0x88,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
0x11, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
0x04, 0x03, 0x13, 0x06, 0x75, 0x62, 0x75, 0x6e,
0x74, 0x75, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35,
0x30, 0x31, 0x32, 0x37, 0x31, 0x36, 0x35, 0x35,
0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x35, 0x30,
0x31, 0x32, 0x34, 0x31, 0x36, 0x35, 0x35, 0x30,
0x31, 0x5a, 0x30, 0x11, 0x31, 0x0f, 0x30, 0x0d,
0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x06, 0x75,
0x62, 0x75, 0x6e, 0x74, 0x75, 0x30, 0x82, 0x01,
0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00,
0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01,
0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf1, 0x85,
0x02, 0x0b, 0x26, 0x3d, 0x2d, 0xcd, 0xcc, 0x75,
0xc2, 0x1d, 0x51, 0x19, 0x7c, 0x1d, 0xbc, 0x1e,
0x14, 0xe5, 0x71, 0x6f, 0xfb, 0xaa, 0x2a, 0x8b,
0x2f, 0x69, 0xe3, 0xe7, 0xc7, 0xa4, 0xc4, 0x79,
0xef, 0x17, 0x0e, 0x4b, 0x37, 0xd8, 0x68, 0x00,
0x81, 0x6a, 0x62, 0x55, 0x79, 0x1d, 0x1d, 0x73,
0x6d, 0xbb, 0x20, 0x43, 0x4e, 0x21, 0x8b, 0xe8,
0x67, 0xb6, 0x0e, 0xfd, 0xde, 0x15, 0x18, 0xff,
0x9f, 0x0d, 0x2b, 0xf6, 0x61, 0xd5, 0x51, 0x1c,
0xfe, 0x5e, 0xca, 0x7f, 0xdc, 0x16, 0xc8, 0x4f,
0x36, 0x3d, 0x17, 0x4b, 0x85, 0x53, 0x2e, 0x85,
0x04, 0x7c, 0xa3, 0x02, 0xdd, 0xf2, 0x9b, 0x86,
0xcd, 0x98, 0x64, 0xd4, 0xcd, 0x10, 0x25, 0x79,
0xd6, 0x81, 0x36, 0x40, 0x72, 0xd3, 0xfd, 0x06,
0xff, 0x55, 0x79, 0x0b, 0xc3, 0x07, 0x7a, 0x04,
0xd3, 0x9a, 0x80, 0x92, 0xd2, 0x33, 0x82, 0x63,
0x87, 0x1f, 0xae, 0x9f, 0xb3, 0x9e, 0x01, 0x41,
0x07, 0x42, 0x02, 0x25, 0x9d, 0x29, 0xb8, 0x67,
0xa0, 0x02, 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x35,
0xde, 0x6b, 0x1a, 0xb9, 0x3f, 0xa0, 0x06, 0xd5,
0x39, 0x0e, 0xc3, 0xfa, 0xe2, 0x6f, 0x7f, 0xb3,
0x4d, 0xee, 0x54, 0x38, 0x78, 0x3b, 0x1b, 0x2e,
0x71, 0xc2, 0xc5, 0x2d, 0xca, 0xf1
};
const unsigned char* data = reinterpret_cast<const unsigned char*>(raw);
size_t len = sizeof(raw)/sizeof(raw[0]);
X509 *cert = d2i_X509(NULL, &data, len);
This will always return cert as NULL and i'm stuck because this seemed like a simple procedure.
Your raw array is the wrong type. That is supposed to be a sequence of simple octets (unsigned char, uint8_t, pick your poison).
Changed as described above, the certificate is extracted successfully:
Code
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
const unsigned char raw[] = // <<======= HERE
{
0x30, 0x82, 0x02, 0xb2, 0x30, 0x82, 0x01, 0x9a,
0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
0xcd, 0xdb, 0x2b, 0xb3, 0xe2, 0xa7, 0x1b, 0x88,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
0x11, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
0x04, 0x03, 0x13, 0x06, 0x75, 0x62, 0x75, 0x6e,
0x74, 0x75, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35,
0x30, 0x31, 0x32, 0x37, 0x31, 0x36, 0x35, 0x35,
0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x35, 0x30,
0x31, 0x32, 0x34, 0x31, 0x36, 0x35, 0x35, 0x30,
0x31, 0x5a, 0x30, 0x11, 0x31, 0x0f, 0x30, 0x0d,
0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x06, 0x75,
0x62, 0x75, 0x6e, 0x74, 0x75, 0x30, 0x82, 0x01,
0x22, 0x30, 0x0d, 0x06, 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 0xe2, 0x6f, 0x7f, 0xb3,
0x4d, 0xee, 0x54, 0x38, 0x78, 0x3b, 0x1b, 0x2e,
0x71, 0xc2, 0xc5, 0x2d, 0xca, 0xf1
};
int main()
{
OpenSSL_add_all_ciphers();
OpenSSL_add_all_digests();
OpenSSL_add_all_algorithms();
const unsigned char *data = raw;
size_t len = sizeof(raw) / sizeof(raw[0]);
X509 *cert = d2i_X509(NULL, &data, (long)len);
printf("%p\n", cert);
if (cert)
{
X509_NAME *name = X509_get_issuer_name(cert);
if (name)
printf("Issuer: %s\n", X509_NAME_oneline(name, NULL, 0));
X509_free(cert);
}
return 0;
}
Output (pointer value varies)
0000018ACA51BEB0
Issuer: /CN=ubuntu

Verify RSA signature in c++ using openssl

I have a public key and a signature of some message, in the form of a byte array.
I'm trying to verify the signature using the public key.
That's what I tried:
int test2()
{
const unsigned char *MESSAGE = (unsigned char *) "My message";
const int MESSAGE_LEN = 10;
unsigned char pubKey[] = {0x2D, 0x7E, 0xDC, 0xFE, 0x5B, 0x17, 0xE4, 0x30, 0x64, 0x09, 0x75,
0xCA, 0xBB, 0x6C, 0x8D, 0xAE, 0x93, 0xB3, 0x0F, 0xA0, 0x0F, 0x59,
0xE2, 0xA5, 0x2F, 0x66, 0x45, 0x3D, 0x89, 0x6D, 0x66, 0x60, 0x60,
0x5B, 0x83, 0xC2, 0xA7, 0xC8, 0x01, 0x52, 0x2D, 0xA9, 0x62, 0xC2,
0x1C, 0xED, 0x85, 0x98, 0xD1, 0xC2, 0x84, 0x01, 0xF4, 0x45, 0xFA,
0x2C, 0x78, 0x05, 0x99, 0x1F, 0xCF, 0x96, 0xDA, 0xC5, 0xC0, 0x46,
0x26, 0xF8, 0x0D, 0x31, 0x01, 0x42, 0x77, 0x46, 0x9C, 0x5B, 0xC5,
0x9D, 0x0D, 0x68, 0xBA, 0x1F, 0x11, 0x89, 0xCC, 0xC3, 0x75, 0xC6,
0x17, 0x4B, 0xFD, 0x1E, 0x1A, 0x19, 0x32, 0x23, 0x2F, 0x9D, 0xAB,
0x51, 0xFB, 0x5A, 0xD3, 0xC7, 0xCE, 0xB0, 0xDE, 0x07, 0x01, 0xB1,
0xB7, 0x90, 0x28, 0x36, 0x9F, 0x15, 0xEB, 0x07, 0x6E, 0x6F, 0x5A,
0x1B, 0x9E, 0x22, 0xC4, 0x02, 0x8F, 0x90, 0x47, 0xEE, 0x78, 0xF4,
0xE8, 0x1D, 0x63, 0xD7, 0x56, 0x2C, 0x13, 0x71, 0xCD, 0xCD, 0x84,
0x50, 0x1D, 0x1C, 0x36, 0x56, 0xD5, 0xDE, 0x20, 0x3A, 0xB5, 0xE8,
0x1B, 0x9A, 0x89, 0xDE, 0x51, 0xAB, 0x1A, 0x0C, 0x51, 0x08, 0xD2,
0x22, 0xB0, 0x74, 0x6D, 0xA3, 0x84, 0x11, 0xF5, 0x91, 0x27, 0xAB,
0x05, 0xB4, 0x01, 0x14, 0xBF, 0xB4, 0x03, 0xD2, 0x38, 0x89, 0xDA,
0xA6, 0x16, 0xBF, 0xB4, 0x0B, 0xD2, 0x7A, 0xFF, 0xB0, 0x0F, 0x42,
0x8A, 0x0A, 0x32, 0xD4, 0x28, 0x77, 0x54, 0xA0, 0xA0, 0xFB, 0x96,
0xB1, 0x69, 0x08, 0x43, 0xB0, 0x25, 0x47, 0x01, 0x58, 0xA0, 0xBE,
0xB3, 0xDF, 0xC4, 0x51, 0xE2, 0x62, 0x2D, 0x95, 0xB3, 0x8D, 0x80,
0x5C, 0x4E, 0x24, 0xC3, 0x2F, 0x9F, 0x6D, 0x7A, 0x02, 0xB7, 0xD9,
0x7F, 0xEE, 0xF1, 0x1C, 0xAF, 0x51, 0xBE, 0x45, 0x5E, 0x85, 0x2E,
0x05, 0x74, 0xB9};
unsigned char exp[] = {0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char signature[] = {0x1A, 0x84, 0x32, 0x9F, 0x73, 0x3F, 0x46, 0xDF, 0x63, 0x41, 0xB4,
0x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DF, 0x8C, 0x53, 0xF4,
0x08, 0xAB, 0x5C, 0x01, 0xA0, 0xB1, 0x4C, 0x10, 0xEB, 0xA9, 0x4C,
0x91, 0x52, 0x3A, 0x4B, 0x84, 0x8A, 0x55, 0x5E, 0x85, 0x1A, 0x8E,
0x70, 0x77, 0x3B, 0x25, 0x2D, 0x63, 0x4E, 0xE4, 0x19, 0xCF, 0x76,
0x07, 0xDE, 0xC4, 0x7B, 0x77, 0x41, 0x3F, 0x46, 0x5E, 0x4F, 0xC9,
0xEE, 0x57, 0xB6, 0x65, 0xFD, 0xFF, 0xD4, 0xC7, 0x0A, 0x10, 0x26,
0xA7, 0x3F, 0xF0};
RSA *rsa = RSA_new();
rsa->n = BN_bin2bn(pubKey, 256, NULL);
rsa->e = BN_bin2bn(exp, 8, NULL);
int errCode = RSA_verify(RSA_PKCS1_PADDING, MESSAGE, MESSAGE_LEN, signature, 256, rsa);
if (errCode == 1)
{
std::cout << "Message signature was verified successfully" << std::endl;
}
else
{
std::cout << "Message signature is incorrect" << std::endl;
}
return 0;
}
That is the right signature for the message, but I keep getting a wrong signature result. What am I doing wrong?
Thanks to jww's comment about the exponent being 72058693549555712, I realized I provided the numbers in little-endian form, where the BN_bin2bn function expect a buffer in big-endian form. I managed to find here a function called BN_bin2lbn that should be perfect for that case, as it expects a buffer in little-endian form. Unfortunately this function doesn't seem to exist in the bn.h file on my computer (which is where BN_bin2bn is declared).
Eventually I managed to overcome this by turning my numbers into big-endian form, using:
std::reverse(pubKey, pubKey + 256);
std::reverse(exp, exp + 8);
Now everything works fine.

Convert String to Const Char XYZ[] PROGMEM {}

How to convert a String to Const Char XYZ[] PROGMEM?
Specific issue:
I am working on Arduino + OLED project (using the squix library) in which I am displaying image defined by WiFi_Logo_bits[] using the following code
void drawImageDemo() {
display.drawXbm(0, 0, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits); // variables are defined below
}
Everything works as it as, but now I want to dynamically get the image data from internet and store in WiFi_Logo_bits[]. I am successfully able to retrieve the data for ex: {0xFE, 0xDE, 0x01......} as String, but cannot assign the value to WiFi_Logo_bits[] PROGMEM as I am having problem with datatypes conversion.
Variables above are defined as below:
#define WiFi_Logo_width 119
#define WiFi_Logo_height 63
const char WiFi_Logo_bits[] PROGMEM = {
0xF2, 0xFF, 0xE7, 0xFF, 0xFF, 0xFE, 0x1F, 0x04, 0x91, 0xF8, 0x01, 0x00,
0x00, 0x00, 0x00, 0xF2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x04, 0x91,
0xF0, 0x03, 0x00, 0x00, 0x10, 0x00, 0xF2, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F,
0x0C, 0x86, 0x81, 0xF8, 0x00, 0x00, 0x00, 0x10, 0x00, 0xE3, 0xFF, 0xFF,
0xFF, 0xFF, 0x17, 0x04, 0x83, 0xE4, 0xF9, 0x06, 0x00, 0x00, 0x00, 0x00,
0xE1, 0xFF, 0xFD, 0xFF, 0xFF, 0x01, 0x82, 0xC0, 0xC9, 0xF8, 0x04, 0x00,
0x00, 0x00, 0x00, 0xD0, 0xFF, 0xFB, 0xFF, 0xBF, 0x00, 0x40, 0xE0, 0x20,
0xFA, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE2, 0xFF, 0xFF, 0xFF, 0x1D, 0x20,
0x20, 0xE0, 0x70, 0xFC, 0x09, 0x00, 0x00, 0x00, 0x40, 0xFC, 0xFF, 0x7B,
0xFF, 0x0B, 0x00, 0x18, 0x70, 0x14, 0xF9, 0x04, 0x00, 0x00, 0x00, 0x00,
0xFE, 0xFF, 0x9F, 0xBF, 0x02, 0x00, 0x04, 0x18, 0xB1, 0xF8, 0x6C, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xDF, 0x01, 0x04, 0x02, 0x86, 0x88,
0xFB, 0x3E, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x9F, 0x00, 0x00,
0xC1, 0x01, 0x3A, 0x60, 0x1E, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF,
0x1F, 0x00, 0xC1, 0x20, 0xA0, 0x42, 0x72, 0x0E, 0x00, 0x00, 0x00, 0x00,
0xFE, 0xFF, 0xB7, 0x9F, 0x00, 0x40, 0x10, 0xB0, 0x61, 0xF4, 0x8E, 0x00,
0x00, 0x00, 0x00, 0xFC, 0xFF, 0xE7, 0x2F, 0x00, 0x30, 0x08, 0x0A, 0x05,
0x01, 0x8E, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFD, 0x0F, 0x00, 0x18,
0x8C, 0x02, 0x87, 0x66, 0x1F, 0x03, 0x00, 0x00, 0x00, 0xBF, 0xFF, 0xFF,
0x1F, 0x00, 0x08, 0x03, 0x80, 0xAE, 0x24, 0x3E, 0x0F, 0x00, 0x00, 0x20,
0xBF, 0x7F, 0xFF, 0x2D, 0x00, 0x04, 0x83, 0x80, 0x8D, 0x24, 0xBF, 0x1B,
0x00, 0xA0, 0x14, 0x9F, 0xFF, 0xBE, 0x03, 0x00, 0x82, 0x61, 0x70, 0xA2,
0x25, 0xFE, 0xB5, 0x00, 0x10, 0x63, 0xFF, 0x2F, 0xFE, 0x05, 0x00, 0x83,
0x10, 0x0C, 0x54, 0x51, 0xFE, 0x63, 0x00, 0x00, 0x00, 0xFF, 0x83, 0xCF,
0x11, 0x80, 0x41, 0x00, 0x02, 0xDA, 0x0B, 0xFE, 0xB7, 0x00, 0x00, 0x00,
0x7E, 0xF2, 0x3B, 0x0A, 0x81, 0x60, 0x80, 0x01, 0xD7, 0x63, 0xFE, 0x3F,
0x02, 0x00, 0x00, 0x1F, 0xF0, 0x5E, 0x08, 0x60, 0x30, 0x40, 0x00, 0x6F,
0x07, 0xFC, 0x7F, 0x0C, 0x00, 0x00, 0x1F, 0xFE, 0x6F, 0x00, 0x20, 0x10,
0x60, 0xC0, 0xFF, 0x4A, 0xFC, 0x77, 0x0B, 0x00, 0x08, 0x2D, 0xFC, 0x5F,
0x80, 0x10, 0x08, 0x10, 0xE0, 0xDF, 0x01, 0xF2, 0xA4, 0x1D, 0x00, 0x00,
0x1A, 0x7E, 0x9F, 0x82, 0x18, 0x04, 0x08, 0xF8, 0x6F, 0x04, 0xD0, 0xF5,
0x3F, 0x00, 0x00, 0x18, 0xFE, 0x3F, 0x62, 0x08, 0x06, 0x06, 0xFC, 0x9F,
0x00, 0x00, 0xE8, 0x7F, 0x00, 0x00, 0xAC, 0xBF, 0x3F, 0x0A, 0x0C, 0x03,
0x01, 0xFC, 0x0B, 0x11, 0x00, 0x60, 0xFF, 0x00, 0x00, 0xDA, 0xFF, 0xBF,
0x20, 0x04, 0x80, 0x00, 0xFC, 0x0A, 0x04, 0x00, 0xC0, 0xE3, 0x00, 0x00,
0x39, 0xFF, 0x1F, 0x30, 0x82, 0x50, 0x20, 0xFF, 0x10, 0x1B, 0x00, 0x00,
0xD0, 0x03, 0x00, 0xDF, 0xFF, 0x3F, 0x28, 0x42, 0x20, 0x00, 0xBF, 0x01,
0x05, 0x00, 0x00, 0xA0, 0x07, 0x00, 0xDF, 0xFF, 0x7F, 0x30, 0x63, 0x30,
0x80, 0x1F, 0x80, 0x6E, 0x01, 0x00, 0x00, 0x07, 0x00, 0xAE, 0xFB, 0xFF,
0x20, 0x23, 0x1C, 0xC0, 0x0F, 0x00, 0x17, 0x00, 0x00, 0x00, 0x0E, 0x00,
0xBB, 0xF8, 0xFD, 0x19, 0x21, 0x0C, 0xE0, 0x07, 0x40, 0x07, 0x02, 0x00,
0x00, 0x0E, 0x00, 0xA7, 0xFA, 0xF9, 0x8B, 0x11, 0x0A, 0xF0, 0x03, 0xC0,
0x7F, 0x0C, 0x00, 0x00, 0x38, 0x00, 0x19, 0xFE, 0x79, 0x0F, 0x13, 0x08,
0xE4, 0x01, 0xF8, 0xBF, 0x02, 0x00, 0x00, 0x60, 0x00, 0x73, 0xFE, 0x77,
0x1F, 0x01, 0x0D, 0xEE, 0x00, 0xFC, 0x7F, 0x05, 0x00, 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 0xFF, 0x1D, 0x00, 0x00, 0xF0, 0x52, 0x74, 0x60, 0x73,
0xD8, 0x8C, 0x6B, 0x8C, 0x1F, 0xFF, 0xFF, 0x2F, 0x00, 0x00, 0xB4, 0x99,
0x6B, 0x80, 0x8C, 0x04, 0x82, 0x67, 0x08, 0xB7, 0xFF, 0xFF, 0x9F, 0x00,
0x00, 0xE0, 0x20, 0x6A, 0x40, 0x1A, 0x11, 0xC2, 0x69, 0x11, 0x3F, 0xFF,
0xFF, 0x1F, 0x00, 0x00, 0xE0, 0x85, 0x50, 0x00, 0x59, 0x48, 0xE1, 0x64,
0x32, 0x7F, 0xFF, 0xFF, 0x9F, 0x00, 0x00, 0xF0, 0x01, 0x20, 0x80, 0x14,
0xD6, 0xE0, 0x71, 0x62, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x64, 0x15,
0x00, 0x80, 0x65, 0x10, 0x30, 0x60, 0xC5, 0xFE, 0xFF, 0xFF, 0x3F, 0x00,
0x00, 0x28, 0x05, 0x00, 0x00, 0x12, 0xAB, 0x70, 0x70, 0x89, 0xFD, 0xFF,
0xFF, 0x1B, 0x00, 0x00, 0x20, 0x02, 0x20, 0x80, 0xD8, 0x84, 0x58, 0x70,
0x09, 0xFB, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29,
0x24, 0x0C, 0x70, 0x0B, 0xFF, 0xFF, 0xFF, 0xBF, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x60, 0x1B, 0x1C, 0x70, 0x16, 0xFE, 0xFF, 0xFF, 0x7F, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xA8, 0x0A, 0x0E, 0x78, 0x04, 0xFC, 0xFF,
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x0E, 0x78,
0x4D, 0xF4, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0,
0x8A, 0x07, 0x7C, 0x4C, 0xF8, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x91, 0x03, 0x21, 0x90, 0xFD, 0xFF, 0xFF, 0xFF, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x95, 0x83, 0x1A,};
The PROGMEM type modifier tells the compiler the array values should be put into flash memory - that makes the variable not only logically const, but also even physically (even if your program would allow modifying the const variable, it couldn't, because flash can't simply be written to like other memory. It would need to re-flash the device on the fly)
The short answer is: If something is declared const PROGMEM, you cannot change it.
In theory you can modify PROGMEM, but:
It must be stored in one flash memory block (it must be erased and programmed as block)
It can't be erased/programmed from regular program sections but from bootloader section (doesn't apply for most ATTinys as they don't have bootloader section). This requires your own bootloader to support it.
Or you can use EEPROM to store this array:
It is not such a big problem to change it. It just needs similar functions to read/write EEMEM variables.
But draw methods in the library are pretty much relying on PROGMEM, so you have to write your own drawXbm function (method if you extend current library).

trouble reading structure from stream, or bytes rather

I'm trying to read a LAS File 1.3 Header from a file.
In every single header that I've seen, The first thing i expect to read is the Format Signature which is always "LASF".
When i try and read the file, All I'm seeing is 'ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ'
I know the header size is 227, I tried to even just read a length of 227 straight from the file but i still don't read what I'm supposed to. I hope this makes sense.
this is what i've tried:
typedef struct Header
{
char File_Signature[4];
USHORT SourceID;
USHORT Reserved1;
UINT GUID1;
USHORT GUID2;
USHORT GUID3;
char GUID4[8];
BYTE VersionMajor;
BYTE VersionMinor;
char SystemID[32];
char GeneratingSoftware[32];
USHORT DOY;
USHORT YEAR;
USHORT HeaderSize;
UINT PointOffset;
INT NumberOfVariableLengthRecords;
BYTE PointDataFormatID;
USHORT PointDataRecordLength;
INT NumberOfPointRecords;
UINT NumberofPointsByReturn1;
UINT NumberofPointsByReturn2;
UINT NumberofPointsByReturn3;
UINT NumberofPointsByReturn4;
UINT NumberofPointsByReturn5;
double XScaleFactor;
double YScaleFactor;
double ZScaleFactor;
double Xoffset;
double Yoffset;
double Zoffset;
double MaxX;
double MinX;
double MaxY;
double MinY;
double MaxZ;
double MinZ;
} LasHeader;
void OpenLasFile()
{
//THIS DOES NOT WORK
char buffer[227];
ifstream myFile ("C:\atlass\area_cov.las");
myFile.read (buffer, 227);
//NOT WORK, TRIED THIS TOO
ifstream input_file("C:\atlass\area_cov.las", ios::binary);
LasHeader header;
input_file.read((char*)&header, sizeof(header));
input_file.close();
//ALL DATA OUTPUT'ed ARE 'ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ'
}
This is a block of binary from the file I'm trying to read.
4C4153460000000001000000020003003132333435363738010241746C6173732041746C6173436F72652020202020202020202020202020202041746C6173436F726520202020202020202020202020202020202020202020201E01DC07E300E300000000000000011C0014012F0014012F0000000000000000000000000000000000FCA9F1D24D62503FFCA9F1D24D62503FFCA9F1D24D62503F00000000B05320410000000024FF53410000000000000000E7B3FA8388A920411B5611E9BC1B20417710D27C2711544114A5EC807EF45341C520B072685D684037894160E5D012C021BE92FF06661701A9600000D803C902E2000100AC7136BDE325044137
My question is: Why am i Reading garbage values, what have i done wrong?
-------------------- UPDATE --------------------------
I tested this and it worked, So it must be a problem reading the file, can anyone help?
what worked was:
unsigned char rawData[552] =
{
0x4C, 0x41, 0x53, 0x46, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00,
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x01, 0x02, 0x41, 0x74, 0x6C, 0x61, 0x73, 0x73,
0x20, 0x41, 0x74, 0x6C, 0x61, 0x73, 0x43, 0x6F, 0x72, 0x65, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x41, 0x74, 0x6C, 0x61, 0x73, 0x43,
0x6F, 0x72, 0x65, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x1E, 0x01, 0xDC, 0x07, 0xE3, 0x00,
0xE3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1C, 0x00, 0x14, 0x01, 0x2F, 0x00, 0x14,
0x01, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFC, 0xA9, 0xF1, 0xD2, 0x4D, 0x62, 0x50, 0x3F, 0xFC, 0xA9, 0xF1, 0xD2, 0x4D,
0x62, 0x50, 0x3F, 0xFC, 0xA9, 0xF1, 0xD2, 0x4D, 0x62, 0x50, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xB0,
0x53, 0x20, 0x41, 0x00, 0x00, 0x00, 0x00, 0x24, 0xFF, 0x53, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xE7, 0xB3, 0xFA, 0x83, 0x88, 0xA9, 0x20, 0x41, 0x1B, 0x56, 0x11, 0xE9, 0xBC,
0x1B, 0x20, 0x41, 0x77, 0x10, 0xD2, 0x7C, 0x27, 0x11, 0x54, 0x41, 0x14, 0xA5, 0xEC, 0x80, 0x7E,
0xF4, 0x53, 0x41, 0xC5, 0x20, 0xB0, 0x72, 0x68, 0x5D, 0x68, 0x40, 0x37, 0x89, 0x41, 0x60, 0xE5,
0xD0, 0x12, 0xC0, 0x21, 0xBE, 0x92, 0xFF, 0x06, 0x66, 0x17, 0x01, 0xA9, 0x60, 0x00, 0x00, 0xD8,
0x03, 0xC9, 0x02, 0xE2, 0x00, 0x01, 0x00, 0xAC, 0x71, 0x36, 0xBD, 0xE3, 0x25, 0x04, 0x41, 0x37,
0xB9, 0x92, 0xFF, 0x77, 0x58, 0x17, 0x01, 0xD7, 0x60, 0x00, 0x00, 0xE2, 0x0A, 0xC9, 0x02, 0xE2,
0x00, 0x01, 0x00, 0x4B, 0x90, 0x11, 0x90, 0xE3, 0x25, 0x04, 0x41, 0x00, 0xBF, 0x92, 0xFF, 0x98,
0x3A, 0x17, 0x01, 0x2B, 0x62, 0x00, 0x00, 0x23, 0x0A, 0x49, 0x02, 0xE4, 0x00, 0x01, 0x00, 0xBF,
0xF5, 0x61, 0xBD, 0xE3, 0x25, 0x04, 0x41, 0x1A, 0xBD, 0x92, 0xFF, 0x30, 0x11, 0x17, 0x01, 0xE4,
0x62, 0x00, 0x00, 0xDF, 0x08, 0x49, 0x02, 0xE4, 0x00, 0x01, 0x00, 0xF8, 0x6E, 0xF3, 0xA6, 0xE3,
0x25, 0x04, 0x41, 0x01, 0xBE, 0x92, 0xFF, 0x67, 0xE7, 0x16, 0x01, 0x83, 0x63, 0x00, 0x00, 0xCB,
0x06, 0x49, 0x02, 0xE5, 0x00, 0x01, 0x00, 0x0B, 0xF3, 0x1E, 0xA7, 0xE3, 0x25, 0x04, 0x41, 0xF2,
0xBB, 0x92, 0xFF, 0x99, 0xD9, 0x16, 0x01, 0x6D, 0x63, 0x00, 0x00, 0x03, 0x09, 0x49, 0x02, 0xE5,
0x00, 0x01, 0x00, 0x82, 0x1C, 0x94, 0x90, 0xE3, 0x25, 0x04, 0x41, 0xFA, 0xBE, 0x92, 0xFF, 0x98,
0xBE, 0x16, 0x01, 0x13, 0x63, 0x00, 0x00, 0xFF, 0x08, 0x49, 0x02, 0xE5, 0x00, 0x01, 0x00, 0xE5,
0xF0, 0x49, 0xA7, 0xE3, 0x25, 0x04, 0x41, 0xEE, 0xBC, 0x92, 0xFF, 0xDE, 0xB0, 0x16, 0x01, 0x04,
0x63, 0x00, 0x00, 0x8E, 0x0B, 0x49, 0x02, 0xE5, 0x00, 0x01, 0x00, 0x95, 0xA0, 0xBF, 0x90, 0xE3,
0x25, 0x04, 0x41, 0xD2, 0xBD, 0x92, 0xFF, 0x19, 0x88, 0x16, 0x01, 0xA9, 0x63, 0x00, 0x00, 0xD1,
0x08, 0x49, 0x02, 0xE7, 0x00, 0x01, 0x00, 0xA7, 0x24, 0xEB, 0x90, 0xE3, 0x25, 0x04, 0x41, 0xA8,
0xBE, 0x92, 0xFF, 0x29, 0x64, 0x16, 0x01, 0x97, 0x63, 0x00, 0x00, 0xFD, 0x04, 0x49, 0x02, 0xE7,
0x00, 0x01, 0x00, 0xC4, 0xF0, 0x11, 0x91, 0xE3, 0x25, 0x04, 0x41, 0x79, 0xD0, 0x92, 0xFF, 0xD0,
0x70, 0x17, 0x01, 0x30, 0x61, 0x00, 0x00, 0x60, 0x02, 0xC9, 0x02, 0xE2, 0x00, 0x01, 0x00, 0x91,
0x65, 0xC1, 0x44, 0xE4, 0x25, 0x04, 0x41, 0x12, 0xC7, 0x92, 0xFF, 0x02, 0x5E, 0x17, 0x01, 0x79,
0x61, 0x00, 0x00, 0x79, 0x05, 0xC9, 0x02, 0xE2,
} ;
LasHeader test;
memcpy(&test, rawData, sizeof(test));
The issue is here:
ifstream myFile ("C:\atlass\area_cov.las");
Backslash is a special character in C strings that forms escape sequences. In this particular case, \a is replaced by a bell character (0x0B), so it is trying to open the wrong path and failing.
Instead, you need to escape all the backslashes that occur in the path by doubling them:
ifstream myFile ("C:\\atlass\\area_cov.las");