Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Commit

Permalink
rollback because fuck this shit powerpc ass
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre FICHEPOIL committed Mar 19, 2018
1 parent 04240b0 commit 1f3122e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 80 deletions.
4 changes: 2 additions & 2 deletions init.c
Expand Up @@ -6,7 +6,7 @@
/* By: pfichepo <pfichepo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/22 10:24:38 by pfichepo #+# #+# */
/* Updated: 2018/03/19 09:45:03 by pfichepo ### ########.fr */
/* Updated: 2018/03/19 11:07:58 by pfichepo ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -42,7 +42,7 @@ void init_commands(t_env *env)
{
if ((env->section = (t_lsection*)malloc(sizeof(t_lsection))) == NULL)
return;
printf("64 = %i swap = %i fat = %i\n", env->is64bit, env->isswap, env->isfattype);
//printf("64 = %i swap = %i fat = %i\n", env->is64bit, env->isswap, env->isfattype);
env->section ->first = NULL;
env->section ->last = NULL;

Expand Down
3 changes: 1 addition & 2 deletions main.c
Expand Up @@ -6,7 +6,7 @@
/* By: pfichepo <pfichepo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/19 09:47:50 by pfichepo #+# #+# */
/* Updated: 2018/03/19 10:43:46 by pfichepo ### ########.fr */
/* Updated: 2018/03/19 10:48:52 by pfichepo ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -44,7 +44,6 @@ char typing(uint32_t type, uint32_t n_sect,
{
char ret;

printf("type = %i\n",addr );
ret = '?';
if ((type & N_TYPE) == N_UNDF)
{
Expand Down
3 changes: 1 addition & 2 deletions nm.c
Expand Up @@ -6,7 +6,7 @@
/* By: pfichepo <pfichepo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/08 11:20:20 by pfichepo #+# #+# */
/* Updated: 2018/03/19 10:18:35 by pfichepo ### ########.fr */
/* Updated: 2018/03/19 10:55:44 by pfichepo ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -23,7 +23,6 @@ void nm2(t_env *env, char *ptr, char* max)
head = *(uint32_t*)ptr;
clearlist(env);
clearsections(env);
printf("0x%08x\n", head);
if (head == MH_MAGIC_64)
handle_64(env, ptr, max, false);
else if (head == MH_CIGAM_64)
Expand Down
6 changes: 2 additions & 4 deletions x86.c
Expand Up @@ -6,7 +6,7 @@
/* By: pfichepo <pfichepo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/23 09:58:17 by pfichepo #+# #+# */
/* Updated: 2018/03/19 10:46:29 by pfichepo ### ########.fr */
/* Updated: 2018/03/19 10:57:40 by pfichepo ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,12 +28,10 @@ static void add_output(int nsyms, void *symoff, void *stroff, t_env* env, bool s
failmessage("Please check file integrity");
if (swap)
{
//array[i].n_value = swap_uint32(array[i].n_value);
array[i].n_value = swap_uint32(array[i].n_value);
array[i].n_type = swap_uint32(array[i].n_type);
array[i].n_sect = swap_uint32(array[i].n_sect);
array[i].n_un.n_strx = swap_uint32(array[i].n_un.n_strx);
printf("array[i].n_type = 0x%08x\n", array[i].n_type);
printf("array[i].n_sect = 0x%08x\n", array[i].n_sect);
}
mlccmd(env, array[i].n_value, typing(array[i].n_type, array[i].n_sect, env->section, array[i].n_value), stringtable + array[i].n_un.n_strx);
}
Expand Down
73 changes: 3 additions & 70 deletions xfat.c
Expand Up @@ -6,7 +6,7 @@
/* By: pfichepo <pfichepo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/23 09:58:23 by pfichepo #+# #+# */
/* Updated: 2018/03/19 10:17:45 by pfichepo ### ########.fr */
/* Updated: 2018/03/19 11:09:19 by pfichepo ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,74 +15,16 @@



static char* get_cputype(cpu_type_t cputype)
{
if (cputype == CPU_TYPE_VAX)
return ("vax");
else if (cputype == CPU_TYPE_MC680x0)
return ("mc680");
else if (cputype == CPU_TYPE_X86 || cputype == CPU_TYPE_I386)
return ("i386");
else if (cputype == CPU_TYPE_X86_64)
return ("x86_64");
else if (cputype == CPU_TYPE_MC98000)
return ("mc98000");
else if (cputype == CPU_TYPE_HPPA)
return ("hppa");
else if (cputype == CPU_TYPE_ARM)
return ("arm");
else if (cputype == CPU_TYPE_MC88000)
return ("mc880000");
else if (cputype == CPU_TYPE_SPARC)
return ("sparc");
else if (cputype == CPU_TYPE_I860)
return ("i860");
else if (cputype == CPU_TYPE_POWERPC)
return ("ppc");
else if (cputype == CPU_TYPE_POWERPC64)
return ("ppc64");
return ("???");
}



static bool validcpu(cpu_type_t cputype)
{
if (cputype == CPU_TYPE_X86_64 || cputype == CPU_TYPE_POWERPC || cputype == CPU_TYPE_ARM64)
return (true);
return (false);

}

static int toprint_arch(struct fat_arch *arch, bool swap, uint32_t n)
{
int i;
cpu_type_t cputype;

i = 0;
while (n--)
{
cputype = (swap) ? swap_uint32(arch->cputype) : arch->cputype;

if (validcpu(cputype))
i++;
arch = (void*)arch + sizeof(struct fat_arch);
}
return (i);
}

static void handle_fat32(t_env *env, bool swap)
{
struct fat_header *header;
struct fat_arch *arch;
struct mach_header *header2;
int toprint;


header = (struct fat_header*)env->ptr;
arch = (struct fat_arch*)(header+1);
header->nfat_arch = (swap) ? swap_uint32(header->nfat_arch) : header->nfat_arch;
toprint = toprint_arch(arch, swap,header->nfat_arch );
while (header->nfat_arch--)
{
arch->cputype = (swap) ? swap_uint32(arch->cputype) : arch->cputype;
Expand All @@ -91,17 +33,8 @@ static void handle_fat32(t_env *env, bool swap)
arch->size = (swap) ? swap_uint32(arch->size) : arch->size;
arch->align = (swap) ? swap_uint32(arch->align) : arch->align;
header2 = (void*)env->ptr + arch->offset;
if (validcpu(arch->cputype))
{
if (toprint > 1)
{
printf("%s (for architecture %s):\n", env->file_name, get_cputype(arch->cputype));
}
if (arch->cputype == CPU_TYPE_X86_64)
nm2(env, (char*)header2, (char*)((void*)header2 + arch->size));
}
printf("cputype = 0x%08x cpusubtype = 0x%08x offset = %i size = %i align = %i \n", arch->cputype, arch->cpusubtype, arch->offset, arch->size, arch->align);


arch = (void*)arch + sizeof(struct fat_arch);
}
}
Expand Down Expand Up @@ -138,7 +71,7 @@ void handle_fat(t_env *env, bool swap)
struct fat_header *header;


printf("%s\n", "fathandle");
//printf("%s\n", "fathandle");
header = (struct fat_header*)env->ptr;
if ((void*)header > (void*)env->end)
failmessage("Fail header");
Expand Down

0 comments on commit 1f3122e

Please sign in to comment.