Author Topic: ObjAsm Tools  (Read 1568 times)

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
ObjAsm Tools
« 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.

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

Regards, Biterider

jj2007

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: ObjAsm Tools
« Reply #1 on: May 16, 2019, 12:25:02 PM »
Hi BiteRider,

In which language did you write it? VirusTotal found zero positives, 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.

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ObjAsm Tools
« Reply #2 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
« Last Edit: June 02, 2019, 03:09:11 AM by Biterider »

LiaoMi

  • Member
  • ****
  • Posts: 593
Re: ObjAsm Tools
« Reply #3 on: May 16, 2019, 08:08:26 PM »
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.

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:

jj2007

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: ObjAsm Tools
« Reply #4 on: May 16, 2019, 10:26:20 PM »
I wonder what I am doing wrong (Proc_Test_32.asm):
Code: [Select]
Working
Register use and preservation check ready.

Working
Variable check ready.

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ObjAsm Tools
« Reply #5 on: May 17, 2019, 02:52:25 AM »
Hi JJ
You should get the following result using the test file (Proc_Test_32.asm)
Code: [Select]
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

jj2007

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: ObjAsm Tools
« Reply #6 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:

Code: [Select]
Working
Register use and preservation check ready.

Working
Variable check ready.

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ObjAsm Tools
« Reply #7 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
The sources can be downloaded here 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

jj2007

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: ObjAsm Tools
« Reply #8 on: June 05, 2019, 09:53:45 PM »
Some glitches:
Code: [Select]
WARNING: possibly unused argument(s) detected.
  Code block name: MbArrayPlot2 (1028)
    - apmargins
    - xEnd1
Both are arguments, and are being used:
Code: [Select]
MbArrayPlot2 proc uses esi ebx arrID, arrTypeAndFlags, apmargins, DotCol, DotSize, xStart, xEnd1 ; setrange
Code: [Select]
  mov eax, xEnd1
  test eax, eax
  .if Sign?   ; default: -1 (0 would mean a single point, valid)
  mov eax, [esi-8] ; # elements
  .endif
Code: [Select]
  mov ebx, apmargins ; apMargins in ArrayPlot macro
  .if ebx<30

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

giDownload proc private uses esi ebx giEbx

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

Code: [Select]
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.

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

RepString proc uses esi edi ecx Dest, Pattern, Repl

Code: [Select]
ERROR: possibly unpreserved register detected.
  Code block name: ForceTextColP (17710)
  Used registers:  ebx
Code: [Select]
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

Code: [Select]
ERROR: possibly unpreserved register detected.
  Code block name: InsDate (22935)
  Used registers:  esi
Code: [Select]
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

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ObjAsm Tools
« Reply #9 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




jj2007

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: ObjAsm Tools
« Reply #10 on: June 06, 2019, 06:43:15 AM »
code after a "if 0" statement is always evaluated.
No problem at all.

Quote
The 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.

Quote
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?
I will see what I can do.

Quote
What 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".

Quote
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?
No such problems on Win7-64 :thumbsup:

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ObjAsm Tools
« Reply #11 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.

Feedback is welcome.  :cool:

Biterider
« Last Edit: June 09, 2019, 06:41:18 PM by Biterider »

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Experienced assembler testers wanted
« Reply #12 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.

Biterider
« Last Edit: June 16, 2019, 06:40:44 PM by Biterider »

jj2007

  • Member
  • *****
  • Posts: 9792
  • Assembler is fun ;-)
    • MasmBasic
Re: ObjAsm Tools
« Reply #13 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:
Code: [Select]
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:

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: ObjAsm Tools
« Reply #14 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