0

I'm doing an exercise: write a C program for Linux that searches for files in ELF, PE32, COFF and a.out formats using the magic number of the file header. I tried writing my own program to find magic number and it worked, however when I try to use it in my whole project it barely works. Here is my program to get file's magic number: https://github.com/hoangtv13/Magic_number And here is my project: https://github.com/hoangtv13/OCP_Lab1 In the 2nd option: find the file with a size smaller than the input size, almost everything is fine, but with the first option I think there is something wrong while reading the file. How should i fix it?

Ivan Ivan
  • 49
  • 3
  • Please post your code directly in the question, not in some external repository. Please also only ask 1 question per question. Either about your problem with magic numbers or file size. Finally, what is your problem with magic numbers? What type of files is not recognized? What happens if you check such a file? You need to run your program in a debugger to see where the wrong decision is taken and which variables don't contain what they should. – Gerhardh Dec 16 '21 at 15:10
  • i wrote a program to find file's magic number (first link) it worked fine but my problem here is when i use that code in my project (second link) it seems like it doesn't work. my project consists of 6 files so i think attaching github will be easier for people to read than writing program here – Ivan Ivan Dec 16 '21 at 15:26
  • People don't like to follow links to external sites. Also those links can go stale making the question worthless. – Gerhardh Dec 16 '21 at 15:28
  • What does "doesn't work" mean? That code does not search for any magic number. It just prints them in a rather complicated way. Also you seem to expect that `magic` might magically be 0-terminated (pun intented ;)). – Gerhardh Dec 16 '21 at 15:30
  • Thanks for the advice, now I'll try to put my project on the post – Ivan Ivan Dec 16 '21 at 15:31
  • After adding the source you should also add information what intput you provide, (what file types with what magic number, etc.) and what output you get, together with the output you would expect. – Gerhardh Dec 17 '21 at 21:34

0 Answers0