八叶草

学习资料记录

移除bzImage文件中'1f8b08'之前内容,存为gz文件

 

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

int _tmain(int argc, _TCHAR* argv[])
{
    FILE
* r=fopen("linux26","rb");
    FILE
* w=fopen("linux26.gz","wb");
    
int s=0;
    
for(;;)
    
{
        unsigned 
char c;
        
int l=fread(&c,1,1,r);
        
if(l>=1)
        
{
            
if(s==3)
            
{
                fwrite(
&c,1,1,w);
            }

            
else if(s==2)
            
{
                
if(c==0x08)
                
{
                    c
=0x1f;
                    fwrite(
&c,1,1,w);
                    c
=0x8b;
                    fwrite(
&c,1,1,w);
                    c
=0x08;
                    fwrite(
&c,1,1,w);
                    
++s;
                }

                
else
                
{
                    s
=0;
                }

            }

            
else if(s==1)
            
{
                
if(c==0x8b)
                
{
                    
++s;
                }

                
else
                
{
                    s
=0;
                }

            }

            
else if(s==0)
            
{
                
if(c==0x1f)
                
{
                    
++s;
                }

            }

        }

        
else
        
{
            
break;
        }

    }

    fclose(w);
    fclose(r);
    
return 0;
}

 

posted on 2012-10-29 16:02 八叶草 阅读(637) 评论(0)  编辑 收藏 引用 所属分类: linux


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理