This site uses cookies own and third. If you continue to browse consider to accept the use of cookies. OK More Info.

[SNIPPET-CONFIG] Lectura de configuración binaria

  • 0 Replies
  • 2882 Views

0 Members and 1 Guest are viewing this topic.

Offline Karcrack

  • *
  • Underc0der
  • Posts: 87
  • Actividad:
    0%
  • Reputación 0
  • Se siente observado ¬¬'
    • View Profile
Comparto este pequeño código para obtener un bit de una array.

Yo lo uso para almacenar una cantidad indeterminada de bits de configuración. Obviamente configuración de estado: verdadero/falso.

Code: (cpp) You are not allowed to view links. Register or Login
struct OPTIONS{
private:
    unsigned long* config;
public:
    OPTIONS(unsigned long* config){
        this->config = config;
    }
    bool getOpt(unsigned long index){
        unsigned int    iIdx;
        unsigned long   dwCfg;

        dwCfg   = *(unsigned long*)(this->config + index/(sizeof(unsigned long)*8));
        iIdx    = index%(sizeof(unsigned long)*8);

        return ((dwCfg>>iIdx)&0x1);
    }
};

Ejemplo de uso:
Code: (cpp) You are not allowed to view links. Register or Login
void main(){
    unsigned long cfg[] = {0xBABA, 0xDEADBEEF};

    OPTIONS o(cfg);

    for(int i = 0; i<64; i++)
        printf("%d", o.getOpt(i));
}

Ejemplo real de uso:
Code: (cpp) You are not allowed to view links. Register or Login
#define INYECT_CODE 0x0
#define MUTEX       0x1
#define FORCE_ADMIN 0x2

void main(){
    OPTIONS o(GetModuleHandle(0));

    if(o.getOpt(INYECT_CODE))
        //Whatever
    if(o.getOpt(MUTEX))
        //Whatever
    if(o.getOpt(FORCE_ADMIN))
        //Whatever
    else
        //Whatever
}

Saludos 8)
I code for $$$.

(PGP ID 0xCC050E77)
ASM, C, C++, VB6... skilled [malware] developer