char和int比较
来源于南邮CTF whyvm1的数据比较,第一次看到就很疑惑
记录一次字符串过滤
下面我有几个操作,就是数据处理完后,不直接结束当前循环,而是从头再来判断一次
其实就怕数据监测的遗漏
...
比如你最后修改了某个内容,让指针移到新的节点,但是当前循环结束的时候也需要移动指针节点
所以就会导致一次多余的移动,同时你自己又不能少移动
所以你就不结束当前循环直接跳转到判断那里,再判断一次
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int ReadFileSize(char* filename);
int main()
{
FILE* fp = 0;
char fpname[] = "F:\\src.txt";
int FileSize = 0;
char* lp1 = 0;
char* lp2 = 0;
int i = 0,j=0;
FileSize = ReadFileSize(fpname);
fp = fopen(fpname, "rb+");
if (fp == 0)
{
printf("wrong open\n");
return -1;
}
//每一次删除0x23个字节
//开始标志是d,结束标志是;
lp1 = (char*)malloc(FileSize + 0x10);
lp2 = (char*)malloc(FileSize + 0x10);
if (lp1 == 0 || lp2==0)
{
printf("wrong malloc\n");
fclose(fp);
return 0;
}
memset(lp1, 0, FileSize + 0x10);
memset(lp2, 0, FileSize + 0x10);
fread(lp1, FileSize, 1,fp);
fclose(fp);
//删除多余项
for (i = 0; i < FileSize;i++ )
{
check_again:
if(!memcmp(&lp1[i],"dword",5))
{
while (1)
{
if (lp1[i] == 0xA)
{
lp1[i] = 0;
i++;
break;
}
lp1[i] = 0;
i++;
}
goto check_again;
}
if (!memcmp(&lp1[i], "byte_6941", 9))
{
memset(&lp1[i], 0, 9);
memcpy(&lp1[i], "a[0x", 4);
lp1[i + 4 ] = lp1[i + 9];
lp1[i + 5] = lp1[i + 10];
lp1[i + 6] = ']';
lp1[i + 9] = 0;
lp1[i + 10]=0;
}
if (!memcmp(&lp1[i], "input", 5))
{
memset(&lp1[i], 0, 5);
memcpy(&lp1[i], "a[0]", 4);
goto check_again;
}
if (lp1[i] == '+')
{
lp1[i] = '-';
i++;
goto check_again;
}
if (lp1[i] == '-')
{
lp1[i] = '+';
i++;
goto check_again;
}
}
for (i = 0; i < FileSize; i++)
{
if (lp1[i]!=0)
{
lp2[j] = lp1[i];
j++;
}
}
//逆序读取
//最后lp2以0xA结束
//printf("%d %X", j, lp2[j]);
j--;
for (; j >= 0; j--)
{
if (lp2[j] == 0xD || lp2[j] == 0xA)
{
lp2[j] = 0;
}
if (!memcmp(&lp2[j], "--", 2))
{
printf("%s\n", &lp2[j]);
}
if (!memcmp(&lp2[j], "++", 2))
{
printf("%s\n", &lp2[j]);
}
if (!memcmp(&lp2[j], "a[", 2))
{
printf("%s\n", &lp2[j]);
}
}
}
int ReadFileSize(char* filename)
{
int size = 0;
FILE* fp = fopen(filename, "r");
if (!fp)
{
printf("wrong open\n");
return -1;
}
fseek(fp, 0L, SEEK_END);
size = ftell(fp);
fclose(fp);
return size;
}
标签:fp,++,lp2,lp1,char,错题,FileSize
From: https://www.cnblogs.com/re4mile/p/17013497.html