0
votes

I'm a security researcher and am wondering how I could remove the added bytes from a file. This function below adds a byte every 4 bytes. But I'd like to know how I could remove those bytes as well. Need a function that will remove these bytes in the order they were added.

Travis

int AddByte(BYTE* bIn, BYTE* bOut, DWORD dwSize, int inc_every)
{
    int increased = 0;

    for (int i = 0; i < dwSize; i++)
    {
        *(bOut + increased) = *(bIn + i);
        increased++;

        if (i % inc_every == 0)
            increased += 1;
    }

    return increased;
}
1
Unfortunately you can't just remove a single byte from a file. You need to "shift" every byte after it to overwrite that byte. Looks like your file is memory mapped in which case one option is to use memmove.kaylum
Do the same thing in reverse. Copy each byte to another array, skipping every 5th byte.Weather Vane
Looking for an example, thanks.Travis
What have you tried? Requests for code are OT. You can use something similar to what you have.Weather Vane

1 Answers

1
votes
int RemoveByte(BYTE* bIn, BYTE* bOut, DWORD dwSize, int inc_every)
{
    int increased = 0;

    for (int i = 0; i < dwSize; i++)
    {

        if ((i - 1) % inc_every != 0)
        {
             *(bOut + increased) = *(bIn + i);
            increased++;
        }
    }

    return increased;
}

Applying this function after AddByte() would give back the original string. Your original function has an offset of 1 (it will skip the second byte), so this function includes the same offset