Answer
stringlengths 38
29k
โ | Id
stringlengths 1
5
| CreationDate
stringlengths 23
23
| Body
stringlengths 55
28.6k
| Title
stringlengths 15
145
| Tags
stringlengths 3
68
|
---|---|---|---|---|---|
<p>You just need to prefix the address with a <code>'*'</code>, like when using <code>break</code>.</p>
<p>For example:</p>
<pre><code>(gdb) python
>gdb.Breakpoint('*0x080487ff')
>end
Breakpoint 1 at 0x80487ff
(gdb)
</code></pre>
| 26843 | 2021-01-22T10:17:12.860 | <p>into GDB python I tried <code>gdb.Breakpoint('0xaaaa')</code></p>
<p>I got error</p>
<p><code>Function 0xaaaa is not defided . Breakpoint 5(0xaaaa) pending</code></p>
<p>and the program not break at this address.</p>
<p>Why is that?</p>
| Set gdb breakpoint by address with gdb python | |gdb|breakpoint| |
<p>What you are observing is the effect of ASLR.
You should focus on the instructions which access this memory location.
To put simply:</p>
<ul>
<li>on x86, you will find some .reloc entries pointing to these instructions;</li>
<li>on x64, the memory operand is RIP related (this is hidden in IDA by default).</li>
</ul>
<p>Since you tagged <code>ollydbg</code>, I'm guessing this is for x86, and the 'bad' news is it's more tedious to patch than for x64. The main reason is related to how the .reloc is working.
When you application is loading, the loader will find a different base image and will apply relocations. Basically (really simplified) it takes 32-bit values and adjust them accordingly to the base address. Those values are offsets inside an instruction. If you modify/patch the instruction and change the offset location (or remove it), the .reloc will corrupt the instruction.</p>
<p>Another solution is creating a new thread and keep modifying this memory location, this is what most trainers do.</p>
| 26847 | 2021-01-22T20:19:53.433 | <p>Sorry if this is a dumb question I'm new to assembly.</p>
<p>Basically I want to modify a function in a .exe file to return with a different data, but my issue is that the memory location of the data segment I want to return is always changing after system restart. For example currently it is <code>.data:018C74F1 byte_18C74F1</code>, next time it's going to differ like <code>.data:16874F1 byte_16874F1</code>. So due to this I am unable to change the return value to that in the file. Is there any way to workaround this?</p>
<p>Thank you very much for any answer given!</p>
| Is it possible to make a dynamic memory allocated .data segment to static in a file? | |ida|ollydbg|static-analysis|dynamic-analysis|functions| |
<p>It was made by humans so there's a spec.</p>
<p><a href="https://i.stack.imgur.com/iXYlI.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/iXYlI.jpg" alt="enter image description here" /></a></p>
<p>I googled it.</p>
<p>Here's <a href="https://usermanual.wiki/Document/AxialMXInstallGuide.392315378/view" rel="noreferrer">a manual which talks about the Axial MX from Accom ~2005</a>. If it's a series of edit controllers, they'll likely work the same under the hood and use the same protocol from one version to the next.</p>
<p><a href="https://i.stack.imgur.com/W0vgG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/W0vgG.png" alt="Ports" /></a></p>
<p>Looks like an RS422 Serial. So you just need to hook it up to a computer with a serial port and take a look at what data is transmitted when you hit a key. You'll have to <a href="https://github.com/devttys0/baudrate/blob/master/baudrate.py" rel="noreferrer">figure out some of the serial port parameters such as rate, parity, etc,</a> but this should get you going.</p>
<p><a href="https://i.stack.imgur.com/fsZow.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fsZow.png" alt="enter image description here" /></a></p>
| 26849 | 2021-01-22T23:21:48.850 | <p>Suppose you've never done reverse engineering before (apart from taking apart already-broken tape recorders). Also suppose you had a machine as pictured below, with a serial-looking and another multi-pin connector on the back. Thirdly, suppose you wanted to use this console as a computer input, hoping to gain control of more than just the keyboard part (it's got a trackball, a hefty jog/cue wheel, rotary dials, blinkenlights, and a two-line character VFD display).</p>
<p>Lastly, suppose you <em>don't</em> have access to any technical specifications! No user manual, no installation guide, no service manual, not even a crappy nth-generation photocopy of the pin-outs. The company no longer exists, and the archive of their web site is of no help. Pretty much all I have is that this console runs on "90-264V" and draws "<42W".</p>
<p>On the plus side, I (used to) know the operation of this console very well. For instance, I can tell you it's got no real brains -- <em>that</em> is in a separate computer, <em>this</em> is merely the controller for it. The main computer costs thousands, and anyway is purpose-built and not useful as a general computing device (I don't think this runs a regular operating system "behind the scenes", at least I could recognize no tell-tale signs from the boot sequence, file system naming, or something like that).</p>
<p>I am confident that I could surely figure out the main power pins based on the red and black wires going to that Molex connector ... but the rest of those pins? All that functionality? I don't even know where to start.</p>
<p>I am a programmer by trade, I'm pretty good with my hands, including competency with a soldering iron and a multimeter. I don't have (access to) an oscilloscope, signal analyzer, or any such fanciness.</p>
<p>A few hints for me? Is this even doable?</p>
<p><a href="https://i.stack.imgur.com/lyrtm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lyrtm.png" alt="Accom Axial editing console" /></a>
<a href="https://i.stack.imgur.com/2YCqc.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2YCqc.png" alt="connectors on the back" /></a>
<a href="https://i.stack.imgur.com/84v0t.png" rel="noreferrer"><img src="https://i.stack.imgur.com/84v0t.png" alt="back side off mode" /></a></p>
<p><strong>EDIT:</strong> By the way, these are the chassis: The Display chassis on top of the Comms chassis (neither of which I have, or plan to acquire).</p>
<p><a href="https://i.stack.imgur.com/wGj6N.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/wGj6N.jpg" alt="Display and Comms chassis" /></a></p>
| Advice on how to attack my first reverse engineering project? | |hardware|communication|physical-attacks| |
<p>One simple way is to take a snapshot of the process memory and then work with it since it includes the modules.</p>
<p>Another is to create a database with all the modules, as described: <a href="https://www.hex-rays.com/blog/several-files-in-one-idb-part-3/" rel="nofollow noreferrer">https://www.hex-rays.com/blog/several-files-in-one-idb-part-3/</a></p>
| 26857 | 2021-01-23T22:58:49.493 | <p>I have a program (P.exe) with several dependencies (A.dll, B.dll etc). I decompiled and studied B.dll, but at runtime, P.exe is using A.dll. The horizon is updating in ISA view-RIP, but I don't have the decompiler view.</p>
<p>How can I get the decompiled view of A.dll, where the horizon is ?</p>
<p>Using IDA pro 7.5</p>
| open decompiler view of current module (dll) in dynamic analysis | |ida|debuggers|dll| |
<p>This is because of your old <code>radare2</code> installation. If you installed <code>radare2</code> via <code>apt</code> its very old.
Build it from latest source instead and you can look at different symbols.</p>
<p>I tried to replicate your problem in an Ubuntu 20.04 docker container</p>
<pre><code>root@4a6deaf68cd8:/tmp# r2 -v
radare2 4.2.1 0 @ linux-x86-64 git.4.2.1
commit: unknown build:
root@4a6deaf68cd8:/tmp# r2 -q -c "aaa; afl" hello_world
Cannot find function at 0x00001060
0x00001090 4 41 -> 34 sym.deregister_tm_clones
0x000010c0 4 57 -> 51 sym.register_tm_clones
root@4a6deaf68cd8:/tmp# /root/bin/r2 -v
radare2 5.1.0 25622 @ linux-x86-64 git.5.1.0
commit: 0939e57001c9eeda296d2699c60b967b5927e637 build: 2021-01-26__20:17:25
root@4a6deaf68cd8:/tmp# /root/bin/r2 -q -c "aaa; afl" hello_world
Warning: run r2 with -e io.cache=true to fix relocations in disassembly
0x00001060 1 46 entry0
0x00001090 4 41 -> 34 sym.deregister_tm_clones
0x000010c0 4 57 -> 51 sym.register_tm_clones
0x00001100 5 57 -> 54 sym.__do_global_dtors_aux
0x00001040 1 11 sym..plt.got
0x00001140 1 9 entry.init0
0x00001000 3 27 sym._init
0x000011e0 1 5 sym.__libc_csu_fini
0x000011e8 1 13 sym._fini
0x00001170 4 101 sym.__libc_csu_init
0x00001149 1 32 main
0x00001050 1 11 sym.imp.printf
root@4a6deaf68cd8:/tmp#
</code></pre>
<p>I used the <code>sys/user.sh</code> in r2's repo to build from source and install new <code>r2</code> at <code>/root/bin/r2</code></p>
<p>In the output - the latest radare2 was able to figure out main and some other functions while the older one could not.</p>
| 26870 | 2021-01-25T18:59:03.757 | <p>I'm trying to learn reverse engineering using Radare2.
For this I compiled a hello world program with GCC on Ubuntu (version: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0).</p>
<pre><code>#include <stdio.h>
int main() {
printf("Hello, world!");
return 0;
}
</code></pre>
<p>Compile it:</p>
<pre><code>gcc -w hello_world.c -o hello_world
</code></pre>
<p>However, when I decompile it using Radare2:</p>
<pre><code>r2 hello_world
[0x00001060]> aaa
[Cannot find function at 0x00001060 sym. and entry0 (aa)
[x] Analyze all flags starting with sym. and entry0 (aa)
[x] Analyze function calls (aac)
[x] Analyze len bytes of instructions for references (aar)
[x] Check for objc references
[x] Check for vtables
[x] Type matching analysis for all functions (aaft)
[x] Propagate noreturn information
[x] Use -AA or aaaa to perform additional experimental analysis.
[0x00001060]> afl
0x00001090 4 41 -> 34 sym.deregister_tm_clones
0x000010c0 4 57 -> 51 sym.register_tm_clones
[0x00001060]>
</code></pre>
<p>The main function does not show up.
Searching for it specifically with pdf @main also does not work.</p>
<p>But the program runs fine, and other information I get using Radare (iI command for example) looks normal.</p>
<p><strong>Can anyone explain to me why I can't get the main function to show?</strong></p>
<p>Edit:
I tried the same thing on Ubuntu 18.04 LTS and I get a different output, this time with the main function</p>
<pre><code>[0x7f1465cb4090]> afl
0x55595d978000 2 64 sym.imp.__libc_start_main
0x55595d9784f0 3 23 sym._init
0x55595d978520 1 6 sym.imp.printf
0x55595d978530 1 6 sub.__cxa_finalize_248_530
0x55595d978540 1 43 entry0
0x55595d978570 4 50 -> 40 sym.deregister_tm_clones
0x55595d9785b0 4 66 -> 57 sym.register_tm_clones
0x55595d978600 4 49 sym.__do_global_dtors_aux
0x55595d978640 1 10 entry1.init
0x55595d97864a 1 28 sym.main
0x55595d978670 4 101 sym.__libc_csu_init
0x55595d9786e0 1 2 sym.__libc_csu_fini
0x55595d9786e4 1 9 sym._fini
0x55595db78fe0 1 1020 reloc.__libc_start_main_224
</code></pre>
| main function not found in GCC compiled code | |radare2|functions|gcc| |
<p>All is good. r2 doesn't refresh this <code>.rodata</code> by default after your change but if you go to the address <code>0x2004</code>, you would see your change.</p>
<pre><code>r2 -w modified_helloworld
w Good, Bye!!!! @0x00002004
s 0x2004
[0x00002004]> px
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00002004 476f 6f64 2c20 4279 6521 2121 2100 0000 Good, Bye!!!!...
</code></pre>
<p>If you want to see your change with <code>iz</code> just reload binary info with <code>ib</code>.</p>
<pre><code>r2 -w modified_helloworld
w Good, Bye!!!! @0x00002004
[0x00001060]> iz
[Strings]
nth paddr vaddr len size section type string
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
0 0x00002004 0x00002004 13 14 .rodata ascii Hello, world!
[0x00001060]> ib
[0x00001060]> iz
[Strings]
nth paddr vaddr len size section type string
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
0 0x00002004 0x00002004 13 14 .rodata ascii Good, Bye!!!!
</code></pre>
| 26887 | 2021-01-27T03:29:04.423 | <p>I was following the response to this <a href="https://reverseengineering.stackexchange.com/questions/17415/how-to-change-a-string-in-a-arm-32bit-lsb-executable-binary-using-radare2">question</a> to change the string of an elf executable. No matter how many times I try, I just can't modify the string. I notice that probably the issue lies in the permissions of rodata section.</p>
<pre><code>[0x00001060]> iS
[Sections]
nth paddr size vaddr vsize perm name
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
...
16 0x00001060 0x185 0x00001060 0x185 -r-x .text
17 0x000011e8 0xd 0x000011e8 0xd -r-x .fini
18 0x00002000 0x12 0x00002000 0x12 -r-- .rodata
...
</code></pre>
<p>Is there a way to write in this section? or is there another way to modify strings?</p>
<p><strong>update</strong></p>
<p>this is the program</p>
<pre><code>#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
</code></pre>
<p>I want to change "Hello World!\n", this is how I am changing the string in radare2</p>
<pre><code>$ r2 -w modified_helloworld
[0x00001060]> iz
[Strings]
nth paddr vaddr len size section type string
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
0 0x00002004 0x00002004 13 14 .rodata ascii Hello, World!
[0x00001060]> w Good, Bye!!!! @0x00002004
[0x00001060]> iz
[Strings]
nth paddr vaddr len size section type string
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
0 0x00002004 0x00002004 13 14 .rodata ascii Hello, World!
[0x00001060]>
</code></pre>
<p>As can be seen, I'm using the w command but when I check the string again, there are no changes.
Thanks in advance.</p>
| Can't modify string in radare2 (.rodata section) | |radare2|elf| |
<p>yes the parser can parse byte by byte<br />
an x86 instruction is MAX 15 Bytes</p>
<p>so if it sees 15 bytes of 0x66 (PREFIX BYTE )one followed by another<br />
it will discard 13 bytes , consider the 14th byte as VALID PREFIX
and disassemble the 14th&15th byte<br />
(same for all LEGACY_PREFIX(2e,...67) ,REX_FAMILY on x64 (0x40,0x4f)</p>
<p>see for a python poc</p>
<pre><code>from capstone import *
CODE = [
b"\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66\x90\x90",
b"\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x90\x90",
b"\x2e\x2e\x2e\x2e\x2e\x2e\x2e\x2e\x2e\x2e\x2e\x2e\x2e\x2e\x90\x90"
]
print("\nCODE[0] parsed notice the Address of Successive instructions")
for i in (Cs(CS_ARCH_X86,CS_MODE_64).disasm(CODE[0],0x10000000)):
print("0x%x:\t%s\t%s" %(i.address, i.mnemonic, i.op_str))
print("\nCODE[1] parsed notice the Address of Successive instructions")
for i in (Cs(CS_ARCH_X86,CS_MODE_64).disasm(CODE[1],0x10000000)):
print("0x%x:\t%s\t%s" %(i.address, i.mnemonic, i.op_str))
print("\nCODE[2] parsed notice the Address of Successive instructions")
for i in (Cs(CS_ARCH_X86,CS_MODE_64).disasm(CODE[2],0x10000000)):
print("0x%x:\t%s\t%s" %(i.address, i.mnemonic, i.op_str))
:\>python dis64.py
CODE[0] parsed notice the Address of Successive instructions
0x10000000: nop
0x1000000f: nop
CODE[1] parsed notice the Address of Successive instructions
0x10000000: xchg eax, r8d
0x1000000f: nop
CODE[2] parsed notice the Address of Successive instructions
0x10000000: nop
0x1000000f: nop
</code></pre>
<p>parsing the opcode is complex procedure (cisc instructions for x86/x86_64)</p>
<p>manually decoding a random stream of bytes</p>
<p>a simple one byte opcode with 4 byte immediate</p>
<pre><code>>>> "{0:040b}".format(0x3dffffffff)
'0011110111111111111111111111111111111111'
========================================================
0x3d 0xff 0xff 0xff 0xff
76543210 | 76543210 | 76543210 | 76543210 | 76543210
00111101 | 11111111 | 11111111 | 11111111 | 11111111
------ds | modregrm sib immediate etc follows
</code></pre>
<p>simple naive parser action will be like</p>
<pre><code>first 6 bits 001111 using a look up table this is a CMP mnemonic
(0x3c,al,imm8 or 0x3d eax,imm32)
7th bit dbit = 0 a register
8th bit sbit = 1 so 32 bit register so takes a 32 bit wide immediate
so this will be
CMP EAX,0xffffffff
</code></pre>
<p>checking with some known implementations</p>
<pre><code>windbg
0:000> eb . 3d ff ff ff ff;u . l 1
ntdll!LdrpDoDebuggerBreak+0x2c:
778b05a6 3dffffffff cmp eax,0FFFFFFFFh
0:000>
objdump
:\>echo "\x3dffffffff" | xxd -r -p > foo.bin
:\>xxd -g 1 foo.bin
00000000: 3d ff ff ff ff =....
:\>objdump.exe -b binary -mi386 -D foo.bin
foo.bin: file format binary
Disassembly of section .data:
00000000 <.data>:
0: 3d ff ff ff ff cmp $0xffffffff,%eax
</code></pre>
<p>you can also use capstone,gdb,llvm,distorm,xed,.......as above</p>
| 26903 | 2021-01-30T03:15:41.960 | <p>How does the parser parse the machine code? Does it go byte by byte? How does it know how many bytes to read when parsing an instruction? Does it have some sorts of tables of bytes to translate the machine code via table directly into assembly like AST?</p>
<p>I am starting to understand how to <em>generate</em> the machine code from Assembly, but how do you go from machine code to assembly essentially, from machine code to an AST used by a VM? What are the general principles?</p>
<p>Are there any open source projects that demonstrate this for x86? I have seem many "x86 vms" on GitHub which interpret assembly instructions, but none that interpret machine code directly. I guess this would be some sort of reverse engineering project (maybe <a href="https://github.com/Recoskie/X86-64-Disassembler-JS" rel="nofollow noreferrer">this</a> is one?), but not sure where to look. Even something which takes the machine code and converts it to assembly string would be valuable to see, something similar to <a href="https://github.com/CyberGrandChallenge/binutils/blob/master/binutils/objdump.c" rel="nofollow noreferrer">objdump</a>, but ideally in JavaScript/Node.js :)</p>
<p><a href="https://github.com/intelxed/xed/blob/fc7480856ab134d0de376a177f4ae675eb9cdd81/src/dec/xed-ild.c#L1450-L1485" rel="nofollow noreferrer">This</a> looks like a good start, is this standard?</p>
<pre><code>void
xed_instruction_length_decode(xed_decoded_inst_t* ild)
{
prefix_scanner(ild);
#if defined(XED_AVX)
if (xed3_operand_get_out_of_bytes(ild))
return;
vex_scanner(ild);
#endif
#if defined(XED_SUPPORTS_AVX512) || defined(XED_SUPPORTS_KNC)
// evex scanner assumes it can read bytes so we must check for limit first.
if (xed3_operand_get_out_of_bytes(ild))
return;
// if we got a vex prefix (which also sucks down the opcode),
// then we do not need to scan for evex prefixes.
if (!xed3_operand_get_vexvalid(ild) && chip_supports_avx512(ild))
evex_scanner(ild);
#endif
if (xed3_operand_get_out_of_bytes(ild))
return;
#if defined(XED_AVX)
// vex/xop prefixes also eat the vex/xop opcode
if (!xed3_operand_get_vexvalid(ild) &&
!xed3_operand_get_error(ild) )
opcode_scanner(ild);
#else
opcode_scanner(ild);
#endif
modrm_scanner(ild);
sib_scanner(ild);
disp_scanner(ild);
imm_scanner(ild);
}
</code></pre>
<p>It looks like a lot of processing to figure out the instructions.</p>
<p>But alas, <a href="https://reverseengineering.stackexchange.com/questions/26904/where-is-the-xed-operand-accessors-source-code">some of the functions source code are missing</a>, like <code>xed3_operand_get_out_of_bytes</code>...</p>
| How do you build a virtual machine to interpret machine code? | |assembly|x86|machine-code|vm| |
<p>Disassembler: Converts machine code (executable binary) to human readable Assembly code.<br />
Decompiler: Converts machine code (executable binary) to higher level languages such as C/C++.</p>
| 26932 | 2021-02-03T12:49:44.877 | <p>I see many reverse engineering lessons and every second person does reverse engineer using Ghidra decompiler and not disassembler as both are available in the same platform. I assume that reversing using decompiler is easy than disassembler(understanding the assembly of the code). Do I'm thinking right?
let's say I'm using Ghidra then when should I see disassembler and when decompiler?
Plus If we have now a free decompiler available in Ghidra then the need for a disassembler is gone and there is no need of understanding the assembly when we have a decompiler?</p>
| Why do reversers nowadays reverse engineer using decompilers and not disassemblers? | |ida|binary-analysis|ghidra|disassemblers|decompiler| |
<p>so this crackme allocates two blocks of memory of size 0x10 and 0x8 and saves the result as buf1 and buf2</p>
<p>buf1 = malloc(0x10);
buf2 = malloc(0x08);</p>
<p>so to overflow into the first byte of second buffer the string must be of length
&buf2-&buf1</p>
<p>it does not write 0x20 bytes into a 0x10 long buffer it trashes/corrupts the memory after 0x10 bytes by overwriting or overflowing or spilling into memory not owned</p>
<p>the address in solution you quote are 20 bytes apart so to overflow into the first byte of second buffer you need 0x21 or 33 bytes</p>
<p>but it may happen that they are 8 bytes apart or 80 bytes apart in such cases you may need a 9 byte or 81 byte long exploit string</p>
<p>for understanding why 31 'A' works you may have to study the function fgets() which stops reading when a '\n' is encountered and how it null terminates the returned string after reading a valid character</p>
<p>shown below is a sample implementation and output</p>
<pre><code>:\>xxd input.txt
00000000: 4141 4141 4141 4141 4141 4141 410a 4141 AAAAAAAAAAAAA.AA
:\>cat fgets.cpp
#include <stdio.h>
#define BUFFERSIZE 16
int main(void)
{
char buffer[BUFFERSIZE] = {0};
buffer[BUFFERSIZE - 1] = 'Z';
buffer[BUFFERSIZE - 2] = 'Z';
for (int i = 0; i < BUFFERSIZE; i++)
{
printf("%02x ", buffer[i]);
}
printf("\n");
FILE *fp = NULL;
errno_t err = fopen_s(&fp, "input.txt", "rb");
if (err == 0 && fp != NULL)
{
fgets(buffer, BUFFERSIZE, fp);
for (int i = 0; i < BUFFERSIZE; i++)
{
printf("%02x ", buffer[i]);
}
printf("\n");
}
}
:\>cl /Zi /W4 /analyze /Od /EHsc /nologo fgets.cpp /link /release
fgets.cpp
:\>fgets.exe
00 00 00 00 00 00 00 00 00 00 00 00 00 00 5a 5a
41 41 41 41 41 41 41 41 41 41 41 41 41 0a 00 5a
</code></pre>
| 26938 | 2021-02-03T21:00:33.457 | <p>I am working with a <a href="https://crackmes.one/crackme/5f05ec3c33c5d42a7c66792b" rel="nofollow noreferrer">binary</a> that involves a buffer overflow on two contiguous memory blocks allocated with malloc. The binary filles up the first buffer with whatever the user inputs and hardcodes the second buffer to 1. There are a couple of solutions for this challenge that I do not understand. Please, consider the following:</p>
<ol>
<li>python3 -c "print('A' * 32 + '\x00' * 4)" | ./simple_overflow</li>
<li>python3 -c "print('A' * 31 + '\n')" | ./simple_overflow</li>
<li>perl -e "print \"A\" x 32 . \"\0\"" | ./simple_overflow</li>
<li>head -c 33 /dev/zero > input && ./simple_overflow < input</li>
</ol>
<p>The first solution is straight forward. It writes 32 bytes into the first buffer and then four null bytes into the second one. Writing 4 bytes makes sense since integers are 4 bytes in size. However, the second answer only writes 31 bytes plus '\n', and the third and fourth solutions use 33 bytes. The three of them work correctly (see screenshot).</p>
<p><a href="https://i.stack.imgur.com/liyDR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/liyDR.png" alt="enter image description here" /></a></p>
<p>If you need to check the asm associated with this binary please see <a href="https://reverseengineering.stackexchange.com/questions/26928/using-gdb-to-find-the-address-of-a-buffer-in-a-stripped-c-binary">here</a>.</p>
<p>Why do solutions 2 to 4 work? Are \n and \0 internally considered integers? What about \x00?</p>
<p><strong>Note:</strong> solutions provided by users nicknamed h0un6, bottonim and escalatedquickly.</p>
| Difference between \n, \0, \x00 and data from /dev/zero when performing a buffer overflow? | |disassembly|debugging|static-analysis|buffer-overflow|crackme| |
<p>You did not understand why your code is using an obfuscador, first you need to remove the obfuscador used by the developer to only then start the process of reconstructing the algorithm, use appropriate tools for this task like DIE (Detect It Easy), after discovering the name of the obfuscador look for a way to clear its torque, there are many ways for almost all obfuscadores.</p>
| 26949 | 2021-02-05T09:25:18.067 | <p><a href="https://i.stack.imgur.com/M3T0S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M3T0S.png" alt="enter image description here" /></a></p>
<p>i try to reverse this code but cant figure it out what is this number mean or how to call it...</p>
| Is the code like this reverse able? (from Assembly - UnityScript) | |disassembly|assembly|decompilation|disassemblers|byte-code| |
<p>Default VS compilation options do not enable debugging information generation so all function names are removed from the final executable (they're not required for execution). You need to build with debug info on and ensure that the PDB file is available when you open the exe in IDA.</p>
| 26955 | 2021-02-05T11:16:31.063 | <p>I've de-compiled in IDA 7.0 (freeware version) such a simple c program (compiled in the Microsoft Visual Studio Community 2019):</p>
<pre><code>#include <stdio.h>
#include <string.h >
char* sayHello(char* resultStr, char* addedStr) {
strcat_s(resultStr, strlen(resultStr)+strlen(addedStr)+1, addedStr);
return resultStr;
}
int main() {
char str_in_1[100] = "Hello";
char str_in_2[] = " World!";
printf ("%s", sayHello(str_in_1, str_in_2));
}
</code></pre>
<p>Now i can't find the string <code>sayHello</code> (function name) either in the <em>Functions window</em> nor in the <em>IDA View-A</em>. How to find out w</p>
| Disassembling Hello World program in IDA | |ida|disassembly|windows| |
<p>its very hard to understand what you want</p>
<blockquote>
<p>How to get machine code of a file(mainly executables) in C?</p>
</blockquote>
<p>so you want a C program that loads an executable file (for example dos,windows,linux exucutable) and showing you the whole or parts of the image (that normaly contains machine code and data)?</p>
<p>so there are several documented file formats that can contain machine code</p>
<ul>
<li>dos exe (legacy exe format: <a href="https://en.wikibooks.org/wiki/X86_Disassembly/Windows_Executable_Files" rel="nofollow noreferrer">https://en.wikibooks.org/wiki/X86_Disassembly/Windows_Executable_Files</a>)</li>
<li>windows exe (pe format: <a href="https://en.wikipedia.org/wiki/Portable_Executable" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Portable_Executable</a>)</li>
<li>linux (elf
format: <a href="https://de.wikipedia.org/wiki/Executable_and_Linking_Format" rel="nofollow noreferrer">https://de.wikipedia.org/wiki/Executable_and_Linking_Format</a>),</li>
<li>dynamic libraries</li>
<li>object files from several compilers in
omf, coff format</li>
<li>pure/properitary binary files with no documented
layout</li>
</ul>
<p>for example see IDAs supported files types: <a href="https://www.hex-rays.com/products/ida/file_formats/" rel="nofollow noreferrer">https://www.hex-rays.com/products/ida/file_formats/</a></p>
<blockquote>
<p>I have written a C program to convert machine code to assembly.</p>
</blockquote>
<p>so you've already got some sort of disassembler?</p>
<blockquote>
<p>But how to get machine code of a file?</p>
</blockquote>
<p>read the spec of your operating system file format and write a small loader/parser, there are serveral C,C++,go,python ... example on github/google...</p>
<blockquote>
<p>How would I go about programming a c program to convert a file to machine code?</p>
</blockquote>
<p>and now you revert you question completely - before - you ask how to load a file with machine-code and now you ask how to convert "a file" to machine-code</p>
<p>what format is "a file" in your example - some sort of source-code or object file format?</p>
<p>Normaly this is the way: C/C++/Assembler/whatever-Source --> Compiler --> Objectfiles --> OS-related-Executable-Format[Machine-Code+Data]</p>
<p>try to ask more precise - its easy to help you when its clear what your exact target is</p>
| 26956 | 2021-02-05T14:30:05.620 | <p>How to get machine code of a file(mainly executables) in C?
I have written a C program to convert machine code to assembly. But how to get machine code of a file? How would I go about programming a c program to convert a file to machine code?</p>
| How to extract machine code from a file(especially executable) in C | |c|executable|exe|machine-code| |
<p>No it does not all pe files do not start at the same address 0x401000<br />
<a href="https://devblogs.microsoft.com/oldnewthing/20141003-00/?p=43923" rel="nofollow noreferrer">historically 0x400000 is the ImageBaseAddress</a> Header is 0x1000 bytes<br />
so .code section starts at 0x401000 for a normal exe</p>
<p>since the Exe's module is the first to be loaded it normally gets its Preferred ImageBase Address</p>
<p>but a relocation table is a part of exe in case there is a conflict and the imagebase needs to be shifted to another base</p>
<p>you can control both aspects using linker switches</p>
<pre><code>C:\>link /? | grep -iE "base|fixed"
/BASE:{address[,size]|@filename,key}
/DYNAMICBASE[:NO]
/FIXED[:NO]
</code></pre>
<p>you can also lookup about rebasing in ida</p>
| 26959 | 2021-02-05T16:16:18.183 | <p>When i load an <code>exe</code> in the <em>IDA</em> the assembled code always starts at <code>00401000</code> address. Does it mean that in <code>pe</code> files the code always starts at that specific address?</p>
| Pe file code starting address | |ida|windows|pe|executable| |
<p>This is compiled to simple jump-table. Firstly it subtracts 1 from the <code>a</code> variable, so now your switch-case is for values in range <0;4> inclusive (instead of <1;5>). Next it checks if <code>a</code> is > 4, if so it jumps to the <code>default</code> label at <code>0A1109F</code>. Note that the <code>JA</code> instruction is for the unsigned values, so it will jump to the <code>default</code> label in case if your value of <code>a</code> is negative.</p>
<p>Now the magic happens. It jumps to the address inside jump-table, the jump-table is 5 elements long (because there are 5 cases in your switch), and each element is 4 bytes long (because you compiled it for 32 bit architecture, and the sizeof pointer is 32 bits there, that's why it's eax*4). The jump-table starts at <code>0A110E8</code>.</p>
<p>So if you dereference pointer at <code>0A110E8</code> you will get the address of "You chose one" block. Because for this case <code>eax=0</code>(it was decremented just moment ago), and <code>[eax*4+0A110E8] = [0A110E8]</code> now.</p>
<p>If you type <code>2</code> to the stdin, then <code>eax=1</code>, so <code>[eax*4+0A110E8] = [1*4+0A110E8] = [0A110EC]</code>. Now you can dereference the pointer 0A110EC and you will get the address of the second switch block, the address where the <code>JMP</code> instruction will redirect program flow in this case. The same rule applies for all the blocks.</p>
| 26975 | 2021-02-07T16:04:16.483 | <p>While I'm trying to disassemble my own C code I am stuck in a problem of not understanding how this Switch statement is implemented in assembly code. Can anyone please help to figure it out? This the switch assembly. Couldn't understand why so many registers are being used plus at the last line it's written "jmp dword ptr [eax<em>4+0A110E8h]". Is this eax</em>4 necessary for switch in assembly or did by the disassembler on its own?
<img src="https://i.stack.imgur.com/wPw2Z.png" alt="enter image description here" /></p>
<p>My C Code:</p>
<pre><code>main() {
int a;
printf("Please enter a no between 1 and 5: ");
scanf("%d", & a);
switch (a) {
case 1:
printf("You chose One");
break;
case 2:
printf("You chose Two");
break;
case 3:
printf("You chose Three");
break;
case 4:
printf("You chose Four");
break;
case 5:
printf("You chose Five.");
break;
default:
printf("Invalid Choice. Enter a no between 1 and 5");
break;
}
}
</code></pre>
| Not able to understand the C-switch statement in disassembly | |disassembly|binary-analysis|c|static-analysis|disassemblers| |
<p>If you are just starting out learn Assembly and Study C, and don't try to learn how to "unpack" commercial protectors (They are commercial for a reason), even if you want to insist on the error easily you will find scripts to do all the work for you, but I ask you, will you learn something new or just say that you know how to unpack with someone else's scripts? focus on the base, I recommend that you read <strong><a href="https://beginners.re/main.html" rel="nofollow noreferrer">beginners RE</a></strong>, if you want an excellent book read <strong>Practical Reverse Engineering: X86, X64, ARM, Windows Kernel</strong>(<strong>ISBN: 9781118787250</strong>), these books will teach you the necessary basics, after finishing your reading you will be able to unpack simple protections, and with a focus you will learn the tricks of commercial protectors and how to get rid of them and differentiate code virtualization, good studies.</p>
| 26997 | 2021-02-11T18:13:50.297 | <p>I would like to known where i can found guides to learn how to unpack packers like Themida, Armadillo, VMProtect, etc. I was searching challenges and guides but i could not found for packers, only other types of challenges. I have to learn how unpack that type of software, i'm new in this world of RE but i need to learn this. Thanks in advance.</p>
| Packers Material for learn how to unpack software | |packers| |
<p>Sounds possible, the difficulty of achieving it I think would depend on:</p>
<ul>
<li>how the objects are allocated (inline access vs allocator)</li>
<li>the type of references (direct addressing vs indirect)</li>
<li>the amount of references that there are to the objects</li>
</ul>
<p>If it's just a small number of references and allocations then it might not matter which method you use - the easiest and fastest would be the best I guess.</p>
<p>If that isn't the case then the next best might be where the allocation is through an allocation function and the references are all indirect. In that case there's no need to fix the references and you'd just need to patch the allocator - to use your custom memory.</p>
<p>If the allocation is inline or the access is direct then fixing the allocations and references might be done with relative ease if they are done using references which are resolved during the loading of the program - i.e relocations (<a href="https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-54839.html" rel="nofollow noreferrer">https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-54839.html</a>). You might then iterate over all the relocations in the relocations section and modifying the ones that refer to the objects structure in the <code>.data</code> section to point to your new <code>.dataex</code> section.</p>
<p>You also might want to take a look at lief (<a href="https://lief.quarkslab.com/" rel="nofollow noreferrer">https://lief.quarkslab.com/</a>). I haven't found your specific use case - but it might help with the boilport in implementing your solution.</p>
| 26999 | 2021-02-12T04:17:55.107 | <p>I have a program which creates a hard-coded number of objects. I patched the binary so that now it can attempt to create more objects than the limit allows, however when it does it allocates them to memory that wasn't supposed to be originally written to in the <code>.data</code> section. Here's an illustration:</p>
<p><a href="https://i.stack.imgur.com/pFIlZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pFIlZ.png" alt="enter image description here" /></a></p>
<p>I'm wondering what approach I should use tackle this. Right now, I used CFF Explorer to create a an exact copy of the <code>.data</code> section, called <code>.dataex</code>, which has double the size of <code>.data</code>, and put it at the end of the binary:</p>
<p><a href="https://i.stack.imgur.com/Ke2El.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ke2El.png" alt="enter image description here" /></a></p>
<p>My initial thought was that there is possibly some way to "shift" the references down so that the program will use the ones in <code>.dataex</code>, and then do another "shift", but this time only from <code>.dataex + n</code>. That way, there is more free space which the program can use to create new objects.</p>
<p>I realise I may be missing/overlooking/misunderstanding many things here, so please let me know if what I want to do is even possible, or if there exists a simpler solution.</p>
| Expanding .data section at particular area | |ida|disassembly|pe|memory|segmentation| |
<p>There are these binary that people make call crackmes. Usually made by the community for other people to learn without braking the law. Crackmes have different levels that sometimes is even harder to crack than softewares published by companies. I really like this website <a href="https://crackmes.one/" rel="nofollow noreferrer">https://crackmes.one/</a></p>
<p>There is also CTF or capture the flag which are security competitions of different parts of security. Companies like goggle have one per year a believe.</p>
<p>You can google about this two and you will get a lot of material</p>
<p>Happy hacking</p>
| 27003 | 2021-02-13T19:39:17.583 | <p><strong>I am surprised this question is not asked by anyone else yet.</strong></p>
<p>Legally, which software -- aside from open source software -- am I able to explore to basically enhance my knowledge of how computer systems work? I would like to add that I am not interested in doing something professional or advanced more suitable to the employees of IT industry. I just want to make myself more intelligent and knowledgeable, possibly delaying dementia and preventing chronic diseases. That is, I am not interested in maintaining virtual machines to reverse engineer malware/illegal software. Thank you.</p>
| Reverse engineering and copyright? | |law|copy-protection| |
<p>For .NET assemblies there's a .NET MetaData Directory that can be found in the Data Directories. From that you can get access to <code>MetaData Header</code> and <code>MetaData Streams</code> that holds all the info for you to extract and located the code.</p>
<p>A good start (or maybe even a complete guide) into this topic would be the "<a href="https://www.red-gate.com/simple-talk/blogs/anatomy-of-a-net-assembly-pe-headers/" rel="nofollow noreferrer">Anatomy of a .NET Assembly</a>" by Simon Cooper.</p>
<p>For the first question - yes, the <code>_CorExeMain</code> is the entry point that does all the tricks to make your assembly to execute. For the explanations of all the things that happen during that call check <a href="https://mattwarren.org/2017/02/07/The-68-things-the-CLR-does-before-executing-a-single-line-of-your-code/" rel="nofollow noreferrer">The 68 things the CLR does before executing a single line of your code</a></p>
| 27004 | 2021-02-14T05:41:51.903 | <p>When i compile a c# code, it compiles into a .NET executable, that only imports _CorExeMain from mscoree.dll, now my questions are :</p>
<ol>
<li><p>Is _CorExeMain the interpreter that fetches ILs and executes their corresponding x86 code just like VMprotect, etc?</p>
</li>
<li><p>Where are the IL bytes actually stored? they seem to be stored in the .text section, but i couldn't find any tool that can find the location that they are stored. where are they stored?</p>
</li>
</ol>
| Where are the .NET IL bytes stored in an .NET executable? | |windows|.net|c#| |
<p>Thereโs no 100% sure way to distinguish a virtual call from a function pointer call but there are some strong hints.</p>
<ol>
<li><p>The virtual function table (vftable) is <em>usually</em> at the very start of the object so assuming the objectโs address is stored in <code>objectreg</code>, you should see something like</p>
<pre><code>mov vftreg, [objectreg]
</code></pre>
</li>
<li><p>The object address (the <em>this</em> pointer) is passed to the virtual method, commonly as the first argument or in a separate register, according to the ABI in use. In Microsoft x86 the <code>ecx</code> register is used for this purpose so the common pattern is:</p>
<pre><code>mov ecx, objectreg
</code></pre>
</li>
<li><p>The call is performed using a slot in the vftable. It can be done either directly using a displacement from the register holding the vftable:</p>
<pre><code>call [vftreg+slotoff]
</code></pre>
</li>
</ol>
<p>Or via an intermediate register:</p>
<pre><code> mov callreg, [vftreg+slotoff]
call callreg
</code></pre>
<p><code>slotoff</code> should be a multiple of a pointer size and may be zero.</p>
<p>In case the method has arguments, they will be loaded as well (usually the <em>this</em> argument is initialized last, just before the call).</p>
<p>You may also find informative <a href="http://www.openrce.org/articles/full_view/23" rel="nofollow noreferrer">my old article</a> on the topic.</p>
| 27005 | 2021-02-14T08:28:34.567 | <p>I'm referring to this question that was asked previously:
<a href="https://reverseengineering.stackexchange.com/questions/26630/virtual-functions-call-asm/26634">Virtual functions call asm</a></p>
<p>I'm wondering how is it possible to know whether this ASM listing represents Virtual Functions calls? What's in the ASM mentioned in the question linked above that tells that this is Virtual Function call?</p>
| Why this ASM represents Virtual Function call? | |disassembly|c++|static-analysis|virtual-functions| |
<p>The C parser of Ghidra has various issues, e.g. it has a less extensive list of sane preprocessor variables and it just completely chokes on GCC attributes. I personally tried some approaches to make this work better, e.g. using the clang/gcc preprocessor to dump one giant header file, but they are still highly experimental and probably require a lot of tinkering, so I would overall just declare the C Parser as an nonviable approach for your problem.</p>
<p>The best way that I have heard of so far is to compile the library with full debug symbols in the version and target you need, then import that into Ghidra. Ghidra should then parse all the PDB/DWARF type information, create all the relevant types and apply the function signatures. Then you can link the library file to the binary you want to analyze in the first place, and propagate that information to it. <s>I don't know a tutorial for that right now, but Ghidra has good support for such projects that involve multiple binaries. If you encounter any issues with that, those are most likely worth a separate dedicated question, because this is then the same process as propagating type information from a library that you had to reverse engineer too.</s></p>
<p>Edit:
I needed to do this recently and wrote it up as a <a href="https://reversing.technology/2021/06/16/ghidra_DWARF_gdt.html" rel="nofollow noreferrer">small blogpost</a>.</p>
<p>The general approach is like I described, but the blogpost itself isn't in a format and as polished as I'd like a StackExchange answer to be, so I don't think that copying it here would be appropriate.</p>
| 27019 | 2021-02-16T00:18:45.040 | <p>I know that the program I am decompiling uses openSSL.<br />
I'd like to add the types from the <code>include</code> folder of the project to the data types.<br />
To do that, I use File => Parse C Source.<br />
I then select the <code>include</code> folder from <a href="https://github.com/openssl/openssl" rel="nofollow noreferrer">the openSSL project</a></p>
<p>For every parse configuration I get</p>
<pre><code>Encountered "<EOF>" at line 0 column 0
Was expecting one of:
"#line"...
<LINEALT>...
";"...
</code></pre>
<p>And if I try to import a subset of the .h files I get the following error because some types are not defined directly in the file.</p>
<pre><code>C parser: Encountered errors during parsing
</code></pre>
<p>Is there a way to import all the types from the source of a project ?</p>
| Ghidra add data types from open source project | |ghidra| |
<p>I think itโs under โFreescaleโ</p>
| 27028 | 2021-02-17T11:18:15.150 | <blockquote>
<p>Motorola/Freescale MC680xx, CPU32 (68330), MC6301, MC6303, MC6800,
MC6801, MC6803, MC6805, MC6808, HCS08, MC6809, MC6811, M68H12C,
ColdFire</p>
</blockquote>
<p>IDA claims to have the support for HCS08. But I can't see it in the list of the processors:
<a href="https://i.stack.imgur.com/RCouO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RCouO.png" alt="enter image description here" /></a></p>
<p>Should I use 6808? Or maybe HCS12?</p>
| Which processor do I specify when I load HCS08 firmware to IDA? | |ida|firmware| |
<p>use python,powershell,xxd -r, javascript<br />
anything that you can script read a group of 2 char and make it one byte;</p>
<p>demo using binascii in python</p>
<pre><code>:\>type asc2hex.py
import sys
import binascii
if(len(sys.argv)==2):
inf = open(sys.argv[1],"rb");
ouf = open("hex"+sys.argv[1] , "wb")
dat= inf.read()
inf.close()
ouf.write(binascii.unhexlify(dat))
ouf.close()
:\>type foo.bin
4d5a
:\>asc2hex.py foo.bin
:\>type hexfoo.bin
MZ
:\>
</code></pre>
| 27039 | 2021-02-18T04:39:24.063 | <p>I extracted pe file from another pe file and I saved it.</p>
<p>I want it execute but when I saved file computer sees it like text file. Altough my actual file starting with "4d 5a" computer sees like text and converts it "34 64".
How can I solve this problem?</p>
<p><a href="https://i.stack.imgur.com/rRBLJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rRBLJ.png" alt="enter image description here" /></a></p>
| how do i use the text like in pe files? | |pe|file-format| |
<p>Yes this is absolutely possible.</p>
<ul>
<li>First, you need to attach a debugger to the executable file and play around with the functionality you are interested in (i.e use it multiple times while keeping an eye on the debugger, stack, interesting memory regions, etc... Usually the shortest path for finding a function is by looking for string/values references and tracing back from there) until you are able to find the starting address of the function in the EXE file (or one of the loaded modules).</li>
<li>After finding the function, you need to check the parameters as well as their correct data types, that's a bit of static analysis where you try to analyze the stack and the type of arithmetic instructions (for instance <code>imul</code> vs <code>mul</code>).</li>
<li>Now you've got both the function address and the correct parameters, from there you can code a DLL that gets injected into that executable on runtime, then hooks the target function and map it to whatever keyboard key(s) you want.</li>
</ul>
<p>This trick is used extensively in game hacks and trainers, especially trainers that use the printing functions of a game to print some custom values at runtime.</p>
| 27056 | 2021-02-20T14:51:16.560 | <p>my Problem is, i have bought a Huion Kamvas 22 Plus pen display for drawing and painting.</p>
<p>On my old Wacom tablet i had some hardware buttons and could map functions/setting of the driver to these hardware buttons.</p>
<p>The new Huion Monitor doesnt have any Hardware Buttons! Thats ok , i just use keyboard shortcuts anyways ...</p>
<p><strong>But theres one problem,</strong></p>
<p>the huion driver window has a function called "switch screen". with that i can switch the mouse output from the Pen to another monitor (in a multi monitor setup). This cant be mapped to any keyboard shortcut though , just (eventual) hardware buttons which come with the huion displays. As i mentioned, my model(the Kamvas 22 plus) doesnt have any buttons though.</p>
<p>Now i want to</p>
<p>A)</p>
<p>find the specific function/argument in a file called "TabletDriverCore.exe" or any of its loaded dlls</p>
<p>and B)</p>
<p>run this function(+ correct arguments) from the command line / autohotkey / whatever</p>
<p>is that possible and how would i achieve that ?</p>
| FINDING & EXECUTING a function from an exe/dll (not compiled by me)? | |dll|exe| |
<p>They might be stored encoded/encrypted and decoded/decrypted in runtime, you can validate this if you can capture any API calls in runtime (Not sure if you tried this, but maybe give it a try, in that case you may deal with SSL Certificate Pinning).
Another possibility is that they might be split, I faced that case couple of times where only the base address of the APIs were stored at the resources string XML files, while the rest of the URIs are declared when used only. You may validate this by looking for some common substrings found in APIs like "/api", "/v", "/send", "/user", etc...</p>
| 27057 | 2021-02-20T15:05:44.750 | <p>i have two apk files , when i decompile them using apktool i can take a look at decompile code , so here is what really confuse me , in the first apk if i searched the hole files for strings witch begin with "https" or "http" i can get all the api urls for that app , but the second apk doesn't work the same way it give me nothing just some google api urls witch belong to google that i dont need , so my question is , why my searching method work in the first apk but not in the second apk , maybe in the second app the urls string are encrypted ,but why the developer would do something like this seems pointless to me because even if the urls are encrypted i can capture them using Wireshark or others capturing tools (i don't want to use the capturing tools just decompiling tools if you could just help on that it would be great)</p>
| finding rest api urls after decompiling apk | |android|apk|api|https-protocol| |
<p>I gave it my shot at this question but the output is still very obfuscated code you will need to re-run it a few passes through some more deobfuscators the code has alot of goto's code and math, you can do it all by hand but it will take months!.</p>
<p>It seems it contains classes to
<code>com.mojang.brigadier.exceptions.CommandSyntaxException</code></p>
<p>Which means this jar file is for Minecraft game.</p>
<p>Since it's for minecraft I found this.
<a href="https://github.com/PetoPetko/Minecraft-Deobfuscator3000" rel="nofollow noreferrer">https://github.com/PetoPetko/Minecraft-Deobfuscator3000</a></p>
<p>I played around with Minecraft Deobfuscator 3000 it seems it renames all fields/methods/params based on 2 different minecraft versions 1.7.10 and 1.12</p>
<p>You would need to get mappings for whichever version this encrypted java file used, both mappings versions failed for me.</p>
<p><img src="https://i.imgur.com/MxjKxn2.png" alt="minecraft" /></p>
<p>This may help you also it's a site with like 6 different online java decompilers.. you can try all 6.
<a href="http://www.javadecompilers.com/" rel="nofollow noreferrer">http://www.javadecompilers.com/</a></p>
<p>This tool also looks very promising on this project.
<a href="https://javadeobfuscator.com/" rel="nofollow noreferrer">https://javadeobfuscator.com/</a>
<br>
(Takes about 3 hours with all transformations and does help with this project..)<br>
Use Transformers:</p>
<pre><code>allatori.FlowObfuscationTransformer
special.FlowObfuscationTransformer
normalizer.SourceFileClassNormalizer
</code></pre>
<p>mess around with the <code>general.peephole</code> remove the Transformers that fail.. I removed 2 of em. <code>RedundantGotoRemover</code> and <code>PeepholeOptimizer</code> the PeepholeOptimizer does do alot of fixes but it crashes.. so maybe you can run it somehow at the very end.</p>
<p>Try getting in contact with Janmm14 or samczsun he made the <a href="https://javadeobfuscator.com/" rel="nofollow noreferrer">https://javadeobfuscator.com/</a> and also works on Minecraft mods so he can help you 100% on this issue.</p>
<p><a href="https://github.com/Janmm14" rel="nofollow noreferrer">https://github.com/Janmm14</a>
<br>
<a href="https://github.com/samczsun" rel="nofollow noreferrer">https://github.com/samczsun</a></p>
<p>The Fernflower or CFR works on some files, Krakatau doesn't seem to work.</p>
<p><strong>CFR gives the best results..</strong></p>
<p>Output Decompiled Files: <a href="http://www.mediafire.com/file/fh74g6uovc4ji2i/encrypted+output.zip/file" rel="nofollow noreferrer">http://www.mediafire.com/file/fh74g6uovc4ji2i/encrypted+output.zip/file</a></p>
<p>I used Procyon on your <code>encryptedFolder.zip</code> it managed to decompile all the files without a problem although some stuff bytecode isn't fully implemented in Procyon so some functions just got comments (no code).</p>
<p>Here is a example of 1 of your files how the code looks like.</p>
<p><a href="https://i.stack.imgur.com/JQlP5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JQlP5.jpg" alt="a" /></a>
<a href="https://i.stack.imgur.com/iVN4O.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iVN4O.jpg" alt="b" /></a></p>
<p>Procyon can generate java code for any java class which will compile without problems.. (wasn't the case for this example, won't compile). Since it is still obfuscated like crazy.</p>
<p>People in the RuneScape hacking community mastered the skill of Java deobfuscating they can unprotect any java code, pretty sure you can find a product in the RuneScape Hacking Community which will do a perfect job.
The tools they use are Zelix KlassMaster, Kopi Java Compiler Suite, jode, and Procyon. That's pretty much all you need.</p>
<p>You may find all you need from this github project
<a href="https://github.com/Rune-Status/rscdump.com-runescape-classic-dump" rel="nofollow noreferrer">https://github.com/Rune-Status/rscdump.com-runescape-classic-dump</a></p>
<p>it has a bunch of runescape java projects that were made in the community which has a bunch of deobfuscators.</p>
<p>When runescape protection got more stronger each time, the community started building their own deobfuscators using java asm, which can outperform any java deobfuscator currently in the public.</p>
<p>You can find some deobfuscators in the public from runescape community on github. I was a member of the runescape community for like 10 years and let me tell you those people are very talented when it comes to java and hacking. One of the users who worked in the Runescape hacking community went on and created a popular website called pastebin.com which shows how smart they are :)</p>
<p><a href="https://github.com/search?q=runescape+deobfuscator" rel="nofollow noreferrer">https://github.com/search?q=runescape+deobfuscator</a></p>
| 27085 | 2021-02-24T02:53:49.880 | <p>I recently downloaded a <code>jar</code> file and was curious to see if it was malicious, so I ran it through <code>FernFlower</code> and it wasn't able to deobfuscate it. When I unzipped the jar, I looked inside it and saw multiple folders, maybe 40~ ish consisting of a mixture of Chinese, Korean, and Arabic. This was raising a heavy red flag for me; so I tried multiple decompiliers consisting of things like JD-Gui, Bytecode viewer, and Krakatau. All seemed to decompile the normal folders fine, but not the mixed language ones.</p>
<p>I think its safe to say that whoever made this jar, clearly didn't want me to check whats inside. I want to make sure it's not a malicious <code>jar</code> file (like I said earlier...)</p>
<p>So how would I go around deobfuscating the jar file?</p>
<p>Because the entire jar is <code>73MB (yikes)</code>, here is a <a href="http://www.mediafire.com/file/n7d38rcj6dmcuu3/encryptedFolder.zip/file" rel="nofollow noreferrer">zip</a> file of one of the language folders</p>
| How to decompile heavily obfuscated classes mixed with Arabic/Chinese/Korean characters? | |java|deobfuscation|jar| |
<p>Note to self, when running <code>memory.removeBlock(blk, monitor)</code> make sure that the memory map is not empty from previous wipes/redefinitions (iterations of the script).</p>
<p>In other words, opening a file creates a default memory map, but the script wasn't contemplating the case where the address map was empty to begin with.</p>
| 27089 | 2021-02-24T11:49:45.517 | <p>I figured it'd be more appropriate to ask this question here:</p>
<p><a href="https://github.com/NationalSecurityAgency/ghidra/issues/2530#issuecomment-785007613" rel="nofollow noreferrer">https://github.com/NationalSecurityAgency/ghidra/issues/2530#issuecomment-785007613</a></p>
<p>Given this linear address space a particular MCU:</p>
<p><a href="https://i.stack.imgur.com/ok1wt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ok1wt.png" alt="V850 mem space" /></a></p>
<p>It's not easily definable as-is on the memory manager, see:</p>
<pre><code>memory = currentProgram.getMemory()
fb = memory.getAllFileBytes()
blk = memory.getBlock(toAddr(0x0))
memory.removeBlock(blk, monitor)
memory.createUninitializedBlock("internal_ram",toAddr(0x3ff8000),0x2fff,False)
memory.createUninitializedBlock("peripherals", toAddr(0x3ffefff),0xfff, False)
memory.createInitializedBlock("rom", toAddr(0x0), fb[0], 0, 0x1000000, False)
disassemble(toAddr(0x0))
</code></pre>
<p>Yields:</p>
<pre><code>Traceback (most recent call last):
File "python", line 1, in <module>
at ghidra.program.database.mem.MemoryMapDB.checkBlock(MemoryMapDB.java:1043)
at ghidra.program.database.mem.MemoryMapDB.removeBlock(MemoryMapDB.java:1850)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Blocks do not belong to this program
ghidra.program.database.mem.MemoryBlockDB@6f03ae13
ghidra.program.database.mem.MemoryBlockDB@38d5ac1c
ghidra.program.database.mem.MemoryBlockDB@6ad8b9ac
</code></pre>
<p>What would be the correct sequence of arguments/flags/(instruction ordering?) to have a correct representation of a loaded V850 16MB firmware (size 0x1000000) on Ghidra? What am I doing wrong?</p>
<p><a href="https://github.com/NationalSecurityAgency/ghidra/files/6035639/nec-.PD703128-mem-address-1.pdf" rel="nofollow noreferrer">Here's the MCU PDF address space section for reference</a></p>
| Wrap-around MCU memory map definition with negative addresses | |ghidra| |
<p>This is possible. You can select desired analysis options in the <code>prescript</code>. Checkout this function - <a href="https://ghidra.re/ghidra_docs/api/ghidra/app/script/GhidraScript.html#setAnalysisOption(ghidra.program.model.listing.Program,java.lang.String,java.lang.String)" rel="nofollow noreferrer">setAnalysisOption</a> in <code>GhidraScript</code> class. You can also look @ this <a href="https://github.com/NationalSecurityAgency/ghidra/blob/2b08598dbabe6a9c911e712bd928e5f84fb00ee8/Ghidra/Features/Base/ghidra_scripts/TurnOffStackAnalysis.java" rel="nofollow noreferrer">example</a> script.</p>
<p>So, in your case you can do something like:</p>
<pre><code>from ghidra.app.script import GhidraScript
setAnalysisOption(currentProgram, "ARM Constant Reference Analyzer", "false")
</code></pre>
| 27094 | 2021-02-24T17:42:44.840 | <p>Basically, Ghidra in headless mode is divided into three phases: preScript, analysis, and postScript.</p>
<p>Pre/post scripts are written extending the <a href="https://ghidra.re/ghidra_docs/api/ghidra/app/script/GhidraScript.html" rel="nofollow noreferrer">GhidraScript</a> class, while analysis ones extend the <a href="https://ghidra.re/ghidra_docs/api/ghidra/app/services/AbstractAnalyzer.html" rel="nofollow noreferrer">AbstractAnalyzer</a> class.</p>
<p>When you run Ghidra in headless mode, you can specify which pre/post scripts you want to run (<code>-preScript</code> and <code>-postScript</code> options).</p>
<p>My questions is: how do I choose which analyses to perform?</p>
<p>For example, if I run this command:</p>
<pre><code>./analyzeHeadless /tmp test -import ~/Downloads/test.elf -scriptPath ~/ghidra_scripts/ -postScript TestScript.java
[...]
INFO -----------------------------------------------------
ARM Constant Reference Analyzer 14.667 secs
[...]
Subroutine References - One Time 0.000 secs
-----------------------------------------------------
Total Time 86 secs
-----------------------------------------------------
(AutoAnalysisManager)
</code></pre>
<p>How can I exclude the <code>ARM Constant Reference Analyzer</code> and add another analysis?</p>
| Specify which analyses to perform in Ghidra headless mode | |ghidra| |
<h1>Findings</h1>
<p>After some digging around in GitHub (turns out several of the portal component's source code is worryingly on GitHub, although I had to decompile it), I discovered that the string is generated using the <strong>AES Rijndael Algorithm</strong>.</p>
<p>I was able to succesfully generate the second string using an arbitrary key like <code>"#lk$.346hopHXIsd"</code> (changed for security reasons). I was unable to do the same for the first one. I suspect a different key is used as both emails correspond to two different kinds of users. I will draft a program that will brute force several keys until it finds a match. Will report back in case this helps (or entertains) anyone.</p>
<p><strong>Edit:</strong></p>
<p>I found a GitHub repo that did several requests to the server, so figured it might have some answers. After browsing through the code, and decompiling a source file (conveniently named Authentication), I extracted the key.</p>
<p><strong>Edit 2:</strong></p>
<p>The key matched one of the cyphered strings. However, as @Robert points out, it is virtually impossible to brute force the algorithm. I will try other methods. I leave this thread open to suggestions and in case it is of help to anyone :D</p>
<p><strong>Edit 3:</strong>
Solved.</p>
| 27097 | 2021-02-24T20:06:50.240 | <h1>TL; DR</h1>
<p>Is there any way you might suggest decrypting this cookie? It was saved under the name <em>mail</em>, so I suspect it encrypts an email address:</p>
<p><code>4520382156EFC790B5B54696C4E175B5695F03D2D59C33858A62D6CDA18B7AB2</code></p>
<p><strong>Edit:</strong> Here is another one using another account:</p>
<p><code>BFE069DB7B7FDED51A7F81DF8CE3CAD8FB8B14D70BE3FA32F26C4A2136170CD6</code></p>
<h2>Motivation</h2>
<p>When using a web portal, I noticed the same cookie is generated for my username every single time (i.e., it does not appear to be random). My concern is that there are several API endpoints with private info that can be accessed anonymously just using said string in the URL.
I suspect the string is a kind of user identifier, but I am not sure if it is generated using the values from my email address, or randomly based on time of creation.</p>
<h2>More details</h2>
<p>I can't go into specifics as I don't want this flaw to be exposed, compromising my info and getting me into trouble. However I know the portal is hosted on <strong>Microsoft IIS Server</strong> and built using the <strong>ASP.NET</strong> framework. I also suspect the implementation is rudimentary, so they probably aren't doing anything more sophisticated.</p>
| Reverse engineer decryption of cookie | |decryption|websites| |
<p>You can use <code>Edit->Functions->Remove function tail</code> to remove the block from whichever function is claiming it as a tail, and <code>Append function tail</code> to add it to the other one. However, this might be a waste of time. Given that the program is obfuscated, it might well be the case that IDA's ordinary analysis techniques and data abstractions for functions aren't very useful -- this is commonly the case for obfuscated code. Do you have a specific reason for wanting the function boundaries to be correct? Is it interfering with something else you're trying to do?</p>
| 27107 | 2021-02-26T07:34:09.313 | <p>I have a function <code>MyFunc</code> in an obfuscated program as follows:</p>
<pre><code>Start address: .text:000000014219FC5D
End address: .text:000000014219FD0E
</code></pre>
<p><code>MyFunc</code> starts off by jumping to <code>.text:000000014143C159</code>, which is recognized correctly by IDA as <code>FUNCTION CHUNK FOR MyFunc</code>.</p>
<p>This basic block jumps to <code>.text:000000014000B524</code>, which is not recognized correctly by IDA. IDA recognizes it as a completely unrelated function. There are 0 other xrefs to this block in the program.</p>
<p>I'm guessing the problem is that the basic block is lower in address than the function start, so IDA can't consider it as a basic block of <code>MyFunc</code>. I'm guessing that the obfuscator splits basic blocks and then shuffles them (mixing them together with BBs from other functions).</p>
<p>What is the recommended approach to take in order to get analysis working?</p>
| IDA refuses to recognize basic block as part of function that jumps to it | |ida|deobfuscation| |
<p>You are looking for <code>DecodeInstruction(ea)</code> in <code>idautils</code> module (I am referring to idapython api).</p>
<p>It returns: <code><class 'ida_ua.insn_t'></code> type object.</p>
<p>In Ida sdk that'd be <a href="https://www.hex-rays.com/products/ida/support/sdkdoc/ua_8hpp.html#af83aad26f4b3e39e7fbda441100f15cf" rel="nofollow noreferrer">decode_insn</a> function.</p>
| 27129 | 2021-03-01T18:01:20.467 | <p>So I was looking around the IDA SDK and I saw <code>insn_t</code> - it looked useful - any ideas how can I retrieve it - I wasn't able to find any function that returns it.</p>
| How to retrieve an `insn_t`? | |ida|idapro-sdk| |
<p>It took me some time to realize that the 2 helps were kind of combined into one.</p>
<p>The first question mark symbol can mean either help or evaluate math expression. The second and third are optional if used in the context of evaluating an expression.</p>
| 27149 | 2021-03-04T06:59:24.787 | <p>So I run radare2 from the command line with <code>r2 -</code> and attempt to display the help with the <code>?</code> command. I read this line which says:</p>
<p><code> ?[??][expr] Help or evaluate math expression</code></p>
<p>I am not sure how to read this. I assume the first <code>?</code> is <code>Help</code> command. And the rest <code>[??][expr]</code> is evaluate math expression. However, something like this <code>?? 0xa</code> does not return anything. So, my question is how to correctly interpret this output from the help.</p>
| Interpret radare2 help | |radare2| |
<p>In order to see what is going on, let's use the value of <code>0x1080</code> for the initial <code>sp</code>.</p>
<p>The stack pointer at the beginning:</p>
<pre><code>esp -> 0x1080
</code></pre>
<p>after <code>sub esp,0x60</code>:</p>
<pre><code>esp -> 0x1020
</code></pre>
<p>So the stack frame of the function is between <code>0x1080</code> and <code>0x1020</code>.</p>
<p>The stack grew from <code>0x1080</code> to <code>0x1020</code>, that why it grows under - from the higher value to the lower.</p>
<p>Then, <code>esp+0x5c</code> is: <code>0x107c</code>.</p>
<p><code>0x107c</code> Is within the stack frame of the function.</p>
| 27152 | 2021-03-04T14:39:30.753 | <p>I am currently learning RE and I came upon this piece of code which made me question whether stack frames grow upward:</p>
<pre><code>0x080483f4 <main+0>: push ebp
0x080483f5 <main+1>: mov ebp,esp
0x080483f7 <main+3>: and esp,0xfffffff0
0x080483fa <main+6>: sub esp,0x60
0x080483fd <main+9>: mov DWORD PTR [esp+0x5c],0x0
</code></pre>
<p>So I understand that from <code><main+0></code> until <code><main+6></code>, we're setting up the stack frame. Being that the stack grows downwards, it makes sense that we <code>sub esp,0x60</code> thereby allocating 96 bytes for the main function's stack frame.</p>
<p>My confusion/doubts, however start on <code><main+9></code> <code>mov DWORD PTR [esp+0x5c],0x0</code> which from what I understood stores the value <code>0</code> in a location 4 bytes above the stack pointer and we know that the stack grows downwards, but this operation seems to indicate that the data in the stack frame is stored bottom up.</p>
<p>So my question is, does that mean that while the stack as a whole grows downwards individual stack frames actually grow upwards?</p>
| Do Stack frames grow upwards? | |disassembly|assembly|stack| |
<p>Yes, it is possible to perform the necessary loading steps in the injector process (i.e., resolving the import addresses) before injecting the DLL, and some injectors/malware do that. See for example address <code>0x18007CD00</code> in <a href="https://github.com/RolfRolles/IDBs/tree/master/ComRAT%20v4" rel="nofollow noreferrer">my ComRAT IDB</a>.</p>
<p>However, doing it that way is more cumbersome, as some of the neccessary DLLs might not already be loaded by the target process (nor the injector process). Therefore, you'd have to inject one or more threads into the target to load the imported DLLs before injecting. To get the addresses of the imported functions, you'd either have to load the DLLs in the injector process also (which should work, since Windows ASLR does not re-randomize the base addresses of a DLL that is already loaded, because the memory for the DLL will be shared), or you'd have to resolve the import addresses within the target process, hence more threads to create. Reflective loading bypasses this by forcing the DLL to load its own imports before beginning normal execution.</p>
| 27157 | 2021-03-05T22:01:59.880 | <p>I'm not sure i understand reflective loading.</p>
<p>An injector process allocates memory in the target, writes a stub and the dll binary to be loaded, and the stub calls ReflectiveLoad in that binary. ReflectiveLoad then does what the windows loader would do so that the dll is properly mapped and has access to the imports if needs.</p>
<p>What confuses me is, could the manual loading portion in principle be done by the injector, still achieving no dropped files? By this I mean reading the target's memory from the injector's process to figure out how the dll needs to be loaded in the target at the address of the allocated memory. Is it a matter of need or convenience? Why exactly has this choice been made?</p>
| Why does reflective dll injection need to perform loading in the target process? | |dll-injection| |
<p>I think intercepting system calls can be done in at least 3 ways:</p>
<ol>
<li>registering a handler for the SIGSYS signal</li>
<li>using <code>seccomp()</code> to filter system calls</li>
<li>selective syscall userspace redirection with <code>prctl()</code></li>
</ol>
<p>From <a href="https://lwn.net/Articles/824380/" rel="nofollow noreferrer">Emulating Windows system calls in Linux</a>:</p>
<blockquote>
<p>To run with any speed at all, Wine must run Windows code directly on the CPU to the greatest extent possible. That must end, though, once the Windows program makes a system call; trapping into the Linux kernel with the intent of making a Windows system call is highly unlikely to lead to good results. Traditionally, Wine has handled this by supplying its own version of the user-space Windows API that implemented the required functionality using Linux system calls. As explained in the patch posting, though, Windows applications are increasingly executing system calls directly rather than going through the API; that makes Wine unable to intercept them.</p>
<p>The good news is that Linux provides the ability to intercept system calls in the form of seccomp(). The bad news is that this mechanism, as found in current kernels, is not suited to the task of intercepting only system calls made from Windows code running within a larger process. Intercepting every system call would slow things down considerably, an effect that tends to make gamers particularly cranky. Tracking which parts of a process's address space make Linux system calls and which make Windows calls within the (classic) BPF programs used by seccomp() would be awkward at best and, once again, would be slow. So it seems that a new mechanism is called for.</p>
<p>The patch set adds a new memory-protection bit for mmap() called PROT_NOSYSCALL which, by default, does not change the kernel's behavior. If, however, a given process has turned on the new SECCOMP_MODE_MMAP mode in seccomp(), any system calls made from memory regions marked with PROT_NOSYSCALL will be trapped; the handler code can then emulate the attempted system call.</p>
</blockquote>
<p>More info:</p>
<ul>
<li><a href="https://lwn.net/ml/linux-kernel/20200712044516.2347844-2-krisman@collabora.com/" rel="nofollow noreferrer">[PATCH v3 1/2] kernel: Implement selective syscall userspace redirection</a></li>
<li><a href="https://lwn.net/Articles/826313/" rel="nofollow noreferrer">Emulating Windows system calls, take 2</a></li>
<li><a href="https://www.kernel.org/doc/html/latest/admin-guide/syscall-user-dispatch.html" rel="nofollow noreferrer">Syscall User Dispatch</a></li>
</ul>
| 27169 | 2021-03-06T23:28:58.910 | <p>I have a binary calling <code>syscall</code> with a code not present on the Linux kernel.</p>
<p>Is it possible that the binary catches the syscall by itself and handles it on-the-fly?</p>
<p>Furthermore, what happens if I call <code>syscall</code> with an invalid code? e.g. <code>syscall(666, args...)</code></p>
<p>I've searched the internet for answers and didn't find anything.
I am aware that syscalls are defined when the kernel boots, so getting an "exotic" syscall to works seems weird at least.</p>
| Is it possible to intercept syscalls with a custom code from inside the program? | |linux|syscall| |
<p>To have an overview of called API in a function you can use Graph feature without pluging :</p>
<ul>
<li>select function</li>
<li>click on menu <code>View > Graphs > Users xrefs chart...</code></li>
<li>in <code>Starting Direction</code> check only <code>Cross references from</code></li>
<li>in <code>Ignore</code> group, check all except <code>Externals</code></li>
</ul>
<p><a href="https://i.stack.imgur.com/W5ioW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W5ioW.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/2Miir.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2Miir.png" alt="enter image description here" /></a></p>
| 27170 | 2021-03-07T02:01:33.927 | <p>I know it's a silly question </p>
<p>I'm using IDA and I want to know if there is a plugin to identify all called APIs inside a function instead of entering each function manually?</p>
| Identify APIs inside functions | |ida-plugin| |
<p>This is not really a re related question. But you can do something like this:</p>
<pre><code>python3 -c 'import string;print(string.ascii_letters)'
</code></pre>
| 27173 | 2021-03-07T03:32:55.123 | <p>I am wanting to execute python command by using python -c but it contain in string library so i need import it.
While reading man i find this:</p>
<pre><code>when called with -c command, it executes the
Python statement(s) given as command. Here command may contain multiโ
ple statements separated by newlines. Leading whitespace is signifiโ
cant in Python statements! In non-interactive mode, the entire input
is parsed before it is executed.
</code></pre>
<p>For example I've tried python3 -c "import string \n print(string.ascii_letters)"
but it didn't work. So what is it new line?</p>
| How to use two commands in python -c? | |python| |
<p>Yes, it is explicitly <a href="https://github.com/x64dbg/x64dbg/issues/1453" rel="nofollow noreferrer">not supported</a> on the issues page, however, if you are very serious about using x64dbg, it does support writing plugins that create breakpoints and react to debugger events such as breakpoints being hit... so you could write your own plugin that does what you want.</p>
| 27177 | 2021-03-07T09:57:29.987 | <p>This is something I know how to do in Olly Debugger, and can't figure out how to do in x64dbg.</p>
<p>In Olly Debugger, it's possible to set a hardware <strong>or</strong> software breakpoint, either on access or on write, to a <strong>memory address.</strong></p>
<p>To be clear: I am referring here to <em>memory</em> breakpoints, which are set by right clicking an address in the dump window. I am <em>not</em> referring to execution breakpoints, like the INT3 breakpoints you can set in the CPU window when you hit F2.</p>
<p>In Olly Debugger, the only practical differences between hardware and software breakpoints is that you're limited to four hardware breakpoints, and with hardware breakpoints, EIP points to the next instruction so you can't see the state of registers or memory before hitting the breakpoint.</p>
<p>In x64dbg, it is also possible to set both hardware or software breakpoints on memory. However, in x64dbg the software memory breakpoints always apply to the <em>entire section</em> in which the memory address resides, which makes software memory breakpoints close to useless (I assume it is just using VirtualProtect to guard the whole section, then breaking on any and all access to the section.) In Olly it was possible to set an unlimited number of <em>software, not hardware,</em> memory breakpoints for an <em>individual byte</em> of memory in the dump window.</p>
<p>Am I just dumb? Is x64dbg really missing this feature?</p>
| In x64dbg, how to set software breakpoint on specific memory address? | |memory|x64dbg|dynamic-analysis|breakpoint| |
<p>Last time I had that a problem like that, I loaded the executable with auto-analysis disabled, then ran a script that detected valid and invalid branches, and patched the valid branches to be non-conditional and nopped out the invalid branches. After that, I just enabled auto-analysis, and as the invalid branches were removed, the analysis results were fine.</p>
<p>Of course, this depends on being able to find the valid and invalid branch <em>instructions</em>, not just their <em>targets</em>. I am unsure what you mean by "a list of known-valid branches", but in case you know the location of the valid branch instructions, or you can write a simple analyzer that detects the patterns with invalid branches, a preprocessor might be a good way to handle the problem.</p>
| 27184 | 2021-03-08T06:04:12.150 | <p>Obfuscation techniques such as opaque predicates often trick IDA's auto-analysis into creating incorrect or contradicting interpretations of the code under analysis.</p>
<p>There is some mention of controlling IDA's auto-analysis via hooks on the <a href="https://www.hex-rays.com/blog/improving-ida-analysis/" rel="nofollow noreferrer">IDA website</a>, however I cannot find other references to this online.</p>
<p>In my case, I have a list of known-valid branches and I want IDA to "prefer" these branches during auto-analysis in order to avoid sp-analysis and invalid decompilation issues.</p>
<p>I have been able to essentially mimic this functionality by scripting my own analysis pass that ignores non- known-valid branches, but I wonder if there is an easier way.</p>
| How to deal with IDA auto-analysis analyzing invalid paths? | |ida|idapython|deobfuscation| |
<p>In addition to what Christian said, I'd like to mention radare's rabin2 tool. The output will defiantly not be perfect. But, it will give you an idea (or sort of a prediction, give it a try!).</p>
<p>You can do:</p>
<pre><code>rabin2 -I a.out | grep lang
</code></pre>
<p>It will output:</p>
<pre><code>$ rabin2 -I a.out | grep lang
lang c++
</code></pre>
<p>Here <code>-I</code> flag extracts binary information.</p>
| 27185 | 2021-03-08T08:16:41.910 | <p>I want to run a quick analysis on a very large number of binaries and determine the language of each one.</p>
| Is there a standalone cli tool which can detect which programming language a binary was written in? | |program-analysis| |
<p>since this is tangentially related to query<br />
I am adding this as another answer instead of editing the first answer<br />
it appears the code in question possibly ignores compiler warnings</p>
<pre><code><source>: In function 'int main()':
<source>:11:40: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
11 | std::cout << foo(std::string("H"), "ello World!\n");
| ^~~~~~~~~~~~~~~
Compiler returned: 0
</code></pre>
<p>so a 32 bit address like 0x880d32 is passed as an argument to a 64 bit program</p>
<p>i was wondering under what circumstances edx would be passed instead of rdx<br />
so i <a href="http://demangler.com/" rel="nofollow noreferrer">demangled</a> the</p>
<pre><code> _ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_PKS5_
</code></pre>
<p>which resulted in</p>
<pre><code>std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, char const*)
</code></pre>
<p>so the code in question actually uses an <strong>Rvalue Reference Declaration</strong></p>
<p><strong>c++11 feature <a href="https://en.wikipedia.org/wiki/C%2B%2B11#Rvalue_references_and_move_constructors" rel="nofollow noreferrer">gccrvalueref</a> , <a href="https://docs.microsoft.com/en-us/cpp/cpp/rvalue-reference-declarator-amp-amp?view=msvc-160" rel="nofollow noreferrer">msvcrvalueref</a></strong><br />
and instead of passing a reference uses an explicit char*<br />
the construction can be ascertained by compiling the code below and looking at disassembly.</p>
<p>code for test</p>
<pre><code>#include <iostream>
#include <string>
std::string foo(std::string _lhs,char *_rhs)
{
return std::operator+(_lhs , _rhs);
}
int main()
{
char rval[] = {"ello World!\n"};
std::cout << foo(std::string("H"), rval);
std::cout << foo(std::string("H"), "ello World!\n");
}
</code></pre>
<p>disassembly of first call to foo() uses proper 64 bit rdx</p>
<pre><code> lea rax, [rbp-176]
lea rdx, [rbp-189]
lea rcx, [rbp-144]
mov rsi, rcx
mov rdi, rax
call foo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char*)
</code></pre>
<p>disassembly of second call to foo() uses a 32 bit offset edx</p>
<pre><code> lea rax, [rbp-96]
lea rcx, [rbp-64]
mov edx, OFFSET FLAT:.LC1 and if linked mov edx,0x402007 a 32 bit address
mov rsi, rcx
mov rdi, rax
call foo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char*)
.LC1:
.string "ello World!\n"
</code></pre>
| 27199 | 2021-03-09T16:42:48.307 | <p>I'm looking through a block of disassembled C++ which works with several <code>std::string</code> instances. I had been confused by several calls to various versions of <code>std::operator+</code>, but this call seems completely wrong (by my understanding anyway):</p>
<pre><code>mov rax, qword [rbp-0xb8]
lea rbx, qword [rax+0xa0]
lea rax, qword [rbp-0x60]
mov edx, 0x880d32 ; "/store/"
mov rsi, rax
mov rdi, rbx
; std::string std::operator+(std::string &&, char const *),
call _ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EEOS8_PKS5_
lea rax, qword [rbp-0x60]
</code></pre>
<p>From context, I have determined that the stack values referenced are:</p>
<ul>
<li><strong><code>rbp-0x60</code></strong>: An <code>std::string</code> on the stack, constructed with <code>std::string(char const *, std::allocator<char> &)</code>.</li>
<li><strong><code>rbp-0xb8</code></strong>: A pointer to <code>this</code>.</li>
</ul>
<p>From the <code>.comment</code> section, I can see the compiler used was GCC 5.4.0, from which I retrieved this implementation of the <code>operator+</code> call above (in <code>namespace std { ... }</code>):</p>
<pre><code>template<typename _CharT, typename _Traits, typename _Alloc>
inline
basic_string<_CharT, _Traits, _Alloc>
operator+(
basic_string<_CharT, _Traits, _Alloc> &&__lhs,
const _CharT *__rhs)
{
return std::move(__lhs.append(__rhs));
}
</code></pre>
<p>I can understand the return value being optimized away since <code>__lhs</code> is modified by <code>operator+</code>, but the parameters don't seem to match. <code>edx</code> referring to the only <code>char *</code> suggests an additional first parameter before those declared in the source. If this was a member function, I would expect that (<code>rdi</code> being <code>this</code>), but <code>operator+</code> is implemented as a non-member.</p>
<p>Am I missing something from the calling convention here?</p>
| What is the first argument (rdi) to operator+ on x86_64 SystemV? | |disassembly|c++|gcc| |
<p>Instead of manual pushing, you should be able to use <a href="https://www.hex-rays.com/blog/practical-appcall-examples/" rel="nofollow noreferrer">Appcall</a>.</p>
| 27219 | 2021-03-12T08:43:10.853 | <p>would you please tell me how to call the function from IDAPython code ?โจ<br></p>
<p>I want to simulate it by manually push to stack as the two arguments and calling the function.</p>
| how to call the function from IDAPython with passing arguments by manually push them to the stack | |ida|idapython|ida-plugin| |
<p>Reduced to the minimum, this is how you get the name of a function and the module in Python 3:</p>
<pre><code>import ida_funcs
import ida_nalt
import idc
import pathlib
reg_address = idc.get_reg_value('EAX') # or use the register relevant to your case
func_name = ida_funcs.get_func_name(reg_address)
# if you want to use the main image name:
#image_name = pathlib.Path(ida_nalt.get_input_file_path()).name
# if you want to use the segment from which the function is coming from:
image_name = idc.get_segm_name(reg_address)
print(f'{image_name}:{func_name}')
</code></pre>
<p>Please note that this probably works properly only in case you have multiple images in the same database. Otherwise <code>idc.get_segm_name</code> might actually return the actual segment name, not the image name.</p>
<p>You can easily rewrite that for Python 2 if needed by not utilizing the <code>pathlib</code> and change the <code>print()</code>-function to be a <code>print</code>-statement in case you want to access the original image file name.</p>
| 27223 | 2021-03-12T12:08:10.603 | <p>For example, in the Registers windows of IDA pro, It show the following.<br>
( I think "WS2_32.dll:ws2_32_shutdown" is a string that IDA automatically resolved.)</p>
<p>EAX 766D32B0 WS2_32.dll:ws2_32_shutdown</p>
<p>So, would you please tell me how to get the function name string (such as WS2_32.dll:ws2_32_shutdown) from the Address (such as 766D32B0) by IDAPython ?</p>
<p>I try to do the following, but it donโt show the function name string..</p>
<p>eax_adddress = idc.get_reg_value("EAX")<br>
print("EAX-->%x" % eax_adddress)<br>
print("FunctionName-->%s" % idc.get_func_name(eax_adddress))<br></p>
| (IDAPython)How to get the function name string from the Function address? | |ida|idapython|ida-plugin| |
<h3>Ghidra method</h3>
<p>You can modify the binary via Ghidra in the following way:</p>
<ul>
<li>load the track</li>
<li>move in the assembly code to the point where it checks the result (if statement)</li>
<li>you will probably be faced with a jump instruction <code>JNZ</code>, just right click on it and select "Patch Instruction" and replace it with the opposite condition <code>JZ</code> (or vice versa).</li>
<li>Now save the project (<code>Ctrl</code>+<code>S</code>)</li>
<li>Then navigate to <code>File</code>><code>Export</code> Program and decide where to save the modified binary</li>
</ul>
<p>If you have problems with the exported binary, try this script: <a href="https://github.com/schlafwandler/ghidra_SavePatch" rel="nofollow noreferrer">https://github.com/schlafwandler/ghidra_SavePatch</a></p>
<h3>LD_PRELOAD method</h3>
<ul>
<li>Create a file called <code>ptrace.c</code> with the following content:</li>
</ul>
<pre><code>long ptrace(int request, int pid, void *addr, void *data) {
return 0;
}
</code></pre>
<ul>
<li>Now build the file as a shared library: <code>gcc -shared ptrace.c -o ptrace.so</code>;</li>
<li>Now lunch the following command: <code>export LD_PRELOAD=./ptrace.so</code></li>
<li>Run <code>ltrace ./launcher</code></li>
</ul>
<blockquote>
<p>Note: you can also use LD_PRELOAD method with GDB</p>
</blockquote>
<h1>GDB method</h1>
<ul>
<li>use GDB to lunch the binary: <code>gdb ./launcher</code></li>
<li>in the GDB client shell: <code>catch syscall ptrace</code></li>
<li>GDB allows you tun run a series of command when you reach a BP: <code>command 1</code></li>
<li>type: <code>set ($rax) = 0</code>, that will change the value inside the "return" register (aka the result of ptrace syscall) <a href="https://www.cs.uaf.edu/2017/fall/cs301/lecture/09_11_registers.html" rel="nofollow noreferrer">x86-registers</a></li>
<li>then enter: <code>continue</code> and <code>end</code>
(as two separated commands)</li>
<li>place a BP on the main function: <code>b main</code> and then type <code>r</code> to continue the execution</li>
</ul>
<p>Another option is to use Qiling framework and hook the function/syscall and always return any other value than "-1", but that seems a bit overkill.</p>
| 27229 | 2021-03-13T01:45:40.653 | <p>I am trying to run <code>ltrace</code> on this file:</p>
<blockquote>
<p>./launcher: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f6f8cf3307e0ee26723f4d03ec68f022d15e56b6, stripped</p>
</blockquote>
<p>When I pop it open in ghidra, and view the decompiled c, I can see that it changes the program flow to somewhere I don't want to be when ltrace is running.</p>
<pre><code> attached_to_ptrace = ptrace(PTRACE_TRACEME,0,1,0);
if (attached_to_ptrace == -1) {
puts("I am not your property!");
exit_code = 1;
}
else {
// execute main loop
}
</code></pre>
<p>Looking at the man page for <code>ptrace</code>, I see:</p>
<pre><code>long ptrace(enum __ptrace_request request, pid_t pid,
void *addr, void *data);
</code></pre>
<p>Meaning that if the program? or ltrace? were to run with a different PID, I would be able to successfully run my program using ltrace.</p>
<p>This is the current output I get when running the program with <code>ltrace</code>:</p>
<pre><code>~/ctf/cyberstart/level13/04 [master|โฆ1] $ ltrace ./launcher
__libc_start_main(0x565a86f0, 1, 0xff837be4, 0x565a8970 <unfinished ...>
ptrace(0, 0, 1, 0) = 0xffffffff
puts("I am not your property!"I am not your property!
) = 24
+++ exited (status 1) +++
</code></pre>
<p>Without ltrace:</p>
<pre><code>~/ctf/cyberstart/level13/04 [master|โฆ1] $ ./launcher
Enter the password:
password
Away now, you anklebiter!
[1]+ Stopped ./launcher
</code></pre>
<p>(This is my second buffer overflow CTF challenge, where the main goal is to mess with this block of code:)</p>
<pre><code> int iVar1;
char local_1e [10];
int local_14;
int local_10;
local_10 = 0;
puts("\nEnter the password: ");
gets(local_1e);
iVar1 = strcmp(local_1e,"PAssw0rd");
if (iVar1 == 0) {
puts("Well done! Unfortunately, you have to try harder.");
local_10 = 0;
}
else {
puts("Away now, you anklebiter!");
}
if (local_10 != 0) {
printf("Unexpected error condition. Control char is %d\n",local_10);
local_14 = param_2 * local_10;
(*(code *)(local_14 + param_1))();
}
</code></pre>
<p><strong>How can I run ltrace in a way such that it isn't detected?</strong></p>
| Run ltrace to avoid detection (on a different PID?) | |debugging|buffer-overflow| |
<p>x64dbg comes in two versions, 32 and 64 bits.</p>
<p><a href="https://i.stack.imgur.com/D6j8j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D6j8j.png" alt="enter image description here" /></a></p>
<p>You need to run the 32-bit version of x64dbg to detect a 32-bit application.</p>
| 27233 | 2021-03-13T13:03:47.613 | <p>I'm learning RE with x64dbg on Windows10.<br />
It does not list a process in the running process list that I want to attach.<br />
The Process is running 32-bit crackme application for learning.</p>
<p>It was created by eagle0wl.</p>
<p><a href="http://www.mysys.org/eagle0wl/" rel="nofollow noreferrer">http://www.mysys.org/eagle0wl/</a></p>
<p>Why x64dbg does not list process?<br />
I have checked that x64dbg on privilege permission and windows Smart Screen is disabled and so on.</p>
<p>I have no idea why the process does not list as an attached process.</p>
<p>Windows 10 20H2</p>
| A Process does not list on x64dbg attach list | |x64dbg|crackme|windows-10| |
<p>A "wait box" comes up when a Python script is running for a while; you can click "cancel" to stop the script. Via keyboard, that should just be <code>ENTER</code> if that dialog has the keyboard focus.</p>
| 27243 | 2021-03-15T03:30:07.033 | <p>Is there any way to STOP the loop of the IDApython ?<br><br>
I want to stop the loop processing of IDAPython with any timing after starting the IDAPython(which contain loop function) from IDApro menu -> File -> Script command.
Is there any keyboard shortcut to stop the script ?</p>
| Is there any way to STOP the loop of the IDApython? | |ida|malware|idapython|ida-plugin| |
<p>The recent updates to the Mach-O format (the <code>LC_DYLD_INFO_ONLY</code> command) have an option of encoding the export symbol information as a trie structure. In such case it's possible that the symbol name does not appear as an exact string in the file.</p>
<p>However, ELF does not use such encoding so normally all symbols must be present as-is in the binary. What seems to happen in your case is that the "missing" symbols are substrings of other symbols with longer names, e.g.:</p>
<ul>
<li><code>getpgrp</code> is a suffix of <code>tcgetpgrp</code></li>
<li><code>execve</code> - of <code>fexecve</code></li>
<li><code>exit</code> - of <code>_exit</code></li>
<li><code>textdomain</code> - of <code>bindtextdomain</code></li>
</ul>
<p>There is no requirement that each symbol must be present as a separate string in the string table. The symbol record encodes an offset to a start of the string in string table and the dynamic linker simply uses the bytes until the next zero for matching. By reusing suffixes of other strings, the string table can be made smaller (often it is a huge contributor to the ELF file's size).</p>
<p>For example, here's the symbol entry for textdomain:</p>
<pre><code>Elf64_Sym <offset aBindtextdomain+4 - offset unk_1DD0, 12h, 0, 0, \ ; "textdomain"
LOAD:0000000000000D38 offset dword_0, 0>
</code></pre>
<p>or</p>
<pre><code>LOAD:0000000000000D38 dd offset aBindtextdomain+4 - offset unk_1DD0; st_name ; "textdomain"
LOAD:0000000000000D38 db 12h ; st_info
LOAD:0000000000000D38 db 0 ; st_other
LOAD:0000000000000D38 dw 0 ; st_shndx
LOAD:0000000000000D38 dq offset dword_0 ; st_value
LOAD:0000000000000D38 dq 0 ; st_size
</code></pre>
<p>As you can see, it points 4 bytes into the string for <code>bindtextdomain</code>. This is perfectly legal and is a common optimization in compilers.</p>
<p><a href="https://sourceware.org/bugzilla/show_bug.cgi?id=18451" rel="nofollow noreferrer">Discussion with the patch</a> which added the feature to GNU ld.</p>
| 27250 | 2021-03-15T22:30:41.683 | <p>I'm cross-comparing a few approaches to testing for binaries that import a symbol and I noticed a YARA rule not finding one in <code>sudo</code> that nm + grep could find.</p>
<p>I looked at it in <code>xxd</code> to figure out why, but couldn't find a match. This explains why the YARA rule misses, but leaves me with a new question: <strong>how are tools like nm or objdump discovering the symbol?</strong></p>
<p>I checked other the other GLIBC symbols that nm reports to see how common this is, and found 5 symbols that didn't match in the output of xxd: <code>execve exit getpgrp sleep textdomain</code>. (I haven't yet manually verified whether any of the others only fail to match because they're split over a line break, but for this search I did run xxd at a width of 256 cols to minimize the likelihood).</p>
<p>I'm running something like:</p>
<pre><code>nm --undefined $(type -p sudo)
xxd -c 40 $(type -p sudo)
</code></pre>
<p>Since this outputs a few thousand lines and there may be platform differences in the binary/commands, I went ahead made a GH repo for reference.</p>
<ul>
<li><a href="https://github.com/abathur/sudo-make-sense/runs/2116615802" rel="nofollow noreferrer">CI run itself</a></li>
<li><a href="https://github.com/abathur/sudo-make-sense/blob/95214d62f61fc79ac0b22961fca60d9d2587a526/ci.log#L399-L5442" rel="nofollow noreferrer">relevant section from a committed copy of the CI output for posterity</a></li>
<li><a href="https://github.com/abathur/sudo-make-sense/blob/435a3df03c217d8792548c6173d9af8e86965148/.github/workflows/ci.yml#L13" rel="nofollow noreferrer">actual invocation producing the CI output</a></li>
<li><a href="https://github.com/abathur/sudo-make-sense/blob/main/sudo" rel="nofollow noreferrer">copy of the sudo binary itself</a></li>
</ul>
| Why might nm find a few undefined symbols that I can't see with xxd? | |static-analysis|symbols| |
<p>Sounds like you want <code>ida_kernwin.ask_file</code>, as in:</p>
<p><code>self.filename=ida_kernwin.ask_file(1, "*.xml", "Enter name of export xml file:")</code></p>
| 27253 | 2021-03-16T04:23:42.577 | <p>I want to some strings to the text-file which is chosen from the save dialog box.<br>
Is there any way to show the save dialog box by IDApython and how to write the script code about that ?</p>
| How to show the save dialog box with IDAPython? | |ida|idapython| |
<p>Here's one approach, for malicious files in a directory named <code>malware</code>:</p>
<pre><code>find malware/ -type f | xargs -n1 -P1 -I{} sh -c 'strings {} | sort | uniq' | sort | uniq -c | sort -n
</code></pre>
<p>The output will look something like the following, where the first number on each line is the number of files containing the string:</p>
<pre><code> ...
1 Sleep
...
2 JFIF
2 SetBkColor
...
5 !This program cannot be run in DOS mode.
5 t@PW
5 @tVH
...
</code></pre>
<p>One useful variation of this when the input files are Windows executables is using <code>strings -el</code> instead of <code>strings</code>, which will cause UTF-16 little-endian strings (also known as wide character strings) to be shown.</p>
<p>To tie string sequences back to the corresponding files use <code>strings -f malware/* | grep <string></code>.</p>
| 27262 | 2021-03-17T21:08:51.917 | <p>Given a set of arbitrary files, what's the best way to identify the text strings shared between them (either in all files or a subset of them) from the Linux command line?</p>
<p>This would be useful for quickly identifying ways to write Yara rules for clusters of similar malicious files (for instance, malicious executables).</p>
| Identify strings shared between multiple files from the Linux command line | |linux|strings|command-line| |
<p>On ARM macOS, like on iOS, most of the common dylibs are no longer shipped as separate files, but are bundled into the <a href="https://www.theiphonewiki.com/wiki/Dyld_shared_cache" rel="nofollow noreferrer">dyld shared cache</a>. You can usually find the caches in <code>/System/Library/dyld/</code>.</p>
| 27274 | 2021-03-21T09:48:29.630 | <p>I'm looking for the following dylib file which is included from process <code>loginwindow</code>.</p>
<p>If I run <code>vmmap</code> to inspect <code>loginwindow</code> while it's up and running I get :</p>
<p><code>user@mycomp / % sudo vmmap -I ``pgrep loginwindow`` | grep libIASUnifiedProgress.dylib</code></p>
<pre><code>__TEXT 1c7566000-1c756e000 [ 32K 32K 0K 0K] r-x/r-x SM=COW /usr/lib/libIASUnifiedProgress.dylib
__DATA_CONST 1fdd05628-1fdd06438 [ 3600 3600 0K 0K] rw-/rw- SM=COW /usr/lib/libIASUnifiedProgress.dylib
__DATA 200ff1f18-200ff27b0 [ 2200 2200 0K 0K] rw-/rw- SM=COW /usr/lib/libIASUnifiedProgress.dylib
__AUTH_CONST 207d4b260-207d4c008 [ 3496 3496 0K 0K] rw-/rw- SM=COW /usr/lib/libIASUnifiedProgress.dylib
__OBJC_CONST 207d4c008-207d4c368 [ 864 864 0K 0K] rw-/rw- SM=COW /usr/lib/libIASUnifiedProgress.dylib
__DATA_DIRTY 20a5b9250-20a5b9460 [ 528 528 528 0K] rw-/rw- SM=COW /usr/lib/libIASUnifiedProgress.dylib
</code></pre>
<p>however, the file doesn't appear to be there ... I'm guessing it's some new trick made by Apple, perhaps do you know how can I find it anyway ?</p>
<p>Thanks,</p>
| macOS under M1, cannot find library | |memory|process|libraries|macos| |
<p>So I finally got around to dig through the Android version of the game's APK file, and while I have not managed to obtain the game assembly code due to the crazy amounts of obfuscation in <code>libil2cpp.so</code>, <code>global-metadata.dat</code> is not obfuscated at all. After looking through it, I can now pretty confidently say that the random algorithm used is <a href="https://en.wikipedia.org/wiki/Xorshift" rel="nofollow noreferrer">Xorshift</a> since I found the string <code>new_Xorshift</code> close to a bunch of other strings related to the minigame. It probably uses 128-bits since there are four 32-bit seeds.</p>
<p>From here on I can either try to deobfuscate the assembly code or try to brute force how exactly Xorshift is used to "shuffle" the deck, but either way, I think this answers my question.</p>
| 27278 | 2021-03-20T12:52:10.087 | <p>I am playing a game for iOS that uses a deck of 48 cards and I would like to reverse engineer the kind of algorithm that is used to generate the random deck of cards such that I can predict which card will show up next. This is what I know about the game.</p>
<ul>
<li>The game was likely made using Unity, as I found that the game regularly sends data to the domain config.uca.cloud.unity3d.com.</li>
<li>In case it is relevant, the game is basically the japanese card game Koi-Koi.</li>
<li>Each card is internally numbered from 1-48 and each deck contains only one of each card.</li>
<li>Each game takes 4 unsigned 32-bit integer seeds as input, x, y, z, and w, and generates the random deck.</li>
<li>These seeds are retrieved by querying a game API, i. e. they are not generated by the game app, which means it is possible to impersonate the API and send custom seeds to the game.</li>
<li>If all seeds are 0, then the deck does not seem to be shuffled at all. It seems to result in a very predictable range of 5-48. (For some reason 1-4, the first โyakuโ, was skipped)</li>
<li>I also tried changing just one of each seed to 1 while the rest remained as 0. For example, x = 1, but y = z = w = 0, which resulted in a deck that seemed random and not similar at all to the unshuffled deck generated when all seeds are zero.</li>
</ul>
<p>Is there someone with experience in random number generators, especially ones commonly used for iOS apps coded in Unity, who has an idea of what kind of algorithm could be used to generate the decks? Could some sort of shuffle algorithm be used?</p>
<p>Edit: I have attempted to shuffle an array using the .NET System.Random class according to this answer where the random object was initiated using a seed of 0.
<a href="https://stackoverflow.com/a/108836">https://stackoverflow.com/a/108836</a></p>
<p>But the problem is that the array is shuffled pseudo-randomly, unlike the game where the โarrayโ is ordered. That is why I think that a type of โRandom.next()โ call doesnโt seem to be used. Could there be some multiplication involved? It would explain why a zero seed leaves the deck unchanged.</p>
| What kind of random algorithm is used in this game? | |ios| |
<p>ARM implements subtraction using addition with the complement of the second argument. Unusually, this implementational detail is exposed in the carry flag behaviour.</p>
<p>The description of the condition flags on page 66 (3-19) of the user guide you link to explains this anomaly -</p>
<pre><code>A carry occurs:
โข ...
โข if the result of a subtraction is positive or zero
โข ...
</code></pre>
<p>There is a similar answered question on Stack Overflow <a href="https://stackoverflow.com/questions/53065579/confusion-about-arm-documentation-on-carry-flag">here</a>.</p>
| 27282 | 2021-03-22T02:30:55.223 | <p>Page 88 of the <a href="https://developer.arm.com/documentation/dui0553/latest/" rel="nofollow noreferrer"><em>ARM Cortex-M4 Generic User Guide</em></a> says "The SBC instruction subtracts the value of Operand2 from the value in Rn. If the carry flag is CLEAR, the result is reduced by one." Why the result is reduced by 1 when the carry flag is CLEAR rather than SET? I think the SBC instruction subtracts the value of the carry flag from the result of subtracting operand2 from Rn, therefore the result is reduced by 1 when the carry flag is SET. Am I wrong?</p>
| Help understanding ARM Cortex-M4 SBC instruction | |assembly|arm| |
<p>My question was resolved by doing the following.
This is an answer.</p>
<p>If you want to update xrefs, at any given time, do the following.<br><br></p>
<pre><code>plan_and_wait(minaddress, maxaddress)
</code></pre>
<p>It was effective to narrow down the scope of the project to a certain extent, because doing it in all areas would have been time consuming.</p>
| 27283 | 2021-03-22T11:17:56.073 | <p>There is a situation where the number of xrefs for a function is dynamically increasing due to the dynamic creation of memory with execution rights attached by VirtualAlloc. <br>I want to get the xrefs of the function, and in this situation, if I check manually in the UI, I get 8 references, but if I use IDAPython to get CodeRefsTo/XrefsTo, I only get 3. <br>This is probably due to the fact that IDAPython does not allow xrefs to be applied to code regions dynamically allocated by VirtualAlloc, or because the cache is not updated. What is the best way to get dynamically changing xrefs with IDAPython ? Can you give me some ideas?</p>
| How to get dynamically changing xrefs with IDAPython | |ida|idapython| |
<p>@blabb 's <a href="https://community.osr.com/discussion/195991/inchoerence-of-the-pte-base-address" rel="nofollow noreferrer">link</a> is the correct answer for local debugging</p>
<blockquote>
<p>Debugger cache is used only for live targets, local kd doesn't really need it. However, local kd still needs to decide how to translate virtual addresses to physical ones when you switch to a process. This is where the different .process options come into play:</p>
</blockquote>
<blockquote>
<p>.process: No translation is performed. All memory accesses are performed in the context of debugger's process. Kernel memory which is valid in any process context (pool, system PTE mappings etc.) will be displayed correctly, everything else (user memory, session space, page tables etc.) will not.</p>
</blockquote>
<blockquote>
<p>.process /p: User addresses are translated using the page directory of the specified process, so commands like !peb should work correctly. Kernel addresses are not translated, so things like session space and page tables may still be displayed incorrectly.</p>
</blockquote>
<blockquote>
<p>.process /P: All addresses, user and kernel, are translated. Use this option if you need to look at session space, page tables or other process-specific data in the kernel space.</p>
</blockquote>
<p>I did not think it would be a bug -- the functionality to do it was clearly available. There has to be a specific usage to account for how local debugging works compared to livekd.</p>
| 27286 | 2021-03-22T14:47:09.383 | <p><a href="https://i.stack.imgur.com/D8LmY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D8LmY.png" alt="enter image description here" /></a></p>
<p>Says the PDPT and PDs of the process are at the same physcial frames (pfns) in both processes.</p>
<p>The first process is <code>winword.exe</code> and the second process is <code>calc.exe</code></p>
<p>The virtual address in the first case is the start of the virtual page containing the header of <code>winword.exe</code>, which VMMap shows to be in the shareable working set, but yet the output shows that the entry in the PDE hasn't ever even been touched.</p>
<p>I then try that virtual address in <code>calc.exe</code>, where VMMap shows no VAD allocation to that range, and it shows the same identical output.</p>
<p>This suggests to me that !pte is showing me the output of some other process, and I can't change it away from that and using <code>.process</code> alone and <code>.process</code> + <code>.context</code> with the correct dirbases (cr3/PML4 physical pages) doesnt work.</p>
<p>I'm using <code>kd -kl</code>, not <code>livekd</code>.</p>
<p>This also happens in <code>windbg</code>. Furthermore, I get the same pfns for both outputs, and those pfns change to a new set every time I reopen the debugger, which suggests that it is using the debuggers context. Is this a limitation with local debugging? I would have thought that a kernel driver would be able to do this correctly.</p>
<p><code>process /p</code> does nothing, and <code>!peb</code> correctly shows the different PEBs of the 2 different processes, but <code>!pte</code> still appears to be using the context of <code>kd</code></p>
<p><code>!vtop</code> appears to be working correctly:</p>
<p><a href="https://i.stack.imgur.com/8pfr3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8pfr3.png" alt="enter image description here" /></a></p>
<p>The problem is reproducible also on <code>windbg</code> (version 6.12) and also I tried version 10. <a href="https://stackoverflow.com/questions/52972057/windows-10-x64-unable-to-get-pxe-on-windbg">This</a> seems to be related. So does <a href="https://social.technet.microsoft.com/Forums/windows/en-US/7880aca9-2bff-410f-a0a7-c8bc24296d43/why-vtop-work-and-not-pte-in-windbg?forum=w7itprogeneral" rel="nofollow noreferrer">this</a> (dreadful answer).</p>
<p>I translated the virtual address to the virtual address of its PTE using <a href="https://stackoverflow.com/questions/52972057/windows-10-x64-unable-to-get-pxe-on-windbg/66751725#66751725">this technique</a> (which is of course the same address that was attempted to be shown in the <code>!pte</code> output, and will be the same PTE address for that virtual address in the context of every process) and <code>db</code> shows nothing at that address either:</p>
<p><a href="https://i.stack.imgur.com/dzQmU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dzQmU.png" alt="enter image description here" /></a></p>
<p>You still need to select the process context because the user side of the page tables as well as PML4 are mapped in differently for each process.</p>
<p><code>db</code> lines up with new state of <code>0x13fe60000</code> according to <code>!pte</code>:</p>
<p><a href="https://i.stack.imgur.com/kBHFf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kBHFf.png" alt="enter image description here" /></a></p>
<p>but <code>!vtop</code> works correctly:</p>
<p><a href="https://i.stack.imgur.com/A6ZwQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A6ZwQ.png" alt="enter image description here" /></a></p>
<p>I mean, the difference is that <code>!vtop</code> is accessing physical memory whereas <code>!db</code> and <code>!pte</code> access virtual memory. <code>!peb</code> works correctly and accesses virtual memory, but is user mode. It seems that it is struggling with reading kernel virtual addresses.</p>
| kd live local debugging !pte and db don't work (only shows context of the debugger for all contexts), but !vtop works | |windows|debugging|windbg|pages| |
<p>hasnext tries to get the function behind the current one. It also skips padding stuff like int3 (0xcc), nop (0x90) and such (on x86). anal.depth defines the limit of this behaviour. every 'next' function will decrement it by one. For more information see canal.c (__core_anal_fcn) and search for has_next.</p>
| 27291 | 2021-03-23T06:36:59.053 | <p>I am trying to understand <code>anal.hasnext</code> control flow configuration option of Radare. The documentation says "Continue analysis after each function. Forces to find a function, after the end of a function." So how far does it continue analysis after the end of a function. Does it stop after finding one more function after the end or continue further. At what point does it stop? Without this would it stop at the <code>ret</code> instruction? Can someone give me code example in <code>C</code> where this could be useful.</p>
| What does anal.hasnext actually do? | |radare2| |
<p>The problem, as I think you realise, is that you are logically moving the calculation of an expression past the point whereby one of its input values gets changed.</p>
<p>Given your current implementation, I'd suggest the easiest approach to handle this is -</p>
<ul>
<li>When an instruction writes to a variable, look to see if there are any expressions involving this variable on your expression stack.</li>
<li>If there are,
<ul>
<li>spill each such existing expression to a new temporary variable, and</li>
<li>replace the existing expressions on the stack with the respective new temporary variable.</li>
</ul>
</li>
<li>Only then generate the write to the original variable</li>
</ul>
<p>Applying this procedure to your code gives -</p>
<pre><code>IL_0002: // stack = { n1 }
IL_0003: // stack = { n2, n1 }
IL_0004: // stack = { n1 % n2 }
IL_0005: // stack = { n2, n1 % n2 }
IL_0006: // this instruction will write to n1
// inspection shows that we have an expression involving n1 on the stack so
// (a) spill this expression to a new temporary variable and
// (b) replace the expression on the stack with the new temporary variable
temp = n1 % n2; // stack = { n2, temp }
// now the write to n1 can safely take place
n1 = n2; // stack = { temp };
IL_0008: // this instruction will write to n2,
// inspection shows no expressions on the stack involving n2
// the write to n2 can safely take place
n2 = temp; // stack = {}
</code></pre>
<p>Removing the comments, the inner loop now looks like the original code.</p>
<pre><code>temp = n1 % n2;
n1 = n2;
n2 = temp;
</code></pre>
| 27298 | 2021-03-24T12:35:58.500 | <p>I'm writing a compiler from .NET CIL code to some high level language. Process is similar to decompilation. I have done some control flow analysis - detecting loops, ifs, and so on. In terms of data flow analysis i've done simple expression propagation by simulating some instructions involving evaluation stack - I treat evaluation stack as hidden variable, push more complex expressions on it, and whenever there is any assignment instruction to some variable (for example <code>starg</code> or <code>stloc</code>) - I pop and assign propagated expression from stack to this variable and translate this expression into statement in high language code. Of course for now it is so simple that it generates failures. Consider a function written in C#:</p>
<pre><code>int GCD(int n1, int n2)
{
while(n2 != 0)
{
int c = n1 % n2;
n1 = n2;
n2 = c;
}
return n1;
}
</code></pre>
<p>This function compiles to IL:</p>
<pre><code>.method private hidebysig
instance int32 GCD (
int32 n1,
int32 n2
) cil managed
{
.maxstack 8
IL_0000: br.s IL_000a
IL_0002: ldarg.1 // load n1 on eval stack
IL_0003: ldarg.2 // load n2 on eval stack
IL_0004: rem // pop n1 and n2 from stack, compute n1 % n2 and push it on stack
IL_0005: ldarg.2 // load n2 on stack
IL_0006: starg.s n1 // pop n2 from stack and store it in n1
IL_0008: starg.s n2 // pop n1 % n2 from stack and store it in n2
IL_000a: ldarg.2
IL_000b: brtrue.s IL_0002
IL_000d: ldarg.1
IL_000e: ret
}
</code></pre>
<p>With this simple propagation we push <code>n1 % n2</code> on stack, then load <code>n2</code> on stack, then we have <code>starg</code> instruction, so we pop expression from stack and translate assignment to statement. Then we pop again, and do the same. Result code looks like this:</p>
<pre><code>GCD(n1, n2) {
while (n2) {
n1 = n2;
n2 = (n1 % n2);
}
return n1;
}
</code></pre>
<p>This indicates that I have to do something inverse to dead code elimination, maybe called like "necessary code introduction". I searched for some sources about methods to introduce new variables in decompilation, but I did not find any. Do you have any ideas?</p>
| Decompilation of CIL code into some high level code - do I need to introduce new variables during data flow analysis? | |decompilation|decompile|decompiler|compilers|compiler-optimization| |
<p>Yes, this is possible with some cooperation from the debugger. The <a href="https://low-priority.appspot.com/ollymigrate/" rel="nofollow noreferrer">OllyMigrate plugin</a> supports migration between following debuggers:</p>
<ul>
<li>OllyDbg</li>
<li>Immunity Debugger</li>
<li>IDA Pro/Freeware</li>
<li>WinDbg</li>
<li>x64dbg</li>
</ul>
<p>It seems Visual Studio is not supported but you can always do it the manual way:</p>
<ol>
<li>Patch an infinite loop (<code>EB FE</code>) at the current EIP/RIP;</li>
<li>Detach the current debugger. The program will be stuck in the infinite loop;</li>
<li>Attach with the new debugger;</li>
<li>Restore the patched bytes and continue debugging.</li>
</ol>
<p>Note: I'm not sure this is the approach used by OllyMigrate. Possibly it uses some kind of handle passing from one debugger to another. Unfortunately the source code is not available.</p>
| 27304 | 2021-03-24T21:39:26.387 | <p>Is it possible to switch between debuggers and preserve where you are paused? Often times I find myself wanting to use a feature from a different debugger while paused in a specific context as each of them have their strengths (IDA has source level stepping, x32dbg has excellent patching, call stacks and easy to use hardware breakpoints, Visual Studio can cast memory to C++ structs in the Watch window). Some are more useful in getting to a destination than others. Is there any kind of software available that enables this feature?</p>
| Switch between debuggers while paused on a breakpoint | |disassembly|windows|debugging|debuggers| |
<p>Yes, <code>mov DWORD PTR 40[rsp], 6</code> is the same as <code>mov DWORD PTR [rsp + 40], 6</code>. The first syntax makes a lot more sense in cases where the constant is the base address of an array, and the register contains a byte offset into that array. That's the use case the syntax was designed for.</p>
| 27309 | 2021-03-25T04:27:10.993 | <p>I am learning about windows x64 calling convention, where the first four arguments are passed to registers and left arguments are passed through the stack. To see it, I checked the assembly of the test file that I made. I understood the passing of first four arguments through the register, the left arguments were passed through the stack but I didn't understood the assembly of the instruction. It looked like this:</p>
<pre><code>mov DWORD PTR 40[rsp], 6
mov DWORD PTR 32[rsp], 5
</code></pre>
<p>I don't know what does 40[rsp] means, maybe rsp+40 .
If anyone knows, please explain to me</p>
| does mov DWORD PTR 32[rsp], 5 means mov DWORD PTR [rsp+32], 5? | |disassembly|windows|functions|stack|x86-64| |
<p>This is untested, and is just a slightly expanded version of an old function <code>GetTarget</code> I have. It's very low-tech (simple API usage only), and (probably) will only work correctly for the x86/64 platform where all conditional jump mnemonics start with <code>j</code> and no mnemonic starts with <code>j</code> that isn't a jump of some type.</p>
<p>The alternative (which I also have) using NN_* code is harder to grasp for a beginner.</p>
<pre><code>def GetTarget(ea):
mnem = GetMnem(ea)
if not mnem:
return BADADDR
opType0 = GetOpType(ea, 0)
if mnem == "jmp" or mnem == "call" or mnem[0] == "j":
if opType0 != o_near and opType0 != o_mem:
print("Can't follow opType0 " + opTypeAsName(opType0))
return BADADDR
else:
return GetOperandValue(ea, 0)
if NextHead(ea) == ea + ItemSize(ea) and isFlow(GetFlags(NextHead(ea))):
return NextHead(ea)
def opTypeAsName(n):
for item in [x for x in dir(idc) if x.startswith('o_')]:
if getattr(idc, item) == n: return item
</code></pre>
<p>Since the way I used to code is really a little embarrassing, here is the same code in <em>correct pythonic idapython 7</em></p>
<pre><code>def GetTarget7(ea):
mnem = idc.print_insn_mnem(ea)
if not mnem:
return idc.BADADDR
opType0 = idc.get_operand_type(ea, 0)
if mnem == "jmp" or mnem == "call" or mnem[0] == "j":
if opType0 != o_near and opType0 != o_mem:
print("Can't follow opType0 " + opTypeAsName(opType0))
return idc.BADADDR
else:
return idc.get_operand_value(ea, 0)
if idc.next_head(ea) == ea + idc.get_item_size(ea) and \
idc.is_flow(idc.get_full_flags(idc.next_head(ea))):
return idc.next_head(ea)
</code></pre>
<p><em>see <a href="https://github.com/sfinktah/sfida" rel="nofollow noreferrer">my github</a> for vim ultisnips auto-expanding 6 to 7 idapython conversion, and idapython syntax file</em></p>
| 27310 | 2021-03-25T08:15:37.280 | <p>here is the original C++ source code of the executable that I've created to do simple RE</p>
<pre><code>#include <iostream>
void myFunction() {
printf("Hello!");
}
int main()
{
myFunction();
return 0;
}
</code></pre>
<p>When I disassembled my executable in IDA, this is the first block that I see
<a href="https://i.stack.imgur.com/RjQXa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RjQXa.png" alt="enter image description here" /></a></p>
<p>With the address being 0x4112c1
<a href="https://i.stack.imgur.com/rjSeA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rjSeA.png" alt="enter image description here" /></a></p>
<p>I've created a simple IDAPython script to find out what is the next address after the <strong>jump _main_0</strong></p>
<pre><code>from idautils import *
from idaapi import *
from idc import *
cursor = 0
start_addr = 0
end_addr = 0
print("----------Starting python script----------\n")
for func in Functions():
name = get_func_name(func)
if "_main" == name:
start_addr = get_func_attr(func, FUNCATTR_START)
end_addr = get_func_attr(func, FUNCATTR_END)
print("Start: 0x%x, End: 0x%x" %(start_addr, end_addr))
cursor = start_addr
print('0x%x %s' % (cursor, generate_disasm_line(cursor, 0)))
cur_addr = next_head(cursor, end_addr)
print("Next Head: 0x%x" %cur_addr)
print("---------Exiting Python script------")
</code></pre>
<p>And this is the following output:</p>
<pre><code>----------Starting python script----------
Start: 0x4112c1, End: 0x4112c6
0x4112c1 jmp _main_0
Next Head: 0xffffffff
---------Exiting Python script------
</code></pre>
<p>I have 2 questions I would like to ask:</p>
<ol>
<li>May I ask why isn't the address of the next head 0x411930 (which is the address of _main_0, as shown in the screenshot below) ?
<a href="https://i.stack.imgur.com/in2qT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/in2qT.png" alt="enter image description here" /></a></li>
<li>Is it possible to make the script go to the address of the mentioned function when it detects a jump statement? (because I thought next head will do the trick)</li>
</ol>
<p>**<em>Disclaimer: I'm kinda new to RE and IDAPython so do bear with me if I ask too much</em></p>
| Is it possible to "jump" to another address when script detects jmp? | |ida|idapython| |
<p>The <a href="https://gist.github.com/uroboro/2cc054e1bc995232a4919044eae29967" rel="nofollow noreferrer">gist</a> contains some old (create 3 yrs ago) r2 instructions and according to, also outdated, r2 book, it looks like <a href="https://radare.gitbooks.io/radare2book/content/search_bytes/intro.html" rel="nofollow noreferrer"><code>/c</code> command</a> was responsible for "search for asm code matching the given string". Currently (<code>radare2 5.2.0-git 26093 @ linux-x86-64 git.5.1.1</code>) the similar instruction could be one from <code>/a</code> group</p>
<pre><code>Usage: /a[?] [arg] Search for assembly instructions matching given properties
| /a push rbp Assemble given instruction and search the bytes
| /a1 [number] Find valid assembly generated by changing only the nth byte
| /aI Search for infinite loop instructions (jmp $$)
| /aa mov eax Linearly find aproximated assembly (case insensitive strstr)
| /ac mov eax Same as /aa, but case-sensitive
| /ad[/*j] push;mov Match ins1 followed by ins2 in linear disasm
| /ad/ ins1;ins2 Search for regex instruction 'ins1' followed by regex 'ins2'
| /ad/a instr Search for every byte instruction that matches regexp 'instr'
| /ae esil Search for esil expressions matching substring
| /af[l] family Search for instruction of specific family (afl=list
| /ai[j] 0x300 [0x500] Find all the instructions using that immediate (in range)
| /al Same as aoml, list all opcodes
| /am opcode Search for specific instructions of specific mnemonic
| /ao instr Search for instruction 'instr' (in all offsets)
| /as[l] ([type]) Search for syscalls (See /at swi and /af priv)
| /at[l] ([type]) Search for instructions of given type
</code></pre>
<p>It looks like especially <code>/ad/</code> should work as it can find sections of code where two instructions are following each other matching some regexp.</p>
<p>Based on this I think the following should work for you:</p>
<pre><code>[0x00000000]>"/ad/ 0xfffffff007622000;0x898"
</code></pre>
| 27316 | 2021-03-26T10:32:20.613 | <p>I am trying to find an offset IOSURFACEROOTUSERCLIENT_VTAB from an iOS kext(IOSurface) using radare2 and there is a need to use the command <code>"/c pointer; offset"</code> as per the instructions in this <a href="https://gist.github.com/uroboro/2cc054e1bc995232a4919044eae29967" rel="nofollow noreferrer"><em><strong>gist</strong></em></a>. On performing the command the expected out put is a list of locations where the specific instruction occurs.</p>
<p>But when i try to run, the previous commands do work as expected. Except for the above command which gives the following output:</p>
<pre><code>[0xfffffff00688b0d4]> "/c 0xfffffff007622000; 0x898"
Usage: /c Search for crypto materials
| /ca Search for AES keys expanded in memory
| /cc[algo] [digest] Find collisions (bruteforce block length values until given checksum is found)
| /cd Search for ASN1/DER certificates
| /cr Search for ASN1/DER private keys (RSA and ECC)
</code></pre>
<p>I'm getting the same response when the double quotes are dropped.</p>
<p>Please help me understand what is wrong here, or if the format for radare2 has changed over the course of time or if I missed something.</p>
<p>I did read the radare2 docs and but could not find any format in this form: <code>"/c pointer; offset"</code></p>
<p>Thanks!</p>
| Radare2 - "/c pointer; offset" command not giving expected response to search instances of the same pair of similar instructions | |radare2|ios|kernel|offset| |
<p>This feature will be part of Ghidra 10 according to the preliminary release notes: <a href="https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Configurations/Public_Release/src/global/docs/WhatsNew.html#L124-L130" rel="nofollow noreferrer">https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Configurations/Public_Release/src/global/docs/WhatsNew.html#L124-L130</a></p>
<blockquote>
<p>Extensions can be added from the <code>Specification Extensions</code> tab under the <code>Options</code> dialog for the Program.</p>
</blockquote>
<p>The beta is already available for download at <a href="https://ghidra-sre.org/" rel="nofollow noreferrer">https://ghidra-sre.org/</a></p>
<h2>Adding new Compiler Spec</h2>
<p>The full process is, starting from a Codebrowser window with some binary named <code>ls</code>:</p>
<p><code>Edit - Options for 'ls'</code>
then this window should open, where you can click on <code>Specification Extensions</code> on the left:</p>
<p><a href="https://i.stack.imgur.com/Jt3do.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jt3do.png" alt="enter image description here" /></a></p>
<p>click <code>Import...</code> and select the file defining the extension. If you want to e.g. define a callfixup that tells the decompiler to treat some function as a <code>NOP</code> if called, you can write a file like this:</p>
<pre><code><callfixup name="objc_retain">
<target name="_objc_retain"/>
<target name="_objc_retainAutorelease"/>
<pcode>
<body><![CDATA[
x0 = x0;
]]></body>
</pcode>
</callfixup>
</code></pre>
<p>It seems like you can only define one extension per file, and can't import multiple files at once. Though at least in my case the actual replacement is often the same, just for different functions, so you can just add multiple targets.</p>
| 27320 | 2021-03-26T16:44:19.573 | <p>Ghidra uses <code>.cspec</code> files like <code>x86win.cspec</code> to define compiler related information, which are imported in the <code>.ldef</code> files like <code>x86.ldef</code> that define a processor language.</p>
<p>How can I add a new <code>CompilerSpec</code> via a <code>.cspec</code> file to Ghidra without editing the existing <code>.ldef</code> file which is inherently part of the Ghidra core, but also without adding a new processor (with a new <code>.ldef</code> file)? This should also work with <code>analyzeHeadless</code>, so no just adding it in the GUI.</p>
<p>This will probably end up requiring an extension which isn't an issue, I just don't know where to either put the file so it gets automatically loaded, or which API functions to call as part of the extension initialization to add the new <code>CompilerSpec</code>. The classes that implement the <code>CompilerSpec</code> interface have public constructors, that take the <code>.cspec</code> file as a parameter, but this doesn't look like it will be automatically added then after just creating an instance of it.</p>
| How to add a new CompilerSpec from a .cspec file to Ghidra? | |ghidra| |
<p><code>af</code> and <code>afr</code> are different. Check radare's code base for deep understanding - <a href="https://github.com/radareorg/radare2/blob/8d678888a97d9aed4049d1a7467132c41ad6ffa7/libr/core/cmd_anal.c" rel="nofollow noreferrer">https://github.com/radareorg/radare2/blob/8d678888a97d9aed4049d1a7467132c41ad6ffa7/libr/core/cmd_anal.c</a>.</p>
<p><a href="https://i.stack.imgur.com/HbTax.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HbTax.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/rZwL1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rZwL1.png" alt="enter image description here" /></a></p>
<p>Now, consider following example to understand how they differ.</p>
<pre><code>#include <stdio.h>
int one()
{
return 1;
}
int fact(int n) {
if (n==0)
return 1;
else if (n==1)
return one();
else
return n*fact(n-1);
}
int main(void) {
return fact(5);
}
</code></pre>
<p>I just used <a href="https://www.cs.mcgill.ca/%7Ecs573/fall2002/notes/lec273/lecture16/16_3.htm" rel="nofollow noreferrer">this</a> factorial code and modified it a little. And following is the radare2 output.</p>
<pre><code>$ radare2 a.out
-- This page intentionally left blank.
[0x00401020]> afl
[0x00401020]> s main
[0x0040114e]> afl
[0x0040114e]> af main
[0x0040114e]> afl
0x0040114e 1 16 main
0x00401111 6 61 sym.fact
[0x0040114e]> afr main
[0x0040114e]> afl
0x0040114e 1 16 main
0x00401111 6 61 sym.fact
0x00401106 1 11 sym.one
</code></pre>
<p>Note the detection of additional function when recursive analysis is used.</p>
| 27322 | 2021-03-27T03:43:20.730 | <p>I am trying to understand the difference between <code>analyze functions</code> and <code>analyze functions recursively</code> in Radare2. Given a code snippet like this:</p>
<pre><code>#include <stdio.h>
void b() {
printf("b is called\n");
}
void a() {
printf("a is called\n");
b();
}
int main() {
a();
return 0;
}
</code></pre>
<p>When I run <code>afr</code> on the main function, it finds the following functions:</p>
<pre><code>0x0000066a 1 21 main
0x0000064d 1 29 sym.a
0x00000510 1 6 sym.imp.puts
0x0000063a 1 19 sym.b
</code></pre>
<p>However, when I run <code>af</code> on the main function, it again finds the same functions:</p>
<pre><code>0x0000066a 1 21 main
0x0000064d 1 29 sym.a
0x00000510 1 6 sym.imp.puts
0x0000063a 1 19 sym.b
</code></pre>
<p>I have not changed the default value of <code>anal.calls</code> which is set to <code>false</code></p>
<p>So, my question is what extra is <code>afr</code> finding that <code>af</code> isn't?</p>
<p>I am using Radare2 version 5.1.1</p>
| `af` vs `afr` in Radare2 | |radare2| |
<p>If you want to use x64dbg for debugging and at the same time IDA Pro for static analysis, I recommend you one of my favourite plugin: <a href="https://github.com/bootleg/ret-sync" rel="nofollow noreferrer">https://github.com/bootleg/ret-sync</a></p>
<p>You can for example run your binary program in a VM with x64dbg and synchronize it to highlight the current instruction in IDA Pro and much more like auto rebase, controlling/BP from IDA, Windbg...</p>
| 27329 | 2021-03-27T18:42:22.443 | <p>I've found a function I want to call in x64dbg, and wanted to see it's prototype and how it looks like in IDA. However, I was expecting to see a function in IDA but land in the middle of one.</p>
<p>The function I want to call in x64dbg:<a href="https://i.stack.imgur.com/GnS9V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GnS9V.png" alt="enter image description here" /></a></p>
<p>I was expecting I could find the static address in IDA doing like so:</p>
<p>RVA: 881C0000</p>
<p>Finding this statically in IDA: 0000000140000000 (base) + 1C88 (RVA) yielding: 140001C88</p>
<p>When seaching for address 140001C88 in IDA I land in the middle of a function, sub_140001B80. I was expecting to land at something like sub_140001C88 Can someone see what I'm doing wrong?</p>
<p><a href="https://i.stack.imgur.com/FHESY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FHESY.png" alt="enter image description here" /></a></p>
<p>(FYI: I'm trying to call a function that presses a button)</p>
| Finding function in IDA from x64dbg | |ida|x64dbg| |
<p>This means that there is no valid opcode for this spot. The other 'valid' opcodes in your picture look also not useful at all. I assume the whole block there is nothing that can be executed.</p>
| 27334 | 2021-03-28T02:35:05.853 | <p>I see such things but I just couldn't understand. Do you have any ideas?</p>
<p>Thank you!</p>
<p><a href="https://i.stack.imgur.com/PhpLW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PhpLW.png" alt="enter image description here" /></a></p>
| What does "???" mean in x32dbg? | |debugging| |
<p>Though Igor kindly answered my immediate question, I was still left with the problem of how to conveniently dispose of these unused <code>fixup</code>s. Fortunately I already use my own <code>MakeUnknown</code> and <code>PatchBytes</code> function, so I was able to simply include removal of <code>fixup</code> information with those and forget about the entire problem.</p>
<p>I am including this code as an example of how to detect if a <code>fixup</code> is present, as <code>ida_fixups.exists_fixup</code> doesn't necessarily return what you think it will, if a <code>fixup</code> is hiding under an unexpected byte within an instruction.</p>
<p>I've also included a <code>fixup visitor</code>.</p>
<pre><code>def MyMakeUnknown(ea, nbytes, flags = 0):
r"""
@param ea: any address within the first item to delete (C++: ea_t)
@param nbytes: number of bytes in the range to be undefined (C++: asize_t)
@param flags: combination of: DELIT_EXPAND DELIT_DELNAMES
DELIT_NOTRUNC DELIT_NOUNAME
DELIT_NOCMT DELIT_KEEPFUNC
@param may_destroy: optional callback invoked before deleting a head item.
if callback returns false then deletion and operation
fail. (C++: may_destroy_cb_t *)
@return: true on sucessful operation, otherwise false
Convert item (instruction/data) to unexplored bytes. The whole item
(including the head and tail bytes) will be destroyed.
"""
# check if caller has invoked with (start_ea, end_ea)
if nbytes > ea:
nbytes = nbytes - ea
result = idaapi.del_items(ea, flags, nbytes)
if not result:
return result
# check for fixups that must be removed
# https://reverseengineering.stackexchange.com/questions/27339/
fx = idaapi.get_next_fixup_ea(ea - 1)
while fx < ea + nbytes:
idaapi.del_fixup(fx)
fx = idaapi.get_next_fixup_ea(fx)
return result
def MyMakeUnkn(ea, flags = 0):
return MyMakeUnknown(ea, 1, flags)
def example_fixup_visitor(ea):
line = idc.generate_disasm_line(ea, 0)
print("{:16x} {}".format(ea, line))
def visit_fixups(iteratee):
ea = idaapi.get_first_fixup_ea()
while ea != idc.BADADDR:
iteratee(ea)
ea = idaapi.get_next_fixup_ea(ea)
# This is a bit length, so it's left until the end.
def PatchBytes(ea, patch=None, comment=None):
"""
@param ea [optional]: address to patch (or ommit for screen_ea)
@param patch list|string|bytes: [0x66, 0x90] or "66 90" or b"\x66\x90"
@param comment [optional]: comment to place on first patched line
@returns int containing nbytes patched
Can be invoked as PatchBytes(ea, "66 90"), PatchBytes("66 90", ea),
or just PatchBytes("66 90").
"""
if isinstance(ea, (list, str)):
ea, patch = patch, ea
elif ea is None:
ea = idc.get_screen_ea()
old_code = idc.is_code(idc.get_full_flags(idc.get_item_head(ea)))
old_head = idc.get_item_head(ea)
if isinstance(patch, str):
def intify(s): return -1 if '?' in s else int(s, 16)
patch = [hex_byte_as_pattern_int(x) for x in patch.split(' ')]
length = len(patch)
# deal with fixups
fx = idaapi.get_next_fixup_ea(ea - 1)
while fx < ea + length:
idaapi.del_fixup(fx)
fx = idaapi.get_next_fixup_ea(fx)
if type(getattr(__builtins__, 'bytes', None)) == 'type' and isinstance(patch, bytes):
idaapi.patch_bytes(ea, patch)
else:
[idc.patch_byte(ea+i, patch[i]) for i in range(length) if patch[i] != -1]
# for i in range(length):
# if patch[i] != -1:
# idc.patch_byte(ea+i, patch[i])
idc.auto_wait()
if comment:
comment_formatted = "[PatchBytes:{:x}-{:x}] {}".format(ea, ea + length, str(comment))
if 'Commenter' in globals():
Commenter(old_head, 'line').add(comment_formatted)
else:
idaapi.set_cmt(old_head, comment_formatted, 0)
if old_code:
head = old_head
while head < ea + length:
inslen = idc.get_item_size(head) \
if idc.is_code(idc.get_full_flags(idc.get_item_head(ea))) \
else idc.create_insn(head)
if inslen < 1:
break
head += inslen
return length
</code></pre>
| 27339 | 2021-03-28T15:31:10.723 | <p>This has plagued me from IDA 6.5 to 7.5.</p>
<pre><code>.text:0000000143EFE8CD CC db 0CCh ; ร OFF64 SEGDEF [_text,140CFC35B]
</code></pre>
<p>It may not look like much, but when a conditional jump is placed over such a location, the result is debilitating.</p>
<pre><code>.text:0000000143EFE8B6 0F 8F 9F DA DF FC jg loc_143019000-231CCA5h
</code></pre>
<p>Every instance creates an <code>xref</code> to the third .text segment at 0x143019000 along with multiple levels of chunk ownership, and Hexrays produces errors such as:</p>
<pre><code>143019029: control flows out of bounds to 14301902A
143019007: control flows out of bounds to 143018FB1
143019023: control flows out of bounds to 143018FCD
</code></pre>
<p>I cannot remove, reproduce or detect the presence of these <code>OFF64 SEGDEF</code> lines, though the conditional jumps have the flag bit FF_0OFF set.</p>
<p>These <code>OFF64 SEGDEF</code>s appear where-ever an <code>abs mov</code> was previously (they're being replaced in a de-obfuscation process), the one in this question previously being:</p>
<pre><code>.text:0000000143EFE8CB 48 BA 5B C3 CF 40 01+ mov rdx, offset loc_140CFC35B
.text:0000000143EFE8CB 00 00 00
</code></pre>
<p>Assembling an identical statement to another another location does not cause one to appear.</p>
<p>I have tried <code>ida_bytes.del_items</code>, <code>ida_bytes.del_value</code> (hides it, but it re-appears when repopulated), <code>ida_bytes.del_mapping</code> and some other things I don't recall. I've also tried forcing re-analysis with the bytes <code>nop</code>ped over, though a need an IDAPython solution.</p>
<p>I've also tried some segment related functions in an effort to create a similar effect, in the hope the anything I know how to make I can then remove, but I failed in this effort also; my experience in segment-based assembly is minimal and from the 90's.</p>
| How to remove OFF64 SEGDEF from IDA disassembly | |ida| |
<p>The earliest break is sxe ibp break on kd communication<br />
if you want to break earlier than that you need to lookup boot debugging<br />
you can use ctrl+alt+d for a debug spew of kdcom kdnet packets sent to and fro</p>
| 27349 | 2021-03-29T12:53:41.563 | <p>This is a theoretical question because I've never set up remote kernel debugging before -- but I will do at some point, which should hopefully answer some of the experimental questions I have.</p>
<p>What happens if you put a breakpoint in the breakpoint trap handling or kdcom / kdnet itself</p>
<p>I can't find a single thing about this, but in the former case, wouldn't the CPU just freeze because the breakpoint is continually being hit without the remote debugger getting chance to remove the breakpoint or iretting to the instruction after the breakpoint.</p>
<p>Also, from what I'm seeing, it seems like a stack trace hides any of the trap handling, and shows the breakpoint as the top frame on the stack.</p>
| How much of the kernel does remote kernel debugging allow you to debug? | |windows|debugging|windbg|kernel| |
<p>I think it's intended behavior as this normal mode (no value prefixes - see later) is probably valid for ascii parameters. Here you are passing a payload that can contain ascii controlling bytes and might cause trouble.</p>
<p>From the broken payload it's clearly visible that there's a missing byte <code>0x0d</code> and this is causing your problems. But why is it missing?</p>
<p>Let's look at the code that sets the values from the new process from rarun2 profile (so basically from <code>dor</code> command in this case).</p>
<p>The profile is being parsed with the following code (<code>libr\socket\run.c</code>):</p>
<pre><code>R_API bool r_run_parse(RRunProfile *pf, const char *profile) {
r_return_val_if_fail (pf && profile, false);
char *p, *o, *str = strdup (profile);
if (!str) {
return false;
}
r_str_replace_char (str, '\r',0); // <------ (1)
p = str;
while (p) {
if ((o = strchr (p, '\n'))) {
*o++ = 0;
}
r_run_parseline (pf, p);
p = o;
}
free (str);
return true;
}
</code></pre>
<p><code>str</code> is our rarun2 profile (what is passed to <code>dor</code>) and char <code>'\r'</code> is in fact <code>0xd</code>. It is being removed from the input on line (1) before it's being passed to <code>r_run_parseline</code> that does parsing and setting process environment variables (like args).</p>
<p>Not sure why the line is there - it might be to unify line endings? (windows/linux)</p>
<p>What can be done to overcome this? Modify your script and use one of the value prefixes. If your script instead of raw bytes prints hexpair strings you can use <code>:</code> to parse it and correctly be passed to your program. So change you script to print like this <code>41414141.....</code></p>
<p>and then from <code>r2</code> use <code>:</code> to indicate that the input is a hexpair string.</p>
<pre><code>dor arg1=:`!python payload.py`
doo
</code></pre>
| 27355 | 2021-03-30T09:49:37.133 | <p>I'm new to Radare2 so i'm trying to learn it by doing some basic buffer overflows. My problem is that, when i try to load some payloads, the stack seems to fake them in some differents ways...</p>
<p>For example, trying to load the input by invoking a simple python script</p>
<pre><code>import struct
def p (x):
return struct.pack('<I',x)
param = ""
param += "A"*30
param += p(0xb7e40db0)
param += p(0xb7e349e0)
param += p(0xb7f61b0b)
print param
</code></pre>
<p>And using this for run it.</p>
<p><code>r2 -d bufferoverflow `python payload.py` </code></p>
<p>I get this stack when overflows.</p>
<p><a href="https://i.stack.imgur.com/FXAZM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FXAZM.png" alt="enter image description here" /></a></p>
<p>I don't use to get any problem by running it this way</p>
<p>However, when i've set some breakpoints, customize some views in order to be more confortable, I've try to reload the file by using "dor" and "doo" commands from Radare2</p>
<p><a href="https://i.stack.imgur.com/UcPL3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UcPL3.png" alt="enter image description here" /></a></p>
<p>But now Radare2 seems to start faking the stack with some random values...</p>
<p><a href="https://i.stack.imgur.com/xW0TR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xW0TR.png" alt="enter image description here" /></a></p>
<p>I'm not sure if it's a problem of mine because i'm doing it the wrong way, or if it's caused by a Radare2 behavior that i don't know.</p>
<p><a href="https://i.stack.imgur.com/o1r5M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o1r5M.png" alt="enter image description here" /></a></p>
| Radare2 does not reload payload correctly | |radare2|stack| |
<p>If you convert the program to a console one (e.g. using EDITBIN), you should be able to run it from a console window and see everything it prints.</p>
| 27377 | 2021-04-01T23:11:29.453 | <p>I'm using IDA to poke around in an old video game and noticed there are lots of calls to the <code>printf</code> function:</p>
<p><a href="https://i.stack.imgur.com/EF1eK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EF1eK.png" alt="" /></a></p>
<p>I can see in another function that <code>dword_5CE914</code> is a bitmask comprising various startup arguments (e.g. <code>debug</code>, <code>nofullscreen</code>, etc). As you may have guessed, <code>0x4000000</code> is the value that indicates the <code>debug</code> switch was present; despite enabling this, there is no visible debug output.</p>
<p>As someone new to software programming, I <em>assume</em> that during the game's development the <code>printf</code> calls would have been outputting to a debugger/console window which were disabled for production.</p>
<p>My question is: how can I view the output now that there is no debugger window?</p>
<p>My current thought process would be to:</p>
<ol>
<li>Create a custom DLL containing a function to output arbitrary text to a .txt file</li>
<li>Inject the DLL into the game's address space</li>
<li>Hook into <code>printf</code> and pass the argument into my function which saves the output</li>
</ol>
<p>Does that sound like a plausible approach, or can someone recommend a better way?</p>
| How can I view the output of printf calls without a console window? | |ida|dll-injection| |
<p>Debug Symbol information is often "stripped off" from <code>C++</code> binaries. Symbol information stores all user-created names, symbols, and types, bounds, fouction boundary and other function related metadata information (it is generally stored according to a popular and standardized "dwarf" format which is widely used and employed in modern compilers). If you want to keep this information then compile your binary with - say <code>-g</code> flag in gcc or clang. For e.g. <code>gcc -g myprog.c</code>. You will find all user-defined symbols rendered by Ghidra.</p>
<p>On the other hand, in <code>C#</code> .NET removal of name symbol metadata is not possible (as reflection requires retrieval of symbol for types at runtime). Thus to work around this, <code>C#</code> symbols are generally <a href="https://www.appsealing.com/code-obfuscation-comprehensive-guide/" rel="noreferrer">obfuscated</a>.</p>
<p>References:
<a href="https://www.appsealing.com/code-obfuscation-comprehensive-guide/" rel="noreferrer">https://www.appsealing.com/code-obfuscation-comprehensive-guide/</a>
<a href="http://www.semdesigns.com/Products/Obfuscators/CSharpObfuscationExample.html" rel="noreferrer">http://www.semdesigns.com/Products/Obfuscators/CSharpObfuscationExample.html</a>
<a href="https://help.gapotchenko.com/eazfuscator.net/53/advanced-features/symbol-names-encryption" rel="noreferrer">https://help.gapotchenko.com/eazfuscator.net/53/advanced-features/symbol-names-encryption</a></p>
| 27402 | 2021-04-06T02:45:16.080 | <p>Why can programs written in C# be reverse-compiled essentially to their original form with variables names (such as dnSpy) while C++ decompilers (such as Ghidra) are unable to decode the variable names?</p>
| Why can C# applications be reverse-compiled with variable names while C++ ones can't? | |c++|dll|c#| |
<p>From type == 0 you see that it writes to param_3 and reads from param_4. So those parameters must be pointers to output and input buffers respectively. In fact, if you change them to correct type (byte *), then I believe Ghidra should be able to simplify the rest of the code to easily understandable form.</p>
<p>The part that modifies param_2 is a simple pseudo-RNG. Note the classic trick of getting rid of the not-very-random lower bits of its output by shifting right.</p>
<p>Also, I didn't check this myself, but I bet types 1 and 2 do the opposite of each other. That is, one of them encrypts and the other decrypts.</p>
| 27414 | 2021-04-07T19:50:12.660 | <p>I'm currently trying to reverse engineer the decryption algorithm for an old online game, using a chat message packet, as it contains text which is easily recognizable.</p>
<p>I used a packet sniffer to get the received packet (which is encrypted) from the server:</p>
<pre><code>5e 00 09 32 3c c1 6e b5 ae be 90 4a 70 8f b7 3d
3a 81 c5 3a f9 11 a6 06 36 3d f3 68 a3 dd 72 a3
ff e1 c3 e9 12 28 d7 c5 a0 f1 ce 38 35 59 19 b6
85 90 76 23 42 af 50 6f 66 52 ec ad f9 da 61 3f
5d 09 ee 8d dd 9e ff ee 7d 27 0f 5c 1e df ba 30
de d0 c8 8c 1b 93 1d 53 66 13 98 ff 29 db
</code></pre>
<p>The first 4 bytes are known and unencrypted:</p>
<p><code>5E 00</code> is the size, here 94.
<code>09 32</code> is the OPCODE as a big endian: here 2354.
What follow is the encrypted payload.</p>
<p>Knowing the encrypted packet, I used Cheat Engine to set a breakpoint right after the winsocket receive function and then search the buffer where the packet is stored.</p>
<p><strong>Important to note:</strong> Apparently, the buffer which stores the received (encrypted) packet will also store the decrypted one.</p>
<p>Checking what writes to this address results in exact one instruction.
<a href="https://i.stack.imgur.com/4ssuh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4ssuh.png" alt="enter image description here" /></a></p>
<p>As the buffer which contains the encrypted packet also contains the decrypted one, I can say for sure that this has to be the function which decrypts the value.</p>
<p>The decrypted packet looks the following (last bits contain the chat message, somewhere in between the username is stored):</p>
<pre><code>5e 00 09 32 00 00 00 00 4d 00 6e 60 00 00 00 00
06 0a 2c 00 00 00 74 00 65 00 73 00 74 00 63 00
68 00 61 00 72 00 31 00 00 00 91 12 ad 14 5e 75
00 00 cf 00 00 00 00 00 28 cd b8 69 fc f7 91 12
aa f1 07 4d 00 00 cf 00 00 00 00 00 10 74 65 73
74 5f 6d 65 73 73 61 67 65 5f 31 32 33 00
</code></pre>
<p>I then used Ghidra to inspect the specific instructions which handle the decryption part - this is where I am currently stuck and don't know how to proceed, as I don't have a deep understanding of this topic.</p>
<pre><code> undefined4 decrypt_package(int type,int param_2,int param_3,int param_4,int param_5)
{
undefined4 success;
int counter;
if ((param_3 == 0) || (param_4 == 0)) {
s = 0;
}
else {
// Old encryption function which only used byte ^ 255
// I assume it's still in here, because the code wasn't cleaned up.
if (type == 0) {
counter = 0;
while (counter < param_5) {
*(byte *)(param_3 + counter) = *(byte *)(param_4 + counter) ^ 0xff;
counter = counter + 1;
}
}
else { // Don't know when this is used - at least not for decryption
if (type == 1) {
param_2 = 0x48473c;
counter = 0;
while (counter < param_5) {
*(byte *)(param_3 + counter) = *(byte *)(param_4 + counter) ^ (byte)((uint)param_2 >> 8);
param_2 = ((uint)*(byte *)(param_3 + counter) + param_2) * 0x2ba339 + 0x2cad2b5;
counter = counter + 1;
}
}
else {
// This block of code is called for the decryption part.
if (type == 2) {
counter = 0;
while (counter < param_5) {
*(byte *)(param_3 + counter) = *(byte *)(param_4 + counter) ^ (byte)((uint)param_2 >> 8)
;
param_2 = ((uint)*(byte *)(param_3 + counter) + param_2) * 0x8e9a99 + 0x685b24;
counter = counter + 1;
}
}
}
}
success = 1;
}
return success;
}
</code></pre>
<p>(Note for the type == 0: When the game first released, it only used a simple XOR with 255 as an encryption, this was apparently later discontinued)</p>
<p>From my understanding, the code does the following (assuming, param_2 is the buffer for the packet?):</p>
<ol>
<li>Loop over the buffer, as long as counter < param_5 (which I assume is the length of the payload to decrypt?)</li>
<li>XOR the byte with a value (first byte that needs to be decrypted would be at position 5, so I assume that param_3 would be a kind of offset to skip the first 4 bytes.)</li>
<li>Return a bool (don't know why it is declared as undefined) whether the decryption worked or not.</li>
</ol>
<p>Below I also posted the assembly code for this block of code (starting at the counter = 0 in the while loop for type == 2)
<a href="https://i.stack.imgur.com/uCtlF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uCtlF.png" alt="enter image description here" /></a></p>
<hr />
<p>As said in the beginning, I am not experienced when it comes to this kind of things.</p>
<p>I therefore would like some additional information on how I would continue from here on, so that I could implement the decryption in my programming language of choice - what exactly is the code block above doing?</p>
<p>I hope I included all information needed.</p>
<p>Thanks for reading (and helping)! :)</p>
| Help regarding XOR game decryption algorithm | |disassembly|static-analysis|decryption|packet|xor| |
<p>Something like:</p>
<pre><code>struct partially_known {
char gap0[12];
int student_id;
char gap10[32];
};
</code></pre>
| 27415 | 2021-04-07T19:58:56.817 | <p>I want to define struct in Ida , but I know only partial of this struct</p>
<p>I only know that in <code>arr[12]</code> that int student_id , and I don't know the rest of struct. Ida recognize that struct as <code>char *</code> .</p>
<p>How can I define that struct?</p>
| Define partial struct with IDA | |ida|struct| |
<p>All statically linked MFC binaries I've seen always include strings for some internal classes. The naming convention can be found in afximpl.h:</p>
<pre><code>#define AFX_WNDCLASS(s) \
_T("Afx") _T(s) _T(_MFC_FILENAME_VER) _STATIC_SUFFIX _UNICODE_SUFFIX _DEBUG_SUFFIX
#define AFX_WND AFX_WNDCLASS("Wnd")
#define AFX_WNDCONTROLBAR AFX_WNDCLASS("ControlBar")
#define AFX_WNDMDIFRAME AFX_WNDCLASS("MDIFrame")
#define AFX_WNDFRAMEORVIEW AFX_WNDCLASS("FrameOrView")
#define AFX_WNDOLECONTROL AFX_WNDCLASS("OleControl")
</code></pre>
<p>So, for example, AfxWnd100s means that the program has been compiled with the static release MFC 10.0 library while AfxWnd140sd will be present in the static debug build of MFC 14.0 (VS2015). The string will be in Unicode (UTF-16) and with the <code>u</code> suffix for Unicode builds (e.g. <code>AfxWnd140sud</code>).</p>
| 27421 | 2021-04-08T13:03:01.693 | <p>I have an exe with symbols stripped that I am trying to reverse engineer. I know the library is linked with MFC but I don't know which version. (Therefore, I can't use something like FLIRT signatures etc. to import known symbols and help reverse engineering).</p>
<p>Is there a way to deduce the version of MFC statically linked into an exe from the exe itself?</p>
<p>I have tried some trial and error approaches but really it caused a lot of trouble as some symbols matched and others don't. I'm looking for a tried and tested way - is something embedded in the metadata of an exe?</p>
| Find out version of statically linked MFC from an exe | |windows|dynamic-linking|mfc| |
<p>I think I'd start with the Raspberry Pi. The reason is that among the pieces you've listed, it's probably the one that has the most available documentation.</p>
<h3>โThe first rule of intelligent tinkering is to save all the pieces.โ -- Aldo Leopold</h3>
<p>Because the Raspberry Pi boots from a MicroSD card, the first thing I'd do would be to <strong>make a copy of that card</strong> and preserve the original. Because it's probably running Raspberry Pi OS (a Linux derivative), it would be easiest to dissect the contents of that card under Linux. Here's a bash script to mount the two partitions of the standard format Pi image:</p>
<pre><code>#!/bin/bash
# Automatically mount a Raspberry Pi image
if [[ ! $(whoami) =~ "root" ]]; then
echo ""
echo "**********************************"
echo "*** This should be run as root ***"
echo "**********************************"
echo ""
exit
fi
if [[ -z $1 ]]; then
echo "Usage: ./mountimg.sh my-favorite-pi.img"
exit
fi
if [[ ! -e $1 ]]; then
echo "Error : Not an image file, or file doesn't exist"
exit
fi
fatoffset=`parted -m $1 unit B print |sed -e 'y/B/ /'|grep fat|awk -F: '{print $2}'`
fatlimit=`parted -m $1 unit B print |sed -e 'y/B/ /'|grep fat|awk -F: '{print $4}'`
extoffset=`parted -m $1 unit B print |sed -e 'y/B/ /'|grep ext4|awk -F: '{print $2}'`
extlimit=`parted -m $1 unit B print |sed -e 'y/B/ /'|grep ext4|awk -F: '{print $4}'`
echo "fatoffset = ${fatoffset}."
echo "fatlimit = ${fatlimit}."
echo "exttoffset = ${extoffset}."
echo "exttlimit = ${extlimit}."
mkdir img1 img2
echo mount -t vfat -o loop,offset=${fatoffset},sizelimit=${fatlimit} "$1" img1
echo mount -t ext4 -o loop,offset=${extoffset},sizelimit=${extlimit} "$1" img2
</code></pre>
<p>Once the copy is mounted, I'd start by looking at its boot sequence.</p>
<h2>What software does it load?</h2>
<p>Study the boot sequence of the Pi from the copy of the SD card. Generally, the interesting bits are likely to have configuration items in <code>/etc</code> and <code>/boot</code>. The startup sequence is <a href="https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#boot-sequence" rel="nofollow noreferrer">well documented</a> so you might find it useful to start there. I have even sometimes seen source code left on a device, so you could get very lucky that way.</p>
<h2>What users exist on the system?</h2>
<p>Custom software for Raspberry Pi-based systems is often installed as either <code>root</code> or as another user. If it's under another user, it could be the default <code>pi</code> user or it could be some newly created user. By examining <code>/etc/passwd</code> you can see which users and systems are provisioned on the machine and get some clues as to what is running. For example, if it has <code>mysql</code> and <code>mosquitto</code> as users, you can conclude that is has both a database and an MQTT broker which suggest further avenues for exploration.</p>
<h2>Try running the software</h2>
<p>A Raspberry Pi is a pretty inexpensive device. I'd suggest getting one, if you don't already have one, and booting it up with your cloned SD card but no peripherals attached. Make a note of what processes are running and look for their binary files on the SD card.</p>
| 27425 | 2021-04-09T06:32:38.953 | <p>I am looking to reverse engineer a construction security camera. I am a self-learner, and have a very general grasp on electrical engineering and coding - so I'm not entirely 'out of my element' - but I understand this is a big challenge that requires a lot of work. I am looking to eventually create an interface that will let see what the camera sees, as well as utilize its PTZ functions. <strong>What would be the most idiot proof method of entry to figure out the interface?</strong></p>
<p>The camera (or camera package I guess) in question is an <a href="https://www.axis.com/en-us/products/axis-q6128-e" rel="nofollow noreferrer">Axis PTZ camera</a>, which is connected to an Axis DC <a href="https://www.axis.com/en-us/products/midspans/axis-t81b22-dc-30-w-midspan-1-port" rel="nofollow noreferrer">PoE midspan</a>. The midspan directly plugs into a Raspberry Pi 3 Model B that bootloads directly from a micro-SD card (to me that was rather surprising). The pi then has three USB cables, two of which run to a proprietary board (which will be described and pictured below), and the third which plugs into a Sierra Wireless AirLink RV50 for transmission via wireless carrier network.</p>
<p>The proprietary board has two JTAG ports, a ten-pin port that connects to an <a href="https://www.adestotech.com/wp-content/uploads/doc8784.pdf" rel="nofollow noreferrer">Adesto SPI flash</a>, and a 20 pin JTAG that connects to a <a href="http://www.latticesemi.com/iCE40#_21E33C7EC0BD48AA80FE384ED73CC895" rel="nofollow noreferrer">Lattice Semi ICE40 HX8X FPGA chip</a>. The only other chips of notable manufacture is a <a href="https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers" rel="nofollow noreferrer">SILabs CP2102</a>, and a <a href="https://www.ti.com/product/ADC088S022?utm_source=supplyframe&utm_medium=SEP&utm_campaign=not_alldatasheet&DCM=yes#product-details##description" rel="nofollow noreferrer">TI CMOS sensor ADC</a>. The board also houses the power transformer and directs power to all the components.</p>
<p><a href="https://i.stack.imgur.com/biVDX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/biVDX.jpg" alt="A picture of the proprietary board (aside from the transformer side)" /></a></p>
<p>There are a few points of access I could try to get access to the control system, but i am curious about all y'alls opinion.</p>
<p>TL;DR <strong>What would be more forgiving of novice blunders?</strong> Would it be better if I were to try to change any programming on the card? Is it better to try to decode the data as it is sent to the WIFI access point? Just curious what the best method of entry/analysis should be. Everything I have seen on the internet involves some sort of IP sniffing, but when the camera has its own unique network system via cellular carrier, and I don't know what it is transmitting... Better to not.</p>
<p>Hoping for the best, and excited to hear any tips you all might have.</p>
<p>Cheers!
Photovoltaeic</p>
| Most idiot-proof method of entry to Reverse Engineer Visual/Control feed for security camera | |hardware| |
<p>You can parse a header using <a href="https://www.hex-rays.com/products/ida/support/idadoc/1367.shtml" rel="nofollow noreferrer">File > Load file > C header file</a> or <a href="https://github.com/trou/apache-module-ida-til" rel="nofollow noreferrer">create a type library</a> beforehand.</p>
| 27428 | 2021-04-09T18:02:39.427 | <p>I am reversing a program that has a lot of internal structs in it.</p>
<p>The problem is that there are a lot of structs, so i can't import them manually using local types->insert.</p>
<p>Lets say i have some header files that have all the definitions of these structs (but obviously a lot of other stuff as well like defines, since its an actual header file), is there anyway i can import this in IDA?</p>
<p>I cannot manually add structs because there are more than 1000 structs in these header files</p>
| Import header files in IDA to get the struct definitions? | |ida|windows|idapython|c|idapro-sdk| |
<p>I found a solution and gonna leave it here for future reference.</p>
<p>First, you need to calculate the linear address (the one the binary will have in run-time) from the RIP offset of the jump. Let's say the RIP offset is <code>0x8fe</code>. You add this, and the offset of the instruction itself (offset from start of .text section) plus the instruction size and you get a number. You then have to add this number to the start of the .text section, but this time, you need to include the <code>SectionAlignment</code> in your calculation. If the RVA of the <code>.text</code> is <code>0x400</code> and the <code>SectionAlignment</code> is <code>0x1000</code>, then the start of the <code>.text</code> will be at Image Base + <code>0x1000</code>.</p>
<p>Then you get the imported function names from the ILT <a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-directory-table" rel="nofollow noreferrer">Import Directory Table</a>. You do this by reading the <code>OriginalFirstThunk</code> pointer to <code>u1.Ordinal</code> and then to <code>Name</code>. For more details look <a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-directory-table" rel="nofollow noreferrer">here</a>.</p>
<p>When doing this, you know the order that the imported functions are imported, per dll.</p>
<p>Now, you need to get the <code>FirstThunk</code> RVA, which will point to a NULL location when the file isn't loaded. However, this RVA is the start of the IAT (in run-time). The size of each import is 8 bytes.</p>
<p>For example, if you see that a <code>CALL QWORD PTR [RIP+0xf8e]</code>, you calculate this number and you get (say) <code>0x0000022D932D2008</code> which is 8 bytes from the start of the IAT, you know that this call calls the <em>second</em> imported function. Since you know the order, you know which function it is.</p>
| 27437 | 2021-04-11T14:27:30.037 | <p>I am writing a program where I map an <code>.exe</code> PE file in memory and I "dissect" it.
I am disassembling the <code>.text</code> section of the target executable, using the <a href="https://github.com/gdabah/distorm" rel="nofollow noreferrer">distorm</a> disassembler.</p>
<p><code>CALL</code> instructions in the disassembly have an offset relative to the <code>RIP</code> register, e.g.: <code>CALL QWORD [RIP+0xf8e]</code>.</p>
<p>I am also reading the <code>Import Descriptor Table</code> and I can see all the function calls from various .dlls there.</p>
<p>When using dumpbin.exe with <code>/section:.text /disasm</code> to disassemble the same target <code>.exe</code>, although it shows the same opcodes <code>ff 15 8e 0f 00 00</code>, it somehow translates this RIP offset to the proper (and correct) Win32 function being called (in my program <code>GetCurrentProcessId()</code>), <code>call qword ptr [__imp_GetCurrentProcessId]</code>.</p>
<p>My question is how to "map"/resolve each <code>CALL</code> instruction that I see in my disassembly to a specific Win32 API call, like dumpbin does, since I don't run this program inside the debugger and therefore the IAT is not overwritten by the Windows loader to show the proper <code>jmp</code> instruction calling the Windows API. Is it a disassembler issue? Can I deduct this somehow using the various PE structures?</p>
| Disassembly call function offset from RIP | |disassembly|windows|pe|x86-64| |
<p>If someone feels the need to do this programmatically in a non-debug setting, this is the code I would use.</p>
<p>Note #1: There are some shortcut functions of my own <code>GetFuncStart</code> and such that are not included, I'm sure you can work them out. The reference to the <code>Commenter</code> class will just have to be removed.</p>
<p>Note #2: The seemingly extreme measures taken in <code>ZeroFunction</code> are the only way I have found to ensure a function is actually rebuilt. None of the ida_auto functions seem to do much. You may opt for something less extreme if it suits you.</p>
<p>Note #3: The order of called functions is reversed to attempt to do the rebuild from the bottom up, hopefully allowing IDA to make more educated guesses about arguments and such.</p>
<p>Note #4: The many superfluous variables, lists and such are from the larger original function which (amongst other things) produces .dot vizgraphs. I have left them in lest someone find a use for them.</p>
<pre><code>def RebuildFuncAndSubs(ea):
subs = RecurseCalled(ea)['calledLocs']
subs.reverse()
for addr in subs:
ZeroFunction(addr)
idc.auto_wait()
ZeroFunction(ea)
idc.auto_wait()
def RecurseCalled(ea=None, width=512):
def all_xrefs_from(funcea, iteratee=None):
if iteratee is None:
iteratee = lambda x: x
xrefs = []
for (startea, endea) in Chunks(funcea):
for head in Heads(startea, endea):
xrefs.extend([GetFuncStart(x.to) for x in idautils.XrefsFrom(head) \
if x.type in (ida_xref.fl_CF, ida_xref.fl_CN, ida_xref.fl_JF, ida_xref.fl_JN) \
and not ida_funcs.is_same_func(funcea, x.to) \
and IsFunc_(x.to)])
xrefs = list(set(xrefs))
return xrefs
if ea is None:
ea = idc.get_screen_ea()
calledNames = list()
calledLocs = list()
visited = set([])
if isinstance(ea, list):
pending = set(ea)
initial = set([GetFuncStart(x) for x in ea])
else:
pending = set([ea])
initial = set([GetFuncStart(ea)])
depth = 0
count = 0
added = [1]
functionCalls = collections.defaultdict(set)
namedFunctionCalls = collections.defaultdict(set)
fwd = dict()
rev = dict()
while pending and len(pending) < width:
target = pending.pop()
count += 1
added[0] -= 1
if added[0] < 1:
depth += 1
added.pop()
visited.add(target)
fnName = idc.get_func_name(target) or idc.get_name(target) or "0x%x" % ref
fnStart = GetFuncStart(target)
if fnStart < idc.BADADDR:
target = fnStart
visited.add(target)
if not fnStart in initial:
calledNames.append(fnName)
calledLocs.append(fnStart)
refs = all_xrefs_from(fnStart)
refs = set(refs)
refs -= visited
size1 = len(pending)
pending |= refs
size2 = len(pending) - size1
added.append(size2)
return {'calledName': calledNames,
'calledLocs': calledLocs,
}
def ZeroFunction(ea, total=False):
print("0x%x: ZeroFunction" % ea)
start = 0
end = 0
# Don't hold the func_t object open
func = clone_items(ida_funcs.get_func(ea))
if not func:
return BADADDR
# Keep existing comments
with Commenter(ea, 'func') as commenter:
fnLoc = func.start_ea
fnName = ida_funcs.get_func_name(fnLoc)
flags = func.flags # idc.get_func_attr(ea, FUNCATTR_FLAGS)
# remove library flag
idc.set_func_attr(fnLoc, FUNCATTR_FLAGS, flags & ~4)
ida_name.del_local_name(fnLoc)
ida_name.del_global_name(fnLoc)
# RemoveAllChunks(ea)
for start, end in idautils.Chunks(ea):
idc.remove_fchunk(start, end)
ida_funcs.del_func(func.start_ea)
idc.set_color(fnLoc, CIC_FUNC, 0xffffffff)
if not total:
func = ida_funcs.func_t(fnLoc)
res = ida_funcs.find_func_bounds(func, ida_funcs.FIND_FUNC_DEFINE | ida_funcs.FIND_FUNC_IGNOREFN)
if res == ida_funcs.FIND_FUNC_UNDEF:
print("0x%x ZeroFunction: func passed flow to unexplored bytes" % fnLoc)
elif res == ida_funcs.FIND_FUNC_OK:
ida_funcs.add_func_ex(func)
idc.auto_wait()
# remove library flag (again)
idc.set_func_flags(fnLoc, idc.get_func_flags(fnLoc) & ~4)
# return original function name
idc.set_name(fnLoc, fnName, idc.SN_NOWARN)
</code></pre>
| 27443 | 2021-04-12T10:10:33.883 | <p>How can i force IDA to re analyze a function recursively (meaning including every function inside of it and so on) and recognize all the functions inside of all the functions? because right now when a PE is mapped, IDA does not recognize any function inside of it, unlike when i analyze the PE file, and i have to click on every function (unk_xxx) and press P in start of it so it can recognize the function..</p>
<p>clicking on reanalyze in options doesnt work either.</p>
<p>Alt + P as suggested here doesn't work either :</p>
<p><a href="https://reverseengineering.stackexchange.com/questions/19967/api-to-force-reanalyze-of-function-alt-p">API to force reanalyze of function (Alt-P)</a></p>
<p>In decompiler view alt+P doesnt do anything at all, and in disassmbly it just edits the function.</p>
<p>Using IDA 7.5.</p>
| Force IDA to reanalyze a function recursively? | |ida|idapro-sdk| |
<p>There are some additional imports required:</p>
<pre><code>from com.google.security import binexport
import java.io.File as File
</code></pre>
<p>without which the codes will not work.</p>
| 27449 | 2021-04-12T22:14:07.253 | <p>I am working on patch diffing using ghidra + bindiff (specifically, <a href="https://github.com/google/binexport/tree/main/java/BinExport" rel="nofollow noreferrer">binexport</a>), and am looking for advice on using bindiff with Ghidra headless.</p>
<p><a href="https://github.com/TakahiroHaruyama/ida_haru/blob/master/bindiff/bindiff.py" rel="nofollow noreferrer">ida_haru</a> does essentially everything that I need, but for IDA instead of Ghidra. Specifically, I am wondering if something like the <code>_make_BinExport()</code> function exists for Ghidra.</p>
<pre><code>def _make_BinExport(self, target, ida_path):
binexp_path = self._get_db_path_noext(target) + '.BinExport'
#binexp_path = os.path.splitext(target)[0] + '.BinExport'
if not self._clear and os.path.exists(binexp_path):
self._dprint('already existed BinExport: {}'.format(binexp_path))
return 0
#cmd = [ida_path, '-A', '-S{}'.format(g_exp_path), '-OExporterModule:{}'.format(binexp_path), target] # the .BinExport filename should be specified in 4.3
cmd = [ida_path, '-A', '-S{}'.format(g_exp_path), '-OBinExportModule:{}'.format(binexp_path), target]
#print cmd
self._dprint('getting BinExport for {}'.format(target))
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
return proc.returncode
</code></pre>
<p>Things I have done:</p>
<ol>
<li>ghidra headless script to get the <code>func_names</code> and <code>min_addr</code> for each function in the binaries,</li>
<li>python script to work with the <code>original_vs_patched.BinDiff</code> files (sqlite3), and correlate results with the <code>func_names</code></li>
</ol>
<p>I'm missing:</p>
<ol start="0">
<li>ghidra headless script to create and export the <code>*.BinExport</code> files</li>
</ol>
<p>Advice and insights appreciated!</p>
| Ghidra headless + bindiff (binexport) | |ghidra|bin-diffing|tool-bindiff| |
<p>By finding the constructor for the structure type that you're looking at, making note of the VTable address, and adding the indicated offsets to obtain the concrete function pointers for the calls in question.</p>
| 27451 | 2021-04-13T00:17:11.547 | <p>I'm reverse engineering a game and came across some function calls like the ones shown below, how do I find where these functions are located / decompile them?</p>
<p><code>(*(BaseClient->int640 + 304))(BaseClient)</code></p>
<p><code>(*(BaseClient->int640 + 224))(BaseClient, *&v32->gap2[262], &v116, *&v32->gap2[342], v34, v33, v146, *&v32->gap2[246], &Mem, 0)</code></p>
<p><a href="https://i.stack.imgur.com/jINoX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jINoX.png" alt="2" /></a>
<a href="https://i.stack.imgur.com/6cHRt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6cHRt.png" alt="1" /></a></p>
| How do I find missing/undefined vtable functions in IDA64? | |ida|c++|c|game-hacking| |
<p>Let's break it down line by line. Assuming <code>x</code> is the thing you want to multiply by <code>21</code> and it's stored in <code>eax</code> (as it is in this example after line <code>34</code>).</p>
<pre><code><39>: mov edx, eax ; so copy the x to edx
<41>: mov eax, edx ; it's pointless to do this mov; after those two lines eax & edx has the value of x
<43>: shl eax, 2 ; so eax = x * 4
<46>: add eax, edx ; so eax = x * 5 (x * 4 + x)
<48>: shl eax, 2 ; so eax = x * 20 (x * 5 * 4)
<51>: add eax, edx ; so eax = x * 21 (x * 5 * 4 + x)
</code></pre>
<p>PS. For the future please post code as a text. Much easier to copy than from the image.</p>
| 27453 | 2021-04-13T11:50:36.460 | <p>I created a code construct in C to see how it looks in x86. I'm confused about the use of the shl instructions. I'm confused about what is happening in between the lines <+39> and <+51> I don't get how those instructions translate to the source code.</p>
<p><a href="https://i.stack.imgur.com/JW4Dm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JW4Dm.png" alt="Code construct" /></a></p>
<p>Here's the source code:
<a href="https://i.stack.imgur.com/Nz3r7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nz3r7.png" alt="Source" /></a></p>
<p>It's obviously compiler optimisation but I'm not understanding how that would be equal to multiplying by 21. [It's bit shifting eax, 0x2, or multiplying by 4 twice, but I don't understand how the add instructions make it go from multiplying by 16 to 21]</p>
<p>Thanks for any help! Rohail.</p>
| Confused about the use of the shl instruction in this disassembly | |disassembly|x86|c|gdb| |
<p>It was pretty easy one so I could do myself:)
We have exploit.c file where I need to debug it in order to get the flag with 'gcc'. I run the program with:</p>
<p><code>gcc -g exploit.c -o exploit</code></p>
<p>and got 'exploit' which is executable <code>exploit.c</code> file.
To launch the binary under a debugger - gdb</p>
<p><code>gdb exploit</code></p>
<p>We have <code>bool c = false;</code> on line 21, so put the break line on it:</p>
<pre><code>break 21
</code></pre>
<p>Then: I changed the value of c by this command: <code>set variable c = true</code>
However, when I went to the next line by โnextโ it become false again.
So I reset the value again: <code>set variable c = true</code> and then next button:
Yay, it printed out the flag:</p>
<pre><code>(gdb) next
The flag is: flaggy-flag
23 return 0;
</code></pre>
| 27469 | 2021-04-14T09:24:59.310 | <p>I have a file named exploit.c inside which:</p>
<pre><code>#include <stdbool.h>
#include <stdio.h>
const char y1 = 'a';
const char y2 = 'b';
const char y3 = 'x';
const char y4 = 'y';
const char y5 = 'i';
const char y6 = 'j';
char x1 = 'f' ^ 'a';
char x2 = 'l' ^ 'b';
char x3 = 'a' ^ 'x';
char x4 = 'g' ^ 'y';
char x5 = 'y' ^ 'i';
char x6 = '-' ^ 'j';
int main() {
bool c = false;
if(c) { printf("The flag is: %c%c%c%c%c%c%c%c%c%c%c\n", x1 ^ y1, x2 ^ y2, x3 ^ y3, x4 ^
y4, x4 ^ y4, x5 ^ y5, x6 ^ y6, x1 ^ y1, x2 ^ y2, x3 ^ y3, x4 ^ y4); }
return 0;
}
</code></pre>
<p>How can I print out the flag without changing the value of boolean but with gcc and gdb?</p>
| Changing value of parameter with gdb | |disassembly|assembly|debugging|gdb|gcc| |
<p>It's not a malware. It's cygwin's ssh-agent and it uses non existent PID as parent. I was able figure this out using a new version of ProcessHacker.</p>
| 27484 | 2021-04-16T16:46:27.060 | <p>I have a suspicious process. I found it by ProcessHacker's network tab.</p>
<p>ProcessHacker display the process as Unknown.</p>
<p>The process listening into a constant port number that's also not found by standard windows tools.</p>
<p>The process id also not found by standard windows tools.</p>
<p>Looking at Wireshark traffic, I see there is traffic going to two IPs in Russia.</p>
<p>I attempted to attach Frida into this process but Frida reports an error like below,</p>
<pre><code>[Error: Unexpected error allocating memory in target process (VirtualAlloc returned 0x00000005)]
</code></pre>
<p>I've used both 64 bit and 32 bit versions of Frida but still same error.</p>
| Unable to attach into mysterious PID | |windows|process|frida|processhacker| |
<p>The <a href="https://itanium-cxx-abi.github.io/cxx-abi/abi.html" rel="nofollow noreferrer">Itanium C++ ABI</a> is sometimes not very clear about what exactly is โvtableโ.</p>
<p>In practice, the symbol such as <code>_ZTV12DerivedClass</code> points to the <em>complete vtable structure</em>, which includes the two pointer-sized slots before it (RTTI pointer and offset to top).</p>
<p>So, to get the start of the virtual function pointers table (what is commonly understood as โthe vtableโ), you have to add 16 (or 8 on 32-but platforms) to the symbolโs address.</p>
| 27485 | 2021-04-16T21:14:35.513 | <p>I know this is compiler/ABI dependent, not necessarily standardized, etc. I've always assumed, from what I've read in several places (e.g. <a href="https://reverseengineering.stackexchange.com/a/5957/33935">an answer here</a> or <a href="https://en.wikipedia.org/w/index.php?title=Virtual_method_table&oldid=1007338497#Example" rel="nofollow noreferrer">the example in wikipedia</a>), that a typical thing a compiler does is having a pointer to the vtable of <code>Class</code> at the start of an object of type <code>Class</code>.</p>
<p>I'm now debugging and instrumenting a function that receives a <code>Class*</code> parameter. <code>Class</code> has virtual functions. I want to <strong>determine if it belongs to a class</strong> that I care about. I probably also want to do other things with it, so I'm trying to get a good understanding.</p>
<p>I look at the disassembly in Ghidra, and I find this about the vtable of that class (paste is coming from an example I wrote, but it's equivalent in a real binary that I want to RE):</p>
<pre><code> **************************************************************
* vtable for DerivedClass *
**************************************************************
_ZTV12DerivedClass XREF[3]: Entry Point(*),
DerivedClass::vtable operator():001039d1(*),
_elfSectionHeaders::00000650(*)
00107c70 00 00 00 ptrdiff_
00 00 00
00 00
00107c70 [0] 0h
00107c78 88 7c 10 addr DerivedClass::typeinfo =
00 00 00
00 00
PTR_ARRAY_00107c80 XREF[2]: operator():001039d8(*),
operator():001039dc(*)
00107c80 94 42 10 addr[1]
00 00 00
00 00
00107c80 94 42 10 00 00 addr DerivedClass::someVirt [0] XREF[2]: operator():001039d8(*),
00 00 00 operator():001039dc(*)
</code></pre>
<p>And here is where my surprise is:</p>
<ol>
<li>I get the address of <code>_ZTV12DerivedClass</code> (e.g. via Frida, <code>Module.findExportByName(null, "_ZTV12DerivedClass")</code> or in GDB, <code>info address _ZTV12DerivedClass</code>).</li>
<li>I get the address of the vtable of the object (it's 64 bits, so 8 first bytes of the object), again, in the debugger or with Frida.</li>
<li>I compare the two, and I get that <em>they are 16 bytes away</em>, the size of 2 pointers: the pointer in the object instance is <strong>not to the start</strong> of the vtable, but at the start of the array of pointers to the virtual functions!</li>
</ol>
<p>This is not Earth-shattering in order to compare the pointers, of course. Just add 16. I've seen explanations of what those first two pointers should be. But I have some doubts:</p>
<ol>
<li>Is it reliable to assume that the difference of 16 is going to be consistent in all classes in the same binary?</li>
<li>Is this common in more compilers?</li>
<li>Do the two positions in the table (the very start of it and the start of the array of pointers to the virtual functions) have any naming convention? I find it surprising that there is a pointer to something and it's not the start of the vtable as found on the disassembly.</li>
<li>Could be some historical legacy? If C++ first had virtual functions but without virtual inheritance or RTTI, it might explain that those two extra pointers were added to the top to not change some other assumptions.</li>
</ol>
| Comparing the static address of the vtable of a class, to the pointer to it held by the object | |linux|gcc|pointer|vtables| |
<p>There are plenty of non-Linux solutions for embedded systems, ranging from an RTOS such as eCos, FreeRTOS, ThreadX, Nucleus and many others to a completely monolithic, custom made firmware without any specific OS environment. About the only way to find out for sure is to start disassembling and figure out how it works.</p>
<p>My old presentation may be of some use for background info:</p>
<p><a href="https://github.com/skochinsky/papers/blob/master/2010-07%20%5BRecon%5D%20Intro%20to%20Embedded%20Reverse%20Engineering%20for%20PC%20reversers.pdf" rel="nofollow noreferrer">https://github.com/skochinsky/papers/blob/master/2010-07%20%5BRecon%5D%20Intro%20to%20Embedded%20Reverse%20Engineering%20for%20PC%20reversers.pdf</a></p>
| 27486 | 2021-04-16T23:05:49.227 | <p>I decided to play around with an old baby monitor, purely to learn something about how such things (I.E. embedded devices) work. I successfully extracted the flash memory, and I was expecting this to have a uboot image plus a squashfs filesystem or something along those lines. binwalk dashes my hopes of that:</p>
<pre><code>$ binwalk motorola_1.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
</code></pre>
<p>Instead it's apparently full of ARM instructions:</p>
<pre><code>$ binwalk -A motorola_1.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
300 0x12C ARM instructions, function prologue
328 0x148 ARM instructions, function prologue
404 0x194 ARM instructions, function prologue
428 0x1AC ARM instructions, function prologue
1176 0x498 ARM instructions, function prologue
1580 0x62C ARM instructions, function prologue
</code></pre>
<p>Now before doing this, I connected to the monitor's UART headers and was presented with some kind of debug program, that allowed me to view the camera's current slew, tweak the display settings and so on. The strings of that program's printouts are all visible within the binary I extracted from the chip if I run <code>strings</code> on it, so this is obviously what was running there. I'm quite confused as to <em>how</em> it was running if the firmware isn't some form of linux image though.</p>
<p>The board has no other flash chip that I can see, though there is a (regrettably unidentifiable) IC that's obviously a processor or SOC of some sort which I suppose could have an internal flash section.</p>
<p>If this isn't some form of linux image, then, <em>what could it be</em>? Pure ARM instructions implies it's just a program, but I don't really understand how it can be executing the program without the OS booting to run it. Or is it likely that I'm simply missing something?</p>
<p>EDIT: The chip, if it matters, is a Winbond W25Q16.V - not exactly a large chip for storing a linux image on...or so it seems to me anyway. But what do I know?</p>
| What could a firmware image be, if not embedded linux? | |linux|arm|embedded|flash| |
<p>I already created a script, However, It probably won't work, Although, There is a folder called assemblies without the mono bundle, you will probably just need to zip the extracted dlls, create the folder, and delete the mono bundle</p>
<p>However, I'm not sure, but anything is possible :)</p>
| 27498 | 2021-04-17T22:49:03.223 | <p>I recently had to make a version of a survivalcraft 2 mod that allowed circuits to run faster</p>
<p>I found this script by stack overflow to unpack a mono bundle app</p>
<p>I already modified the .dll, but I need to repack it, and I don't know anything about pyelftools</p>
<p>Script:</p>
<pre><code>from elftools.elf.elffile import ELFFile
from zipfile import ZipFile
from cStringIO import StringIO
import gzip, string
data = open('libmonodroid_bundle_app.so').read()
f = StringIO(data)
elffile = ELFFile(f)
section = elffile.get_section_by_name('.dynsym')
for symbol in section.iter_symbols():
if symbol['st_shndx'] != 'SHN_UNDEF' and symbol.name.startswith('assembly_data_'):
print symbol.name
dll_data = data[symbol['st_value']:symbol['st_value']+symbol['st_size']]
dll_data = gzip.GzipFile(fileobj=StringIO(dll_data)).read()
outfile = open(symbol.name[14:].replace('_dll', '.dll'), 'w+'); print symbol.name[14:].replace('_dll', '.dll')
outfile.write(dll_data)
outfile.close()
</code></pre>
| How to repack the monobundleapp | |android|c#| |
<p>I just found what appears to be the official version of the adjustment function for the transmigration of worthless min-spd based offsets into heaven sent frame based offsets.</p>
<h3>cfunc.get_stkoff_delta()</h3>
<p><em>Possible implementation:</em></p>
<pre><code>def GetMinSpdAdjustment(funcea):
func = ida_funcs.get_func(funcea)
return 0 - (func.frsize + func.frregs + idc.get_spd(idc.get_min_spd_ea(func.start_ea)))
</code></pre>
<p><em>Example usage:</em></p>
<pre><code>vu = idaapi.open_pseudocode(funcea, 0)
vu.cfunc.lvars[10].get_stkoff() - vu.cfunc.get_stkoff_delta()
</code></pre>
<p><em>Complete example:</em></p>
<pre><code>
# call rename_lvar(old, new, ea)
def get_pseudocode_vu(ea, vu):
if vu:
return vu
return idaapi.open_pseudocode(ea, 0)
def label_stkvar(offset, name, ea=None, vu=None):
sid = idc.get_frame_id(ea)
old_name = idc.get_member_name(sid, offset)
if old_name:
if old_name == name:
return old_name
if idc.set_member_name(sid, offset, name):
return old_name
def rename_lvar(old, new, ea, uniq=0, vu=None):
def make_unique_name(name, taken):
if name not in taken:
return name
fmt = "%s_%%i" % name
for i in range(3, 1<<10):
name = fmt % i
if name not in taken:
return name
old = old.strip()
new = new.strip()
if old == new:
return True
vu = get_pseudocode_vu(ea, vu)
names = [n.name for n in vu.cfunc.lvars]
if new in names:
if uniq:
return False
new = make_unique_name(new, names)
lvars = [n for n in vu.cfunc.lvars if n.name == old]
if lvars:
lvar = lvars[0]
if lvar.is_stk_var():
offset = lvar.get_stkoff() - vu.cfunc.get_stkoff_delta()
old_name = label_stkvar(offset, new, ea=ea, vu=vu)
return vu.rename_lvar(lvar, new, 1)
</code></pre>
| 27507 | 2021-04-20T11:18:55.907 | <p>When using the stack offset for a variable obtained via <code>ida_hexrays.lvar_t.stk.get_stkoff()</code> or <code>ida_hexrays.vdloc_t.stkoff()</code> the results vary between "correct", and 8 or 16 bytes out as measured either manually or as compared to the results obtained from:</p>
<pre><code>id = idc.get_frame_id(here())
for member in idautils.StructMembers(id):
offset, name, size = member
</code></pre>
<p>The incorrect offsets are sourced from:</p>
<pre><code>func = idaapi.get_func(ea)
vu = idaapi.open_pseudocode(func.start_ea, 0)
[n.get_stkoff() for n in vu.cfunc.lvars if n.is_stk_var()]
</code></pre>
<p><em>[edit]: the difference appears to be caused by the pseudo-code vu reporting offsets relative to the minimal SPD, whilst everything else uses the post-prologue SPD (code beneath)</em></p>
<pre><code>def GetPseudoStackOffsetCorrection(funcea):
func = ida_funcs.get_func(funcea)
return func.frsize + func.frregs + idc.get_spd(idc.get_min_spd_ea(func.start_ea))
</code></pre>
<p><em>[edit 2]: this alternate method works <strong>sometimes</strong>. it functions by looking at the insn located at <code>lvar_t.defea</code> (assumedly "defined at ea") and calculating from there. However 10% of the time <code>lvar.defea</code> points at a conditional jmp, so again -- very kludgy</em></p>
<pre><code>def get_stkoff_from_lvar(lvar, debug=1):
ea = idc.get_item_head(lvar.defea)
func = ida_funcs.get_func(ea)
if not func:
return idc.BADADDR
for n in range(2):
if idc.get_operand_type(ea, n) == idc.o_displ:
offset = idc.get_operand_value(ea, n) + func.frsize - func.fpd
if debug:
lvar_name = lvar.name
sid = idc.get_frame_id(func.start_ea)
frame_name = idc.get_member_name(sid, offset)
print("[debug] offset:0x{:x}, lvar_name:{}, frame_name:{}"
.format(offset, lvar_name, frame_name))
return offset
</code></pre>
<p><em>[edit]: kludges aside (which I would prefer not to use) I have issues with my</em>
[...] "rename, retype and remap" (with regex) package, which I recently noted does not update the "stack" (visible in assembly) names when calling <code>vu.rename_lvar</code> as would normally happen when performing a rename via <kbd>N</kbd></p>
<p>Without an accurate offset, there is no way for the code to rename the corresponding stack variable <code>var_18</code> when renaming the pseudo-code variable <code>v1</code> (for example).</p>
<p>Any solution to this general problem is welcome, though preferentially one that allows the correct stack location of pseudo-code variables would be best as I will shortly be attempting "watch-variables" via flare-emu.</p>
<p>These are some results from a test function written to compare the conflicting results I have been receiving, and to confirm to myself that there is no magic "just deduct func.frregs" type answer.</p>
<p>Function 1.</p>
<pre><code>func.flags : FUNC_FRAME | FUNC_PURGED_OK | FUNC_SP_READY
func.frregs : 8
func.frsize : c0
func.fpd : a0
ida_frame.frame_off_retaddr : c8
ida_frame.frame_off_lvars : 0
ida_frame.frame_off_args : d0
ida_frame.frame_off_savregs : c0
name lvar_offset1 stk_offset
-------------- ------------ ----------
range 0x30 0x28
guide 0x38 0x30
ImageBase 0x58 0x50
_stack_padding 0xd8 0xd0
</code></pre>
<p>Function 2</p>
<pre><code>func.flags : FUNC_FRAME | FUNC_PURGED_OK | FUNC_SP_READY
func.frregs : 8
func.frsize : 1c0
func.fpd : 190
ida_frame.frame_off_retaddr : 1c8
ida_frame.frame_off_lvars : 0
ida_frame.frame_off_args : 1d0
ida_frame.frame_off_savregs : 1c0
name lvar_offset1 stk_offset
------------------------- ------------ ----------
lpTopLevelExceptionFilter 0x50 0x40
LibFileName 0x88 0x78
Handle 0xc8 0xb8
lpProcName 0x110 0x100
hObject 0x198 0x188
hModule 0x1a0 0x190
</code></pre>
<p>Function 3</p>
<pre><code>func.flags : FUNC_FRAME | FUNC_PURGED_OK | FUNC_SP_READY
func.frregs : 8
func.frsize : 40
func.fpd : 20
ida_frame.frame_off_retaddr : 48
ida_frame.frame_off_lvars : 0
ida_frame.frame_off_args : 50
ida_frame.frame_off_savregs : 40
name lvar_offset1 stk_offset
------ ------------ ----------
accum1 0x20 0x20
accum2 0x2c 0x2c
</code></pre>
<p>I can provide the test code if required, though it's not small.</p>
<p><em>[edit: test code attached, warning: not pretty]</em></p>
<pre><code># test code:
# sync_lvars_to_stk(func_ea)
def get_func_flag_names(f):
return [x for x in [k for k in dir(idc)
if k.startswith('FUNC_')]
if f.flags & getattr(idc, x)]
def _get_vu(ea, vu):
if vu: return vu
return idaapi.open_pseudocode(idaapi.get_func(ea).start_ea, 0)
def get_lvars(ea, vu=None):
vu = _get_vu(ea, vu)
return [n.get_stkoff() for n in vu.cfunc.lvars if n.is_stk_var()]
def dump_stkvars(ea=None, iteratee=None):
def get_member_tinfo(sid, offset):
s = ida_struct.get_struc(sid)
m = ida_struct.get_member(s, offset)
tif = ida_typeinf.tinfo_t()
try:
if ida_struct.get_member_tinfo(tif, m):
return tif
except TypeError:
pass
results = []
sid = idc.get_frame_id(ea)
for member in idautils.StructMembers(sid):
o = AttrDict()
o.offset, o.name, o.size = member
o.mid = idc.get_member_id(sid, o.offset)
o.name = idc.get_member_name(sid, o.offset)
o.size = idc.get_member_size(sid, o.offset)
o.flags = idc.get_member_flag(sid, o.offset)
tif = get_member_tinfo(sid, o.offset)
o.tifname = str(tif) if tif else ''
o.sid = sid
if callable(iteratee): iteratee(o)
results.append(o)
return results
def indexBy(o, key):
r = {}
for x in o:
r[x[key]] = x
return r
def sync_lvars_to_stk(ea, vu=None):
vu = _get_vu(ea, vu)
func = idaapi.get_func(ea)
print("\n{:28}: {}\n{:28}: {:3x}\n{:28}: {:3x}\n{:28}: {:3x}\n{:28}: {:3x}\n{:28}: {:3x}\n{:28}: {:3x}\n{:28}: {:3x}\n"
.format(
"func.flags", " | ".join(get_func_flag_names(func)),
"func.frregs", func.frregs,
"func.frsize", func.frsize,
"func.fpd", func.fpd,
"ida_frame.frame_off_retaddr", ida_frame.frame_off_retaddr(func),
"ida_frame.frame_off_lvars", ida_frame.frame_off_lvars(func),
"ida_frame.frame_off_args", ida_frame.frame_off_args(func),
"ida_frame.frame_off_savregs", ida_frame.frame_off_savregs(func),
))
stkvars = indexBy(dump_stkvars(ea), 'name')
lvars = []
if vu and func:
stk_lvars = [(n.name, n.tif.get_size(),
n.location.stkoff(),
) for n in vu.cfunc.lvars if n.location.is_stkoff()]
for name, size, offset in stk_lvars:
o = AttrDict()
o.update({
'name': name,
'size': size,
'lvar_offset': offset,
})
lvars.append(o)
lvars = indexBy(lvars, 'name')
lvar_names = lvars.keys()
for name in lvar_names:
if name in stkvars:
print({
'name': name,
'lvar_offset': lvars[name].lvar_offset,
'stk_offset': stkvars[name].offset,
})
class AttrDict(dict):
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self
</code></pre>
| ida_hexrays.lvar_t.stk.get_stkoff() incorrect ยฑ 0x10 | |ida|idapython| |
<p>See your emulator, your ADB communication probably failed, open your terminal and check that your emulator is displayed with an ADB device, generate a new RSA certificate and try again, I recently had the same problem with debugger from IDA and its competitor JEB, and that was the solution that worked for me.</p>
<p><a href="https://www.trustwave.com/en-us/resources/blogs/spiderlabs-blog/debugging-android-libraries-using-ida/" rel="nofollow noreferrer">See also how to properly configure the ADB for your IDA or emulator / device.</a></p>
<p>Try to allow local connections via adb using:</p>
<blockquote>
<p>"adb forward tcp:23946 tcp:23946". This will allow connections to localhost:23946 and forward those to the emulator.</p>
</blockquote>
| 27510 | 2021-04-20T15:57:33.840 | <p>I have a running IDA debug-server on my virtual android device(check attachments).
The problem is: when I try hit Attach procces it gives me an error(check title).
Here is some kinda params that I'm using: <a href="https://i.stack.imgur.com/smk79.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/smk79.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/HVmVy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HVmVy.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/lV0hu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lV0hu.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/xOMBZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xOMBZ.png" alt="enter image description here" /></a></p>
<p>I have already seen similliar question here: <a href="https://reverseengineering.stackexchange.com/questions/17445/failed-to-use-ida-to-remote-android-debug">Failed to use IDA to remote android debug</a>
As @0xC0000022L said: <em>You need to select Remote Linux in the debugger attach menu of IDA</em>, but I don't have this particular option. Is there any ideas? I appreciate any help. Thank you!</p>
| Remote debugging android native lib(.so) No connection could be made because the target machine actively refused it. when connecting to | |ida|android| |
<p>The I/O register names and bit layouts for processors that support them are stored in processor-specific <code>.cfg</code> files. For M16C, the files are <code>m16c60.cfg</code> and <code>m16c80.cfg</code>:</p>
<pre><code>dm0con 0x2c DMA0 control register
dm0con.dmbit_dm0con 0 Transfer unit bit select bit
dm0con.dmasl_dm0con 1 Repeat transfer mode select bit
dm0con.dmas_dm0con 2 DMA request bit
dm0con.dmae_dm0con 3 DMA enable bit
dm0con.dsd_dm0con 4 Source address direction select bit
dm0con.dad_dm0con 5 Destination address direction select bit
</code></pre>
<p>You can either edit the default registers or make a copy of the default <code>.m16c</code> device section under a new name and select it at load time.</p>
<p><a href="https://i.stack.imgur.com/tqwEM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tqwEM.png" alt="enter image description here" /></a></p>
| 27518 | 2021-04-21T06:27:13.987 | <p>I've just started reversing some microcontroller code and have the RAM, ROM, and SFR (Special Function Registers) segments set up. I've selected my processor architecture and it has named most of the registers correctly automatically. However, a few are incorrect (I assume this is due to variations between specific chips in the architecture family).</p>
<p>This is not a problem for most registers as I can simply rename and recomment them. However, some of the registers have the specific bits labelled and I have tried absolutely everything I can to remove them. I can rename the register itself and recomment it just fine, but I cannot modify or delete the bit specific fields.</p>
<p>In the image I have renamed the register at 002C to "VW2C" and added the correct comment. The previous name was "dm0con". As can be seen, the bit specific fields are still there and trying to rename or recomment them just edits the actual register itself.</p>
<p>I have searched and searched online but it is hard to find the answer since I'm not even sure what the proper name for these fields are. I have looked through all the toolbars and submenus but cannot get rid of these bit specific definitions.</p>
<p><a href="https://i.stack.imgur.com/HYqi0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HYqi0.jpg" alt="enter image description here" /></a></p>
| IDA Pro - How to remove multi-line bit definitions for register | |ida|disassembly|assembly|tools|register| |
<p>I am not sure what you are asking (never used sticky notes and don't have it installed )<br />
but if you want to run sticky notes from command line you can do something like this</p>
<p>the command below will run calculator instead of the wildcard <em>calc</em> use <em>stick</em></p>
<pre><code>C:\>powershell -c "(get-startapps -name *calc*).Appid
Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
C:\>start shell:appsfolder\Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
</code></pre>
<p>you can obviously use this with python withsomething like</p>
<pre><code>C:\>python -c "import os;os.system(\"start explorer shell:appsfolder\Microsoft.WindowsCalculator_8wekyb3d8bbwe!App\")"
</code></pre>
<p>if you need to start a new note from a script checkout</p>
<pre><code>:\>pip show uiautomation
Name: uiautomation
Version: 2.0.11
Summary: Python UIAutomation for Windows
Home-page: https://github.com/yinkaisheng/Python-UIAutomation-for-Windows
Author: yinkaisheng
Author-email: yinkaisheng@live.com
License: Apache 2.0
Location: c:\python39\lib\site-packages
Requires: comtypes
Required-by:
</code></pre>
<p>with this it is a single liner the Name ="New Note" is taken from your comments be aware the uwp app needs to be in foreground for this to work
tooltip remark</p>
<pre><code>:\>python -c "import uiautomation as auto;auto.ButtonControl(Seachdepth=1,Name =\"New note\").Click()"
</code></pre>
<p>a gif</p>
<p><a href="https://i.stack.imgur.com/4IrZz.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4IrZz.gif" alt="enter image description here" /></a></p>
| 27522 | 2021-04-21T16:50:11.967 | <p>For a silly little project I wanted to do, I wanted to make it so that I could open new notes (Microsoft Sticky Notes) from an external script - preferably python. Although I'm not good at reverse engineering I thought that it shouldn't be too hard because I <em>thought</em> it was a standalone exe.
It was only until I couldn't launch the exe on it's own that I realised it's a UWP app which means I couldn't do my go-to debugging it in IDA.</p>
<p>(Just to mention now, I noticed that sticky notes always has two processes running - <code>ApplicationFrameHost</code> which I assume is the main sticky notes window and another process which I assume is the actual open sticky notes. All the methods I've tried, I've tried on both processes to be certain.)</p>
<p>I started by opening sticky notes in IDA and trying to use the debugger, but as mentioned, that didn't get me too far so I opened it up in Binary Ninja instead, just to explore a bit. I didn't know what to look for, so I didn't find much. However, BN did show a lot of strings except apparently they aren't used anywhere in the program. Things like:</p>
<pre><code>BCreateStickyNoteViaJumplistAction - "Jumplist" is also in the name of the plus icon used as the button - C:\Program Files\WindowsApps\Microsoft.MicrosoftStickyNotes_3.8.8.0_x64__8wekyb3d8bbwe\Assets\JumpListNewNote.png`
CreateNewNote .... WithNewStickyNote
TryGet_ViewState_IsSticky
</code></pre>
<p>and lots of what looks like C# code. But as I mentioned, BN showed no references to these (and other) strings and as I'll mention later, the strings in x64dbg all seemed "encoded" so I never found a use for these anyway.</p>
<p>Next I think I tried out WinDBG (preview). I tried first by just attaching it to the running sticky notes process (and then launching the app using the <code>launch app package</code>) but I wasn't able to do anything with that. It just told me the DLL's that were being loaded, including the ones missing which means I couldn't launch the exe directly, like:</p>
<pre><code>C:\Program Files\WindowsApps\Microsoft.NET.Native.Runtime.2.2_2.2.28604.0_x64__8wekyb3d8bbwe\mrt100_app.dll
C:\Program Files\WindowsApps\Microsoft.NET.Native.Framework.2.2_2.2.29512.0_x64__8wekyb3d8bbwe\SharedLibrary.dll
</code></pre>
<p>Maybe it's possible to somehow point the exe to these DLL so I could launch it via IDA but I think it's a stretch.</p>
<p>I did a few other small things here and there like ollydbg and <a href="http://www.codedebug.com/php/Products/Products_NikPEViewer_20v.php" rel="nofollow noreferrer">PE Disassembler viewer</a> but they are not of significance.</p>
<p>The thing I have been trying the most is x64dbg. On my own, I didn't really get anything done; I didn't find anything related to buttons or their handler's. So I tried googling to see if someone else had tried reverse engineering a UWP and came across <a href="https://reverseengineering.stackexchange.com/questions/17127/how-to-reverse-engineer-a-windows-10-uwp-app">this</a>. I gave the second answer a go, since it was quicker to do at the time. However, when you click to open a new note, no new DLL's will be loaded so I couldn't use that. I tried also breaking when a new thread is created which did cause it to stop execution when I created a new note but I don't think each new note is its own thread, I think that was just some other internal Windows thing.</p>
<p>The reason I didn't try the first answer is that they hook into <code>CreateFileW</code> from <code>KernelBase.dll</code> to "redirect" the resources accessed, since it loads a new DLL when <code>Restart now</code> is pressed, but again, in my situation, nothing new is loaded when a new note is created.
I did also try EventHook and just using <code>GetProcessById</code> to get the sticky notes process but that doesn't really expose much.</p>
<p>I feel like I have what I need to do this, I just don't quite know how. If anyone could point me in the right direction I'd really appreciate it.</p>
| Reverse engineer sticky notes to allow external script to open new notes | |ida|debugging|windbg|x64dbg| |
<p>Based on a datasheet found on Internet (<a href="http://www.lanzhi-tech.com/filedownload/99240" rel="noreferrer">http://www.lanzhi-tech.com/filedownload/99240</a>) it seems that the ATS2815 is a chip that has everything to manage a Bluetooth speaker and, probably, it is inside a lot of different speakers, all with the same interface.</p>
<p>According to the datasheet it has "internal ROM and internal RAM for program and data". So, I suppose, that the core firmware that implements the Bluetooth protocol and the main chip features is inside the ATS2815 chip.</p>
<p>On the external NOR flash EEPROM XT25F08B, which is 1Mbyte in size (8 Mbit), probably there is configuration data (like information on his Bluetooth name, paired devices, and so on) and maybe, but not sure on this, some "application" that can be loaded in RAM and executed.</p>
<p>On the Datasheet, there are multiple pins labeled UART_TX or UART_RX but it says also that the chip has only one UART interface; anyway I would try to see if on some of these pins there is something printed during the boot cycle.</p>
<p>You can also try to read the NOR flash using an 8 pin adapter like this one: <a href="https://amzn.to/39A9JFd" rel="noreferrer">https://amzn.to/39A9JFd</a>, an EEPROM flash programmer like the "TL866II Plus" (or cheaper clones) and the related Xgpro EEPROM reader/programmer software.</p>
<p>According to the datasheet, it seems that the ATS1815 chip doesn't have a JTag interface, so it seems that this interface is not available here.</p>
| 27528 | 2021-04-22T11:24:17.130 | <p>I have a bluetooth speaker. <a href="https://www.harmanaudio.in/FUZE+100.html" rel="noreferrer">Infinity Fuze 100</a>.</p>
<p>It's a good speaker.</p>
<p>But it has annoying messages on startup and shutdown. And for other interface events. I'd like to either get rid of them entirely, or replace them with simple beeps, instead of wordy messages.</p>
<p>I'm confident if I can get the firmware binary I should be able to patch it the way I want. I do have experience reversing software successfully.</p>
<p>This is my first attempt at hardware hacking however and I'm a bit stuck.</p>
<p><strong>What I've tried so far:</strong></p>
<p>1 - Looked up online if this speaker has a service mode. So I could just connect it via usb, set it to service mode and read/write firmware. Some speakers do have this. <a href="https://www.harmanaudio.in/on/demandware.static/-/Sites-masterCatalog_Harman/default/dwe2cb4420/pdfs/Manuals-FUZE100-QSG.pdf" rel="noreferrer">According to its manual</a>, this speaker doesnt seem to.</p>
<p>2 - I tried holding down various button combinations hoping some combo will put it into a service mode that may be undocumented in the manual. Din't work.</p>
<p>3 - Read online maybe I need to manually get at the firmware using something called JTAG, so I opened up the speaker and took out the board to inspect it. Here are its front and back:</p>
<p><a href="https://i.stack.imgur.com/knMd2.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/knMd2.jpg" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/7Xwxl.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/7Xwxl.jpg" alt="enter image description here" /></a></p>
<p>4 - I can't see an obvious JTAG interface. So I looked up the data sheet for the main chip : ATS2815, which seems to be a fully integrated blue tooth audio chip.</p>
<p><a href="https://i.stack.imgur.com/9H2ux.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9H2ux.png" alt="enter image description here" /></a></p>
<p>Even though I looked at its pin layout, I can't figure out if JTAG is present?</p>
<p>5 - I also looked up the chip XT25F08B, and that seems to be a NOR flash memory.
Here is <a href="https://static.chipdip.ru/lib/050/DOC007050537.pdf" rel="noreferrer">the data sheet</a>.</p>
<p>What I'm wondering is:</p>
<ul>
<li>Where is the JTAG interface? Am I missing something obvious?</li>
<li>My guess is that the firmware must reside on XT25F08B flash memory. Is this
correct?</li>
<li>If it is true, then is there a simple and direct way to read/write this memory without bothering with JTAG (if it's not present or can't be figured out)?</li>
</ul>
<p><strong>Maybe all this is entirely the wrong approach, and there is another way to get at the firmware?</strong></p>
| How do I extract the firmware from this bluetooth speaker board? | |firmware|hardware|jtag| |
<p>Because it is compiler specific , it is not required to be internally the same always. It seems though that CLANG and GCC use <strong>R0</strong> to store this.</p>
<p><strong>C++</strong></p>
<pre><code>class MyClass {
int field_;
public:
void set_field() { this->field_ = 42; }
};
void test() {
MyClass x;
x.set_field();
}
</code></pre>
<p><strong>ARM:</strong></p>
<pre><code>test():
push {r11, lr}
mov r11, sp
sub sp, sp, #8
add r0, sp, #4
bl MyClass::set_field()
mov sp, r11
pop {r11, lr}
bx lr
MyClass::set_field():
sub sp, sp, #4
str r0, [sp]
ldr r1, [sp]
mov r0, #42
str r0, [r1]
add sp, sp, #4
bx lr
</code></pre>
<p><strong>Intel :</strong></p>
<pre><code>MyClass::set_field():
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-8], rdi
mov rax, QWORD PTR [rbp-8]
mov DWORD PTR [rax], 42
nop
pop rbp
ret
test():
push rbp
mov rbp, rsp
sub rsp, 16
lea rax, [rbp-4]
mov rdi, rax
call MyClass::set_field()
nop
leave
ret
</code></pre>
| 27531 | 2021-04-22T17:09:11.670 | <p>I came across this part in the book <a href="https://mirrors.ocf.berkeley.edu/parrot/misc/openbooks/programming/ReverseEngineeringForBeginners.en.pdf" rel="nofollow noreferrer">Reverse Engineering For Beginners</a> book by Denis Yurichev. It writes about reverse engineering Classes in C++, but it doesn't provide any examples in ARM.</p>
<p>Page 546</p>
<pre><code>_this$ = -4
; size = 4
??0c@@QAE@XZ PROC ; c::c, COMDAT
; _this$ = ecx
push ebp
mov ebp, esp
push ecx
mov DWORD PTR _this$[ebp], ecx
mov eax, DWORD PTR _this$[ebp]
mov DWORD PTR [eax], 667
mov ecx, DWORD PTR _this$[ebp]
mov DWORD PTR [ecx+4], 999
mov eax, DWORD PTR _this$[ebp]
mov esp, ebp
pop ebp
ret 0
??0c@@QAE@XZ ENDP ; c::c
_this$ = -4 ; size = 4
_a$ = 8
; size = 4
_b$ = 12
; size = 4
??0c@@QAE@HH@Z PROC ; c::c, COMDAT
; _this$ = ecx
push ebp
mov ebp, esp
push ecx
mov DWORD PTR _this$[ebp], ecx
mov eax, DWORD PTR _this$[ebp]
mov ecx, DWORD PTR _a$[ebp]
mov DWORD PTR [eax], ecx
mov edx, DWORD PTR _this$[ebp]
mov eax, DWORD PTR _b$[ebp]
mov DWORD PTR [edx+4], eax
mov eax, DWORD PTR _this$[ebp]
mov esp, ebp
pop ebp
ret 8
??0c@@QAE@HH@Z ENDP ; c::c
</code></pre>
<p>As you can see <strong>ECX</strong> is used to hold the pointer of this for accessing the members of the class. How is this done in ARM assembly?</p>
| Reverse Engineering Classes in ARM | |arm|class-reconstruction| |
<p>According to the descriptions provided in the question, Enigma Virtual Box does not necessarily virtualize a code, but rather allows the application's files and records to be consolidated into a single executable file, ie the reason for not being able to analyze is that the new file generated is a loader, already the .Net binary using ConfuserEx can be mostly deobfuscated (When not using mutation or not the latest version in which a manual unpack is needed), you can use tools to do the job for you, see a list of links:</p>
<ul>
<li><a href="https://github.com/EVBExtractor/evb-extractor" rel="nofollow noreferrer">Enigma Virtual Box</a></li>
<li><a href="https://github.com/XenocodeRCE/ConfuserEx-Unpacker" rel="nofollow noreferrer">ConfuserEx-Unpacker</a></li>
<li><a href="https://github.com/BedTheGod/ConfuserEx-Unpacker-Mod-by-Bed" rel="nofollow noreferrer">ConfuserEx-Unpacker-Mod-by-Bed</a></li>
<li>Confuser unpack by pc-ret(I didn't find a reliable link)</li>
</ul>
<p>To manually obfuse you need to run it with a debugger until you reach EntryPoint from there, dump it and clean it with de4dot (in the older versions of the confuser).</p>
| 27532 | 2021-04-22T21:07:17.037 | <p><a href="https://i.stack.imgur.com/L4ADx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L4ADx.png" alt="enter image description here" /></a></p>
<p>from previous question i still dont get any info or any process at all... now i asking again with this question is this virtualize code or something? i try many thing and it still didnt work [i unpack this dll from enigma virtual box]</p>
<p>hope someone can guide me from this thing thank you</p>
<hr />
<p>Update</p>
<p>for someone who still checking this thread</p>
<p>the problem is DLL itself that get obfuscate,the unpack is not hard and this is not il2 file [this is pc desktop game] this obfuscate is undetect even by DIE [my guess is the author just rename the obfuscate that make deobfuscate program like de4dot unable to deobfus ]</p>
<p>and idk how to rename it back because all of the methods are unreadble just like my image post</p>
<p>so im still stuck with this... and i am so busy im sorry if someone who have the same problem didnt get much info except how to unpack [my guess that the author rename the obfuscate because the EVB that the author use also rename it with something else that make DIE undetect packer]</p>
| devirtualize? or what is this obfuscator? and how to get rid of this | |disassembly|obfuscation|deobfuscation| |
<p>Well, I managed to do it with the add_dref() function:</p>
<pre><code>add_dref(frm, to, type)
Create a data cross-reference.
Parameters:
to - linear address of referenced data (C++: ea_t)
type - cross-reference type (C++: dref_t)
Returns: bool
success (may fail if user-defined xref exists from->to)
</code></pre>
<p>So I can just call this for every resolved symbols:</p>
<pre><code>add_dref(instruction_addr, resolved_symbol_address, 1)
</code></pre>
| 27536 | 2021-04-23T12:47:01.143 | <p>I am working on an IDAPython script that is supposed to fix the disassembly of a firmware, by resolving it's symbol table.</p>
<p>The core of the script is working fine, but I have some issue when it comes to editing the way IDA is displaying stuff in the disassembly panel.</p>
<p>The idea is the following:</p>
<p>I have an original instruction like:</p>
<pre><code>LDR R1,=0xAAAAAAAA
</code></pre>
<p>After the execution of my script, the offset 0xAAAAAAAA is resolved into it's current value, let's say 0xBBBBBBBB, and it adds a comment next to the original instruction:</p>
<pre><code>LDR R1,=0xAAAAAAAA ; symbol_address=0xBBBBBBBB, symbol_value='DummyString'
</code></pre>
<p>But since I'm only adding a comment, I'm loosing the xRefs to and from the strings.</p>
<p>What i want to achieve is to edit the instruction itself, so IDA can create the xRefs to the Strings. Something like:</p>
<pre><code>LDR R1,=aDummyString
</code></pre>
<p>I used this snippet to edit the operand address, which is working:</p>
<pre><code>create_strlit(resolved_addr, 0, STRTYPE_C) # Defined the resolved string's addr as a proper string
new_inst = original_ins.replace(hex(original_addr), hex(resolved_addr)) # Simplified for clarity
set_manual_insn(addr, new_inst) # Edit the instruction with the new resolved addr
</code></pre>
<p>But my disassembly view does not make the link between the address and the string itself.</p>
<pre><code>LDR R1,=0xBBBBBBBB
</code></pre>
<p>When i hover my cursor on 0xBBBBBBBB, i can see the correct string; When I click on this address, IDA takes me to the string's location. But it has not created any proper xRefs, and the display does not inform me that this is a string location.</p>
<p>I tried theses functions to turn the operand into a string reference, but without success:</p>
<pre><code>op_plain_offset(addr, 1, 0)
op_offset(addr, 1, REF_OFF32) # I also tried REF_OFF8 and REF_OFF16, just in case
</code></pre>
<p>But it does not update the disassembly view as I want.</p>
<p>And when i try to do it by hand by doing "right click" -> "Enter the current operand manually", it works fine :/</p>
<p>Any suggestion how to do that ?</p>
<p>Thanks</p>
| IDApython - Turning a modified operand into a string reference | |idapython|arm|automation| |
<p>The legacy BIOS code is usually stored compressed in the UEFI filesystem. You can find it in UEFITool by looking for the magic string <code>IFE$</code> (<code>49 46 45 24</code>) - signature of the <a href="https://github.com/fengmm521/VirtualBox_studay/blob/master/VirtualBox-5.2.16/src/VBox/Devices/EFI/Firmware/IntelFrameworkPkg/Include/Protocol/LegacyBios.h" rel="nofollow noreferrer"><code>EFI_COMPATIBILITY16_TABLE</code></a> structure.</p>
<p>In AMI based firmware it is usually a RAW subsection of a file names CSMCORE. The following script parses the AMI format raw stream and extracts the legacy BIOS as well as any option ROMs that may be present:
<a href="https://github.com/coreboot/bios_extract/blob/master/csmcoreparse.py" rel="nofollow noreferrer">https://github.com/coreboot/bios_extract/blob/master/csmcoreparse.py</a></p>
| 27545 | 2021-04-24T07:34:13.737 | <p>Where is the legacy BIOS (the 16 bit reset code that jumps to the POST entry point at F000:E05B and indeed POST itself and all the BIOS routines) originally stored on a UEFI system before it's shadowed to 0xF0000? And the embedded option ROMs before they're shadowed to 0xC0000? And what shadows the legacy BIOS to 0xF000: ME, the Startup ACM, SEC or the legacy BIOS itself?</p>
<p>It doesn't appear to be in the SPI flash BIOS region (I've searched byte sequences in the dump on IDA). I thought it might be on the LPC or EC flash but my laptop <a href="https://notebookschematics.com/wp-content/uploads/2020/09/Dell-Inspiron-15-7577-CKA50-CKF50-Schematic-LA-E992P.jpg" rel="nofollow noreferrer">doesn't appear to have one</a> (and neither does my flash descriptor show an EC region so don't ask me where the EC ROM is stored either, but it's <a href="https://i.stack.imgur.com/FZKC8.jpg" rel="nofollow noreferrer">supposed to be on the SPI flash</a>, and the schematic doesn't appear to show it having a private SPI flash, but it must do; maybe that's where the legacy BIOS is?); plus it looks like you can only configure the <a href="https://www.intel.com/content/www/us/en/products/docs/chipsets/100-c230-series-chipset-pch-datasheet-vol-2.html" rel="nofollow noreferrer">PCH</a> to send all BIOS ranges to either LPC/eSPI or SPI and not 0xF0000 to one and 0xFFFF0000 to another. My laptop is booted into legacy BIOS and has EA at 0xFFFF0 (so obviously a legacy BIOS shadow) and 90 90 E9 at 0xFFFFFFF0. I can't find anything on this and I've been searching all sorts of combinations on verbatim search for hours, hundreds of manuals, UEFI papers, specifications, and not one mentions it.</p>
| Where is the legacy BIOS stored on a UEFI system? | |intel|bios|spi|uefi| |
<p>In the firmware package, the <code>/etc/int.d/rcS</code> startup script has these lines at the end:</p>
<pre><code>#for fs upgrade
#/bin/sd_upgrade_fs.sh
/bin/sd_upgrade_fs.sh
#for factory test
#sh /bin/mfg_test.sh
#/bin/watchdog.sh&
#/lib/modules/usb_mod
#exec /usr/etc/nanoX.local
</code></pre>
<p>And in <code>/bin/sd_upgrade_fs.sh</code> you can see how the initial firmware is written to the device. By looking up "eb600e" and "eb600em" present in <code>/files/</code>. I found <a href="https://www.mobileread.com/forums/showthread.php?t=60496" rel="nofollow noreferrer">this old thread</a> with some suggestions on how to trigger a firmware update process.</p>
| 27552 | 2021-04-25T09:06:53.297 | <p>Am wondering how to replace the firmware on a Longshine Shinebook (<a href="https://manual.longshine.de/4_GPL_Product_Driver/LCS-Shinebook/LCS-Shinebook_Manual.pdf" rel="nofollow noreferrer">manual</a>, <a href="https://manual.longshine.de/4_GPL_Product_Driver/LCS-Shinebook/LCS-Shinebook_Libre_Firmware.rar" rel="nofollow noreferrer">firmware</a>, <a href="https://manual.longshine.de/4_GPL_Product_Driver/LCS-Shinebook/LCS-Shinebook_Opensource.tgz" rel="nofollow noreferrer">more stuff</a>).</p>
<p><a href="https://i.stack.imgur.com/vtpyh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vtpyh.jpg" alt="enter image description here" /></a></p>
<p>Assuming I modify the firmware files, how do I put the new version on the device? I'm guessing there is some standard method for triggering the update.</p>
| Replacing firmware, Longshine Shinebook | |firmware|linux| |
<p>To answer my own question, this appears to be a custom compression format by Bosch, the manufacturer of the car head unit.</p>
<p>I have been successful in decompressing all of the PNG files; my solution can be found on GitHub <a href="https://github.com/sapphire-bt/lcn2kai-decompress" rel="nofollow noreferrer">here</a>.</p>
<p>It would have been impossible to reverse engineer the compression format without disassembling the firmware as the data at the beginning of the file is used to retrieve values from a hardcoded "code table".</p>
| 27569 | 2021-04-27T16:11:15.850 | <p>I've come across some files which are used in a car's satellite navigation system. Looking at the files in a hex editor shows the <code>โฐPNG</code> signature, but the chunks do not follow the format spec - for example:</p>
<pre>Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 05 00 10 00 43 50 52 4E 41 56 5F 32 36 02 00 00 ....CPRNAV_26...
00000010 03 00 01 00 1C 00 00 00 08 01 00 00 4B 00 CA 3D ............K.ร=
00000020 FC 06 35 54 38 25 56 C8 1F 50 E9 06 04 58 85 5E รผ.5T8%Vร.Pรฉ..Xโฆ^
00000030 8C 91 E1 AD 84 DF 60 49 FC 01 61 FF 47 A9 D5 6A ลโรก.โร`Iรผ.aรฟGยฉรj
00000040 B5 B2 06 48 65 0D D0 FA BE C3 D3 0E A1 EF 3B BC ยตยฒ.He.รรบยพรร.ยกรฏ;ยผ
00000050 EF F0 BE C3 73 0E A1 EF 3B BC EF F0 BE C3 73 0E รฏรฐยพรs.ยกรฏ;ยผรฏรฐยพรs.
00000060 A1 DB E1 0F 58 E4 3E <strong>89 50 4E 47 0D 0A 1A 0A</strong> 00 ยกรรก.Xรค><strong>โฐPNG....</strong>. // PNG begins here
00000070 00 00 <strong>0D 49 48 44 52</strong> F0 E0 08 02 B2 E1 7C 5E 00 ..<strong>.IHDR</strong>รฐร ..ยฒรก|^. // IHDR chunk indicated as 13 (0x0D) bytes, yet this is clearly not the case
00000080 01 73 52 47 42 00 AE CE 1C E9 06 62 4B 47 44 00 .sRGB.ยฎร.รฉ.bKGD.
00000090 FF A0 BD A7 93 09 70 48 59 73 0B 11 01 7F 64 5F รฟ ยฝยงโ.pHYs....d_
000000A0 91 07 74 49 4D 45 07 E0 02 18 07 12 13 CC F8 BA โ.tIME.ร .....รรธยบ
000000B0 BA B6 49 44 41 54 78 DA ED D2 C1 0D 04 00 31 C4 ยบยถIDATxรรญรร...1ร
000000C0 FE 2B 33 83 AF B4 23 5C 2E A7 27 E0 8B 92 00 43 รพ+3ฦยฏยด#\.ยง'ร โนโ.C
000000D0 83 A1 C1 D0 60 68 0C 0D 86 06 43 83 A1 C1 D0 18 ฦยกรร`h..โ .Cฦยกรร.
000000E0 1A 0C 0D 86 06 31 34 18 1A 63 68 30 34 C6 30 8D ...โ .14..ch04ร0.
000000F0 60 86 AB 05 8F 4F 03 C2 58 19 85 B6 00 49 45 4E `โ ยซ..O.รX.โฆยถ.IEN
00000100 44 AE 42 60 82 00 00 00 DยฎB`โ...</pre>
<p>As you can see, several standard PNG chunk names are present (<code>sRGB</code>, <code>bKGD</code>, <code>IDAT</code>, etc.) however the data between them appears to be compressed/encrypted.</p>
<p>My observations so far:</p>
<ul>
<li>bytes <code>0x14-17</code> seem to be a DWORD indicating the custom header size (<code>0x1C</code> or 28 bytes)</li>
<li>bytes <code>0x1C-1D</code> seem to be a WORD indicating the size of the data between themselves and where the actual PNG header begins (<code>0x4B00</code> or 75 bytes, including the 2 size bytes) - this might be the compressed data table/dictionary</li>
<li>files are aligned to 4 byte blocks with <code>0x00</code></li>
<li>of the 2,196 compressed PNG files, exactly half have the same <code>IHDR</code> data: <code>F0 E0 08 02 B2 E1 7C 5E 00 01</code>; the other half have <code>01 90 88 08 02 E0 58 21 6D</code></li>
<li>similarly, half of the files' compressed data/dictionaries begin with the same 22 bytes: <code>FC 06 31 46 85 53 68 85 84 F9 95 6E 40 80 55 E8 C5 18 19 DE 4A F8</code>; the other half begin with <code>FC 06 35 54 38 25 56 C8 1F 50 E9 06 04 58 85 5E 8C 91 E1 AD 84</code> - note how <em>every</em> file begins with <code>FC 03 3x xx</code></li>
</ul>
<hr />
<p><strong>Update 2:</strong> I've created a <a href="https://github.com/sapphire-bt/lcn2kai-decompress" rel="nofollow noreferrer">GitHub repository</a> with my progress so far, for anyone who's willing to take a look.</p>
<p><strong>Update 1:</strong> After digging around, I've managed to find a copy of the firmware with the symbols included (available here: <a href="https://www.mediafire.com/file/a0u7k2m87aj1jp6/Files.zip/file" rel="nofollow noreferrer">https://www.mediafire.com/file/a0u7k2m87aj1jp6/Files.zip/file</a>) and I'm pretty sure I've located the correct function for decompressing the files: <code>cpr_tclDecompressAlgorithm::bDecompressData</code>.</p>
<p>Unfortunately, I'm not able to make a great deal of sense of it, but what I can see from the symbols is that:</p>
<ul>
<li>a couple of custom structs are used in the decompression method, <code>cpr_tclCodeTable</code> and <code>cpr_tclCodeTableEntry</code></li>
<li>the structs are then used with methods called <code>cpr_tclCodeTable::iu32SearchIndexOfCode</code> and <code>cpr_tclCodeTable::corfoGetCodeEntry</code></li>
<li>decompression begins by calling <code>cpr_tclDecompressAlgorithm::u32GetNextBits</code> to read 32 bits / 4 bytes</li>
<li>the return value from <code>u32GetNextBits</code> is used with <code>& 3</code> and right shifted 2 bits, which indicates the first two bits are used as some kind of flag</li>
</ul>
<p>I will post IDA's pseudocode of the function below, but I'm not expecting anyone to spend a great deal of time on this - I just wondered if anyone can recognise what's happening here, e.g. Huffman, LZSS, etc.</p>
<pre><code>int __fastcall cpr_tclDecompressAlgorithm::bDecompressData(int a1, int a2, int a3, size_t a4, unsigned int a5, int a6)
{
int v7; // r8
unsigned int v10; // r5
int v11; // r9
void *v12; // r0
unsigned int v13; // r8
unsigned int v14; // r0
const cpr_tclCodeTable *CodeTable; // r11
unsigned int v16; // r6
unsigned int v17; // r7
unsigned int v18; // r0
int v19; // r0
int v20; // r2
int v21; // r3
int v22; // r5
int v23; // r0
int v24; // r7
unsigned int v25; // r1
int v26; // r3
_BYTE *v27; // r0
size_t v28; // r6
__int16 v29; // r12
int v30; // r2
int v31; // r5
int v32; // r0
unsigned int v33; // r10
int v34; // r3
_BYTE *v35; // r1
int v36; // r0
unsigned int v37; // r12
int v38; // r3
void *v39; // r0
size_t v40; // r5
int v41; // r2
int result; // r0
int v43; // r3
int v44; // r2
_BYTE *v45; // r2
int v46; // r0
int v47; // r3
_BOOL4 v48; // r3
int v49; // r0
*(_DWORD *)(a1 + 16) = a4;
v7 = a2 & 3;
*(_DWORD *)(a1 + 12) = a3;
*(_DWORD *)(a1 + 4) = a2;
*(_DWORD *)(a1 + 8) = a2;
if ( (a2 & 3) != 0 )
{
v49 = trc_szGetFileName(
"/opt/bosch/DI_SWNAVI_13.2C5P10/di_swnavi/components/dapi/devicemanager/devicehandler/compression/cpr_decompression.cpp");
trc_tclGlobalTrace::vTraceLevel1(21504, 332, v49, "CPR read access to unaligned adress 0x%x", a2);
return 0;
}
cpr_tclDecompressAlgorithm::vInterpreteHeader((cpr_tclDecompressAlgorithm *)a1, a5);
v10 = a5 - *(_DWORD *)(a1 + 48);
if ( a4 < a5 )
{
if ( a4 <= v10 )
{
*(_DWORD *)(a1 + 48) = v7;
v10 = a4;
v11 = 1;
goto LABEL_7;
}
*(_DWORD *)(a1 + 48) = a4 - v10;
}
v11 = v7;
LABEL_7:
v12 = *(void **)(a1 + 12);
v13 = (unsigned int)v12 + v10;
if ( !v10 )
goto LABEL_34;
if ( a6 == 3 )
{
v14 = cpr_tclDecompressAlgorithm::u32GetNextBits((cpr_tclDecompressAlgorithm *)a1, 0x20u);
CodeTable = (const cpr_tclCodeTable *)(*(_DWORD *)a1 + 44 * (v14 & 3));
v16 = v14 >> 2;
v17 = 2;
cpr_tclDecompressAlgorithm::vInit((cpr_tclDecompressAlgorithm *)a1, CodeTable);
while ( 1 )
{
while ( 1 )
{
if ( *(_DWORD *)(a1 + 12) >= v13 )
goto LABEL_34;
v18 = cpr_tclCodeTable::iu32SearchIndexOfCode(CodeTable, v16);
v19 = cpr_tclCodeTable::corfoGetCodeEntry(CodeTable, v18);
v20 = *(_DWORD *)(v19 + 12);
v21 = *(unsigned __int8 *)(v19 + 16);
v22 = v19;
v17 += v21;
v16 >>= v21;
if ( v20 != 3 )
break;
v23 = cpr_tclDecompressAlgorithm::u32GetNextBits((cpr_tclDecompressAlgorithm *)a1, v17);
v24 = *(unsigned __int8 *)(v22 + 17);
v25 = v23 | v16;
v26 = (v23 | v16) & ~(-1 << v24);
v27 = *(_BYTE **)(a1 + 12);
v28 = (unsigned __int16)(v26 + *(_WORD *)(v22 + 2));
v29 = *(_WORD *)(v22 + 6);
v30 = *(_DWORD *)(a1 + 44);
v31 = *(unsigned __int8 *)(v22 + 18);
if ( v13 < (unsigned int)&v27[v28] )
{
if ( v11 != 1 )
{
v32 = trc_szGetFileName(
"/opt/bosch/DI_SWNAVI_13.2C5P10/di_swnavi/components/dapi/devicemanager/devicehandler/compression/cpr"
"_decompression.cpp");
trc_tclGlobalTrace::vTraceLevel1(
21504,
253,
v32,
"CPR Overwrite Copy n=%d wpos=0x%x epos=0x%x",
v28,
*(_DWORD *)(a1 + 12),
v13);
LABEL_24:
result = 0;
goto LABEL_35;
}
v28 = (unsigned __int16)(v13 - (_WORD)v27);
}
v33 = v25 >> v24;
v34 = -(unsigned __int16)(v29 + (((v25 >> v24) & ~(-1 << v31)) << v30));
v35 = &v27[-(unsigned __int16)(v29 + (((v25 >> v24) & ~(-1 << v31)) << v30))];
if ( v28 == 2 )
{
*v27 = v27[v34];
*(_BYTE *)(*(_DWORD *)(a1 + 12) + 1) = v35[1];
}
else
{
memcpy(v27, v35, v28);
}
v17 = v31 + v24;
*(_DWORD *)(a1 + 12) += v28;
v16 = v33 >> v31;
}
if ( v20 == 2 )
{
v36 = cpr_tclDecompressAlgorithm::u32GetNextBits((cpr_tclDecompressAlgorithm *)a1, v17);
v17 = *(unsigned __int8 *)(v22 + 17);
v37 = v36 | v16;
v38 = (v36 | v16) & ~(-1 << v17);
v39 = *(void **)(a1 + 12);
v40 = (unsigned __int16)(v38 + *(_WORD *)(v22 + 2));
if ( v13 < (unsigned int)v39 + v40 )
{
if ( v11 != 1 )
{
v41 = trc_szGetFileName(
"/opt/bosch/DI_SWNAVI_13.2C5P10/di_swnavi/components/dapi/devicemanager/devicehandler/compression/cpr"
"_decompression.cpp");
trc_tclGlobalTrace::vTraceLevel1(
21504,
291,
v41,
"CPR Overwrite Lit n=%d wpos=0x%x epos=0x%x",
v40,
*(_DWORD *)(a1 + 12),
v13);
goto LABEL_24;
}
v40 = (unsigned __int16)(v13 - (_WORD)v39);
}
v16 = v37 >> v17;
memcpy(v39, *(const void **)(a1 + 8), v40);
v43 = *(_DWORD *)(a1 + 12) + v40;
v44 = *(_DWORD *)(a1 + 8) + v40;
}
else
{
v45 = *(_BYTE **)(a1 + 12);
if ( (_BYTE *)v13 == v45 )
{
v46 = trc_szGetFileName(
"/opt/bosch/DI_SWNAVI_13.2C5P10/di_swnavi/components/dapi/devicemanager/devicehandler/compression/cpr_d"
"ecompression.cpp");
trc_tclGlobalTrace::vTraceLevel1(
21504,
306,
v46,
"CPR Overwrite Lit1 n=1 wpos=0x%x epos=0x%x",
*(_DWORD *)(a1 + 12),
v13);
goto LABEL_24;
}
*v45 = **(_BYTE **)(a1 + 8);
v43 = *(_DWORD *)(a1 + 12) + 1;
v44 = *(_DWORD *)(a1 + 8) + 1;
}
*(_DWORD *)(a1 + 12) = v43;
*(_DWORD *)(a1 + 8) = v44;
}
}
if ( a6 == 1 )
{
memcpy(v12, *(const void **)(a1 + 4), v10);
result = 1;
*(_DWORD *)(a1 + 12) += v10;
}
else
{
LABEL_34:
result = 1;
}
LABEL_35:
v47 = *(_DWORD *)(a1 + 48);
v48 = v47 != 0;
if ( result != 1 )
v48 = 0;
if ( v48 )
{
memset(*(void **)(a1 + 12), 0, *(_DWORD *)(a1 + 48));
result = 1;
}
return result;
}
</code></pre>
| Has anyone encountered PNGs where the chunk data is encrypted/compressed? | |decompress|binary-format| |
<p>The pintool is a DLL which is injected into the target process and runs in its context. Since mspaint is a GUI program, it does not have a console to which print output could go. You have the following options:</p>
<ol>
<li>Change mspaint.exe subsystem to console so that a console window is allocated on startup.</li>
<li>Call <code>AllocConsole()</code> in your pintool and set up stdout/stderr to go there (not sure about the details here).</li>
<li>Use an explicitly opened log file for output instead of stderr.</li>
</ol>
| 27575 | 2021-04-28T08:16:26.640 | <p>I'm writing a pin tool (Windows, x64, PIN 3.18), and it starts like this:</p>
<pre><code>int main(int argc, char *argv[]) {
std::cerr << "Initializing..." << std::endl;
</code></pre>
<p>This is how I'm calling the tool:
<code>C:\pin\intel64\bin\pin -t C:\pin\source\tools\MyPinTool\x64\Release\MyPinTool.dll -- mspaint.exe</code></p>
<p>Nothing is ever printed to stderr. <code>fprintf(stderr, ...)</code> also prints nothing. stdout seems to behave in the same way.
The tool itself works, and if I instead fprintf to a file, that works as well.
It doesn't seem to me like I'm deviating from the docs examples.</p>
<p>I also searched in the docs for stuff related to output with no luck.</p>
<p>Why is nothing getting printed?</p>
| PIN tool doesn't write to stdout or sterr on windows | |pintool| |
<p>If you run <code>strings</code> on your firmware file, you can typically get a lot of helpful information. In this case, since I don't know what your device is other than a Harman Kardon "something," I searched through the strings in a text editor until I found the line</p>
<blockquote>
<p>User-Agent:Harman Kardon AVR151/AVR1510</p>
</blockquote>
<p>Just to double-check the firmware does belong to the Harman Kardon AVR151/1510, I downloaded the latest release from <a href="https://www.harmankardon.com/software.html" rel="nofollow noreferrer">their website</a> and did a binary diff between that firmware and the firmware you linked. Strangely enough, the firmware you linked and the one on Harman Kardon's website are only different by the first byte in the file; the rest of the bytes in each file are identical.</p>
<p>Finding out what processor is in there can be tricky. You could take it apart and look, but you probably don't need to (and if it's under warranty, that can be a risky proposition, but then again so can modifying the firmware...) For a lot of devices, you can get internal photos by searching <code>FCC [device name]</code> because devices using the radio spectrum in the US have to go through FCC certification. The FCC page for this family of receivers provides <a href="https://fccid.io/APIAVR1610AN/Internal-Photos/Internal-photos-1878949" rel="nofollow noreferrer">internal photos</a>, but they're too low-res to figure out what ICs are in there. A good next step is searching <code>AVR151 teardown</code> and <code>AVR151 repair</code> since, for most devices, someone's opened it up and tried to repair it. In this case, I found a <a href="https://www.youtube.com/watch?v=iubls0DAOIk" rel="nofollow noreferrer">youtube video</a> of someone performing a board level repair on the AVR151 and at about 8m44s, you can see a shot of the main logic board showing all the components on it:</p>
<p><a href="https://i.stack.imgur.com/pCIGd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pCIGd.jpg" alt="screenshot from a youtube video showing the logic board from the AVR-151 with visible ICs" /></a></p>
<p>The STM32 on the bottom left seems to be the main programmable IC on the board, with the part number STM32F205Z6T6 (<a href="https://www.st.com/resource/en/datasheet/stm32f205rb.pdf" rel="nofollow noreferrer">pdf</a>). The Analog Devices chip goes to the HDMI ports on the back panel and is an ADV7623 HDMI transceiver (you can also find a couple references to the ADV7623 in the <code>strings</code> output for the firmware file.) The ESMT chip is an SDRAM, and the CS497024 is an audio DSP. The chips on the right side that are cut off are another audio DSP and a Frontier Silicon Chorus FS1230, which looks like an SoC meant for integrated audio tuners and other devices, since it connects to an RF front-end as well as displays, non-volatile storage, networking, etc. (<a href="https://frontiersmart.com/sites/default/files/Chorus3_PB.pdf" rel="nofollow noreferrer">pdf</a>). I believe it is also programmable, but beyond that data brief PDF, I can't find much information on the chip.</p>
<p>If you look at the datasheet for the STM32F205Z6T6, it's got 1MB of flash memory, but the firmware file you posted is 3MB, so chances are there's more than just STM32 firmware in that file. If you analyze the entropy in the posted firmware, you see a couple distinct regions of high entropy (<a href="https://i.stack.imgur.com/l7Uzt.jpg" rel="nofollow noreferrer">image, linked because it's very tall</a>)* separated by blank space represented as white blocks, so my guess is there's a region of code for the bootloader, another region for the main firmware for the STM32F205, and probably some data that could be written to non-volatile storage, firmware/configuration for the FS1230, or any number of other things, and not necessarily in that order.</p>
<p>If you look at the file at offset 0xFFFFF (1MB, or the size of the STM32F205 flash), you'll see there's a pretty sharp break between blank data and the start of some new data, so I'd guess that this may be where the firmware stops and the other data begins. That said, the same thing happens at offset 0x1FFFFF (2MB), so you'll have to do some further analysis. See:</p>
<p><a href="https://i.stack.imgur.com/tQ2SW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tQ2SW.png" alt="screenshot of a hex editor showing a data break at 1MB" /></a></p>
<p><a href="https://i.stack.imgur.com/tgtHX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tgtHX.png" alt="screenshot of a hex editor showing a data break at 2MB" /></a></p>
<p>If you really want to dig deeper, the description in the youtube video I linked earlier claims to provide the factory service manual for the AVR151, though I'm not sure how it was obtained so I'll refrain from linking it here; likewise, with the information here, coupled with the provided firmware, I think you should have a pretty good start. I believe Igor Skochinsky is correct in saying that at least some of this provided firmware file is code for that STM32F205 (or at least, I'd be surprised if it wasn't), though I didn't go too in-depth with loading it into some toolset and playing with it any further.</p>
<p>My gut feeling is that most of the interesting stuff happens in that FS1230 and information on that chip is difficult to come by, so you may have a tough time deciphering what's going on there or determining how to modify the firmware or reverse engineer it without a datasheet or reference manual. That said, there's a lot of interesting strings in the binary file and you now know quite a bit about what's inside the AVR-151, so I think you should have quite a bit to go on.</p>
<p>*special thanks to <a href="https://twitter.com/scanlime" rel="nofollow noreferrer">scanlime</a> for the technique of generating a pgm file for visualizing file entropy:</p>
<blockquote>
<p>(echo "P5 512 4096 255"; cat ./avr.fw) > avrfw.pgm</p>
</blockquote>
| 27580 | 2021-04-29T07:26:30.680 | <p>First of all, I'm very new to reverse engineering, but I know about hex, binary, opcodes, et cetera.</p>
<p>I'm trying to reverse engineer a Harman Kardon firmware file, because I think there are some API calls hidden in the firmware that may be useful for home automation.</p>
<p>For some reason, binwalk only says there is a XML file in the firmware (but doesn't extract it). And there seems to be some MIPS16e instructions in it, which I don't know how to extract.</p>
<p><code>binwalk -AB</code> output:</p>
<pre><code>DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
504842 0x7B40A MIPS16e instructions, function prologue
777848 0xBDE78 XML document, version: "1.0"
</code></pre>
<p>I also checked the file for other texts (which are in it). Therefore, I think it isn't encrypted.
The "XML document" is only this: <code><?xml version="1.0" encoding="UTF-8"?><harman><avr><common><status><name></code>.</p>
<p>After that, only other random texts, which can be seen in the menu of the device, are showed.</p>
<p>I don't know if it is okay to dump the firmware here, so I won't unless someone asks for it.</p>
<p>How to proceed in reverse engineering this?</p>
| Harman Kardon firmware reverse engineering | |firmware|firmware-analysis|binwalk| |
<p>The program exiting with code 126 in GDB can occur if the executable file under debug and its sources are in a shared directory in a virtual machine.
I copied the files in a non-shared directory in the same virtual machine and GDB could debug without errors.</p>
| 27589 | 2021-05-01T09:19:13.607 | <p>I want to reverse engineer a program. I managed to find the entry point but every time I want to launch the application I get the same error `During startup program exited with code 126.</p>
<p>Here is what I did:</p>
<pre><code>โโโ(kaliใฟkali)-[~/Documents/Guessy]
โโ$ gdb guessy\?token=eyJ1c2VyX2lkIjoxNDM4LCJ0ZWFtX2lkIjpudWxsLCJmaWxlX2lkIjoxNjd9.YIyJZA.QQbX2E3vChspI95coiZvSzAwDOo
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from guessy?token=eyJ1c2VyX2lkIjoxNDM4LCJ0ZWFtX2lkIjpudWxsLCJmaWxlX2lkIjoxNjd9.YIyJZA.QQbX2E3vChspI95coiZvSzAwDOo...
(No debugging symbols found in guessy?token=eyJ1c2VyX2lkIjoxNDM4LCJ0ZWFtX2lkIjpudWxsLCJmaWxlX2lkIjoxNjd9.YIyJZA.QQbX2E3vChspI95coiZvSzAwDOo)
(gdb) break 1
No symbol table is loaded. Use the "file" command.
(gdb) break 0x0000000000006160
Function "0x0000000000006160" not defined.
Make breakpoint pending on future shared library load? (y or [n])
(gdb) run
Starting program: /home/kali/Documents/Guessy/guessy?token=eyJ1c2VyX2lkIjoxNDM4LCJ0ZWFtX2lkIjpudWxsLCJmaWxlX2lkIjoxNjd9.YIyJZA.QQbX2E3vChspI95coiZvSzAwDOo
zsh:1: permission denied: /home/kali/Documents/Guessy/guessy?token=eyJ1c2VyX2lkIjoxNDM4LCJ0ZWFtX2lkIjpudWxsLCJmaWxlX2lkIjoxNjd9.YIyJZA.QQbX2E3vChspI95coiZvSzAwDOo
During startup program exited with code 126.
</code></pre>
<p>I found the entrypoint with this:</p>
<pre><code>โโโ(kaliใฟkali)-[~/Documents/Guessy]
โโ$ objdump -f /bin/ls 130 โจฏ
/bin/ls: file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x0000000000006160
</code></pre>
| startup program exits with code 126 when executing program at entrypoint | |x86|gdb|elf|x86-64| |
<p>There are several implementations of python rc4 available in GitHub repositories</p>
<p>As Already pointed out You need to Cleanup and Rename all those local_xxx names</p>
<p>in the answer above by @Guillaume it seems he is implying the Array Initialization part as KSA and the KSA as PRGA<br />
I don't think you have posted the PRGA in your query</p>
<p>the Array Initialization part can be done with a onliner as below</p>
<pre><code>S=list(range(256))
</code></pre>
<p>the KSA in the query above contains few junk lines<br />
which can be safely removed for example right shifting a 32bit by 0x1f and then by 0x18 will always result in 0</p>
<p>so substituting 0 in place of uVar2 you can see local_10 will always be iVar1 so you can simply eliminate the local_10</p>
<p>and a swap in python can be a tuple exchange<br />
the first function in your query is a xor exchange function<br />
so based on the above premise you can simply recode in python as below<br />
the code below generates two keystreams for two plaintexts</p>
<pre><code>def one(a,b):
i=0
while(i<b):
a[i] = a[i] ^ 0x50
i=i+1
return a
print(one([1,2,3,4,5],5),"\n***************************\n")
S = list(range(256))
print(S[0:16])
Key = [b"Attack at dawn",b"Defend at Night"]
k=0
j=0
inLen=len(Key)
for k in range(0x256):
k=( ( k + S[j] + Key[0][j%inLen] ) % 256 )
S[j],S[k]=S[k],S[j]
print(S[0:16])
for k in range(0x256):
k=( ( k + S[j] + Key[1][j%inLen] ) % 256 )
S[j],S[k]=S[k],S[j]
print(S[0:16])
</code></pre>
<p>executing this you should get something like this</p>
<pre><code>:\>python conv2py.py
[81, 82, 83, 84, 85]
***************************
S_initial [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
S_for_Key[0] [104, 16, 114, 140, 4, 95, 6, 0, 89, 203, 219, 212, 25, 117, 14, 215]
S_for_Key[1] [199, 217, 227, 209, 193, 123, 190, 75, 189, 161, 153, 168, 111, 92, 152, 203]
</code></pre>
| 27606 | 2021-05-04T03:23:59.430 | <p>i have snippet code that i want to convert to python to understand the types that ghidra use such <code>*(byte *)</code> and <code>*(code *)</code> and <code>*(uchar *)</code> etc..</p>
<p>the first code:</p>
<pre><code>void one(int param_1,int param_2) {
int local_8;
local_8 = 0;
while (local_8 < param_2) {
*(byte *)(param_1 + local_8) = *(byte *)(param_1 + local_8) ^ 0x50;
local_8 = local_8 + 1;
}
return;
}
local_14 = 0;
byte local_12c [256];
local_24 = strlen(param_4);
local_10 = 0;
while (local_14 < 0x100) {
local_12c[local_14] = (byte)local_14;
local_14 = local_14 + 1;
}
local_18 = 0;
while (local_18 < 0x100) {
iVar1 = (int)param_4[local_18 % (int)local_24] + (uint)local_12c[local_18] + local_10;
uVar2 = (uint)(iVar1 >> 0x1f) >> 0x18;
local_10 = (iVar1 + uVar2 & 0xff) - uVar2;
swap(local_12c + local_18,local_12c + local_10);
local_18 = local_18 + 1;
}
</code></pre>
<p>writing a python code for this code it will help me a lot to understand the logic that ghidra use with these kind of instructions such as <code>swap(local_12c + local_18,local_12c + local_10);</code> is it a number value ? how to swap a numbers without variables</p>
| convert code to python | |decompilation|c++|ghidra|python| |
<p><code>00040000</code> looks like a 32 bit value representing the length of the data.</p>
<p>If we decode it in little-endian we get <code>1024</code>:</p>
<pre><code>sage: int.from_bytes(bytes.fromhex('00040000'), 'little')
1024
</code></pre>
<p>I'm assuming this gives the number of bits that follow; the next 1024 bits (<code>n</code>) are:</p>
<pre><code>f21a03ef61ad05c0af8d2acf29d3d779c2f73b61aa88533dac358410ac7a08d005dbd6325bb5064eb8afb24e3aef680cfad779d854b7ef97d4f5a1f2f16eb63ebf1b1235f89b65053c01f68a19bcda4183516c20cd907a49301d1314f956fbcc2018e4cfe6991c224d0e177eb11d7fae8477cd6701580754cc116782a0b6b6db
</code></pre>
<p>Followed by 1024 bits (<code>e</code>) that are</p>
<pre><code>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001
</code></pre>
<p>The latter is very likely the exponent, however in big-endian:</p>
<pre><code>sage: int.from_bytes(bytes.fromhex('00010001'), 'big')
65537
</code></pre>
<p>65537 is a very commonly used exponent.</p>
<p>Since <code>e</code> is in big-endian, I assume <code>n</code> is too, so your public modulus is:</p>
<pre><code>sage: int.from_bytes(bytes.fromhex('f21a03ef61ad05c0af8d2acf29d3d779c2f73b61aa88533dac358410ac7a08d005dbd6325bb5064eb8afb24e3aef680cfad779d854b7ef97d4f5a1f2f16eb63ebf1b1235f89b65053c01f68a19bcda4183516c20cd907a49301d1314f956fbcc2018e4cfe6991c224d0e177eb11d7fae8477cd6701580754cc116782a0b6b6db'), 'big')
170009540932613151769038469988293650218844004053584339002200232194264352712884216925985784801458591501781573072892989116728048997832334682982748978655741179946010134561466243581524386945399240608537896417387019700398948330733836779231824938918338194668413830256507020494474648180467264074322450994971415066331
</code></pre>
<p>Then, there is another public key of the same length <code>00040000</code> with the same <code>e</code> <code>00010001</code>.</p>
<p>It's public modulus is:</p>
<pre><code>sage: int.from_bytes(bytes.fromhex('af5105fa343e9d8e72294fb8e752a703f54f9b403826f8dd06cf2628ece496806e182ab0e88591f6c0ee7873cb69409e735c62105dd2e28bd45428806836cdb8d94b204ace06d342d24ed824c6988b7db3bd840b50071d291aa4a8cda9187a3f698616fb8ae398f0011a3e38ef31312f07aba316b35858d8e5fe7e7ef8c01209'), 'big')
123111431213688323191113429717081285154340099011946618199498087171573056754335780131987080307395734064403880657942875702088682210145904820435534801337217797703105810136529933603381871426734823683013576987571192787312359697878601542181638347168216122667608679225431011863788903839101406098646701462875195576841
</code></pre>
| 27608 | 2021-05-04T11:22:41.520 | <p>I'm trying to figure out the format/encoding for this:</p>
<p><code>00040000a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000100040000a56e4a0e70101759a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001</code>
to replicate it with my own public key.</p>
<p>I've looked at this <a href="https://crypto.stackexchange.com/questions/41871/how-to-find-the-encoding-of-an-rsa-public-key">https://crypto.stackexchange.com/questions/41871/how-to-find-the-encoding-of-an-rsa-public-key</a> and from what I can see there are similarities, though it doesn't seem to be the same as that.</p>
| Reversing encoding of a RSA public key | |cryptography| |
<p>After I ran:</p>
<pre><code>0: kd> .symfix C:\debug\symbols
*** Unable to resolve unqualified symbol in Bp expression 'user32.SetWindowTextW'.
*** Unable to resolve unqualified symbol in Bp expression 'user32.SetWindowTextW'.
0: kd> !sym noisy
noisy mode - symbol prompts on
0: kd> .reload /f
</code></pre>
<p>Now I was able to use it:</p>
<pre><code>0: kd> dd user32!SetWindowTextW
00007ffc`243c1cb0 245c8948 83485708 8b4830ec 108ae8fa
00007ffc`243c1cc0 8b480000 c08548d8 8b483c74 035ae8c8
</code></pre>
| 27610 | 2021-05-04T13:51:15.380 | <p>I have a WinForm project in C++.<br />
I attached a kernel debugger to my VMware machine.<br />
I set a breakpoint on the kernel and switched context to my application:</p>
<pre><code>0: kd> !process 0 0 WindowsProject1.exe
PROCESS ffffcf07bad91080
SessionId: 1 Cid: 22c8 Peb: dd35f3e000 ParentCid: 1598
DirBase: 1b9b83000 ObjectTable: ffffe5829cb59b00 HandleCount: 145.
Image: WindowsProject1.exe
0: kd> .process ffffcf07bad91080
Implicit process is now ffffcf07`bad91080
WARNING: .cache forcedecodeuser is not enabled
</code></pre>
<p>I also understand that I can do it like that:</p>
<pre><code>0: kd> dx -s Debugger.Sessions[0].Processes[8904].SwitchTo()
</code></pre>
<p>Anyway, I want to find the <code>SetWindowTextW</code> function and set a breakpoint on that.<br />
I tried to find it in the process context:</p>
<pre><code>0: kd> dd user32!SetWindowTextW
Couldn't resolve error at 'user32!SetWindowTextW'
</code></pre>
<p>Why it doesn't find it?</p>
| Can't resolve a function from a process module (user32.dll): "Couldn't resolve error at '<module>!<function>'" | |debuggers|windbg| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.