masm plugin help
i am stuck , and i think i will give up . i spent 3 days trying to make to work . but..............
it's hard to program in language that did not have arithmetic expression.
anyway
i am trying to use 'char right[5100];' as an array of string by calculation the address that
i will write to it or read from it by using this formula
eax = indx
imul eax, 255
edx = @right
eax += edx;
edx = @val
H_strcpy(eax , edx );
but it did not work ,
here is my entire code
//******************************************************//
// //
// //
// Masm plugin //
// By Emil Halim //
// 11/11/2011 //
// //
//******************************************************//
plugins off;
plugins emit;
program WIN32DLL 'Masm PLUGIN';
#include 'zirplug/framework.zir';
#include 'zirutils.zir';
//////////////////////////////
const strLoaded = 'Masm plugin has loaded!';
function H_strcpy(Dword dst,src)
{
Eax = dst;
Edx = src;
push Eax;
BL = [Edx];
while ( BL != 0)
{
[Eax] = BL;
Eax++; Edx++;
BL = [Edx];
}
[Eax] = 0;
pop Eax;
}
function H_strcat(Dword dst,src)
{
Eax = dst;
Edx = src;
push Eax;
while (byte [Eax] != 0) { Eax++; }
while (byte [Edx] != 0)
{
BL = [Edx];
[Eax] = BL;
Edx++; Eax++;
}
[Eax] = 0;
pop Eax;
}
inline procedure H_strjoin(;)
{
$temp = 1;
$to = $argc - 1;
$repeat $to:
H_strcat($arg[0],$arg[$temp]);
$temp++;
$end
}
//////////////////////////////
function event_Data() {
uses edi;
char buf[2048];
char val[255];
char var[255];
char right[5100];
char tmp[255];
dword indx;
boolean Flg = true;
if(Flg)
{
// always start with '{'
eax = Ziron_ExpectNextToken(zirBraceOpen);
if (eax == -1) {
Ziron_FatalError('Expected { symbol');
return true;
}
repeat {
// found '}' so let's finished
eax = Ziron_PeekNextToken();
if (eax == zirBraceClose)
{
Ziron_GetNextToken();
//Ziron_ShowMessage(Ziron_GetStringValue());
break;
}
buf=0;
right=0;
indx = 0;
// get the variable name and hold it in Var
eax = Ziron_ExpectNextToken(zirIdent);
if (eax == -1) {
Ziron_FatalError('Expected Variable Name');
return true;
}
H_strcpy(@var,Ziron_GetStringValue());
// get DB or DW or DD or DQ
eax = Ziron_ExpectNextToken(zirIdent);
if (eax == -1) {
Ziron_FatalError('Expected Variable Name');
return true;
}
strCmp('db',strLower(Ziron_GetStringValue()));
// found DB
if(eax)
{
@digit:
// get whatever after DB
eax = Ziron_GetNextToken();
if(eax == zirQuestionSym)
{
H_strjoin(@buf, 'byte ' , @var, ' = ' , '0;' );
Ziron_Exec(@buf);
continue;
}
case (eax) {
state zirHEXADECIMAL:
H_strcpy(@val,'0x');
H_strcat(@val,Ziron_GetStringValue());
break;
state zirNUMBER:
H_strcpy(@val,Ziron_GetStringValue());
break;
default:
Ziron_FatalError('Expected number');
return true;
} //end case
//pointer addr = @right + indx * 255;
eax = indx
imul eax, 255
edx = @right
eax += edx;
edx = @val
H_strcpy(eax , edx );
// check for ','
eax = Ziron_PeekNextToken();
if (eax == zirCOMMA) {
Ziron_GetNextToken(); // remove ','
indx++;
goto @digit
}
if(indx == 0)
{
buf = 0;
H_strjoin(@buf, 'byte ' , @var, ' = ' , @val , ';' );
Ziron_ShowMessage(@buf);
Ziron_Exec(@buf);
}
else
{
H_strcat(@buf, 'byte ' );
ecx = 0;
while(ecx < indx)
{
push ecx;
IntToStr(ecx,@tmp);
eax = ecx; imul eax,255; edx = @right; eax += Edx;
pointer pt = eax;
H_strjoin(@buf, @var, '[' , @tmp ,']=' , pt , '; ' );
pop ecx ; ecx++;
}
}
Ziron_ShowMessage(@buf);
Ziron_Exec(@buf);
}
};
return true;
}
else
{
return false; // let Ziron handle the line
}
}
procedure FileEntry(DWord handle; char* strCode) {
eax = strOffset(strCode, '.DATA');
while (char[eax] <> 0) {
char[eax] = "_";
eax = strOffset(eax, '.DATA');
}
eax = strOffset(strCode, '.CODE');
while (char[eax] <> 0) {
char[eax] = "_";
eax = strOffset(eax, '.CODE');
}
}
function InitPlugin(pointer pGetF) {
Ziron_LoadAll(pGetF); //use framework utility function to load all
//register our keyword
Ziron_RegisterKeyword('_Data', @event_Data);
return strLoaded;
}
entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
if (iReason == DLL_PROCESS_ATTACH) {
return true;
}
return false;
}
exports InitPlugin, FileEntry;
http://www.freewebs.com/ogremagic/index.htm