-
Notifications
You must be signed in to change notification settings - Fork 1
/
nm_fat.c
40 lines (36 loc) · 1.43 KB
/
nm_fat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* nm_fat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: glasset <glasset@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/19 14:35:58 by glasset #+# #+# */
/* Updated: 2016/10/31 15:07:45 by glasset ### ########.fr */
/* */
/* ************************************************************************** */
#include "nm.h"
int reverse_int(int x)
{
x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF);
return (x << 16) | (x >> 16);
}
void header_fat(char *ptr, char *filename)
{
struct fat_header *header;
struct fat_arch *arch;
int i;
int offset;
i = 0;
header = (void *)ptr;
arch = (void *)ptr + sizeof(header);
while (i < reverse_int(header->nfat_arch))
{
if (reverse_int(arch->cputype) == CPU_TYPE_X86_64
|| reverse_int(arch->cputype) == CPU_TYPE_X86)
offset = arch->offset;
arch++;
i++;
}
nm(ptr + reverse_int(offset), filename);
}