flat assembler
Message board for the users of flat assembler.

Index > Main > bootstraping fasmg, x64dbg, to reproduce PE P016

Author
Thread Post new topic Reply to topic
beowulf34



Joined: 16 Oct 2022
Posts: 3
beowulf34 19 Oct 2022, 03:03
@bitRAKE

Moving our conversation here.

I am trying to reproduce your PE P016 assembly solution:
Code:
POWER EQU 1000

_DATA SEGMENT
        Number DWORD (POWER+31)/32 DUP (0)
_DATA ENDS

        ; set up number in binary
        lea ebp, [Number]
        mov eax, POWER
        bts [ebp], eax

        ; convert to decimal to sum digits
        mov edi, LENGTHOF Number - 1
        mov ecx, 10
        xor ebx, ebx ; sum

_0:     mov esi, edi ; dwords to convert
        xor edx, edx
@@:     mov eax, [ebp][esi*4]
        div ecx
        mov [ebp][esi*4], eax
        dec esi
        jns @B

        add ebx, edx

        cmp DWORD PTR [ebp][edi*4], 0
        jne _0
        dec edi
        jns _0
    


Full source is here:
https://github.com/bitRAKE/fasmg_playground/blob/master/math/Project%20Euler/P016.asm

You recommended fasm assembler with the x64dbg/radare2 debugger.

I have tried the fasmg and fasm windows releases, without success to compile the P016.asm.

I have successfully executed fasmg on macos to run the P016.g script. It cannot create an output file. Likewise, fasmg.exe via wine also runs the P016.g script and cannot create an output file.

Trying to compile the .asm file results in:
Error: source file 'win64a.inc' not found.
None of the releases appear to contain this file. As far as I can tell it is some sort of legacy fasm windows support include dependency.

The fasm windows release gets a little further:

Code:
wine /Users/jhg/Work/euler/fasm_win/FASM.EXE P016.asm 
flat assembler  version 1.73.300024:fixme:ntdll:NtQuerySystemInformation info_class SYSTEM_PERFORMANCE_INFORMATION
  (655359 kilobytes memory)
P016.asm [3]:
        POWER = 1000
error: unexpected characters.
    


I do not have /r/n line endings, which git can sometimes change to /n for unix (I am macos native). I see you have a .gitattributes which disables this translation, so it's not that.

Thoughts?

Cheers,
Joe
Post 19 Oct 2022, 03:03
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 19 Oct 2022, 03:51
The following steps produce no error:
Code:
git clone https://github.com/bitRAKE/fasmg_playground.git
cd "fasmg_playground\math\Project Euler"
fasmg P016.g
fasmg P016.asm
P016.exe    
... this first executes fasmg with a script to produce the answer, and then secondly builds an executable which is also executed to produce the answer. Two separate solutions to the same problem.

This does require having your environment configured correctly. Which means fasmg on the PATH and INCLUDE defined such that it points to "\fasmg\packages\x86\include". Whatever problem you are having is most likely due to insufficient environment configuration.

This newer repo is even a simpler process:
Code:
git clone --recursive https://github.com/bitRAKE/fasmg-umbrella
cd fasmg-umbrella
environment.cmd    
... and the terminal is all set to go. It links to fasmg on github. Examine the command file that sets up the environment. The older(playground) repo assumes an existing fasmg environment.

'win64a.inc' is indeed part of fasmg - you may find it at:
\fasmg\packages\x86\include\win64a.inc

Good luck.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 19 Oct 2022, 03:51
View user's profile Send private message Visit poster's website Reply with quote
beowulf34



Joined: 16 Oct 2022
Posts: 3
beowulf34 20 Oct 2022, 02:14
The "flat assembler g jmhx"/fasmg.jmhx does not include the packages directory.

My download of fasm_win also does not have the packages directory, though it does have WIN64A.INC. Which was of course not showing in the prior search due to case sensitive search:

Code:
find . -name "win64a.inc"
find . -iname "win64a.inc"
./fasm_win/INCLUDE/WIN64A.INC
    


This did the trick inside the `wine cmd`:
Code:
@SET this=%~dp0
@SET this=%this:~0,-1%

@REM Configure environment to build examples:
@SET path=%this%\fasmg\core;%path%
@REM Order is important, FIFO search:
@SET include=%this%;%this%\addon\packages\x64\include;%this%\fasmg\packages\x86\include
@ECHO should be able to build any of the examples with: fasmg {file}.asm
    


Also needed to run this registry patch to get x64dbg to go:
Code:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Wine\AppDefaults]
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\x32dbg.exe]
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\x32dbg.exe\DllOverrides]
"dbghelp"="native,builtin"
"msvcp120"="native,builtin"
"msvcr120"="native,builtin"
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\x64dbg.exe]
[HKEY_CURRENT_USER\Software\Wine\AppDefaults\x64dbg.exe\DllOverrides]
"dbghelp"="native,builtin"
"msvcp120"="native,builtin"
"msvcr120"="native,builtin"
    


It works. =)


Description: it works
Filesize: 398.92 KB
Viewed: 2059 Time(s)

itworks.jpg


Post 20 Oct 2022, 02:14
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 20 Oct 2022, 03:47
A typical debug session would be, load the EXE, F9 - execute until entry breakpoint, and then use a combination of F2/F7/F8/F9 to navigate execution. You'll probably want to examine machine state, memory, etc. Might seem over-whelming at first, but becomes second nature. Don't worry about making a mistake - the EXE can always be reloaded, and try again. Change things, break stuff, etc.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 20 Oct 2022, 03:47
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.