Hi,
as winter comes and the "stay home and safe thing" continues I might be interested in testing that hardware thingy.
as winter comes and the "stay home and safe thing" continues I might be interested in testing that hardware thingy.
Etiquette, expectations, entitlement...
@autoexec_bin | #magiclantern | Discord | Reddit | Server issues
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
#define EOS_LOG_R2 (1LL << 59) /* export unique calls to radare2 */
{ EOS_LOG_R2 | EOS_LOG_CALLSTACK | CPU_LOG_TB_NOCHAIN, "r2",
"EOS: export called functions to radare2 (implies callstack,nochain,singlestep)" },
static FILE * r2 = NULL;
/* QEMU is usually closed with CTRL-C, so call this when finished */
static void close_r2(void)
{
fprintf(r2, "\n");
fclose(r2);
fprintf(stderr, "%s saved.\n", idc_path);
}
static void eos_r2_log_call(EOSState *s, CPUState *cpu, CPUARMState *env,
TranslationBlock *tb, uint32_t prev_pc, uint32_t prev_lr, uint32_t prev_size)
{
static int stderr_dup = 0;
if (!r2)
{
snprintf(idc_path, sizeof(idc_path), "%s.r2", MACHINE_GET_CLASS(current_machine)->name);
fprintf(stderr, "Exporting called functions to %s.\n", idc_path);
r2 = fopen(idc_path, "w");
assert(r2);
atexit(close_r2);
fprintf(r2, "# List of functions called during execution. */");
fprintf(r2, "# Generated from QEMU. \n\n");
stderr_dup = dup(fileno(stderr));
}
/* bit array for every possible PC & ~3 */
static uint32_t saved_pcs[(1 << 30) / 32] = {0};
uint32_t pc = env->regs[15];
uint32_t lr = env->regs[14];
uint32_t sp = env->regs[13];
/* log each called function to IDC, only once */
int pca = pc >> 2;
if (!(saved_pcs[pca/32] & (1 << (pca%32))))
{
saved_pcs[pca/32] |= (1 << pca%32);
/* log_target_disas writes to stderr; redirect it to our output file */
/* todo: any other threads that might output to stderr? */
assert(stderr_dup);
fflush(stderr); fflush(r2);
dup2(fileno(r2), fileno(stderr));
fprintf(stderr, " /* from "); log_target_disas(cpu, prev_pc, prev_size, 0);
fprintf(stderr, " * -> "); log_target_disas(cpu, tb->pc, tb->size, 0);
char * task_name = eos_get_current_task_name(s);
fprintf(stderr, " * %s%sPC:%x->%x LR:%x->%x SP:%x */\n",
task_name ? task_name : "", task_name ? " " : "",
prev_pc, pc, prev_lr, lr, sp
);
fprintf(stderr, " s 0x%X \n", pc);
env->thumb == 1? fprintf(stderr, " afB 16\n af @ 0x%X\n", pc):fprintf(stderr, " af @ 0x%X\n", pc);
//TODO find solution for name printf("afn 0x%08X %s\n",ea,name);
fprintf(stderr, "\n");
dup2(stderr_dup, fileno(stderr));
}
}
Quote from: a1ex on June 25, 2018, 01:12:16 PM
Included this in the install script. Please test, in particular on Mac, WSL, 32-bit Ubuntu and 64-bit Ubuntu.
r2 -i load_db.r2 -d gdb://localhost:1234
## Pretty stuff
# Solarized theme
eco solarized
# Use UTF-8 to show cool arrows
e scr.utf8 = true
e scr.utf8.curvy=true
# Show comments at right of disassembly if they fit in screen
e asm.cmtright=true
## Processor stuff
# set arch and cpu type
e io.va = true
e asm.arch = arm
e asm.bits = 16
e asm.cpu=cortex
# anal.armthumb (aae computes arm/thumb changes (lot of false positives ahead))
e anal.armthumb=true
# Shows pseudocode in disassembly. Eg mov eax, str.ok = > eax = str.ok
e asm.pseudo = true
# (Show ESIL instead of mnemonic)
# e asm.esil = true
# Selected: asm.describe (Show opcode description)
e asm.describe = false
#asm.emu (Run ESIL emulation analysis on disasm)
e asm.emu = true
e asm.section.sub = true
e io.va=true
S 0x00000000 0x00000000 0x00003fff tcmcode mrwx #00000000 - 00003FFF: eos.tcm_code
S 0x00004000 0x00004000 0x1FFFC000 eosram mrw- #00004000 - 1FFFFFFF: eos.ram
S 0x40000000 0x40000000 0x00004000 eosramuncached0 mrw- #40000000 - 40003FFF: eos.ram_uncached0
S 0x40004000 0x40004000 0x1FFFC000 eosramuncached mrw- #40004000 - 5FFFFFFF: eos.ram_uncached
S 0x80000000 0x80000000 0x00010000 tcmram mrw- #80000000 - 8000FFFF: eos.tcm_data
S 0xBFE00000 0xBFE00000 0x00200000 eosramextra mrw- #BFE00000 - BFFFFFFF: eos.ram_extra
S 0xc0000000 0xc0000000 0x20000000 eosiomem mrw- #C0000000 - DFFFFFFF: eos.iomem
S 0xfc000000 0xfc000000 0x20000000 eosrom1 mr-x #FC000000 - FDFFFFFF: eos.rom1
S 0xfe000000 0xfe000000 0x20000000 eosrom1m mr-x#FE000000 - FFFFFFFF: eos.rom1_mirror
#include "stubshelper.h"
int main(void)
{
MakeAutoNamedFunc(0xFE0FD5C9, "LoadScript");
#include <stdio.h>
void MakeAutoNamedFunc(unsigned int ea ,char name[])
{
printf("af @ 0x%08X\n",ea);
printf("afn 0x%08X %s\n",ea,name);
}
void NSTUB(unsigned int ea ,char name[])
{
printf("af @ 0x%08X\n",ea);
printf("afn 0x%08X %s\n",ea,name);
}
s <name>
VV
to inspect a function.r2 -i load_db.r2 -d gdb://localhost:1234
## Pretty stuff
# Solarized theme
eco solarized
# Use UTF-8 to show cool arrows
e scr.utf8 = true
e scr.utf8.curvy=true
# Show comments at right of disassembly if they fit in screen
e asm.cmtright=true
## Processor stuff
# set arch and cpu type
e io.va = true
e asm.arch = arm
e asm.bits = 16
e asm.cpu=cortex
# anal.armthumb (aae computes arm/thumb changes (lot of false positives ahead))
e anal.armthumb=true
# Shows pseudocode in disassembly. Eg mov eax, str.ok = > eax = str.ok
e asm.pseudo = true
# (Show ESIL instead of mnemonic)
# e asm.esil = true
# Selected: asm.describe (Show opcode description)
e asm.describe = false
#asm.emu (Run ESIL emulation analysis on disasm)
e asm.emu = true
e asm.section.sub = true
e io.va=true
S 0x00000000 0x00000000 0x00003fff tcmcode mrwx #00000000 - 00003FFF: eos.tcm_code
S 0x00004000 0x00004000 0x1FFFC000 eosram mrw- #00004000 - 1FFFFFFF: eos.ram
S 0x40000000 0x40000000 0x00004000 eosramuncached0 mrw- #40000000 - 40003FFF: eos.ram_uncached0
S 0x40004000 0x40004000 0x1FFFC000 eosramuncached mrw- #40004000 - 5FFFFFFF: eos.ram_uncached
S 0x80000000 0x80000000 0x00010000 tcmram mrw- #80000000 - 8000FFFF: eos.tcm_data
S 0xBFE00000 0xBFE00000 0x00200000 eosramextra mrw- #BFE00000 - BFFFFFFF: eos.ram_extra
S 0xc0000000 0xc0000000 0x20000000 eosiomem mrw- #C0000000 - DFFFFFFF: eos.iomem
S 0xfc000000 0xfc000000 0x20000000 eosrom1 mr-x #FC000000 - FDFFFFFF: eos.rom1
S 0xfe000000 0xfe000000 0x20000000 eosrom1m mr-x#FE000000 - FFFFFFFF: eos.rom1_mirror
#include "stubshelper.h"
int main(void)
{
MakeAutoNamedFunc(0xFE0FD5C9, "LoadScript");
#include <stdio.h>
void MakeAutoNamedFunc(unsigned int ea ,char name[])
{
printf("f %s = 0x%0X\n",name,ea);
}
void NSTUB(unsigned int ea ,char name[])
{
printf("f %s = 0x%0X\n",name,ea);
}
af @@@f
s fcn.<name>
Vpp
to inspect a function.QuoteWell no error and if this output is expected yes
Does this work on Mac, or it's back to square one?
./findstub.py 750D
Test run...
./run_canon_fw.sh 750D,firmware=";boot=0" -d calls,tail -display none -monitor stdio -serial file:uart.log
call 0xFE3CDF44(fe1f845c "PowerMgr", 20, 400, fe1f82e9) at [init:fe1f837d:fe506533]
Task found
211B CreateStateObject
1775 register_interrupt
80001FC5 create_semaphore
1E45 task_create
??? DebugMsg
??? create_msg_queue
FE445CB9 register_func
$ ansi2txt -v
ansi2txt - version 0.2.2, compiled on May 1 2018 at 13:15:18.
$ bash --version
bash --version
GNU bash, version 4.4.19(1)-release (x86_64-apple-darwin16.7.0)
$ ggrep -V
ggrep -V
ggrep (GNU grep) 3.1
Packaged by Homebrew
...
GREP=grep
if [ $(uname) == "Darwin" ]; then
if [[ -n $(which ggrep) ]]; then
export GREP=ggrep
else
echo
echo "Error: you need GNU grep to run this script"
echo "brew install grep"
exit 1
fi
...
test_run=$(cat test_run.txt)
in the script.
b *0xFE172BB2
task_create_log
# from 750D/debugmsg.gdb
b *0xFE52F980
assert_log
# from 750D/debugmsg.gdb
b *0x1774
register_interrupt_log
# from 750D/debugmsg.gdb
b *0xFE445CB8
register_func_log
# from 750D/debugmsg.gdb
b *0x...
mpu_send_log
# from 750D/debugmsg.gdb
b *0x...
mpu_recv_log
b *0xFE3CDFE4
create_semaphore_log
b *0x1C18
create_msg_queue_log
b *0x211A
CreateStateObject_log
call 0xFE3CDE84(c0003, 60000053, 1, 5)
at [SFRead:fe32bd4f:fe32a717]
-> 0x186F at [SFRead:fe3cde84:fe32bd53]
call 0xFE3CDF94(90007, 0, 73, 0)
at [TaskMain:fe1c1c7f:fe2eb9fb]
-> 0x800020B3 at [TaskMain:fe3cdf94:fe1
c1c83]
call 0x800056DC(2ee300, 0, 73, 0)
at [TaskMain:800020bb:fe1c1c83]
-> 0xFE172B85 at [TaskMain:800056dc:800
Quote from: DieHertz on May 04, 2018, 03:17:21 PM
I'm still figuring my way through radare2,
# Show comments at right of disassembly if they fit in screen
e asm.cmtright=true
# Shows pseudocode in disassembly. Eg mov eax, str.ok = > eax = str.ok
e asm.pseudo = true
# (Show ESIL instead of mnemonic)
# e asm.esil = true
# Selected: asm.describe (Show opcode description)
e asm.describe = false
#asm.emu (Run ESIL emulation analysis on disasm)
e asm.emu = true
# Solarized theme
eco solarized
# Use UTF-8 to show cool arrows
e scr.utf8 = true
e scr.utf8.curvy=true
# set arch and cpu type
e io.va = true
e asm.arch = arm
e asm.bits = 16
e asm.cpu=cortex
# anal.armthumb (aae computes arm/thumb changes (lot of false positives ahead))
e anal.armthumb=true
# initialize esil vm
#e esil.stack.addr = 0x20000000
#e esil.stack.size = 0x000f0000
e asm.section.sub = true
e io.va=true
#S ${esil.stack.addr} ${esil.stack.addr} ${esil.stack.size} ${esil.stack.size} ram mrwx
#00000000 - 00003FFF: eos.tcm_code
S 0x0000000 0x00000000 0x3fff 0x3fff tcmcode mrwx
#00004000 - 1FFFFFFF: eos.ram
S 0x00004000 0x00004000 0x1FFFBFFF 0x1FFFBFFF eosram mrw-
#40000000 - 40003FFF: eos.ram_uncached0
S 0x40000000 0x40000000 0x3fff 0x3FFF eosramuncached0 mrw-
#40004000 - 5FFFFFFF: eos.ram_uncached
S 0x40004000 0x40004000 0x1FFFBFFF 0x1FFFBFFF eosramuncached mrw-
#80000000 - 8000FFFF: eos.tcm_data
S 0x80000000 0x80000000 0xffff 0xffff tcmram mrw-
#BFE00000 - BFFFFFFF: eos.ram_extra
S 0xBFE00000 0xBFE00000 0x1fffff 0x1fffff eosramextra mrw-
#C0000000 - DFFFFFFF: eos.iomem
S 0xc0000000 0xc0000000 0x1fffffff 0x1fffffff eosiomem mrw-
#FC000000 - FDFFFFFF: eos.rom1
#FE000000 - FFFFFFFF: eos.rom1_mirror
S 0xfc000000 0xfc000000 0x1fffffff 0x1fffffff eosrom1 mr-x
S 0xfe000000 0xfe000000 0x1fffffff 0x1fffffff eosrom1m mr-x
aa
aaa
aae
e anal.hasnext = true
# e io.sectonly = true
e search.in = io.sections.exec
#aac
dbe 0xFE020000
r2 -aarm -b16 -d gdb://localhost:1234
MakeAutoNamedFunc(0x00002404, "�F�F��V��_task");
MakeAutoNamedFunc(0x0000240E, "�F�F��V��_task");
MakeAutoNamedFunc(0x00002418, "�F�F��V��_task");
MakeAutoNamedFunc(0x00002422, "�F�F��V��_task");
#!/bin/bash
# Mirror of gnu.org to be used.
MIRROR=https://ftp.gnu.org/gnu
#create Directory
mkdir ~/crossgcc
cd ~/crossgcc
mkdir src
cd src
# get a bunch of stuff
wget -c $MIRROR/gdb/gdb-8.1.tar.xz
# let's unpack
tar jxf gdb-8.1.tar.xz
# now build
# read about CC='gcc -m32' but also that newer gdb should handle 32 bit fine ...
mkdir build-gdb
cd build-gdb
../gdb-8.1/configure --target=arm-none-eabi --prefix=$HOME/crossgcc/
make all install 2>&1 | tee make.log
echo "Done, please add: "
echo $HOME/crossgcc/bin
echo "to your PATH"
2>&1 | ansi2txt
portion,Quote from: t3r4n on April 30, 2018, 12:18:45 PMoriginal threadBut so far I can't get it to talk to me properly.... so I watched the output of qemu with -d uart :
[UART] at 0xFE0204F4:FE02013C ESC[1;33m[0xC0800010] <- 0x19 : ???
[UART] at 0xFE020500:FE02013C ESC[1;33m[0xC0800018] <- 0x4 : interrupt flags?
[UART] at 0xFE02050C:FE02013C ESC[1;33m[0xC0800008] <- 0x8081 : Flags?
|&
with 2>&1 |
in the scriptmake && make install
lbrew install grep
void
__attribute__((noreturn,noinline,naked))
copy_and_restart( int offset )
{
zero_bss();
// Copy the firmware to somewhere safe in memory
const uint8_t * const firmware_start = (void*) ROMBASEADDR;
const uint32_t firmware_len = RELOCSIZE;
uint32_t * const new_image = (void*) RELOCADDR;
blob_memcpy( new_image, firmware_start, firmware_start + firmware_len );
/*
* in cstart() make these changes:
* calls bzero(), then loads bs_end and calls
* create_init_task
*/
// Reserve memory at the end of malloc pool for our application
// Note: unlike most (all?) DIGIC 4/5 cameras,
// the malloc buffer is specified as start + size (not start + end)
// so we adjust both values in order to keep things close to the traditional ML boot process
// (alternative: we could adjust only the size, and place ML at the end of malloc buffer)
uint32_t ml_reserved_mem = (uintptr_t) _bss_end - INSTR( HIJACK_INSTR_BSS_END );
INSTR( HIJACK_INSTR_BSS_END ) += ml_reserved_mem;
INSTR( HIJACK_INSTR_BSS_END + 4 ) -= ml_reserved_mem;
// Fix the calls to bzero32() and create_init_task()
FIXUP_BRANCH( HIJACK_FIXBR_BZERO32, my_bzero32 );
FIXUP_BRANCH( HIJACK_FIXBR_CREATE_ITASK, my_create_init_task );
// Set our init task to run instead of the firmware one
INSTR( HIJACK_INSTR_MY_ITASK ) = (uint32_t) my_init_task;
// Make sure that our self-modifying code clears the cache
sync_caches();
// We enter after the signature, avoiding the
// relocation jump that is at the head of the data
// this is Thumb code
MEM(0xD20C0084) = 0;
thunk __attribute__((long_call)) reloc_entry = (thunk)( RELOCADDR + 0xC + 1 );
reloc_entry();
Page created in 0.131 seconds with 13 queries.