I built ANSI C MS-Windows file manager, <500 LoC (from scratch)

I built ANSI C MS-Windows file manager, <500 LoC (from scratch)

https://gitlab.com/win326174234/sa01

Even though I am 19, I consider myself a seasoned win32/nt developer. I worked at a company, which deals a lot with winapi and windows system programming in general. I built this project for anyone, who practices either C or winapi (including gdi). I sticked with ANSI C and simple code flow without complicated constructions and jumps for this one to achieve readability and easy-to-build mental model. I am planning to make a hand-written x86 assembly version for this as well. I’ll be using the same approach — 5-6 instructions, no complicated SIMD or cache lines usage.

Software is licensed under MIT license. Any suggestions and notes are welcome.

u/Capable-Cap9745 — 3 days ago

Same Makefile, different results

Not sure if this fits, but I just figured out the root cause of long build process failing. Sun’s dmake is defaulting to the first rule in Makefile for whatever reason, completely ignoring the one given as argument. That’s why "dmake install" invocations were silently ignoring the "install" step

u/Capable-Cap9745 — 25 days ago

Реверс инженеринг, C, Sh, Asm — где искать работу?

Где найти работу/подработку, как C/Assembly разработчик или как реверс инженер? HH, фриланс биржи, почти все ищут веб разработчиков

Опыт разработки ~7 лет, обратной разработки ~5 лет. Стек — ANSI C/C99/C11, UNIX Shell (sh), Bash, Tcl, Perl5, x86_64/amd64 (включая расширения, такие как MMX, SSE*, AVX, AVX512), i386/x86/x32, Aarch64, Aarch32 Assembly, GNU Make, CMake. Git, GitHub/GitLab/Codeberg, Docker, Ghidra, IDA Pro, Binja, Wireshark, QEMU/KVM

Платформы — UNIX/UNIX-like (BSD, Solaris/Illumos, HP-UX, SCO), GNU/Linux, WinNT

API — POSIX, Win32Api, NT Api

Разбираюсь в кодовой базе Solaris/Illumos и Linux, программной среде UNIX. Есть опыт работы с Legacy кодом, написания технической документации. Уверенно чувствую себя в любых POSIX и LSB средах

reddit.com
u/Capable-Cap9745 — 1 month ago
▲ 4 r/kernel

connect(2) syscall errno=74 (EBADMSG) on Android?

EDIT: Solved!

details in my comment

PoC

Source:

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <arpa/inet.h>
int main(void) {
  struct sockaddr_in a = { .sin_family = AF_INET,
    .sin_port   = htons(5050),
    .sin_addr   = { .s_addr = inet_addr("127.0.0.1") } };
  int s = socket(AF_INET, SOCK_STREAM, 0);
  if (s < 0) { perror("socket"); return 1; }
  if (connect(s, (struct sockaddr*)&a, sizeof a) < 0) {
    printf("connect failed: %s (errno=%d)\n", strerror(errno), errno);
    return 1;
  }
  puts("connected");
  return 0;
}

From adb shell:

$ su
# cd /data
# ./test2
connect failed: Not a data message (errno=74)
# uname -a
Linux localhost 4.19.110-android-x86_64-g066cc1d #1 SMP PREEMPT Wed Mar 25 11:32:46 CST 2020 x86_64

It doesn't matter if something is listening on tcp://localhost:5050 or not, output is the same. I am running inside QEMU, Android x86 9 (amd64). The application itself is aarch64 (running through android native bridge)

Problem

I've never seen this errno before and I can't seem to figure it out by myself. I tried:

  • Zero-initializing sockaddr_in and initializing field by field
  • Using IPPROTO_TCP instead of 0 as third argument for socket(2)
  • Using other addresses I can ping from environment (10.0.2.2 for PC host and 10.0.2.15 for QEMU localhost)
  • Setting socket to blocking/nonblocking mode with ioctl(2) via FIONBIO and fcntl(2)

Snippet works perfectly on GLIBC/MUSL-based GNU/Linux systems: as expected errno is ECONNREFUSED

Any help will be appreciated, thank you

u/Capable-Cap9745 — 2 months ago