#ZIP signature

31 messages · Page 1 of 1 (latest)

turbid coral
#

So I'm debugging


std::size_t size = file.tellg();

for (size_t i = 0, end = size - 128; i < end; ++i) {
  if (v[i] == 0x50 && v[i + 1] == 0x4b && v[i + 2] == 0x03 && v[i + 3] == 0x04 && v[i + 4] == 0x14) {
  
  When it reaches this check I receive false, why?

 g_logger.info("Signature not found at index " + std::to_string(i));```

When it's time to unzip the data.zip for reading, it gives an error in the signature, does anyone know why? because the header matches
.
undone blazeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

wispy scaffold
#

Check the actual values you get.

#

Wait, is the log line in the if or else branch?

turbid coral
wispy scaffold
#

Is it in the if or in the else?

turbid coral
#
        // Verifique a assinatura ZIP
        if (v[i] == 0x50 && v[i + 1] == 0x4b && v[i + 2] == 0x03 && v[i + 3] == 0x04 && v[i + 4] == 0x14) {
            g_logger.info("Found ZIP signature at index " + std::to_string(i));

            // Obtenha os tamanhos de compressão e descompressão
            uint32_t compSize = *(uint32_t*)&v[i + 18];
            uint32_t decompSize = *(uint32_t*)&v[i + 22];

            g_logger.info("ZIP signature details - CompSize: " + std::to_string(compSize) + ", DecompSize: " + std::to_string(decompSize));

            // Verifique se os tamanhos estão dentro do intervalo permitido
            if (compSize < 1024 * 1024 * 512 && decompSize < 1024 * 1024 * 512) {
                // Log de sucesso e dados selecionados
                g_logger.info("Valid ZIP signature found. CompSize and DecompSize are within the allowed range.");
                data = std::make_shared<std::vector<uint8_t>>(&v[i], &v[v.size()]);
                g_logger.info("Data vector created successfully with size: " + std::to_string(data->size()));
                break;
            } else {
                g_logger.info("CompSize or DecompSize out of allowed range.");
            }
        } else {
            // Opcional: Log de onde a assinatura não foi encontrada
            g_logger.info("Signature not found at index " + std::to_string(i));
        }
    }

    if (!data) {
        g_logger.info("No valid ZIP signature found in the vector.");
    }
    ```
wispy scaffold
#

OK, then check the values.

turbid coral
#

        // Log dos valores antes do if
        oss << "Valores antes do if:\n";
        oss << "v[" << i << "] = 0x" << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << (int)v[i] << "\n";
        oss << "v[" << i + 1 << "] = 0x" << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << (int)v[i + 1] << "\n";
        oss << "v[" << i + 2 << "] = 0x" << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << (int)v[i + 2] << "\n";
        oss << "v[" << i + 3 << "] = 0x" << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << (int)v[i + 3] << "\n";
        oss << "v[" << i + 4 << "] = 0x" << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << (int)v[i + 4] << "\n";

        // Log da assinatura encontrada
        oss << "Found ZIP signature at index " << i;

        // Passar a mensagem formatada para o logger
        g_logger.info(oss.str());
wispy scaffold
#

See they don't match the signature.

#

Also this would be easier to observe in a debugger.

turbid coral
wispy scaffold
#

?

wispy scaffold
turbid coral
# wispy scaffold Was this screenshot not the data you are trying to read?

Yes, it's for my game client, if it doesn't read it, it won't open, this part is after encryption but for some reason there was an error in the zip signature, to prevent them from stealing the textures of my game, there are many servers, and I pay a high price for textures, someone comes and steals

wispy scaffold
#

Then you need to debug your decryption.

turbid coral
#

both are encrypted, it shouldn't be the same, the game client at this point has already been able to decrypt the encryption

wispy scaffold
#

You are making the picture very murky.

#

Is the data you showed in the screenshot what you are actually reading in?

wispy scaffold
#

Then you need to debug how you are reading that data.

turbid coral
wispy scaffold
#

The data you actually get is not matching what's in that file.

turbid coral
#

    if (!file.is_open()) {
        g_logger.fatal("Failed to open file: " + m_binaryPath.string());
        return false;
    }

    g_logger.info("File opened successfully: " + m_binaryPath.string());

    file.seekg(0, std::ios_base::end);
    std::size_t size = file.tellg();
    file.seekg(0, std::ios_base::beg);
    g_logger.info("File size: " + std::to_string(size));

    if (size < 1024 || size > 1024 * 1024 * 128) {
        file.close();
        g_logger.fatal("File size out of range.");
        return false;
    }

    std::vector<uint8_t> v(1 + size);

    file.read((char*)&v[0], size);

    // Verifique se a leitura foi bem-sucedida
    std::streamsize bytesRead = file.gcount();
    if (!file || bytesRead != static_cast<std::streamsize>(size)) {
        g_logger.fatal("Error reading file. Expected " + std::to_string(size) + " bytes, but read " + std::to_string(bytesRead) + " bytes.");
        file.close();
        return false;
    }
wispy scaffold
#

Check the data after that initial file read.

turbid coral
wispy scaffold
#

That doesn't sound related.

turbid coral
#

oh my god I did it I spent all day for this 😅

#

!solved