Jump to content
Tuts 4 You

From nasm to masm


Yoshi

Recommended Posts

when i use nasm.exe in cmd and choose the filepath to my asm file it will generate a new file. Just like this in cmd; nasm.exe mynasmsource.asm. this will geneate a new file.


 


now i want do the same with masm32. i got the same source but this time written in masm, now i need that new file like what nasm.exe generated.


how?


Edited by Yoshi
Link to comment

convert INTEL to NASM syntax...

C++ code (not tested too much, but should work for basic ASM instructions):

static bool issegment(const char* str){    if(!strncasecmp(str, "gs", 2))        return true;    if(!strncasecmp(str, "fs", 2))        return true;    if(!strncasecmp(str, "es", 2))        return true;    if(!strncasecmp(str, "ds", 2))        return true;    if(!strncasecmp(str, "cs", 2))        return true;    if(!strncasecmp(str, "ss", 2))        return true;    return false;}static const char* Intel2Nasm(const char* intel){    char temp[256]="";    static char nasm[256]="";    memset(nasm, 0, sizeof(nasm));    memset(temp, 0, sizeof(temp));    int len=strlen(intel);    for(int i=0,j=0; i<len; i++) //fix basic differences and problems    {        if(!strncasecmp(intel+i, "ptr", 3)) //remote "ptr"        {            i+=2;            if(intel[i+1]==' ')                i++;            continue;        }        else if(!strncasecmp(intel+i, "  ", 2)) //remove double spaces            continue;        else if(intel[i]=='\t') //tab=space        {            j+=sprintf(temp+j, " ");            continue;        }        j+=sprintf(temp+j, "%c", intel[i]);    }    len=strlen(temp);    for(int i=0,j=0; i<len; i++)    {        if(temp[i]==' ' and temp[i+1]==',')            continue;        else if(temp[i]==',' and temp[i+1]==' ')        {            j+=sprintf(nasm+j, ",");            i++;            continue;        }        else if(issegment(temp+i) and temp[i+2]==' ')        {            j+=sprintf(nasm+j, "%c%c", temp[i], temp[i+1]);            i+=2;            continue;        }        else if(temp[i]==':' and temp[i+1]==' ')        {            j+=sprintf(nasm+j, ":");            i++;            continue;        }        j+=sprintf(nasm+j, "%c", temp[i]);    }    len=strlen(nasm);    for(int i=0,j=0; i<len; i++)    {        if(issegment(nasm+i) and nasm[i+2]==':' and nasm[i+3]=='[')        {            j+=sprintf(temp+j, "[%c%c:", nasm[i], nasm[i+1]);            i+=3;            continue;        }        j+=sprintf(temp+j, "%c", nasm[i]);    }    strcpy(nasm, temp);    return nasm;}

intel2nasm.zip

Edited by Mr. eXoDia
Link to comment

thank both of you but that is not really what i want to do.


 


let me explain.


 


i found a crypter.


in this package there is nasm/nasm.exe. and a stub.asm.


 


when i use nasm.exe in cmd and choose the filepath to the stub.asm, it will generate a new stub file. this new stub file will be used in the crypter.


 


now i got my own written stub in masm which is called stub2.asm.so how do i convert my own stub to a new file and use it in the crypter?


Edited by Yoshi
Link to comment

I knew you meant this, you need to manually convert the syntax. MASM uses invoke for example, nasm doesnt have this. Notice that default interpretion mode in NASM is DEC, so you should prefix your values with 'h'

The converter provided converts stuff like "mov byte ptr fs:[X]" to "mov byte [fs:X]" automatically. You could use the code I provided to parse a file and convert the basic syntax first.

Greetings

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...