Home > OS >  Adding and removing byte from a file in a loop
Adding and removing byte from a file in a loop

Time:07-09

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;
}

CodePudding user response:

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

  • Related