The MASM Forum

Projects => ObjAsm => Topic started by: Biterider on May 16, 2019, 05:21:01 AM

Title: ObjAsm Tools
Post by: Biterider on May 16, 2019, 05:21:01 AM
Hi
To improve the quality of the MASM code, years ago I developed a rudimentary tool that verifies the register preservation of regular procedures that follows the MS Windows ABI.

These days I needed this tool again and decided to port and update it.
Now, procedures and methods are supported for 32-bit, 64-bit, and mixed code.

I uploaded a trial version and a pdf help file here http://objasm.x10host.com/DwnFiles/OA_Tools.zip (http://objasm.x10host.com/DwnFiles/OA_Tools.zip).

I would be glad, if someone would like to test the tool.  :P

Regards, Biterider
Title: Re: ObjAsm Tools
Post by: jj2007 on May 16, 2019, 12:25:02 PM
Hi BiteRider,

In which language did you write it? VirusTotal found zero positives (https://www.virustotal.com/gui/file/71ad0ff22d59b9b9720d3db0ce1d36df96d89c9142cfa32d13c293ee6460eaef/detection), so it definitely wasn't Assembly :P

What does it do? I've tried to analyse a few sources, inter alia the 20k lines of my editor, modified by some arbitrary push edi commands, and it doesn't find anything.
Title: Re: ObjAsm Tools
Post by: Biterider on May 16, 2019, 04:09:56 PM
Hi jj
Thanks for testing the app. It is written im pure asm (MASM/ObjAsm).  :icon_mrgreen:

In the attachment are a few files I used for testing. Let the program analyse them and you will have something to play with.

Biterider
Title: Re: ObjAsm Tools
Post by: LiaoMi on May 16, 2019, 08:08:26 PM
Quote from: Biterider on May 16, 2019, 05:21:01 AM
Hi
To improve the quality of the MASM code, years ago I developed a rudimentary tool that verifies the register preservation of regular procedures that follows the MS Windows ABI.

These days I needed this tool again and decided to port and update it.
Now, procedures and methods are supported for 32-bit, 64-bit, and mixed code.

I uploaded a trial version and a pdf help file here http://objasm.x10host.com/DwnFiles/OA_Tools.zip (http://objasm.x10host.com/DwnFiles/OA_Tools.zip).

I would be glad, if someone would like to test the tool.  :P

Regards, Biterider

Hi Biterider,

the program works fine, I have a lot of incorrect matches!  :biggrin: I am an ideal candidate for testing :greenclp:
Title: Re: ObjAsm Tools
Post by: jj2007 on May 16, 2019, 10:26:20 PM
I wonder what I am doing wrong (Proc_Test_32.asm):
Working
Register use and preservation check ready.

Working
Variable check ready.

Title: Re: ObjAsm Tools
Post by: Biterider on May 17, 2019, 02:52:25 AM
Hi JJ
You should get the following result using the test file (Proc_Test_32.asm)
Working.
ERROR: unpreserved registers detected.
  Code block name: BStrCScan (27)
  Used registers:  edi
Working
Register use and preservation check ready.

Working.
Variable check ready.


What about the rest of the test files?

Biterider
Title: Re: ObjAsm Tools
Post by: jj2007 on May 17, 2019, 03:26:55 AM
Can you explain step by step what you have to do to check a file?
Menu Checks/All, select a *.asm file, OK produces always the same window and output:

Working
Register use and preservation check ready.

Working
Variable check ready.
Title: Re: ObjAsm Tools
Post by: Biterider on June 02, 2019, 03:27:29 AM
Hi
This is the second round of the OA-Tools. I refactored the code to added more features:
Now you can scan for unpreserved registers, unused locals and unused arguments.
Annotations are also implemented (false positives).
Other things like high contrast settings can be changed in the color setup. Output font can also be selected. Finally I added the description of all these features in the pdf help file, that can be launched from the help menu of the application (the file must be in the same directory as the .exe file).

The download of the binary files (64 bit & wide string) is http://objasm.x10host.com/DwnFiles/OA_Tools.zip (http://objasm.x10host.com/DwnFiles/OA_Tools.zip)
The sources can be downloaded here http://objasm.x10host.com/DwnFiles/OA_Tools_Src.zip (http://objasm.x10host.com/DwnFiles/OA_Tools_Src.zip)

For those that are fluent in other languages (implemented are EN, DE, ES), please check the .rc file. If you want to translate the string table, please let me know.  :cool:

Biterider
Title: Re: ObjAsm Tools
Post by: jj2007 on June 05, 2019, 09:53:45 PM
Some glitches:
WARNING: possibly unused argument(s) detected.
  Code block name: MbArrayPlot2 (1028)
    - apmargins
    - xEnd1

Both are arguments, and are being used:
MbArrayPlot2 proc uses esi ebx arrID, arrTypeAndFlags, apmargins, DotCol, DotSize, xStart, xEnd1 ; setrange

  mov eax, xEnd1
  test eax, eax
  .if Sign?   ; default: -1 (0 would mean a single point, valid)
mov eax, [esi-8] ; # elements
  .endif

  mov ebx, apmargins ; apMargins in ArrayPlot macro
  .if ebx<30


WARNING: possibly unused argument(s) detected.
  Code block name: giDownload (1921)
    - private


giDownload proc private uses esi ebx giEbx

WARNING: possibly unused argument(s) detected.
  Code block name: Chkjj (3315)
    - arg


if 0
.data?
cjj dd ?
.code
Chkjj proc arg
pushad
  mov ecx, MenuTable[4*12]
  .if ecx>127
mov eax, [ecx]
.if eax!=cjj
; deb 4, "CJJ####", ecx, eax, $arg  <<<<<<<<<<<<<<<<<<<<<<<<<
mov cjj, eax
.endif
  .endif
popad
@MbRet
Chkjj endp
endif


Correctly recognised, except that the whole code is IF 0 ... ENDIF.

ERROR: possibly unpreserved register detected.
  Code block name: RepString (12486)
  Used registers:  edi esi


RepString proc uses esi edi ecx Dest, Pattern, Repl

ERROR: possibly unpreserved register detected.
  Code block name: ForceTextColP (17710)
  Used registers:  ebx

ForceTextColP proc ; arg
push ebx
mov ebx, [esp+8]
.if GetSelCol(0)!=ebx
invoke SetSelFormat, ebx, CFM_COLOR
.endif
pop ebx
retn 4
ForceTextColP endp


ERROR: possibly unpreserved register detected.
  Code block name: InsDate (22935)
  Used registers:  esi

InsDate proc
LOCAL txrg:TEXTRANGE
  GetCurSel
  .if eax<127
mov txrg.chrg.cpMin, edx
add eax, edx
mov txrg.chrg.cpMax, eax ; overwrite
push esi
mov esi, SelXXL$
invoke GetDateFormat, 0809h, DATE_LONGDATE, 0, 0, esi, 127 ; Country codes: see MSDN
invoke RepSel, addr txrg, esi ; we insert date & time separately to enable undo of time
GetCurSel
mov txrg.chrg.cpMin, edx
mov txrg.chrg.cpMax, edx ; Start=end, insert
invoke lstrcpy, esi, chr$(", ")
lea edx, [esi+Len(esi)]
invoke GetTimeFormat, 0, 0, 0, chr$("HH':'mm':'ss"), edx, 127
invoke RepSel, addr txrg, esi
pop esi
  .endif
  @MbRet
InsDate endp
Title: Re: ObjAsm Tools
Post by: Biterider on June 06, 2019, 06:14:05 AM
Hi JJ
Thank you for your feedback.  :thumbsup:
First and foremost, this application is a scanner and it knows nothing about program logic or about symbols and their values. This means that the code after a "if 0" statement is always evaluated.
To fix this flaw, a full functional assembler should be implemented, which is completely out of scope.
The same applies to self preserved (by the coder) registers. There is no simple way to know, if the preservation logic is correct.
Nevertheless, there are some bugs that you showed in the previous post. If possible, can you post or send it to me via a private channel the relevant source file?

What I can say atm is, that "private" before "uses" is not considered as a keyword. I will read the manual again to see out if there are other possible situations that can lead to a misrecongnition.

I'm not sure what you mean in the Chkjj procedure. "arg" is not the same as "$arg" and it is in a commented-out line. Text that is commented-out is not scanned. Maybe I'm missing here something...

I have been told that the setup dialog has some problems with the tab control in unknown circumstances. Can you please check if there is a problem on your machine. BTW, which OS do you use?

Biterider



Title: Re: ObjAsm Tools
Post by: jj2007 on June 06, 2019, 06:43:15 AM
Quote from: Biterider on June 06, 2019, 06:14:05 AMcode after a "if 0" statement is always evaluated.
No problem at all.

QuoteThe same applies to self preserved (by the coder) registers. There is no simple way to know, if the preservation logic is correct.
Correct, but it should be mentioned in a prominent place.

QuoteNevertheless, there are some bugs that you showed in the previous post. If possible, can you post or send it to me via a private channel the relevant source file?
I will see what I can do.

QuoteWhat I can say atm is, that "private" before "uses" is not considered as a keyword.
For MASM, "private" in that position means "do not publish that symbol".

QuoteI have been told that the setup dialog has some problems with the tab control in unknown circumstances. Can you please check if there is a problem on your machine. BTW, which OS do you use?
No such problems on Win7-64 :thumbsup:
Title: Re: ObjAsm Tools
Post by: Biterider on June 09, 2019, 06:47:31 AM
Hi
Here is the next update.
I fixed the old issues and added a new feature to scan macros. The documentation is updated accordingly.  :icon_idea:
To improve productivity, I have formatted the output slightly differently so that it can be copied and pasted directly as argument for annotations.

This version and the pdf help file can be downloaded from here http://objasm.x10host.com/DwnFiles/OA_Tools.zip (http://objasm.x10host.com/DwnFiles/OA_Tools.zip).

Feedback is welcome.  :cool:

Biterider
Title: Experienced assembler testers wanted
Post by: Biterider on June 16, 2019, 05:09:36 PM
Hi
Thanks to the support of some members of the board, I was able to bring forward this test application. The last addition was the ability to check macros for arguments and locals.  :icon_idea:

The user interface has been significantly improved and more graphics, text and languages like Chinese have been added. The user experience was unified in all dialogues.  :icon_idea:

There are many very interesting techniques used for this application that are worth discussing. They will be treated in a separate thread.
The final source code will be released shortly with ObjAsm Beta 3. The reason is that some additions had to be made and without them, the source cannot be compiled properly.

Since this is the almost final version, I would like to ask some people to re-examine the application for errors, missing features, and so on.  :cool:

The download is as usual http://objasm.x10host.com/DwnFiles/OA_Tools.zip (http://objasm.x10host.com/DwnFiles/OA_Tools.zip).

Biterider
Title: Re: ObjAsm Tools
Post by: jj2007 on June 16, 2019, 06:40:21 PM
Hi BiteRider,
This is what I get immediately in the debug centre after dragging a big source over the exe:
Object ID = 100000t (OA_OAT_App), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 250t (OA_RegKey), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 100000t (OA_OAT_App), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 250t (OA_RegKey), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 100000t (OA_OAT_App), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 250t (OA_RegKey), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 100000t (OA_OAT_App), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 250t (OA_RegKey), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 100000t (OA_OAT_App), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 250t (OA_RegKey), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)
Object ID = 100000t (OA_OAT_App), Error Code = 536870999t (RKY_GET_DW_FAILED: Reading a DWORD failed)


Apart from this glitch, it works fine, and I have found several unused local variables. May save a few bytes :tongue:
Title: Re: ObjAsm Tools
Post by: Biterider on June 16, 2019, 06:47:05 PM
Hi JJ
This is the debug version. It shows that some entries in the registry are missing, which is OK.
I uploaded now the release version, that doesn't show these messages.

Biterider
Title: Re: ObjAsm Tools
Post by: HSE on June 17, 2019, 01:22:29 AM
Hi Biterider|

Setup is perfect now  :thumbsup:

Utilizar anotaciones
Las modificaciones tienen efecto en las ventanas nuevas
Seleccionar el idioma de la aplicaciĆ³n
Title: Re: ObjAsm Tools
Post by: Biterider on June 17, 2019, 04:37:37 AM
Hi JJ, HSE
Thanks for testing. I think everything works now.  :thumbsup:
I hope this tool will help us to find the most common programming problems.


I'll keep the download up for a few more days and then integrate the tool into the OA package.


Regards, Biterider
Title: Re: ObjAsm Tools
Post by: sinsi on June 17, 2019, 08:02:00 AM
Is this specific to ObjAsm only or any MASM source?

Quote
Working...
ERROR: possibly unpreserved register(s) detected.
  Code block:  desktopinit (106)
  Register(s): ebx esi


desktopinit proc public uses ebx esi pst:PTR IStream

Title: Re: ObjAsm Tools
Post by: Biterider on June 17, 2019, 04:20:38 PM
Hi Sinsi
I'm not able to find something wrong here.  :rolleyes:
I'm testing with
desktopinit proc public uses ebx esi pst:PTR IStream
  push ebx
  pop esi
  ret
desktopinit endp


Make sure you habe selected 32 bit code in the setup dialog (press F2 for quick access). A wrong setting here may produce this message.
If the setting is correct, can you send me or post the whole file that contains this procedure?

Thank you!
Biterider
Title: Re: ObjAsm Tools
Post by: sinsi on June 20, 2019, 09:27:23 AM
OK, the problem seems to be the case used

MyProc proc uses ebx ;lower case
    xor ebx,ebx      ;matching case, no problem
    ret
MyProc endp

MyOtherProc proc USES EBX ;upper case
    xor ebx,ebx           ;lower case, triggers warning
    ret
MyOtherProc endp

Quote
ERROR: possibly unpreserved register(s) detected.
  Code block:  MyOtherProc (10)
  Register(s): ebx
Working
WARNING: possibly unnecessary register preservation detected.
  Code block:  MyOtherProc (10)
  Register(s): EBX

One other small complaint, having to load the file every time to check it.
Title: Re: ObjAsm Tools
Post by: jj2007 on June 20, 2019, 05:17:47 PM
Quote from: sinsi on June 20, 2019, 09:27:23 AM
OK, the problem seems to be the case used

Right, the tool should issue a warning "lousy and inconsistent coding style" :badgrin:

QuoteOne other small complaint, having to load the file every time to check it.

True. CommandLineToArgvW and WM_DROPFILES (DragQueryFile, DragFinish) are your friends.
Title: Re: ObjAsm Tools
Post by: Biterider on June 20, 2019, 07:49:25 PM
Hi Sinsi
QuoteMyOtherProc proc USES EBX
That was a good one. Thank your for investigating the issue.  :thumbsup:
It was easy to correct. A new version can be downloaded (build 79).

QuoteOne other small complaint, having to load the file every time to check it.
I'm not sure if you tried the child window context menu. It has 2 items to open the analysed file and to recheck it.

Regards, Biterider
Title: Re: ObjAsm Tools
Post by: Biterider on June 20, 2019, 07:55:57 PM
Hi JJ
QuoteRight, the tool should issue a warning "lousy and inconsistent coding style" :badgrin:
I agree with you  :wink2:

QuoteCommandLineToArgvW and WM_DROPFILES
Dropping files dosn't make much sense atm, since you have to trigger the check type from the menu.  :sad:
Command line arguments may be a good option.  :icon_idea:

Some questions remain for this operation mode:
- single file analysis or batch mode?
- output to window or console?

Regards, Biterider
Title: Re: ObjAsm Tools
Post by: LiaoMi on June 20, 2019, 08:11:05 PM
Quote from: Biterider on June 20, 2019, 07:55:57 PM
Dropping files dosn't make much sense atm, since you have to trigger the check type from the menu.  :sad:

It would be convenient if a single window with the choice of architecture appears when dragging a file  :icon_idea:
Title: Re: ObjAsm Tools
Post by: Biterider on June 21, 2019, 04:17:26 AM
Hi JJ, LiaoMi
I took LiaoMis idea and implemented the code to drop files into the application.  :thumbsup:

The new release (build 80) can be downloaded.

Regards, Biterider