diff --git "a/stack_exchange/RE/RE Q&A 2021.csv" "b/stack_exchange/RE/RE Q&A 2021.csv" new file mode 100644--- /dev/null +++ "b/stack_exchange/RE/RE Q&A 2021.csv" @@ -0,0 +1,31959 @@ +Id,PostTypeId,AcceptedAnswerId,ParentId,CreationDate,DeletionDate,Score,ViewCount,Body,OwnerUserId,OwnerDisplayName,LastEditorUserId,LastEditorDisplayName,LastEditDate,LastActivityDate,Title,Tags,AnswerCount,CommentCount,FavoriteCount,ClosedDate,CommunityOwnedDate,ContentLicense +26681,2,,26672,1/1/2021 14:54,,1,,"
To get the program’s argument, you need to check argv[1]
instead of argv[0]
. From cppreference:
++",60,,,,,1/1/2021 14:54,,,,0,,,,CC BY-SA 4.0 +26682,1,26684,,1/2/2021 2:36,,2,101,"The parameters of the two-parameter form of the main function allow +arbitrary multibyte character strings to be passed from the execution +environment (these are typically known as command line arguments), the +pointers
+argv[1].. argv[argc-1]
point at the first characters in each +of these strings.argv[0]
is the pointer to the initial character of a +null-terminated multibyte string that represents the name used to +invoke the program itself (or an empty string "" if this is not +supported by the execution environment).
During debugging a binary in IDA Pro, I've noticed types of the form
+30 uint16_n 00000002 struct {uint16_t inner;}
+42 uint32_n 00000004 struct {uint32_t inner;}
+
+where the fields in each row from left to right correspond to Ordinal
, name
, size
, description
in the Local Types subview of IDA Pro. While the sizes seem to match the uintX_t
counterparts, I would appreciate it if someone can explain the reasoning for introducing uintX_n
types and the difference they have with the well known uintX_t
types in which X=8,16,32
.
It's probably AES. I saw config files at HG8245Hv5 and HG8245H5 and passwords are looking similar. A bit (just a bit:D) more info is here: https://the-infosec.com/2017/03/20/huawei-hg8245h-router-privilege-escalatio/
+",35385,,,,,1/2/2021 7:38,,,,13,,,,CC BY-SA 4.0 +26684,2,,26682,1/2/2021 11:14,,3,,"It seems these types are custom to the program you’re analyzing and probably come from the debug information (e.g. DWARF).
+The standard types from stdint.h
are usually typedefs and not structs.
My college has its ERP platform in a Flash interface, accessible only via Internet Explorer. I am looking into ways I can interface with it via things like ruffle. So I can write my own frontend using modern frameworks. Thing is, accessing the ERP from anything other Internet Explorer results in the browser download a Flash file campus-lynx.swf
. This means the platform is locked to Windows only. Flashfox on Android works as well.
The ERP is available directly at erp.nitdelhi.ac.in or clicking "internet" at the top of nitdelhi.ac.in.
+",35404,,245,,1/5/2021 13:09,1/5/2021 13:09,Reverse Engineering an ERP interface written in Flash,Intercept the traffic between the browser / plugins and the server. I would start with Wireshark.
+The traffic between the client and the server will be some form of network requests which you can write code to generate / consume.
+",34929,,34929,,1/4/2021 16:02,1/4/2021 16:02,,,,0,,,,CC BY-SA 4.0 +26687,2,,26674,1/3/2021 0:18,,0,,"If you do not necessary want to use IDA, you could use radare2 and then do:
+radare2 <your_file>
+
+then do:
+/x <youropcodes>
+
+.
+Example:
+/x 900a0b0c90
+
+.
+To get examples of how to use this command on radare2 you could use:
+/x?
+
+.
+If you necessary want to use IDA pro for your knowledge, you could skip my answer.
+",25421,,,,,1/3/2021 0:18,,,,0,,,,CC BY-SA 4.0 +26688,1,26689,,1/3/2021 0:53,,0,1626,"I am very unsure if this is the right place to as or if I need to ask this at another forum, but here it goes.
+I am trying to reverse engineer a .NET program with the use of dnspy. I installed dnspy with choco install dnspy
. I was then able to start dnspy in by calling it in pwsh, but when debugging the program I get the following error Could not start the debugger. Use 32-bit dnSpy to debug 32-bit applications
. I then found this link that said to restart the debugger with dnspy-x86
. But still the debugger is 64 bit. I also tried to run dnspy by running dnspy -x86
.
I see here in chocolatey.org that the 32 bit is checked in virustotal. But I am unsure if the 32-bit version is included. I also cant find any information on flags or parameters dnspy is able to take.
+My question is if dnspy 32 bit is installed by using choco or if one has to install the 32-bit manually. And if dnspy 32 bit is installed with choco, how do I start it in 32 bit.
+",31468,,,,,1/3/2021 2:57,dnSpy: how to start 32 bit version,<.net>By default choco doesn't want to install 32bit if you are on 64bit system. But, with a little bit of effort, I found that to install 32bit you will need to add either add: --x86 or --forcex86 to force x86 (32bit) installation on 64 bit systems.
+To download dnspy 32 bit you would run: choco install dnspy --x86
Alternatively, you can go to dnSpy github and download it from there.
+For next time please refer to choco install docs and read the entire help section
+I hope you learn something new today ☺
+",35367,,,,,1/3/2021 2:57,,,,0,,,,CC BY-SA 4.0 +26690,1,,,1/3/2021 9:34,,2,106,"I want to ask can I use windows 10 for malware analysis, I'm asking this because I see many reversers and analysts using windows 7 for this purpose. Can anyone please guide me?
+",34958,,,,,1/3/2021 13:18,Using windows 10 for malware analysis,Yes, Windows 10 can be used for malware analysis. All the modern RE tools, such as IDA Pro, Ghidra, Binary Ninja, etc. run on it.
+",4658,,,,,1/3/2021 13:18,,,,0,,,,CC BY-SA 4.0 +26692,2,,26685,1/3/2021 15:40,,3,,"++My college has its erp platform in a flash interface, accesible only via Internet Explorer. +Thing is, accessing the erp from amything other internet explorer results in the browser download a flash file "campus-lynx.swf". This means the platform is locked to windows only.
+
You are obviously wrong. Application work in firefox without any problems. Even site itself state "Best Peformed With Mozilla FireFox Version 2 and above".
+Most recent Firefox versions start dropping Flash support, that may be the case. But you always can install portable version of Firefox 52 without this issue.
+Judging by controls look and feel the application was build with Adobe Flex Builder.
+There was several commercial Flash decompilers such as https://www.eltima.com/products/flashdecompiler/ +You can try to decompile SWF file to figure out protocols being used.
+Most probably there is something standard such as XML or Action Message Format.
+UPD: Network activity tab in browser clearly indicate usage of AMF protocol. There is a plenty of AMF support libraries for various programming languages. Google it.
+",22704,,22704,,1/3/2021 15:57,1/3/2021 15:57,,,,0,,,,CC BY-SA 4.0 +26694,2,,26439,1/4/2021 0:06,,1,,"Drivers using USBVIDEO.sys follow the specifications laid out here:
+https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/usb-video-class-driver-overview
+The tool USBView which is part of the Windows Driver Kit can extract more info about the USB device.
+USB tracing can assist workout more details around the communication, using a tool such as WireShark
+An analysis of the setup program for the driver can work out further information. This is a fairly complex topic though but some methods could include:
+a) Use a tool to monitor driver installation such as ProcMon (http://live.sysinternals.com/ProcMon.exe) Generally this works best if driver & application is not installed, you start monitoring then run install program and connect device during trace.
+b) Static analyze the installer using tools such as UniExtract , Orca (if MSI), then analyse the executable contents with reverse engineering tools such as Ghidra or IDA Pro
+",2229,,,,,1/4/2021 0:06,,,,0,,,,CC BY-SA 4.0 +26695,1,,,1/4/2021 2:50,,1,93,"This seems like a very basic use case and I can't get it to work properly. I'm developing my own test application in Visual Studio c++. I want to test it through several IDA debugging sessions. Every time I modify the code, recompile and try to debug it, IDA warns me that the input has changed and that I should reload the binary, which I do through "File -> Load file -> Reload input file". I then go to "Options -> General -> Analysis -> Reanalyze program".
+Is this the correct way to do things?
+I'm also quite concerned because sometimes this loop fails as the function window show many (more) functions with (null) name and "sp analysis failed" all over the disassembly. I then have to close the project and start a new one, which is rather annoying.
+Any pointers on how to speed this whole thing up are welcome. Please note that I'm much less interested in removing the errors messages than removing the problems associated with them.
+",10182,,,,,6/5/2021 22:01,How to avoid database / code mismatch when developing and debugging your own code in IDA?,While it's not possible to obfuscate object files, it is possible to obfuscate the underlying assembly file. There is no such thing as name obfuscation in C++ since references are by address, not by name. Using full optimization (-O3 -Ob2 -flto) can also make it hard to reverse engineer your code. Also, you can also use VMProtect/Denuvo to encrypt and obfuscate your executable.
+You may find those posts useful
+https://stackoverflow.com/questions/137038/how-do-you-get-assembler-output-from-c-c-source-in-gcc
+https://reverseengineering.stackexchange.com/a/22052/33533
+",33533,,,,,1/4/2021 10:44,,,,0,,,,CC BY-SA 4.0 +26700,1,26702,,1/4/2021 12:24,,2,131,"The only method i know to break on a DriverEntry
of a rootkit driver when its loaded is to disassmble nt!IopLoadDriver
and find an indirect call in it and break on it. Setting a break point on rootkitDriverName!DriverEntry
doesn't work either for some reason.
Is there any easier way to break on the rootkit driver entry? Why does rootkitDriverName!DriverEntry
not work?
Why do some antiviruses hook x64 Ntdll in WOW64 process? However, the same antiviruses do not hook Ntdll in the native x64 processes.
+",24208,,,,,1/4/2021 16:22,Why do some antiviruses hook x64 Ntdll in WOW64 process?,Try enabling break on module load:
+sxe ld rootkitDriverName
+
+See also https://reverseengineering.stackexchange.com/a/2638/60
+",60,,60,,1/4/2021 20:16,1/4/2021 20:16,,,,7,,,,CC BY-SA 4.0 +26704,1,26711,,1/4/2021 23:09,,0,88,"I understand that LOBYTE is an IDA macro for retrieving the lower byte of a variable. My question is what is the difference between the result of x=x-1
and LOBYTE(x)=x-1
when x
is smaller than or equal to 0xff
? I should add that I'm implicitly assuming that x>0
. Thank you!
The images are packed, data is little-endian where it matters.
+General format:
+struct CGFHeader {
+ uint32_t magic;
+ uint32_t flags;
+ uint32_t frame_count;
+ uint32_t frame_metadata_size;
+ uint32_t frame_payload_size;
+ uint32_t unk1;
+ uint32_t unk2;
+};
+
+Then repeated frame_count
times, starting at +0x1c
:
struct FrameMeta {
+ uint32_t unk1;
+ uint32_t unk2;
+ uint32_t width;
+ uint32_t height;
+ uint32_t unk3;
+ uint32_t payload_offset;
+};
+
+For frame N, the payload data starts at sizeof(CGFHeader) + cgf_header.frame_count*sizeof(FrameMeta) + frame_meta[N].payload_offset
(i.e. at the corresponding payload_offset
, based immediately after the metadata structs).
Each line/row of the packed image data is packed independently. Each line is prefixed by a uint32_t
of that line's length (including the length field). Process the packed data as follows:
Read a method uint8_t
and a length uint8_t
(referred to n
below), and process per the below table.
Method | +How to process | +
---|---|
0x00 |
+Append n transparent pixels. If n is 0, pad the line with transparent pixels to expected width. |
+
0x01 |
+Read n pairs of (palette_index, alpha) values from the packed data, appending to the line. |
+
0x02 |
+Read a single (palette_index, alpha) pair from the packed data. Append it to the line n times. |
+
0x03 |
+Read n palette_index values from the packed data, appending to the line. |
+
0x04 |
+Read a single palette_index from the packed data. Append it to the line n times. |
+
Keep processing method uint8_t
and a length uint8_t
bytes from the packed data until you have the full line width.
In order to interpret the actual color values, you'll need the corresponding palette. The two formats you've mentioned:
+CPAL254X3STD
just has (in this case) 254 RGB triplets appended after that header value.CPAL254X3ALPHA
is the same, but with a 0x100000 byte structure appended that gets referred to as an "alpha map". I have not bothered to look at it at all.Rough python3 example of processing, dumping frames to 0.png, 1.png, etc in subdirectory:
+import errno
+import os
+import struct
+import sys
+
+from PIL import Image
+
+class HugoPalette(object):
+ def __init__(self, rawdat):
+ assert(len(rawdat) >= 12)
+ assert(rawdat[0:4] == b'CPAL') # palette
+ self.alpha_map = None
+ self.entries = None
+ num_entries = int(rawdat[4:7])
+ assert(rawdat[7:9] == b'X3') # rgb triples
+ if rawdat[9:12] == b'STD': # palette
+ assert(len(rawdat) >= 12 + num_entries*3)
+ self.entries = []
+ offset = 12
+ for n in range(num_entries):
+ self.entries.append(struct.unpack_from("BBB" ,rawdat, offset))
+ offset = offset + 3
+ elif rawdat[9:14] == b'ALPHA': # palette and alphamap
+ assert(len(rawdat) >= 14 + num_entries*3 + 0x100000)
+ self.entries = []
+ offset = 14
+ for n in range(num_entries):
+ self.entries.append(struct.unpack_from("BBB" ,rawdat, offset))
+ offset = offset + 3
+ self.alphamap = rawdat[14 + num_entries*3:14 + num_entries*3 + 0x100000] # not sure how to interpret
+ else:
+ raise NotImplementedError("unknown palette type")
+
+
+class HugoImage(object):
+ def __init__(self, width, height, rawdat, offset):
+ self.width = width
+ self.height = height
+
+ rows = []
+ for n in range(height):
+ (packed_line_length,) = struct.unpack_from("<L", rawdat, offset)
+ assert(len(rawdat) >= offset + packed_line_length)
+ packed_line = rawdat[offset+4:offset+packed_line_length]
+ line = []
+ index = 0
+ # unpacking:
+ # 00 nn = skip nn pixels [nn=00: skip to end of line]
+ # 01 nn pp aa [pp aa ...] = insert nn entries from trailing pp, replacing alpha with aa
+ # 02 nn pp aa = repeat pp for nn pixels, replacing alpha with aa
+ # 03 nn pp [pp ...] = insert nn entries from trailing pp
+ # 04 nn pp = repeat pp for nn pixels
+ while True:
+ method = packed_line[index]
+ pixel_count = packed_line[index+1]
+ index = index + 2
+ if method == 0:
+ if pixel_count == 0:
+ while(len(line) < self.width):
+ line.append((0, 0))
+ break
+ line.extend([(0,0)]*pixel_count)
+ elif method == 1:
+ for p in range(pixel_count):
+ line.append((packed_line[index], packed_line[index+1]))
+ index = index + 2
+ elif method == 2:
+ line.extend([(packed_line[index], packed_line[index+1])]*pixel_count)
+ index = index + 2
+ elif method == 3:
+ for p in range(pixel_count):
+ line.append((packed_line[index],0xff))
+ index = index + 1
+ elif packed_line[index] == 4:
+ line.extend([(packed_line[index], 0xff)]*pixel_count)
+ index = index + 1
+ assert(len(line) == self.width)
+ rows.append(line)
+ offset = offset + 4 + index
+ self.rows = rows
+
+def load_images(rawdat):
+ HEADER_STRUCT_SIZE=0x1c
+ METADATA_STRUCT_SIZE=0x18
+ offset = 0
+ assert(len(rawdat) >= offset + HEADER_STRUCT_SIZE)
+ (magic, _, count, metadata_size, payload_size, _, _) = struct.unpack_from("<LLLLLLL", rawdat, offset)
+ offset = offset + HEADER_STRUCT_SIZE
+ assert(magic == 0x46464743)
+ assert(metadata_size == count * METADATA_STRUCT_SIZE)
+ metadata = []
+ for n in range(count):
+ assert(len(rawdat) >= offset + METADATA_STRUCT_SIZE)
+ metadata.append(struct.unpack_from("<LLLLLL", rawdat, offset))
+ offset = offset + METADATA_STRUCT_SIZE
+ images = []
+ for im in metadata:
+ images.append(HugoImage(im[2], im[3], rawdat, offset + im[5]))
+ return images
+
+
+def main(args):
+ if len(args) != 3:
+ print(f"usage: python3 {args[0]} palette.pal image.cgf")
+ sys.exit(1)
+ with open(args[1], "rb") as infile:
+ dat = infile.read()
+ pal = HugoPalette(dat)
+
+ with open(args[2], "rb") as infile:
+ dat = infile.read()
+ images = load_images(dat)
+
+ output_dir = args[2] + ".extracted"
+ output_index = 0
+
+ try:
+ os.makedirs(output_dir)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+
+ for i in images:
+ img = Image.new('RGBA', (i.width, i.height))
+ for y in range(i.height):
+ for x in range(i.width):
+ (index, alpha) = i.rows[y][x]
+ pal_entry = pal.entries[index]
+ col = (pal_entry[0], pal_entry[1],pal_entry[2], alpha)
+ img.putpixel((x,y), col)
+ img.save(os.path.join(output_dir, str(output_index) + ".png"), "PNG")
+ output_index = output_index + 1
+
+if __name__ == '__main__':
+ main(sys.argv)
+
+",12017,,,,,1/4/2021 23:20,,,,2,,,,CC BY-SA 4.0
+26706,2,,25619,1/5/2021 0:19,,1,,"Patch bytes shows only 16 bytes at a time, which is not enough to display the entire string.
+Easier to use the Hex Dump view to edit the string. This can be opened with View -> Open Subviews -> Hex Dump. If necessary right click "Synchronize with ..." and specify view to sync with.
+You can right click to select option to "Edit..." in this view. Once done editing right click again and you can select option to "Apply Changes" or hit F2.
+",2229,,,,,1/5/2021 0:19,,,,0,,,,CC BY-SA 4.0 +26707,2,,26670,1/5/2021 2:44,,0,,"try
+SU_WAP>display file /var/wifi.txt
+
+Echolife HG8245W5-6T shell block
+",35425,,245,,1/5/2021 12:35,1/5/2021 12:35,,,,4,,,,CC BY-SA 4.0 +26708,1,26709,,1/5/2021 6:34,,1,43,"I have seen many drivers with a section named PAGE, but couldn't find good enough information on it, what is the role of this section?
+",30154,,,,,1/5/2021 12:47,What is the role of PAGE section in windows Drivers?,Simple, it's a section that will supposedly be mapped as paged memory. This can contain code or data and is governed by the PAGED_CODE macro, among others, at source code level.
+That is, whatever gets stored in that section cannot be accessed at arbitrary IRQLs. Quote:
+++If the IRQL > APC_LEVEL, the PAGED_CODE macro causes the system to ASSERT.
+
Also see this for an entry point into the overall topic. But I reckon given the specific nature of your question you are aware of paged and nonpaged pool and so on.
+",245,,,,,1/5/2021 12:47,,,,0,,,,CC BY-SA 4.0 +26710,1,,,1/5/2021 14:49,,2,328,"I just reached the the topic of Compilers in the book "Reversing:Secrets of Reverse Engineering" So, I want to ask, is the knowledge of Compilers necessary for becoming a Malware Reverse Engineer?
+Can anyone please guide me? ☺️
+",34958,,1323,,1/8/2021 19:43,1/10/2021 20:01,The Knowledge of Compiler for becoming a good Reverser,Quote From Link
+#define LOBYTE(x) (*((_BYTE*)&(x)))
+
+is that a hypothetical query x is treated as address
+so x-1 will be a 32 bit type on a x86 machine so theoretically
+you cannot assign a 32 bit type to an 8 bit type
+LOBYTE(x) will be a byte and not an address so again
+theoretically you cannot assign a byte to a byte
LOBYTE(x) is an AND operation that extracts the unsigned byte from a specific address
+x as address contents LOBYTE(x) (byte *)&x = LOBYTE(x)-1
+0x00400000 0xffffffff 0x000000ff byte[0x004000000] = 0x000000ff -1 =0x000000fe
+
+so if you look as a DWORD 0x400000 will now contain 0xfffffffe
+demo using a python script
+:\>cat LOBYTE.py
+import ctypes
+
+def LOBYTE(arg):
+ return arg.value & 0x000000ff
+
+x = ctypes.c_ulong(0xffffffff)
+print( "x as address" , ctypes.byref(x))
+print( "x holds" , hex(x.value))
+print("result of LOBYTE(x)", LOBYTE(x))
+x.value = ( (x.value & 0xffffff00 ) | LOBYTE(x)- 1 )
+print( "x holds" , hex(x.value))
+
+
+:\>python LOBYTE.py
+x as address <cparam 'P' (017CA098)>
+x holds 0xffffffff
+result of LOBYTE(x) 255
+x holds 0xfffffffe
+
+",3473,,,,,1/5/2021 17:02,,,,0,,,,CC BY-SA 4.0
+26712,1,,,1/5/2021 19:15,,1,225,"I know that the PE loader is the one that is responsible for assigning addresses in a PE Import Address Table, so why when we inject code using process hollowing we don't build the IAT? +We just copy all the sections and headers but we don't resolve the addresses in the IAT. I don't understand how it works, does the resolving happens after the injection or something?
+",35431,,35431,,1/5/2021 19:22,1/6/2021 14:41,Import Address Table in Process Hollowing,If you were given a piece of source code written in a language you had never seen before, you would want to study the syntax and rules of the language so that you could understand what the piece of code is doing.
+A compiler transforms a high-level human friendly language (C for example) into in binary instructions that a CPU can run directly. These binary instructions are called assembly.
+Understanding the process by which a program is compiled from human friendly languages to binary instructions is helpful for anyone writing programs because it lets you reason about what actually happens on the computer. Studying compilers helps you understand the syntax and rules at work when the compiler writes a program in assembly.
+Compilers do all manner of smart things to make programs "better" or "faster". They can remove code which will never be executed, they can reorder chunks of code to use less memory, they can precompute constant values at compile time rather than running them at execution time.
+By understanding what a compiler can do, you can recognize how it rewrites programs when it creates assembly. As a reverse engineer, recognizing these patterns will let you reason about what the original human friendly code was doing.
+Knowledge of compilers and their output will make it easier to spot when something different has been introduced into an existing program.
+Compilers are to computers what the discovery of flight was to transportation. They are a revolutionary technological breakthrough which are often taken for granted.
+The two go-to references are Ullman (commonly known as the "Dragon Book") and Appel (commonly known as the "Tiger Book"). Or good old Wikipedia on Compilers. You can pickup a used early edition copy of Ullman for $20. It's well worth it.
+",34929,,34929,,1/7/2021 15:23,1/7/2021 15:23,,,,0,,,,CC BY-SA 4.0 +26715,1,,,1/6/2021 9:32,,1,138,"The ".thread" command is used to change the thread context in Windows kernel debugging. +MSDN
+But I encountered the below situation:
+0: kd> .thread ffffc082`13599040
+Implicit thread is now ffffc082`13599040
+0: kd> .thread
+Implicit thread is now ffffc082`29313080
+
+2.Execute the following two commands consecutively. I want to change the rip of the thread ffffc08213599040, But command "r rip=xxx" failed.
+0: kd> .thread ffffc082`13599040
+Implicit thread is now ffffc082`13599040
+0: kd> r rip = fffff803`3de6341d
+Last set context:
+ ^ Bad register error in 'r rip = fffff803`3de6341d'
+
+",35069,,,,,1/6/2021 15:40,Windbg .thread command is useless?,You can use Ghidra to generate call graphs for various binaries, including x86 Linux ELF binaries.
+",30460,,,,,1/6/2021 14:27,,,,0,,,,CC BY-SA 4.0 +26717,2,,26712,1/6/2021 14:41,,1,,"Obviously you should resolve the address in IAT.
+This is a manually mapped dll code, you can take a look.
+#include <stdio.h>
+#include <Windows.h>
+#include <intrin.h>
+
+typedef HMODULE(WINAPI* pLoadLibraryA)(LPCSTR);
+typedef FARPROC(WINAPI* pGetProcAddress)(HMODULE, LPCSTR);
+
+typedef BOOL(WINAPI* PDLL_MAIN)(HMODULE, DWORD, PVOID);
+
+typedef struct _MANUAL_INJECT
+{
+ PVOID ImageBase;
+ PIMAGE_NT_HEADERS NtHeaders;
+ PIMAGE_BASE_RELOCATION BaseRelocation;
+ PIMAGE_IMPORT_DESCRIPTOR ImportDirectory;
+ pLoadLibraryA fnLoadLibraryA;
+ pGetProcAddress fnGetProcAddress;
+}MANUAL_INJECT, * PMANUAL_INJECT;
+
+DWORD WINAPI LoadDll(PVOID p)
+{
+ PMANUAL_INJECT ManualInject;
+
+ HMODULE hModule;
+ INT64 i, Function, count, delta;
+
+ PDWORD ptr;
+ PWORD list;
+
+ PIMAGE_BASE_RELOCATION pIBR;
+ PIMAGE_IMPORT_DESCRIPTOR pIID;
+ PIMAGE_IMPORT_BY_NAME pIBN;
+ PIMAGE_THUNK_DATA FirstThunk, OrigFirstThunk;
+
+ PDLL_MAIN EntryPoint;
+ VOID (*EntryPointNew)(VOID);
+
+ ManualInject = (PMANUAL_INJECT)p;
+
+ pIBR = ManualInject->BaseRelocation;
+ delta = (DWORD)((LPBYTE)ManualInject->ImageBase - ManualInject->NtHeaders->OptionalHeader.ImageBase); // Calculate the delta
+
+ // Relocate the image
+
+ while (pIBR->VirtualAddress)
+ {
+ if (pIBR->SizeOfBlock >= sizeof(IMAGE_BASE_RELOCATION))
+ {
+ count = (pIBR->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD);
+ list = (PWORD)(pIBR + 1);
+
+ for (i = 0; i < count; i++)
+ {
+ if (list[i])
+ {
+ ptr = (PDWORD)((LPBYTE)ManualInject->ImageBase + (pIBR->VirtualAddress + (list[i] & 0xFFF)));
+ *ptr += delta;
+ }
+ }
+ }
+
+ pIBR = (PIMAGE_BASE_RELOCATION)((LPBYTE)pIBR + pIBR->SizeOfBlock);
+ }
+
+ pIID = ManualInject->ImportDirectory;
+
+ // Resolve DLL imports
+
+ while (pIID->Characteristics)
+ {
+ OrigFirstThunk = (PIMAGE_THUNK_DATA)((LPBYTE)ManualInject->ImageBase + pIID->OriginalFirstThunk);
+ FirstThunk = (PIMAGE_THUNK_DATA)((LPBYTE)ManualInject->ImageBase + pIID->FirstThunk);
+
+ hModule = ManualInject->fnLoadLibraryA((LPCSTR)ManualInject->ImageBase + pIID->Name);
+
+ if (!hModule)
+ {
+ return FALSE;
+ }
+
+ while (OrigFirstThunk->u1.AddressOfData)
+ {
+ if (OrigFirstThunk->u1.Ordinal & IMAGE_ORDINAL_FLAG)
+ {
+ // Import by ordinal
+
+ Function = (INT64)ManualInject->fnGetProcAddress(hModule, (LPCSTR)(OrigFirstThunk->u1.Ordinal & 0xFFFF));
+
+ if (!Function)
+ {
+ return FALSE;
+ }
+
+ FirstThunk->u1.Function = Function;
+ }
+
+ else
+ {
+ // Import by name
+
+ pIBN = (PIMAGE_IMPORT_BY_NAME)((LPBYTE)ManualInject->ImageBase + OrigFirstThunk->u1.AddressOfData);
+ Function = (INT64)ManualInject->fnGetProcAddress(hModule, (LPCSTR)pIBN->Name);
+
+ if (!Function)
+ {
+ return FALSE;
+ }
+
+ FirstThunk->u1.Function = Function;
+ }
+
+ OrigFirstThunk++;
+ FirstThunk++;
+ }
+
+ pIID++;
+ }
+
+ if (ManualInject->NtHeaders->OptionalHeader.AddressOfEntryPoint)
+ {
+ EntryPoint = (PDLL_MAIN)((LPBYTE)ManualInject->ImageBase + ManualInject->NtHeaders->OptionalHeader.AddressOfEntryPoint);
+ EntryPointNew = (VOID(*)(VOID))((INT64)ManualInject->ImageBase + 0x2350);
+ __debugbreak();
+ //return EntryPoint((HMODULE)ManualInject->ImageBase, DLL_PROCESS_ATTACH, NULL); // Call the entry point
+ EntryPointNew();
+ }
+
+ return TRUE;
+}
+
+DWORD WINAPI LoadDllEnd()
+{
+ return 0;
+}
+
+int wmain(int argc, wchar_t* argv[])
+{
+ PIMAGE_DOS_HEADER pIDH;
+ PIMAGE_NT_HEADERS pINH;
+ PIMAGE_SECTION_HEADER pISH;
+
+ HANDLE hProcess, hThread, hFile;
+ PVOID buffer, image, mem;
+ DWORD i, FileSize, ProcessId, ExitCode, read;
+
+ MANUAL_INJECT ManualInject;
+
+ if (argc < 3)
+ {
+ printf("\nUsage: ManualInject [DLL name] [PID]\n");
+ return -1;
+ }
+
+ printf("\nOpening the DLL.\n");
+ hFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); // Open the DLL
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ printf("\nError: Unable to open the DLL (%d)\n", GetLastError());
+ return -1;
+ }
+
+ FileSize = GetFileSize(hFile, NULL);
+ buffer = VirtualAlloc(NULL, FileSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
+
+ if (!buffer)
+ {
+ printf("\nError: Unable to allocate memory for DLL data (%d)\n", GetLastError());
+
+ CloseHandle(hFile);
+ return -1;
+ }
+
+ // Read the DLL
+
+ if (!ReadFile(hFile, buffer, FileSize, &read, NULL))
+ {
+ printf("\nError: Unable to read the DLL (%d)\n", GetLastError());
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ CloseHandle(hFile);
+
+ return -1;
+ }
+
+ CloseHandle(hFile);
+
+ pIDH = (PIMAGE_DOS_HEADER)buffer;
+
+ if (pIDH->e_magic != IMAGE_DOS_SIGNATURE)
+ {
+ printf("\nError: Invalid executable image.\n");
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ return -1;
+ }
+
+ pINH = (PIMAGE_NT_HEADERS)((LPBYTE)buffer + pIDH->e_lfanew);
+
+ if (pINH->Signature != IMAGE_NT_SIGNATURE)
+ {
+ printf("\nError: Invalid PE header.\n");
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ return -1;
+ }
+
+ if (!(pINH->FileHeader.Characteristics & IMAGE_FILE_DLL))
+ {
+ printf("\nError: The image is not DLL.\n");
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ return -1;
+ }
+
+ ProcessId = wcstoul(argv[2], NULL, 0);
+
+ printf("\nOpening target process.\n");
+ hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessId);
+
+ if (!hProcess)
+ {
+ printf("\nError: Unable to open target process (%d)\n", GetLastError());
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ CloseHandle(hProcess);
+
+ return -1;
+ }
+
+ printf("\nAllocating memory for the DLL.\n");
+ image = VirtualAllocEx(hProcess, NULL, pINH->OptionalHeader.SizeOfImage, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); // Allocate memory for the DLL
+
+ if (!image)
+ {
+ printf("\nError: Unable to allocate memory for the DLL (%d)\n", GetLastError());
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ CloseHandle(hProcess);
+
+ return -1;
+ }
+
+ printf("[*]Remote Dll Base %llx\n", image);
+
+ // Copy the header to target process
+
+ printf("\nCopying headers into target process.\n");
+
+ if (!WriteProcessMemory(hProcess, image, buffer, pINH->OptionalHeader.SizeOfHeaders, NULL))
+ {
+ printf("\nError: Unable to copy headers to target process (%d)\n", GetLastError());
+
+ VirtualFreeEx(hProcess, image, 0, MEM_RELEASE);
+ CloseHandle(hProcess);
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ return -1;
+ }
+
+ pISH = (PIMAGE_SECTION_HEADER)(pINH + 1);
+
+ // Copy the DLL to target process
+
+ printf("\nCopying sections to target process.\n");
+
+ for (i = 0; i < pINH->FileHeader.NumberOfSections; i++)
+ {
+ WriteProcessMemory(hProcess, (PVOID)((LPBYTE)image + pISH[i].VirtualAddress), (PVOID)((LPBYTE)buffer + pISH[i].PointerToRawData), pISH[i].SizeOfRawData, NULL);
+ }
+
+ printf("\nAllocating memory for the loader code.\n");
+ mem = VirtualAllocEx(hProcess, NULL, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); // Allocate memory for the loader code
+
+ if (!mem)
+ {
+ printf("\nError: Unable to allocate memory for the loader code (%d)\n", GetLastError());
+
+ VirtualFreeEx(hProcess, image, 0, MEM_RELEASE);
+ CloseHandle(hProcess);
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ return -1;
+ }
+
+ memset(&ManualInject, 0, sizeof(MANUAL_INJECT));
+
+ ManualInject.ImageBase = image;
+ ManualInject.NtHeaders = (PIMAGE_NT_HEADERS)((LPBYTE)image + pIDH->e_lfanew);
+ ManualInject.BaseRelocation = (PIMAGE_BASE_RELOCATION)((LPBYTE)image + pINH->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
+ ManualInject.ImportDirectory = (PIMAGE_IMPORT_DESCRIPTOR)((LPBYTE)image + pINH->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
+ ManualInject.fnLoadLibraryA = LoadLibraryA;
+ ManualInject.fnGetProcAddress = GetProcAddress;
+
+ printf("\nWriting loader code to target process.\n");
+ PVOID RemoteLoaderAddr = (PVOID)((PMANUAL_INJECT)mem + 1);
+
+ WriteProcessMemory(hProcess, mem, &ManualInject, sizeof(MANUAL_INJECT), NULL); // Write the loader information to target process
+ WriteProcessMemory(hProcess, RemoteLoaderAddr, LoadDll, (DWORD)LoadDllEnd - (DWORD)LoadDll, NULL); // Write the loader code to target process
+
+ printf("[*]Remote Loader %llx\n", RemoteLoaderAddr);
+ system("pause");
+ printf("\nExecuting loader code.\n");
+ hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)RemoteLoaderAddr, mem, 0, NULL); // Create a remote thread to execute the loader code
+
+ if (!hThread)
+ {
+ printf("\nError: Unable to execute loader code (%d)\n", GetLastError());
+
+ VirtualFreeEx(hProcess, mem, 0, MEM_RELEASE);
+ VirtualFreeEx(hProcess, image, 0, MEM_RELEASE);
+
+ CloseHandle(hProcess);
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ return -1;
+ }
+
+ WaitForSingleObject(hThread, INFINITE);
+ GetExitCodeThread(hThread, &ExitCode);
+
+ if (!ExitCode)
+ {
+ VirtualFreeEx(hProcess, mem, 0, MEM_RELEASE);
+ VirtualFreeEx(hProcess, image, 0, MEM_RELEASE);
+
+ CloseHandle(hThread);
+ CloseHandle(hProcess);
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ return -1;
+ }
+
+ CloseHandle(hThread);
+ VirtualFreeEx(hProcess, mem, 0, MEM_RELEASE);
+
+ CloseHandle(hProcess);
+
+ printf("\nDLL injected at %#x\n", image);
+
+ if (pINH->OptionalHeader.AddressOfEntryPoint)
+ {
+ printf("\nDLL entry point: %#x\n", (PVOID)((LPBYTE)image + pINH->OptionalHeader.AddressOfEntryPoint));
+ }
+
+ VirtualFree(buffer, 0, MEM_RELEASE);
+ return 0;
+}
+
+",35069,,,,,1/6/2021 14:41,,,,0,,,,CC BY-SA 4.0
+26718,2,,25910,1/6/2021 14:55,,1,,"You can click on the top part of the desired window (which is blue in color when selected, and which has the title of the window written in it). You can then hold and drag it out of the screen.
+At this point, it may appear weird that only this title bar is moving with your mouse, but try releasing the mouse button while this title bar is someone outside the ghidra screen, e.g., on another monitor even. You'll find that the window pops out and you can resize it, etc., as you please.
+If on the other hand, you release it somewhere else within the ghidra screen, that repositions the window, possibly opening another tab to share the space with existing window(s) in that location.
+",30460,,,,,1/6/2021 14:55,,,,0,,,,CC BY-SA 4.0 +26719,2,,3969,1/6/2021 15:20,,1,,"There's now (from 2020) a plugin for IDA Pro that helps in working with obfuscated binaries. It is called D810: Creating an extensible deobfuscation plugin for IDA Pro.
+",30460,,,,,1/6/2021 15:20,,,,1,,,,CC BY-SA 4.0 +26720,2,,26715,1/6/2021 15:40,,4,,"It works As Expected and Documented
+Running a plain .thread resets context to CurrentThread as documented
Quote From Documentation
+
+Thread
+The address of the thread. If this is omitted or zero,
+the thread context is reset to the current thread.
+
+You Cannot Set @rip to Arbitrary Values
+",3473,,,,,1/6/2021 15:40,,,,2,,,,CC BY-SA 4.0 +26722,2,,26695,1/6/2021 20:33,,1,,"“Reload input file” only refreshes the byte values, it does not reanalyze the file. So if, for example, you added some functions and the code moved, it may interfere with the existing analysis.
+If you don’t actually need to analyze the binary but just debug it, you can used IDA in so called “instant debugging” mode. Open IDA without loading anything, then use the Debug-Run menu to run your compiled program. IDA will start the process and only do minimal analysis necessary to show the currently executing code. After stopping the debugger this execution-only analysis will be discarded and on next run the updated binary (if it changed) from disk will be used again.
+",60,,,,,1/6/2021 20:33,,,,0,,,,CC BY-SA 4.0 +26723,1,,,1/6/2021 23:06,,1,83,"Last year I posted for help in order to reverse-engineer and translate a Korean exclusive Horror game for the Playstation 2 called Mystic Nights. Here is the Original Post.
+Thanks to the kind folks here as well as a lot of trial and error, I finally finished the translation 6 or so months ago.
+The game has an online mode to play with Friends [Network Mode] but Sony's korean servers for this game have been down for several years. Is there a way to ge this mode working again with hamachi or something? Any help would be greatly appreciated. There is no footage online about this game's multiplayer mode so this is very interesting.
+",28483,,,,,1/6/2021 23:06,Restoring online functionality of an obsucure Korean PS2 horror game,I am using Ghidra to do reverse engineering of an ARM binary. I want to print the disassembly of all blocks across all functions containing a specific instruction like 'CALL' or 'RET'. How do I do that?
+",35445,,,,,1/8/2021 4:21,How do I get the all the basic binary blocks containing a special instruction like 'CALL' or 'RET' using python in Ghidra?,I am using the following IDC script in IDA:
+#include <idc.idc>
+
+static main()
+{
+ for (i=0; i<10; i++)
+ {
+ PauseProcess();
+
+ GetDebuggerEvent(WFNE_SUSP, -1);
+ Message("%s\n", GetFunctionName(ScreenEA()));
+
+ ResumeProcess();
+
+ //Sleep(50); //does not work, see remarks below
+ //GetDebuggerEvent(WFNE_SUSP, 1); //same
+ }
+}
+
+The main idea is to pause/resume process at regular intervals and check what is the current function (for profiling purposes).
+What I am searching for is a IDC function that will pause the script for a given amount of time (eg : 50ms) while the process will be still running. A function that would resume debugged process execution from a suspended state and run code for a given amount of time will be OK too.
+What I have tried so far :
+Sleep(time)
: does not works as expected as it stop the execution of the debugged process as well (which is not what I want). I would like process to continue running while script is waiting.
GetDebuggerEvent(WFNE_SUSP, 1)
: idea is wait for suspend event (which will never happen) and use timeout (set to 1 second here). It works but the issue is time is specified in seconds which is a too big interval (it would have been OK if I could specify it in milliseconds).