|
http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=6326 [복사]
/*사용자로 부터 2자리의 16진수를 입력 받아, MS-DOS Date/Time의형식으로 값을 해석하여, 시간을 출력하는 함수를 구현하고 원리를
설명하시오. 주어진 소스에 ToDo 외 추가적 수정이 필요했는가? 필요했다면 왜
했는가?
? 입력: 2자리의 16진수 (4바이트)
? 출력: Text 형식의 날짜 표현
예) 2013년 3월 14일 14시 53분 04초
*/
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#define LENGTH 250
int Test_Little_Endian();
void DOSTIME_to_Text(int dostime);
int LittleEndian_to_BigEndian(int num);
unsigned int extract_hex(const char *src);
int main()
{
char input_buffer[251]={0,};
int count = 0;
unsigned int before_endian = 0;
unsigned int after_enddian = 0;
printf("시간변환해보자\n");
printf("포렌식시스템\n");
printf("input (8hex value)");
count = input_string(input_buffer);
if(count !=8)
{
printf("잘못입력하셨습니다.");
return -1;
}
before_endian = extract_hex(input_buffer);
if(/*작업*/)//if the input data is on the little endian
{
//작업
}
else
{
//작업
}
DOSTIME_to_Text(after_enddian);
getchar();
return 0;
}
int Test_Little_Endian()
{
unsigned num = 0x00FF;
return *((char*)&num)==(num>>24)?0:1;
return 0;
}
void DOSTIME_to_Text(int dostime)
{
int year;
int month;
int day;
int hour;
int min;
int sec;
int result;
sec=0;//작업
min=0;//작업
hour=0;//작업
day=0;//작업
month=0;//작업
year=0;//작업
printf("%d 년 %d 월 %d 일 %d 시 %d 분 %d 초",year,month,day,hour,min,sec);
}
int LittleEndian_to_BigEndian(int num)
{
return ((num>>24)&0xff) | //move byte 3 to byte 0
((num<<8)&0xff0000)|
((num>>8)&0xff00)|
((num<<24)&0xff000000);
}
unsigned int extract_hex(const char *src)
{
int errno;
char hex_low[4+1]={0};
char hex_high[4+1]={0};
unsigned int val;
unsigned long val2;
if(strlen(src)<8) return -1;
memcpy(hex_low, src+4, 4);
memcpy(hex_high, src, 4);
if(strspn(hex_low,"0123456789AaBbCcDdEeFf")<4) return -1;
if(strspn(hex_high,"0123456789AaBbCcDdEeFf")<4) return -1;
val = strtol(hex_high,NULL,16)<<16;
val+=strtol(hex_low,NULL,16);
return val;
}
int input_string(char * s)
{
char *t = 0;
int size = 0;
int len;
do
{
s[LENGTH-2] = 0;
fgets(s, LENGTH, stdin);
len = strlen(s);
size +=len;
t = realloc(t,size);
strcat(t,s);
}
while(len == LENGTH-1 && s [LENGTH-2] !='\n');
return len-1;
} |
Hit : 4580 Date : 2013/04/07 02:57
|