• 记一次把聊天表情包转成文件再还原的故事


    第一步转成txt: xxd xxx.gif

    第二步txt文件转移到自己电脑, 略

    第三步加工txt文件, 只需要中间这些二进制。 由于mac不支持grep -P命令, 改用awk命令;

    由于mac下sed ':label;N;s/ /:/;t label' 运行结果不符合预期,改用awk命令。

    tail -n2 dumpling-for-you.txt|awk '{for(i=2;i<NF&&i<=9;i++) print $i}'|awk -v RS="" '{gsub(" ","");print}'

     

    第四步开始转换!!! 编码风格诡异, 请轻拍~~

    #include <iostream>
    #include <fstream>
    #include <stdio.h>
    
    int main(){
        FILE * in;
        FILE * out;
        if((in = fopen("xxx.hex", "rb"))==NULL){
            printf("打开输入文件失败
    ");
            return -1;
        }
        if((out = fopen("yyy.gif","wb"))==NULL){
            printf("打开输出文件失败
    ");
            return -1;
        }
    
    //    fseek(in,0,SET_SEEK);
    //    fseek(out,0,SEEK_END);
    //    printf("移动到文件头
    ");
    
        char * buf=(char *)malloc(2);
        rewind(out);
        int dec_val;
        char dec_vals[100];  
        int dec_index=0;
        int count=0;
        while((fgets(buf,2,in))!=NULL && count++>=0){
            dec_val = strtol(buf, NULL, 16);   // decimal
            dec_vals[dec_index]=dec_val*16;
            if((fgets(buf,2,in)!=NULL)){// 读第二个8字节
                dec_val = strtol(buf, NULL, 16);   // decimal
                dec_vals[dec_index]+=dec_val;
            }else{
                break;
            }
            dec_index++;
            if(dec_index==100){
                printf("before fwrite, pos=%ld
    ", ftell(out));
                fseek(out, 0, SEEK_END);
                fwrite(dec_vals, 1, dec_index, out);
                dec_index=0;
                printf("after fwrite, pos=%ld
    ", ftell(out));
            }
        }
        fwrite(dec_vals, 1, dec_index, out);
    
        fclose(in);
        fclose(out);
        return 1;
    }

    第五步把得到的gif添加到微信表情,然后四处炫耀

    小节:

    1. mac上没有gdb,强行安装的gdb也非常难用,可以使用lldb

    2. mac对grep、sed命令的支持与linux有些出入

  • 相关阅读:
    [AWS DA
    [CSS] Grid: X: justify-content, Y: align-items, X & Y: place-content
    [AWS] Lab: Network Load Balancer
    [Netlify serverless] Dependencies are not automatically install in functions
    python pandas
    pytorch suds numpy pandas
    unistd.h sleep() stdlib.h exit()
    万字报告详解:数字人民币产业图景
    33个Kubernetes安全工具
    人工智能时代都需要哪些数学知识?这些经典教材给你划重点
  • 原文地址:https://www.cnblogs.com/yinkw/p/sotry1.html
Copyright © 2020-2023  润新知