Created
October 23, 2021 19:21
-
-
Save bigunclemax/4deb35310b5d23dc2b403096ee3027a2 to your computer and use it in GitHub Desktop.
RE_sync3_update_boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Usage: %s [-i] [-m] raw partition | |
-i Path of IFS image file | |
-m Path of MLO image file | |
-t Toggle active IFS partition | |
-r replace current IFS with new one | |
raw partition Path of raw partition to write IFS and MLO image files, default value is /dev/hd0. | |
*/ | |
typedef unsigned char undefined; | |
typedef unsigned char byte; | |
typedef unsigned int dword; | |
typedef long long longlong; | |
typedef unsigned char uchar; | |
typedef unsigned int uint; | |
typedef unsigned long ulong; | |
typedef unsigned long long ulonglong; | |
typedef unsigned char undefined1; | |
typedef unsigned int undefined4; | |
typedef unsigned short ushort; | |
typedef unsigned short word; | |
typedef struct stat64 stat64, *Pstat64; | |
typedef longlong int64_t; | |
typedef int int32_t; | |
typedef ulonglong uint64_t; | |
struct stat64 { | |
int64_t st_ino; | |
int64_t st_size; | |
int32_t st_dev; | |
int32_t st_rdev; | |
int32_t st_uid; | |
int32_t st_gid; | |
int32_t st_mtime; | |
int32_t st_atime; | |
int32_t st_ctime; | |
int32_t st_mode; | |
int32_t st_nlink; | |
int32_t st_blocksize; | |
int32_t st_nblocks; | |
int32_t st_blksize; | |
uint64_t st_blocks; | |
}; | |
typedef void _IO_lock_t; | |
typedef struct _IO_marker _IO_marker, *P_IO_marker; | |
typedef struct _IO_FILE _IO_FILE, *P_IO_FILE; | |
typedef long __off_t; | |
typedef longlong __quad_t; | |
typedef __quad_t __off64_t; | |
typedef ulong size_t; | |
struct _IO_FILE { | |
int _flags; | |
char * _IO_read_ptr; | |
char * _IO_read_end; | |
char * _IO_read_base; | |
char * _IO_write_base; | |
char * _IO_write_ptr; | |
char * _IO_write_end; | |
char * _IO_buf_base; | |
char * _IO_buf_end; | |
char * _IO_save_base; | |
char * _IO_backup_base; | |
char * _IO_save_end; | |
struct _IO_marker * _markers; | |
struct _IO_FILE * _chain; | |
int _fileno; | |
int _flags2; | |
__off_t _old_offset; | |
ushort _cur_column; | |
char _vtable_offset; | |
char _shortbuf[1]; | |
_IO_lock_t * _lock; | |
__off64_t _offset; | |
void * __pad1; | |
void * __pad2; | |
void * __pad3; | |
void * __pad4; | |
size_t __pad5; | |
int _mode; | |
char _unused2[15]; | |
}; | |
struct _IO_marker { | |
struct _IO_marker * _next; | |
struct _IO_FILE * _sbuf; | |
int _pos; | |
}; | |
// WARNING! conflicting data type names: /stat.h/stat64 - /stat64 | |
typedef void * __gnuc_va_list; | |
typedef struct timespec timespec, *Ptimespec; | |
typedef long __time_t; | |
struct timespec { | |
__time_t tv_sec; | |
long tv_nsec; | |
}; | |
typedef struct _IO_FILE FILE; | |
typedef int __ssize_t; | |
typedef __ssize_t ssize_t; | |
typedef uint __uid_t; | |
typedef uint __nlink_t; | |
typedef ulonglong __u_quad_t; | |
typedef __u_quad_t __dev_t; | |
typedef __quad_t __blkcnt64_t; | |
typedef __u_quad_t __ino64_t; | |
typedef uint __mode_t; | |
typedef ulong __ino_t; | |
typedef uint __gid_t; | |
typedef long __blksize_t; | |
typedef struct Elf32_Shdr Elf32_Shdr, *PElf32_Shdr; | |
typedef enum Elf_SectionHeaderType_ARM { | |
SHT_ANDROID_REL=1610612737, | |
SHT_ANDROID_RELA=1610612738, | |
SHT_ARM_ATTRIBUTES=1879048195, | |
SHT_ARM_DEBUGOVERLAY=1879048196, | |
SHT_ARM_EXIDX=1879048193, | |
SHT_ARM_OVERLAYSECTION=1879048197, | |
SHT_ARM_PREEMPTMAP=1879048194, | |
SHT_CHECKSUM=1879048184, | |
SHT_DYNAMIC=6, | |
SHT_DYNSYM=11, | |
SHT_FINI_ARRAY=15, | |
SHT_GNU_ATTRIBUTES=1879048181, | |
SHT_GNU_HASH=1879048182, | |
SHT_GNU_LIBLIST=1879048183, | |
SHT_GNU_verdef=1879048189, | |
SHT_GNU_verneed=1879048190, | |
SHT_GNU_versym=1879048191, | |
SHT_GROUP=17, | |
SHT_HASH=5, | |
SHT_INIT_ARRAY=14, | |
SHT_NOBITS=8, | |
SHT_NOTE=7, | |
SHT_NULL=0, | |
SHT_PREINIT_ARRAY=16, | |
SHT_PROGBITS=1, | |
SHT_REL=9, | |
SHT_RELA=4, | |
SHT_SHLIB=10, | |
SHT_STRTAB=3, | |
SHT_SUNW_COMDAT=1879048187, | |
SHT_SUNW_move=1879048186, | |
SHT_SUNW_syminfo=1879048188, | |
SHT_SYMTAB=2, | |
SHT_SYMTAB_SHNDX=18 | |
} Elf_SectionHeaderType_ARM; | |
struct Elf32_Shdr { | |
dword sh_name; | |
enum Elf_SectionHeaderType_ARM sh_type; | |
dword sh_flags; | |
dword sh_addr; | |
dword sh_offset; | |
dword sh_size; | |
dword sh_link; | |
dword sh_info; | |
dword sh_addralign; | |
dword sh_entsize; | |
}; | |
typedef enum Elf32_DynTag_ARM { | |
DT_ANDROID_REL=1610612751, | |
DT_ANDROID_RELA=1610612753, | |
DT_ANDROID_RELASZ=1610612754, | |
DT_ANDROID_RELR=1879040000, | |
DT_ANDROID_RELRENT=1879040003, | |
DT_ANDROID_RELRSZ=1879040001, | |
DT_ANDROID_RELSZ=1610612752, | |
DT_AUDIT=1879047932, | |
DT_AUXILIARY=2147483645, | |
DT_BIND_NOW=24, | |
DT_CHECKSUM=1879047672, | |
DT_CONFIG=1879047930, | |
DT_DEBUG=21, | |
DT_DEPAUDIT=1879047931, | |
DT_FEATURE_1=1879047676, | |
DT_FILTER=2147483647, | |
DT_FINI=13, | |
DT_FINI_ARRAY=26, | |
DT_FINI_ARRAYSZ=28, | |
DT_FLAGS=30, | |
DT_FLAGS_1=1879048187, | |
DT_GNU_CONFLICT=1879047928, | |
DT_GNU_CONFLICTSZ=1879047670, | |
DT_GNU_HASH=1879047925, | |
DT_GNU_LIBLIST=1879047929, | |
DT_GNU_LIBLISTSZ=1879047671, | |
DT_GNU_PRELINKED=1879047669, | |
DT_HASH=4, | |
DT_INIT=12, | |
DT_INIT_ARRAY=25, | |
DT_INIT_ARRAYSZ=27, | |
DT_JMPREL=23, | |
DT_MOVEENT=1879047674, | |
DT_MOVESZ=1879047675, | |
DT_MOVETAB=1879047934, | |
DT_NEEDED=1, | |
DT_NULL=0, | |
DT_PLTGOT=3, | |
DT_PLTPAD=1879047933, | |
DT_PLTPADSZ=1879047673, | |
DT_PLTREL=20, | |
DT_PLTRELSZ=2, | |
DT_POSFLAG_1=1879047677, | |
DT_PREINIT_ARRAY=32, | |
DT_PREINIT_ARRAYSZ=33, | |
DT_REL=17, | |
DT_RELA=7, | |
DT_RELACOUNT=1879048185, | |
DT_RELAENT=9, | |
DT_RELASZ=8, | |
DT_RELCOUNT=1879048186, | |
DT_RELENT=19, | |
DT_RELR=36, | |
DT_RELRENT=37, | |
DT_RELRSZ=35, | |
DT_RELSZ=18, | |
DT_RPATH=15, | |
DT_RUNPATH=29, | |
DT_SONAME=14, | |
DT_STRSZ=10, | |
DT_STRTAB=5, | |
DT_SYMBOLIC=16, | |
DT_SYMENT=11, | |
DT_SYMINENT=1879047679, | |
DT_SYMINFO=1879047935, | |
DT_SYMINSZ=1879047678, | |
DT_SYMTAB=6, | |
DT_TEXTREL=22, | |
DT_TLSDESC_GOT=1879047927, | |
DT_TLSDESC_PLT=1879047926, | |
DT_VERDEF=1879048188, | |
DT_VERDEFNUM=1879048189, | |
DT_VERNEED=1879048190, | |
DT_VERNEEDNUM=1879048191, | |
DT_VERSYM=1879048176 | |
} Elf32_DynTag_ARM; | |
typedef struct Elf32_Dyn_ARM Elf32_Dyn_ARM, *PElf32_Dyn_ARM; | |
struct Elf32_Dyn_ARM { | |
enum Elf32_DynTag_ARM d_tag; | |
dword d_val; | |
}; | |
typedef struct Elf32_Sym Elf32_Sym, *PElf32_Sym; | |
struct Elf32_Sym { | |
dword st_name; | |
dword st_value; | |
dword st_size; | |
byte st_info; | |
byte st_other; | |
word st_shndx; | |
}; | |
typedef struct Elf32_Phdr Elf32_Phdr, *PElf32_Phdr; | |
typedef enum Elf_ProgramHeaderType_ARM { | |
PT_ARM_EXIDX=1879048192, | |
PT_DYNAMIC=2, | |
PT_GNU_EH_FRAME=1685382480, | |
PT_GNU_RELRO=1685382482, | |
PT_GNU_STACK=1685382481, | |
PT_INTERP=3, | |
PT_LOAD=1, | |
PT_NOTE=4, | |
PT_NULL=0, | |
PT_PHDR=6, | |
PT_SHLIB=5, | |
PT_TLS=7 | |
} Elf_ProgramHeaderType_ARM; | |
struct Elf32_Phdr { | |
enum Elf_ProgramHeaderType_ARM p_type; | |
dword p_offset; | |
dword p_vaddr; | |
dword p_paddr; | |
dword p_filesz; | |
dword p_memsz; | |
dword p_flags; | |
dword p_align; | |
}; | |
typedef struct Elf32_Rel Elf32_Rel, *PElf32_Rel; | |
struct Elf32_Rel { | |
dword r_offset; // location to apply the relocation action | |
dword r_info; // the symbol table index and the type of relocation | |
}; | |
typedef struct Elf32_Ehdr Elf32_Ehdr, *PElf32_Ehdr; | |
struct Elf32_Ehdr { | |
byte e_ident_magic_num; | |
char e_ident_magic_str[3]; | |
byte e_ident_class; | |
byte e_ident_data; | |
byte e_ident_version; | |
byte e_ident_osabi; | |
byte e_ident_abiversion; | |
byte e_ident_pad[7]; | |
word e_type; | |
word e_machine; | |
dword e_version; | |
dword e_entry; | |
dword e_phoff; | |
dword e_shoff; | |
dword e_flags; | |
word e_ehsize; | |
word e_phentsize; | |
word e_phnum; | |
word e_shentsize; | |
word e_shnum; | |
word e_shstrndx; | |
}; | |
typedef uchar uint8_t; | |
typedef uint uint32_t; | |
void __DT_INIT(void) | |
{ | |
return; | |
} | |
int printf(char *__format,...) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_printf_00103434)(); | |
return iVar1; | |
} | |
void _init_array(void) | |
{ | |
(*(code *)PTR__init_array_00103438)(); | |
return; | |
} | |
int snprintf(char *__s,size_t __maxlen,char *__format,...) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_snprintf_0010343c)(); | |
return iVar1; | |
} | |
void _preinit_array(void) | |
{ | |
(*(code *)PTR__preinit_array_00103440)(); | |
return; | |
} | |
void __cxa_finalize(void) | |
{ | |
(*(code *)PTR___cxa_finalize_00103444)(); | |
return; | |
} | |
int system(char *__command) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_system_00103448)(); | |
return iVar1; | |
} | |
void * malloc(size_t __size) | |
{ | |
void *pvVar1; | |
pvVar1 = (void *)(*(code *)PTR_malloc_0010344c)(); | |
return pvVar1; | |
} | |
void writeblock(void) | |
{ | |
(*(code *)PTR_writeblock_00103450)(); | |
return; | |
} | |
int fstat64(int __fd,stat64 *__buf) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_fstat64_00103454)(); | |
return iVar1; | |
} | |
int fprintf(FILE *__stream,char *__format,...) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_fprintf_00103458)(); | |
return iVar1; | |
} | |
void __deregister_frame_info(void) | |
{ | |
(*(code *)PTR___deregister_frame_info_0010345c)(); | |
return; | |
} | |
ssize_t read(int __fd,void *__buf,size_t __nbytes) | |
{ | |
ssize_t sVar1; | |
sVar1 = (*(code *)PTR_read_00103460)(); | |
return sVar1; | |
} | |
void strlcpy(void) | |
{ | |
(*(code *)PTR_strlcpy_00103464)(); | |
return; | |
} | |
int memcmp(void *__s1,void *__s2,size_t __n) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_memcmp_00103468)(); | |
return iVar1; | |
} | |
void readblock(void) | |
{ | |
(*(code *)PTR_readblock_0010346c)(); | |
return; | |
} | |
char * strdup(char *__s) | |
{ | |
char *pcVar1; | |
pcVar1 = (char *)(*(code *)PTR_strdup_00103470)(); | |
return pcVar1; | |
} | |
void _init_libc(void) | |
{ | |
(*(code *)PTR__init_libc_00103474)(); | |
return; | |
} | |
int getopt(int ___argc,char **___argv,char *__shortopts) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_getopt_00103478)(); | |
return iVar1; | |
} | |
void * memset(void *__s,int __c,size_t __n) | |
{ | |
void *pvVar1; | |
pvVar1 = (void *)(*(code *)PTR_memset_0010347c)(); | |
return pvVar1; | |
} | |
int open64(char *__file,int __oflag,...) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_open64_00103480)(); | |
return iVar1; | |
} | |
void _fini_array(void) | |
{ | |
(*(code *)PTR__fini_array_00103484)(); | |
return; | |
} | |
int atexit(__func *__func) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_atexit_00103488)(); | |
return iVar1; | |
} | |
int fputc(int __c,FILE *__stream) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_fputc_0010348c)(); | |
return iVar1; | |
} | |
int access(char *__name,int __type) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_access_00103490)(); | |
return iVar1; | |
} | |
void exit(int __status) | |
{ | |
(*(code *)PTR_exit_00103494)(); | |
return; | |
} | |
size_t strlen(char *__s) | |
{ | |
size_t sVar1; | |
sVar1 = (*(code *)PTR_strlen_00103498)(); | |
return sVar1; | |
} | |
__off64_t lseek64(int __fd,__off64_t __offset,int __whence) | |
{ | |
__off64_t _Var1; | |
_Var1 = (*(code *)PTR_lseek64_0010349c)(); | |
return _Var1; | |
} | |
void __register_frame_info(void) | |
{ | |
(*(code *)PTR___register_frame_info_001034a0)(); | |
return; | |
} | |
int close(int __fd) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_close_001034a4)(); | |
return iVar1; | |
} | |
int vfprintf(FILE *__s,char *__format,__gnuc_va_list __arg) | |
{ | |
int iVar1; | |
iVar1 = (*(code *)PTR_vfprintf_001034a8)(); | |
return iVar1; | |
} | |
void free(void *__ptr) | |
{ | |
(*(code *)PTR_free_001034ac)(); | |
return; | |
} | |
void _btext(void) | |
{ | |
int *piVar1; | |
int iVar2; | |
int in_stack_00000000; | |
piVar1 = (int *)(&stack0x00000008 + in_stack_00000000 * 4); | |
do { | |
iVar2 = *piVar1; | |
piVar1 = piVar1 + 1; | |
} while (iVar2 != 0); | |
_init_libc(); | |
(*(code *)PTR__preinit_array_00103440)(&__DT_INIT_ARRAY,&__DT_INIT_ARRAY); | |
return; | |
} | |
void FUN_00100ca4_print_help(void) | |
{ | |
fprintf((FILE *)&_Stderr, | |
"\nUsage: %s [-i] [-m] raw partition\n\n\t-i Path of IFS image file\n\t-m Path of MLO image file\n\t-t Toggle active IFS partition\n\t-r replace current IFS with new one\n\traw partition Path of raw partition to write IFS and MLO image files, default value is /dev/hd0.\n\n" | |
,"update_boot"); | |
return; | |
} | |
// WARNING: Globals starting with '_' overlap smaller symbols at the same address | |
void FUN_00100cc8_close_all_files(void) | |
{ | |
if (_DAT_00103544_IFS_MLO_fd != 0) { | |
close(_DAT_00103544_IFS_MLO_fd); | |
} | |
if (_DAT_00103548_hd0_fd != 0) { | |
close(_DAT_00103548_hd0_fd); | |
} | |
if (_DAT_0010354c_read_buff != (void *)0x0) { | |
free(_DAT_0010354c_read_buff); | |
} | |
if (_DAT_00103550_file_read_buff == (void *)0x0) { | |
return; | |
} | |
free(_DAT_00103550_file_read_buff); | |
return; | |
} | |
void FUN_00100d30_print_error_and_exit | |
(char *param_1,undefined4 param_2,undefined4 param_3,undefined4 param_4) | |
{ | |
undefined4 uStack12; | |
undefined4 uStack8; | |
undefined4 uStack4; | |
uStack12 = param_2; | |
uStack8 = param_3; | |
uStack4 = param_4; | |
fprintf((FILE *)&_Stderr,"%s: ","update_boot"); | |
vfprintf((FILE *)&_Stderr,param_1,&uStack12); | |
fputc(10,(FILE *)&_Stderr); | |
FUN_00100cc8_close_all_files(); | |
// WARNING: Subroutine does not return | |
exit(1); | |
} | |
// WARNING: Globals starting with '_' overlap smaller symbols at the same address | |
void FUN_00100d88_erase(int param_1) | |
{ | |
int iVar1; | |
int iVar2; | |
memset(_DAT_0010354c_read_buff,0,_DAT_00103554_hd0_blksize << 3); | |
iVar2 = 0x7b4c; | |
do { | |
iVar1 = writeblock(_DAT_00103548_hd0_fd,_DAT_00103554_hd0_blksize,param_1,8, | |
_DAT_0010354c_read_buff); | |
if (iVar1 != 8) { | |
FUN_00100d30_print_error_and_exit("Write block failed, block no = %d",param_1); | |
} | |
param_1 = param_1 + 8; | |
iVar2 = iVar2 - param_1; | |
} while (iVar2 != 0); | |
return; | |
} | |
// WARNING: Globals starting with '_' overlap smaller symbols at the same address | |
void FUN_00100e0c_do_flash_file(int param_1,int param_2) | |
{ | |
int iVar1; | |
int iVar2; | |
int iVar3; | |
int iVar4; | |
size_t sVar5; | |
size_t __nbytes; | |
int iVar6; | |
__aeabi_idivmod(param_1,_DAT_00103554_hd0_blksize); | |
if (__nbytes != 0) { | |
param_1 = param_1 - __nbytes; | |
} | |
if (param_1 < 1) { | |
iVar6 = 0; | |
} | |
else { | |
iVar6 = 0; | |
iVar4 = param_1; | |
do { | |
iVar3 = _DAT_00103554_hd0_blksize; | |
iVar1 = __divsi3(_DAT_00103554_hd0_blksize + -1 + iVar4,_DAT_00103554_hd0_blksize); | |
if (7 < iVar1) { | |
iVar1 = 8; | |
} | |
iVar2 = __divsi3(iVar6,iVar3); | |
memset(_DAT_0010354c_read_buff,0,iVar3 << 3); | |
iVar3 = readblock(_DAT_00103544_IFS_MLO_fd,_DAT_00103554_hd0_blksize,iVar2,iVar1, | |
_DAT_0010354c_read_buff); | |
if ((iVar1 != iVar3) && (iVar4 != iVar3)) { | |
FUN_00100d30_print_error_and_exit("Read block failed, block no = %d",iVar2); | |
} | |
iVar4 = writeblock(_DAT_00103548_hd0_fd,_DAT_00103554_hd0_blksize,iVar2 + param_2,iVar1, | |
_DAT_0010354c_read_buff); | |
if (iVar1 != iVar4) { | |
FUN_00100d30_print_error_and_exit("Write block failed, block no = %d",iVar2 + param_2); | |
} | |
iVar6 = _DAT_00103554_hd0_blksize * iVar1 + iVar6; | |
iVar4 = param_1 - iVar6; | |
} while (0 < iVar4); | |
} | |
iVar4 = _DAT_00103554_hd0_blksize; | |
if (__nbytes != 0) { | |
iVar6 = __divsi3(iVar6,_DAT_00103554_hd0_blksize); | |
iVar3 = __divsi3(iVar4 + -1 + __nbytes,iVar4); | |
memset(_DAT_0010354c_read_buff,0,iVar4 << 3); | |
sVar5 = read(_DAT_00103544_IFS_MLO_fd,_DAT_0010354c_read_buff,__nbytes); | |
if (__nbytes != sVar5) { | |
FUN_00100d30_print_error_and_exit("Read failed, block no = %d",iVar6); | |
} | |
iVar4 = writeblock(_DAT_00103548_hd0_fd,_DAT_00103554_hd0_blksize,iVar6 + param_2,iVar3, | |
_DAT_0010354c_read_buff); | |
if (iVar3 != iVar4) { | |
FUN_00100d30_print_error_and_exit("Write block failed, block no = %d",iVar6 + param_2); | |
} | |
} | |
return; | |
} | |
// WARNING: Could not reconcile some variable overlaps | |
// WARNING: Globals starting with '_' overlap smaller symbols at the same address | |
void main(int param_1,char **param_2) | |
{ | |
int iVar1; | |
size_t sVar2; | |
int iVar3; | |
ssize_t sVar4; | |
size_t sVar5; | |
size_t sVar6; | |
int extraout_r1; | |
int extraout_r1_00; | |
int extraout_r1_01; | |
int extraout_r1_02; | |
int extraout_r1_03; | |
int extraout_r1_04; | |
char *__s; | |
char *__file_IFS; | |
char *__file_MLO; | |
__off64_t _Var7; | |
uint in_stack_fffff744; | |
uint8_t auStack2224_ifs_file_block [512]; | |
uint8_t local_6b0_buff512 [512]; | |
char local_4b0 [64]; | |
stat64 auStack1136_s_stat; | |
char local_428_raw_partition_path [1024]; | |
bool bVar1_do_replace; | |
bool bVar1_do_toggle; | |
// /dev/hd0 | |
local_428_raw_partition_path._0_4_ = 0x7665642f; | |
local_428_raw_partition_path._4_4_ = 0x3064682f; | |
local_428_raw_partition_path[8] = '\0'; | |
memset(local_428_raw_partition_path + 9,0,0x3f7); | |
bVar1_do_replace = false; | |
bVar1_do_toggle = false; | |
__file_MLO = (char *)0x0; | |
__file_IFS = (char *)0x0; | |
while (iVar1 = getopt(param_1,param_2,"i:m:tr"), iVar1 != -1) { | |
switch(iVar1) { | |
case 0x69: | |
// -i | |
if (__file_IFS != (char *)0x0) { | |
free(__file_IFS); | |
} | |
__file_IFS = strdup(_optarg); | |
break; | |
default: | |
printf("Unknown argument \'%s\'",*param_2); | |
FUN_00100ca4_print_help(); | |
if (__file_MLO != (char *)0x0) { | |
free(__file_MLO); | |
} | |
if (__file_IFS == (char *)0x0) { | |
return; | |
} | |
free(__file_IFS); | |
return; | |
case 0x6d: | |
// -m | |
if (__file_MLO != (char *)0x0) { | |
free(__file_MLO); | |
} | |
__file_MLO = strdup(_optarg); | |
break; | |
case 0x72: | |
// -r | |
bVar1_do_replace = true; | |
break; | |
case 0x74: | |
// -t | |
bVar1_do_toggle = true; | |
} | |
} | |
if (param_2[_optind] != (char *)0x0) { | |
iVar1 = access(param_2[_optind],0); | |
if (iVar1 == 0) { | |
__s = param_2[_optind]; | |
if ((*__s == '\0') || (sVar2 = strlen(__s), 0x3ff < sVar2)) { | |
fprintf((FILE *)&_Stderr, | |
"[%s] is the invalid path because of length. Using the default path: %s\n",__s, | |
local_428_raw_partition_path); | |
} | |
else { | |
strlcpy(local_428_raw_partition_path,__s,0x400); | |
} | |
} | |
else { | |
fprintf((FILE *)&_Stderr," Path \'%s\' doesn\'t exist. Using the default path: \'%s\'\n", | |
param_2[_optind],local_428_raw_partition_path); | |
} | |
} | |
_DAT_00103548_hd0_fd = open64(local_428_raw_partition_path,0x8002); | |
if (_DAT_00103548_hd0_fd == -1) { | |
FUN_00100d30_print_error_and_exit("Failed to open \'%s\'",local_428_raw_partition_path); | |
} | |
iVar1 = fstat64(_DAT_00103548_hd0_fd,(stat64 *)&auStack1136_s_stat); | |
if (iVar1 == -1) { | |
FUN_00100d30_print_error_and_exit | |
("Failed to read block size of \'%s\'",local_428_raw_partition_path); | |
} | |
// 0x6000 - Block special | |
if ((auStack1136_s_stat.st_mode & 0xf000U) == 0x6000) { | |
// Prefered I/O block size for object | |
_DAT_00103554_hd0_blksize = auStack1136_s_stat.st_blksize; | |
} | |
else { | |
FUN_00100d30_print_error_and_exit("Error %s is not a block device",local_428_raw_partition_path) | |
; | |
} | |
// alloc 8 blocks? | |
_DAT_0010354c_read_buff = malloc(_DAT_00103554_hd0_blksize << 3); | |
if (_DAT_0010354c_read_buff == (void *)0x0) { | |
FUN_00100d30_print_error_and_exit("Failed to allocate memory for read buffer"); | |
} | |
if (__file_IFS != (char *)0x0) { | |
// FLASH IFS | |
_DAT_00103544_IFS_MLO_fd = open64(__file_IFS,0x8000); | |
if (_DAT_00103544_IFS_MLO_fd == -1) { | |
FUN_00100d30_print_error_and_exit("Failed to open \'%s\'",__file_IFS); | |
} | |
iVar1 = fstat64(_DAT_00103544_IFS_MLO_fd,(stat64 *)&auStack1136_s_stat); | |
if (iVar1 == -1) { | |
FUN_00100d30_print_error_and_exit("Failed to read size of IFS image"); | |
} | |
memset(auStack2224_ifs_file_block,0,0x200); | |
iVar1 = readblock(_DAT_00103544_IFS_MLO_fd,0x200,0,1,auStack2224_ifs_file_block); | |
if (iVar1 == 1) { | |
if (auStack2224_ifs_file_block._8_4_ != 0xff7eeb) { | |
FUN_00100d30_print_error_and_exit | |
("Error: IFS image is not valid, startup singnature is not found."); | |
} | |
} | |
else { | |
FUN_00100d30_print_error_and_exit("Failed to read IFS image header"); | |
} | |
// GET ACTIVE partition info | |
memset(local_6b0_buff512,0,0x200); | |
iVar1 = readblock(_DAT_00103548_hd0_fd,0x200,2,1,local_6b0_buff512); | |
if (iVar1 != 1) { | |
FUN_00100d30_print_error_and_exit("Failed to read active partition"); | |
} | |
memset(local_4b0,0,0x40); | |
if (local_6b0_buff512._0_4_ == 0xdeadbeaf) { | |
if (local_6b0_buff512._4_4_ == 0) { | |
iVar1 = 4; | |
} | |
else { | |
iVar1 = 0; | |
} | |
// if _4_4 == 0, addr 0x7cd2, else 0x0184 | |
FUN_00100e0c_do_flash_file | |
((uint)auStack1136_s_stat.st_size, | |
*(undefined4 *)((int)uint32_t_ARRAY_001034c4 + iVar1)); | |
if (bVar1_do_replace) { | |
FUN_00100e0c_do_flash_file | |
((uint)auStack1136_s_stat.st_size,uint32_t_ARRAY_001034c4[local_6b0_buff512._4_4_] | |
); | |
} | |
if (bVar1_do_toggle) { | |
snprintf(local_4b0,0x40,"mmc_change_active -t 0 %s",local_428_raw_partition_path); | |
system(local_4b0); | |
} | |
} | |
else { | |
FUN_00100e0c_do_flash_file((uint)auStack1136_s_stat.st_size,0x184); | |
if (bVar1_do_replace) { | |
FUN_00100e0c_do_flash_file((uint)auStack1136_s_stat.st_size,0x7cd2); | |
} | |
snprintf(local_4b0,0x40,"mmc_change_active -a %s",local_428_raw_partition_path); | |
system(local_4b0); | |
} | |
} | |
if (__file_MLO == (char *)0x0) { | |
FUN_00100cc8_close_all_files(); | |
} | |
else { | |
_DAT_00103544_IFS_MLO_fd = open64(__file_MLO,0); | |
if (_DAT_00103544_IFS_MLO_fd == -1) { | |
FUN_00100d30_print_error_and_exit("Failed to open new MLO image \'%s\' ",__file_MLO); | |
} | |
iVar3 = fstat64(_DAT_00103544_IFS_MLO_fd,(stat64 *)&auStack1136_s_stat); | |
iVar1 = extraout_r1; | |
if (iVar3 == -1) { | |
FUN_00100d30_print_error_and_exit("Failed to read size of new MLO image"); | |
iVar1 = extraout_r1_00; | |
} | |
// seek to 512 (0x200) | |
_Var7 = lseek64(_DAT_00103544_IFS_MLO_fd,(ulonglong)in_stack_fffff744 << 0x20,iVar1); | |
if (_Var7 == -1) { | |
FUN_00100d30_print_error_and_exit("Failed to seek to new MLO offset"); | |
} | |
sVar4 = read(_DAT_00103544_IFS_MLO_fd,local_6b0_buff512,8); | |
if (sVar4 == 8) { | |
iVar1 = extraout_r1_01; | |
if (0x10000 < local_6b0_buff512._0_4_) { | |
FUN_00100d30_print_error_and_exit("Error: new MLO image is too big."); | |
iVar1 = extraout_r1_03; | |
} | |
if (local_6b0_buff512._4_4_ != 0x40300008) { | |
FUN_00100d30_print_error_and_exit | |
("Error: new MLO image is not valid, load address is diffrent."); | |
iVar1 = extraout_r1_04; | |
} | |
} | |
else { | |
FUN_00100d30_print_error_and_exit("Failed to read new MLO GP header"); | |
iVar1 = extraout_r1_02; | |
} | |
// seek to 0x20200 | |
_Var7 = lseek64(_DAT_00103548_hd0_fd,(ulonglong)in_stack_fffff744 << 0x20,iVar1); | |
if (_Var7 == -1) { | |
FUN_00100d30_print_error_and_exit("Failed to seek to current MLO offset"); | |
} | |
sVar4 = read(_DAT_00103548_hd0_fd,local_4b0,8); | |
if (sVar4 == 8) { | |
// if newMLO and mmcMLO sizes match | |
if (local_6b0_buff512._0_4_ == local_4b0._0_4_) { | |
// alloc buffer of blksz*8 size for file reading | |
_DAT_00103550_file_read_buff = malloc(_DAT_00103554_hd0_blksize << 3); | |
if (_DAT_00103550_file_read_buff == (void *)0x0) { | |
FUN_00100d30_print_error_and_exit("Failed to allocate memory to read MLO data"); | |
} | |
if (0 < (int)local_4b0._0_4_) { | |
iVar1 = 0; | |
sVar2 = local_4b0._0_4_; | |
do { | |
if ((int)(sVar2 + _DAT_00103554_hd0_blksize * -8) < 0 == | |
SBORROW4(sVar2,_DAT_00103554_hd0_blksize * 8)) { | |
sVar2 = _DAT_00103554_hd0_blksize * 8; | |
} | |
memset(_DAT_0010354c_read_buff,0,sVar2); | |
sVar5 = read(_DAT_00103544_IFS_MLO_fd,_DAT_00103550_file_read_buff,sVar2); | |
if (sVar5 == sVar2) { | |
sVar6 = read(_DAT_00103548_hd0_fd,_DAT_0010354c_read_buff,sVar2); | |
if (sVar5 == sVar6) { | |
iVar3 = memcmp(_DAT_00103550_file_read_buff,_DAT_0010354c_read_buff,sVar2); | |
if (iVar3 != 0) { | |
FUN_00100e0c_do_flash_file((uint)auStack1136_s_stat.st_size,0x100); | |
break; | |
} | |
} | |
else { | |
FUN_00100d30_print_error_and_exit("Failed to read MLO data"); | |
} | |
} | |
else { | |
FUN_00100d30_print_error_and_exit("Failed to read MLO data"); | |
} | |
iVar1 = iVar1 + sVar2; | |
sVar2 = local_4b0._0_4_ - iVar1; | |
} while (0 < (int)sVar2); | |
} | |
} | |
else { | |
FUN_00100e0c_do_flash_file((uint)auStack1136_s_stat.st_size,0x100); | |
} | |
} | |
else { | |
FUN_00100d30_print_error_and_exit("Failed to read current MLO GP header"); | |
} | |
FUN_00100cc8_close_all_files(); | |
free(__file_MLO); | |
} | |
if (__file_IFS != (char *)0x0) { | |
free(__file_IFS); | |
} | |
return; | |
} | |
uint __divsi3(uint param_1,uint param_2) | |
{ | |
int iVar1; | |
uint uVar2; | |
int iVar3; | |
uint uVar4; | |
uint uVar5; | |
bool bVar6; | |
bool bVar7; | |
bool bVar8; | |
bool bVar9; | |
bool bVar10; | |
bool bVar11; | |
bool bVar12; | |
bool bVar13; | |
bool bVar14; | |
bool bVar15; | |
bool bVar16; | |
bool bVar17; | |
bool bVar18; | |
bool bVar19; | |
bool bVar20; | |
bool bVar21; | |
bool bVar22; | |
bool bVar23; | |
bool bVar24; | |
bool bVar25; | |
bool bVar26; | |
bool bVar27; | |
bool bVar28; | |
bool bVar29; | |
bool bVar30; | |
bool bVar31; | |
bool bVar32; | |
bool bVar33; | |
bool bVar34; | |
bool bVar35; | |
bool bVar36; | |
uVar5 = param_1 ^ param_2; | |
if (param_2 == 0) { | |
__div0(); | |
return 0; | |
} | |
uVar2 = param_2; | |
if ((int)param_2 < 0) { | |
uVar2 = -param_2; | |
} | |
if (uVar2 - 1 == 0) { | |
if ((int)param_2 < 0) { | |
param_1 = -param_1; | |
} | |
return param_1; | |
} | |
uVar4 = param_1; | |
if ((int)param_1 < 0) { | |
uVar4 = -param_1; | |
} | |
if (uVar4 <= uVar2) { | |
if (uVar4 < uVar2) { | |
param_1 = 0; | |
} | |
if (uVar4 == uVar2) { | |
param_1 = (int)uVar5 >> 0x1f | 1; | |
} | |
return param_1; | |
} | |
if ((uVar2 & uVar2 - 1) == 0) { | |
iVar1 = count_leading_zeroes(uVar2); | |
uVar4 = uVar4 >> (0x1fU - iVar1 & 0xff); | |
if ((int)uVar5 < 0) { | |
uVar4 = -uVar4; | |
} | |
return uVar4; | |
} | |
iVar3 = count_leading_zeroes(uVar4); | |
iVar1 = count_leading_zeroes(uVar2); | |
iVar1 = 0x1f - (iVar1 - iVar3); | |
if (iVar1 == 0) { | |
bVar6 = uVar2 << 0x1f <= uVar4; | |
if (bVar6) { | |
uVar4 = uVar4 + uVar2 * -0x80000000; | |
} | |
bVar7 = uVar2 << 0x1e <= uVar4; | |
if (bVar7) { | |
uVar4 = uVar4 + uVar2 * -0x40000000; | |
} | |
bVar8 = uVar2 << 0x1d <= uVar4; | |
if (bVar8) { | |
uVar4 = uVar4 + uVar2 * -0x20000000; | |
} | |
bVar9 = uVar2 << 0x1c <= uVar4; | |
if (bVar9) { | |
uVar4 = uVar4 + uVar2 * -0x10000000; | |
} | |
bVar10 = uVar2 << 0x1b <= uVar4; | |
if (bVar10) { | |
uVar4 = uVar4 + uVar2 * -0x8000000; | |
} | |
bVar11 = uVar2 << 0x1a <= uVar4; | |
if (bVar11) { | |
uVar4 = uVar4 + uVar2 * -0x4000000; | |
} | |
bVar12 = uVar2 << 0x19 <= uVar4; | |
if (bVar12) { | |
uVar4 = uVar4 + uVar2 * -0x2000000; | |
} | |
bVar13 = uVar2 << 0x18 <= uVar4; | |
if (bVar13) { | |
uVar4 = uVar4 + uVar2 * -0x1000000; | |
} | |
bVar14 = uVar2 << 0x17 <= uVar4; | |
if (bVar14) { | |
uVar4 = uVar4 + uVar2 * -0x800000; | |
} | |
bVar15 = uVar2 << 0x16 <= uVar4; | |
if (bVar15) { | |
uVar4 = uVar4 + uVar2 * -0x400000; | |
} | |
bVar16 = uVar2 << 0x15 <= uVar4; | |
if (bVar16) { | |
uVar4 = uVar4 + uVar2 * -0x200000; | |
} | |
bVar17 = uVar2 << 0x14 <= uVar4; | |
if (bVar17) { | |
uVar4 = uVar4 + uVar2 * -0x100000; | |
} | |
bVar18 = uVar2 << 0x13 <= uVar4; | |
if (bVar18) { | |
uVar4 = uVar4 + uVar2 * -0x80000; | |
} | |
bVar19 = uVar2 << 0x12 <= uVar4; | |
if (bVar19) { | |
uVar4 = uVar4 + uVar2 * -0x40000; | |
} | |
bVar20 = uVar2 << 0x11 <= uVar4; | |
if (bVar20) { | |
uVar4 = uVar4 + uVar2 * -0x20000; | |
} | |
bVar21 = uVar2 << 0x10 <= uVar4; | |
if (bVar21) { | |
uVar4 = uVar4 + uVar2 * -0x10000; | |
} | |
bVar22 = uVar2 << 0xf <= uVar4; | |
if (bVar22) { | |
uVar4 = uVar4 + uVar2 * -0x8000; | |
} | |
bVar23 = uVar2 << 0xe <= uVar4; | |
if (bVar23) { | |
uVar4 = uVar4 + uVar2 * -0x4000; | |
} | |
bVar24 = uVar2 << 0xd <= uVar4; | |
if (bVar24) { | |
uVar4 = uVar4 + uVar2 * -0x2000; | |
} | |
bVar25 = uVar2 << 0xc <= uVar4; | |
if (bVar25) { | |
uVar4 = uVar4 + uVar2 * -0x1000; | |
} | |
bVar26 = uVar2 << 0xb <= uVar4; | |
if (bVar26) { | |
uVar4 = uVar4 + uVar2 * -0x800; | |
} | |
bVar27 = uVar2 << 10 <= uVar4; | |
if (bVar27) { | |
uVar4 = uVar4 + uVar2 * -0x400; | |
} | |
bVar28 = uVar2 << 9 <= uVar4; | |
if (bVar28) { | |
uVar4 = uVar4 + uVar2 * -0x200; | |
} | |
bVar29 = uVar2 << 8 <= uVar4; | |
if (bVar29) { | |
uVar4 = uVar4 + uVar2 * -0x100; | |
} | |
bVar30 = uVar2 << 7 <= uVar4; | |
if (bVar30) { | |
uVar4 = uVar4 + uVar2 * -0x80; | |
} | |
bVar31 = uVar2 << 6 <= uVar4; | |
if (bVar31) { | |
uVar4 = uVar4 + uVar2 * -0x40; | |
} | |
bVar32 = uVar2 << 5 <= uVar4; | |
if (bVar32) { | |
uVar4 = uVar4 + uVar2 * -0x20; | |
} | |
bVar33 = uVar2 << 4 <= uVar4; | |
if (bVar33) { | |
uVar4 = uVar4 + uVar2 * -0x10; | |
} | |
bVar34 = uVar2 << 3 <= uVar4; | |
if (bVar34) { | |
uVar4 = uVar4 + uVar2 * -8; | |
} | |
bVar35 = uVar2 << 2 <= uVar4; | |
if (bVar35) { | |
uVar4 = uVar4 + uVar2 * -4; | |
} | |
bVar36 = uVar2 << 1 <= uVar4; | |
if (bVar36) { | |
uVar4 = uVar4 + uVar2 * -2; | |
} | |
uVar2 = (((((((((((((((((((((((((((((((uint)bVar6 * 2 + (uint)bVar7) * 2 + (uint)bVar8) * 2 + | |
(uint)bVar9) * 2 + (uint)bVar10) * 2 + (uint)bVar11) * 2 + | |
(uint)bVar12) * 2 + (uint)bVar13) * 2 + (uint)bVar14) * 2 + | |
(uint)bVar15) * 2 + (uint)bVar16) * 2 + (uint)bVar17) * 2 + | |
(uint)bVar18) * 2 + (uint)bVar19) * 2 + (uint)bVar20) * 2 + | |
(uint)bVar21) * 2 + (uint)bVar22) * 2 + (uint)bVar23) * 2 + (uint)bVar24) | |
* 2 + (uint)bVar25) * 2 + (uint)bVar26) * 2 + (uint)bVar27) * 2 + | |
(uint)bVar28) * 2 + (uint)bVar29) * 2 + (uint)bVar30) * 2 + (uint)bVar31) * 2 + | |
(uint)bVar32) * 2 + (uint)bVar33) * 2 + (uint)bVar34) * 2 + (uint)bVar35) * 2 + | |
(uint)bVar36) * 2 + (uint)(uVar2 <= uVar4); | |
if ((int)uVar5 < 0) { | |
uVar2 = -uVar2; | |
} | |
return uVar2; | |
} | |
// WARNING: Could not recover jumptable at 0x00101834. Too many branches | |
// WARNING: Treating indirect jump as call | |
uVar5 = (*(code *)(iVar1 * 0xc + 0x10183c))(); | |
return uVar5; | |
} | |
void __aeabi_idivmod(void) | |
{ | |
__divsi3(); | |
return; | |
} | |
void __div0(void) | |
{ | |
code *UNRECOVERED_JUMPTABLE; | |
// WARNING: Could not recover jumptable at 0x00101a28. Too many branches | |
// WARNING: Treating indirect jump as call | |
UNRECOVERED_JUMPTABLE = (code *)software_udf(0xfffe,0x101a28); | |
(*UNRECOVERED_JUMPTABLE)(); | |
return; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment