elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 03:05  


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse)
| | |-+  [SRC] STACK for C++
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [SRC] STACK for C++  (Leído 850 veces)
RHL


Conectado Conectado

Mensajes: 968


mental


Ver Perfil
[SRC] STACK for C++
« en: 25 Noviembre 2011, 02:51 »

Hola :D
este es mi primer code hecho en C++ :3
me base en una pregunta que se hizo hace poco en el foro y me dio ganas de hacer el codigo, mi humilde codigo
es una simulacion de como trabaja la pila en asm :3 mi codigo soporta desplazamientos de punteros, en asm seria
de los registros ESP, EBP, para que apunten a diferentes lugares de la pila tambien tiene el registro EBP.
tambien pido a los grandes en c++ consejos, recomendaciones, todo lo que sea para poder mejorar ;D

Código
//	.MODEL 386,486,586 xD
// .STACK 100h // Size Segment STACK
class ClsSTACK
{
public:
ClsSTACK():ClsESP(&SegSTACK[0]),ClsEBP(0) {} // Inicialize Value
void ClsPUSH(int Reg); // Instruction PUSH Operator
int ClsPOP(); // Instruction POP Operator
int SegSTACK[0x100]; // Segment STACK
int* ClsESP; // STACK POINTER
int* ClsEBP; // BASE POINTER
};
 
void ClsSTACK::ClsPUSH(int Reg)
{
*ClsESP = Reg;
ClsESP++;
}
 
int ClsSTACK::ClsPOP()
{
return *ClsESP--;
}
 
// .DATA
// ValS DWORD 0
// .CODE
// inicio:
// MOV EDX,@DATA
// MOV DS,EDX
int main()
{
ClsSTACK MSTACK; //Make STACK
int ValS = 0;
 
MSTACK.ClsPUSH(0x10);
MSTACK.ClsPUSH(0x0);
MSTACK.ClsPUSH(0x0);
MSTACK.ClsPUSH(0x10);
MSTACK.ClsPUSH(0x100);
MSTACK.ClsPUSH(0x200);
MSTACK.ClsESP--; // ADD ESP,04h
ValS = MSTACK.ClsPOP(); // POP EAX
// MOV DS:ValS,EAX ; ValS = 100h
// Test BASE POINTER
MSTACK.ClsEBP = MSTACK.ClsESP;        // MOV EBP,ESP
MSTACK.ClsEBP = MSTACK.ClsEBP-4; // ADD EBP,8h
ValS = *MSTACK.ClsEBP; // MOV EAX,EBP
ValS = MSTACK.ClsPOP(); // POP EAX ; Not Change
 
return 0;
// end inicio
}

;D


« Última modificación: 25 Noviembre 2011, 19:10 por RHL » En línea
RyogiShiki


Desconectado Desconectado

Mensajes: 709


げんしけん - Hikkikomori FTW!!!


Ver Perfil WWW
Re: [SRC] STACK for C++
« Respuesta #1 en: 25 Noviembre 2011, 03:09 »

Código
int ClsSTACK::ClsPOP()
{
return *ClsESP;
ClsESP--;
}

El return debería ir después del decremento, no?

Saludos


En línea

RHL


Conectado Conectado

Mensajes: 968


mental


Ver Perfil
Re: [SRC] STACK for C++
« Respuesta #2 en: 25 Noviembre 2011, 03:33 »

Hey :xD gracias
de hecho debe ser asi:

Código
int ClsSTACK::ClsPOP()
{
return *ClsESP--;
}

si lo escribo antes el ESP devolvera un DWORD incorrecta al que se espera  ;D
En línea
BlackZeroX (Astaroth)
Wiki

Desconectado Desconectado

Mensajes: 2.831


I'Love...!¡.


Ver Perfil WWW
Re: [SRC] STACK for C++
« Respuesta #3 en: 25 Noviembre 2011, 07:24 »

Código
 
void ClsSTACK::ClsPUSH(int Reg)
{
ClsESP++;
*ClsESP = Reg;
}
 
 

El incremento al parecer debe ir despues de la asignacion...

Código
 
void ClsSTACK::ClsPUSH(int Reg)
{
*ClsESP = Reg;
ClsESP++;
}
 
 

tambien puedes hacerlo asi:

Código
 
void ClsSTACK::ClsPUSH(int Reg)
{
*(ClsESP++) = Reg;
}
 
 
En línea

Web Principal-->[ Blog(VB6) | Host File (Public & Private) | Scan Port | (New)MyInfraPC (Descubre mi Contraseña venefi. $) ]



The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi
RHL


Conectado Conectado

Mensajes: 968


mental


Ver Perfil
Re: [SRC] STACK for C++
« Respuesta #4 en: 25 Noviembre 2011, 07:41 »

 sabia lo de parentesis :3 guardado , gracias BlackZeroX
« Última modificación: 25 Noviembre 2011, 07:48 por RHL » En línea
BlackZeroX (Astaroth)
Wiki

Desconectado Desconectado

Mensajes: 2.831


I'Love...!¡.


Ver Perfil WWW
Re: [SRC] STACK for C++
« Respuesta #5 en: 25 Noviembre 2011, 08:37 »

@RHL
yo lo haria algo asi... aun ya existe una libreria en c++ para esto...

Código:

#include <cstring>

class CStack {
private:
    unsigned m_uSize;
    int *m_puSTACK;     // Segment STACK
unsigned m_uESP;    // STACK POINTER
unsigned m_uEBP;  // BASE POINTER

public:
CStack(unsigned size); // Inicialize Value
virtual ~CStack();
void push(int iReg); // Instruction PUSH Operator
int pop();              // Instruction POP Operator
bool isFull();
    unsigned ESP();
    unsigned ESP(unsigned ESP);

    unsigned EBP();
    unsigned EBP(unsigned EBP);
};

CStack::CStack(unsigned size) : m_uESP(NULL), m_uEBP(0) {
    m_puSTACK = new int[m_uSize = size];
    memset(m_puSTACK, 0, m_uSize * sizeof(int));
}

CStack::~CStack() {
    delete m_puSTACK;
}

unsigned CStack::ESP() {
    return m_uESP;
}

unsigned CStack::ESP(unsigned ESP) {
    return m_uESP = ESP;
}

unsigned CStack::EBP() {
    return m_uEBP;
}

unsigned CStack::EBP(unsigned EBP) {
    if (EBP > m_uSize)
        EBP = m_uSize;
    return m_uEBP = EBP;
}

bool CStack::isFull(){
    return m_uSize == m_uESP ? true:false;
}

void CStack::push(int iReg) {
    if (m_uESP > m_uSize) return;
m_puSTACK[m_uESP++] = iReg;
}

int CStack::pop(){
    int iRet;
    if (m_uESP == m_uEBP)
        return m_puSTACK[m_uEBP];
    iRet = m_puSTACK[m_uESP - 1];
    m_puSTACK[--m_uESP] = 0;
return iRet;
}


Código
 
#include <iostream>
#include "include/aa.h"
 
using namespace std;
 
int main()
{
CStack oStack(12);
 
oStack.push(45);
oStack.push(46);
oStack.push(47);
oStack.push(48);
cout << oStack.pop() << endl;
oStack.push(49);
cout << oStack.pop() << endl;
cout << oStack.isFull() << endl;
cout << oStack.ESP() << endl;
oStack.ESP(10);
cout << oStack.isFull() << endl;
cout << oStack.ESP() << endl;
while (oStack.ESP())
       cout << oStack.pop() << endl;
return 0;
}
 
 

Dulces Lunas!¡.
En línea

Web Principal-->[ Blog(VB6) | Host File (Public & Private) | Scan Port | (New)MyInfraPC (Descubre mi Contraseña venefi. $) ]



The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Stack Overflow???
Bugs y Exploits
sybille0 3 763 Último mensaje 9 Septiembre 2004, 08:27
por sybille0
ayuda con stack overflow y stack no ejecutable
Bugs y Exploits
pepsi 1 785 Último mensaje 12 Mayo 2005, 16:54
por Rojodos
Ani stack overflow
Foro Libre
BLABLABLA 0 279 Último mensaje 18 Abril 2007, 00:08
por BLABLABLA
Duda Stack..
Bugs y Exploits
visualfree 1 1,238 Último mensaje 8 Diciembre 2009, 04:41
por sirdarckcat
Ayuda con la Pila (Stack)
ASM
isidora 6 1,336 Último mensaje 3 Diciembre 2011, 03:33
por Иōҳ
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines