From 0f8e5e8e7835df17442f19f65bd84e3298336a65 Mon Sep 17 00:00:00 2001 From: myitinos Date: Fri, 24 Aug 2018 23:30:53 +0800 Subject: [PATCH] v1.0 --- calc | Bin 0 -> 13016 bytes calc.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ calc.sh | 1 + 3 files changed, 105 insertions(+) create mode 100755 calc create mode 100644 calc.c create mode 100755 calc.sh diff --git a/calc b/calc new file mode 100755 index 0000000000000000000000000000000000000000..ec5aa6d9b43019d51b63c4bfec9471b608ac6861 GIT binary patch literal 13016 zcmeHNdvH|M89$pP5D_+!xA@?qF!C^)01^Tg&4z5abb?SMYO8SB>~6@)W_P=L7Xvel zbOMgs7-c%vLEDbbIAiS}w%9sWZAXHkJUae?l~%{vX-c(|h*;E$(JJZhJNJCM_ulM| zcBX%Iax!S7T~5=Dm|uLL!#wMR*c+VWuZ*b5($tU)wSa) z$%1M!!}MuYk3mJ*j##qmQg&U+j_G+-F{a!;Y8yS9l|MIaf{YSV(xtTVT{A-YS(TC< zMOmLI+kFdmRL`%QRG7pjRbHvM98~pZs+ucm;<2{68*1W_>Ub=X?W*poudA-R!JkR` zm&$gNf6`rhORKCB^*4u>>O2h(VI=?Ioj>33?DVBadX4YCbI;b_Jona=;c+Cp3=j94 z@MvPMr>cywDR?L?yy}4~+gn3bD?jStVPXkvzb(kKz6}<~z-V?rEBoaPnN*H zQv!du1m0T$uPK3_0j}Y3CyINq`tL7+YbEeYOW+>@CmVO#3E&zx2tI`8GBHbNnkJ<@ zKQ=48)`fQ{yupPFjJGfiuR0O!ikZSNVwq%kc-D15w5d zg?AX?jvYpOC??TxM<^{aW+avnsdOx1wiA=gnna>$h<0VnXeUg=T_K}A24At=QIUz7 zJKM6Pn+|uTAf-x?_q1trhTv;$%euxj#!~-^eC~#PZmEB{FxG8eZ=ita_89!9H?Ln4 zPbQ+9Lv8UWylwAHCX_eBQZ1^82+>R`!~7}B|IunwCLfYme^A2w@!}DJ=ljf9Y%=LS zr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S&gytk`x?SuIn|4gO7Kmm+v>f<-p zo9+1=Rmm&`U;-UY1Xb;vr1dg+Lle2S#5=XnZLGr zNnKX5%NAO|S9qdxT~Gd8->yvOReTQa#J$4g0b>(*aZbhK)ds_Vd48Na@$rJkvlE{n zxSySPh2Zhw#4iy%4xRW!!Q<75Un+RsI`K(jqv{tYK3P;1=_jx76L{&wwbBNttQRL;+lt~-^XGhaD=)q#@p|IKr{g|^W`|_nD`p6u|8}8QV76<; z^b6<0PJLeO3Mefj<&}ZFI$x&a4PO;KJuBoY!H?ix4Z2@!*_VSM{Xw zC^h5p6p2G8aPrUVI_Xl{g~x-FLtdvPh@XRaiq*eVyB?Q*rigv^!%XF@n4f2)Z0e}~ zdRh7z-CxI*zPp}pNqqG9IVb&$?q4q&Fa>cqrN$vo|%_pO(Onl)zsHPH}LT`&Zx^%5f(;61>I@g5L&wiWt5APsfV{jc2}3z~fMa(`LrZ zwzvDkqHqz!FguMfT?L`rDv_kIJ)Ud}#f=CKWim!6+a+*jlZr=i6ysk}x3aFd65UgY z8KHDKw9AMl%=9kNo(^?J4V-~=?t+PpGoWcYRKqw0LX`}oc~fA0&5>jz$7yKb+cRHvQ^vZgQL)#U%J(2adWn;LP7>fu$ zaUCHXd-@~067XkHGi^zBM$>eh=wJ-U($RQ`3{)-^H-%q@)sL)ydlIY}?ZPijI4C9M zsPacU)D-K8zzK7fsWsOu3(lj2P-iTRI?{_-|pv=?N1-d8Z?eKAyIQtp@)TalwZ zC)@M>gXsdL$@OPFraK^~JuLIQPhr}i?A`TOu-J_Z#gy%NKf{#w)m*;2{ri-CqjJdm z9;SBt8PIXtKM0IsqPFw-{Sohz@P^|^?*7j~YPaWo6w^M3HN8VviRr^&?e@IiV#@Vp zH_S8riOXJ7`v|7LbXAzkWq(h)?0Nsj)U_>zx)=lv?*pVv +#include +#include +#include +#include + +/* + * SIGFPE bisa nempel di CPU, perlu dicari solusi + * Test openssl lewat socat + */ + +void signal_handler(int sig) +{ + signal(SIGFPE, signal_handler); + system("/bin/sh"); + exit(1); +} + +int main(int argc, char const *argv[]) +{ + int i_a = 0; + int i_b = 0; + int total = 0; + + setvbuf(stdin, NULL, _IONBF, 0); + setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stderr, NULL, _IONBF, 0); + + signal(SIGFPE, signal_handler); + + puts("Welcome to Online Calculator v3.1"); + puts(""); + puts("Operator supported: + - * /"); + puts("ex: 2 + 2"); + puts("ex: 2 + a //'a' to use last results"); + puts(""); + puts("------------------------------------"); + + while (1) + { + char c_a[11] = ""; + char c_b[11] = ""; + char opt = 0; + printf(">"); + + if (scanf("%10s %c %10s", c_a, &opt, c_b) < 3) + { + puts("Failed to parse expression!"); + return 0; + } + else + { + int r1_a = sscanf(c_a, "%d", &i_a); + int r2_a = strcmp("a", c_a) == 0; + int r1_b = sscanf(c_b, "%d", &i_b); + int r2_b = strcmp("a", c_b) == 0; + + if ((i_b == 0 && r2_a) && opt == '/') + { + puts("Floating point exception (core dumped)"); + return 0; + } + + if (r2_a) + { + i_a = total; + } + + if (r2_b) + { + i_b = total; + } + + if ((r1_a || r2_a) && (r1_b || r2_b)) + { + switch (opt) + { + case '+': + total = i_a + i_b; + break; + case '-': + total = i_a - i_b; + break; + case '*': + total = i_a * i_b; + break; + case '/': + total = i_a / i_b; + break; + default: + puts("Unknown operator!"); + return 0; + } + printf("=%d\n", total); + } + else + { + puts("Failed to parse operand!"); + return 0; + } + } + } + return 0; +} diff --git a/calc.sh b/calc.sh new file mode 100755 index 0000000..c454252 --- /dev/null +++ b/calc.sh @@ -0,0 +1 @@ +socat TCP-listen:8080,reuseaddr,fork EXEC:./calc