注册 登录
自由的生活_软路由 返回首页

的个人空间 https://bbs.routerclub.com/?0 [收藏] [复制] [分享] [RSS]

日志

一段处理汇编的代码

热度 1已有 118 次阅读2008-8-14 08:30

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct aa {
 char name[16];
 char val[8];
 struct aa * next ;
}
;
int main(int argc,char*argv[])
{
    FILE*fp,*fp1 ;
    char buffer[128];
    char temp[128];
    struct aa*zhi ;
    struct aa*head,*curren,*tmp ;
    char*p1,*p2,*p3,*p4,*p5 ;
    int len ;
    int biaoz=0 ;
    head=NULL ;
   
    if(argc < 2 ){
   printf("请输入要处理的由ida生成的asm文件名 \n\n本程序由想得太美制作  \n2010年11月10日晚\n");
   return 1;
   }  
  
  
    fp=fopen(argv[1],"r");
    if(fp==NULL)
    {
        printf("不能打开输入文件\n");
        return 1 ;
    }
     

    fp1=fopen("out.asm","w");
    if(fp==NULL)
    {
        printf("不能打开输出文件\n");
        return 1 ;
    }
    fputs("__declspec(naked) int test(unsigned char * buff)\n",fp1);
    fputs("{\n",fp1);
    fputs(" __asm\n",fp1);
    fputs(" {\n",fp1);

    while(fgets(buffer,128,fp)!=NULL)
    {
        len=strlen(buffer);
        if(len<=1)continue ;
        if(!memcmp(buffer,";",1)) continue;        
        p1=strstr(buffer,"=");
        if(p1!=NULL)
        {
            if(head==NULL)
            {
                head=(struct aa*)malloc(sizeof(struct aa));
                memcpy(head->name,buffer,(p1-buffer));
                head->name[p1-buffer]='\0' ;
                p2=strrchr(buffer,' ');
                memcpy(head->val,p2+1,(buffer+len-p2));
                head->val[buffer+len-p2+1]='\0' ;
                head->next=NULL ;
                fprintf(fp1,"#define %s %s", head->name,head->val);
            }
            else
            {
                curren=head ;
                while(curren->next!=NULL)
                {
                    curren=curren->next ;
                    if (memcmp(curren->name,buffer,(p1-buffer)) == 0 && (p1-buffer)==strlen(curren->name)) goto xxv32;
                }
                zhi=(struct aa*)malloc(sizeof(struct aa));
                curren->next=zhi ;
                zhi->next=NULL ;
                memcpy(zhi->name,buffer,(p1-buffer));
                zhi->name[p1-buffer]='\0' ;
                p2=strrchr(buffer,' ');
                memcpy(zhi->val,p2+1,(buffer+len-p2));
                zhi->val[buffer+len-p2+1]='\0' ;
                fprintf(fp1,"#define %s %s", zhi->name,zhi->val);
            }
            xxv32:
              continue ;
        }
     }
    
     fputs("\n",fp1);
     fputs("\n",fp1);
    
     fseek(fp,0, SEEK_SET);
     while(fgets(buffer,128,fp)!=NULL)
    {
     len=strlen(buffer);
        if(len<=1)continue ;
        if(! memcmp(buffer,";",1)) continue; 
         
     if(strstr(buffer,"near")!=NULL)
        {
            p5=strstr(buffer,"proc");
            *(p5-1)=':' ;
            *p5='\0' ;
            strcpy(temp,buffer);
            biaoz+=1 ;
            if(biaoz>=2)
            {
                fputs(temp,fp1);
                fputs("\n",fp1);
            }
            continue ;
        }
      if(strstr(buffer,"endp")!=0)     continue ;
      if(strstr(buffer,"=")!=0)        continue ;
      if(strstr(buffer,"public")!=0)   continue ;
      fputs(buffer,fp1); 
    }
   
    fputs(" }\n",fp1);
    fputs("}\n",fp1);
      
    fclose(fp);
    fclose(fp1);
    printf("转换完成!\n");
    return 0 ;
}


路过

雷人

握手

鲜花

鸡蛋

发表评论 评论 (2 个评论)

回复 想得太美 2008-8-19 17:25
在处理一些代码时仍然会出错。。
回复 11 2013-2-8 16:04
http://bbs.pediy.com/showthread.php?t=155258

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2026-3-10 08:44 , Processed in 0.049598 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

返回顶部